hrain is a small application that produces reports about precipitation events at an area where there are some rainfall measuring stations. You can see it in action at http://hoa.ntua.gr/ (choose “Rainfall events”). It automatically searches the time series to find rainfall events, which it displays in an index resembling a tag cloud (we call this the “event cloud”), and also displays a short report about each event.
To install hrain:
In settings.py, add enhydris.hrain to INSTALLED_APPS, and also specify the configuration variables presented in the next section.
Add the following to urls.py:
urlpatterns += patterns('', ('^rain/', include('enhydris.hrain.urls')))The above will result in the URL of your hrain installation being “rain/”, but you can choose something else if you prefer.
Run python manage.py syncdb to create the database tables for hrain. Note that hrain does not use South for migrations, because its database tables only store information that can be re-created, and therefore you can safely delete them and recreate them.
Run python manage.py hrain_refresh_events. This command will retrieve the time series from the database, analyze them, and cache the necessary information in the database tables. Any information already existing in the database tables is removed before this, as are any cached charts. You probably want to setup this command to run periodically, e.g. once a day.
A tuple of pairs. Let’s look at an example from http://hoa.ntua.gr/:
HRAIN_TIMESERIES = (( 14, 7), # Agios Kosmas
(793, 8), # Anw liosia
(378, 7), # Galatsi
(296, 7), # Hlioupoli
(453, 10), # Mandra
( 1, 10), # Menidi
(645, 12), # Pendeli
(718, 12), # Pikermi
( 27, 17), # Psyttalia
(586, 10), # Zografou
)
The first number of each pair is the time series id, and the second is a weight for calculating the surface precipitation of each event. The weights do not need to add up to 1 or 100; the result is divided by their sum.
These variables are parameters that define how the rainfall event identification algorithm works. The first two of these variables are floats; the next two are integers; and the last one is a datetime.timedelta. For an explanation of their meaning, see ts_identify_events(). Example from http://hoa.ntua.gr/:
from datetime import timedelta
HRAIN_START_THRESHOLD = 0.39
HRAIN_NTIMESERIES_START_THRESHOLD = 2
HRAIN_END_THRESHOLD = 0.19
HRAIN_NTIMESERIES_END_THRESHOLD = 1
HRAIN_TIME_SEPARATOR = timedelta(hours=2)
hrain generates some charts (on demand) and stores them in a directory. HRAIN_STATIC_CACHE_PATH defines the directory, and HRAIN_STATIC_CACHE_URL defines how to access the contents of this directory from the web. Example from http://hoa.ntua.gr/:
import os
HRAIN_STATIC_CACHE_PATH = os.path.join(MEDIA_ROOT, 'cache')
HRAIN_STATIC_CACHE_URL = MEDIA_URL + '/cache/'
These variables define the co-ordinates of the rain contour map. The first variable is a tuple of four elements, which are x0, y0, x1, and y1; that is, the co-ordinates of the lower left and the upper right corner. The second variable is the SRID in which these co-ordinates are given. Example from http://hoa.ntua.gr/:
HRAIN_CONTOUR_SRID = 2100
HRAIN_CONTOUR_CHART_BOUNDS = (455000, 4192000, 500000, 4220000)
These variables define the appearance of the event cloud. The first is a pair of font sizes, lowest and largest, and the second is an increment. The event cloud will be automatically adjusted so that the largest event receives the largest font size, the smallest event receives the smallest font size, and all other events are uniformly scaled in between but rounded so that they are in the specified increment. The “size’ of the event refers to its total surface precipitation. Example from http://hoa.ntua.gr/:
HRAIN_EVENT_CLOUD_FONTSIZE_RANGE = 8, 20
HRAIN_EVENT_CLOUD_FONTSIZE_INCREMENT = 3