floodsimilarity

Configuartion

The configuration for the required data sources must be provided as a json file: The following schema describes the required structure ./floodsimilarity/json/config_schema.json

An example json file used during testing looks like that:

{
    "hydro": {
        "service": {
            "url": "http://vmhydro29-dmz.gfz-potsdam.de/api/"
        }
    },
    "raster": {
        "service": {
            "precipitation": {
                "url": "https://data.awi.de/rasdaman/ows/",
                "version": "2.0.1",
                "rename_rules": {
                    "lat": "Lat", 
                    "lon": "Long",
                    "date": "ansi",
                    "precipitation": "precipitation"
                },
                "sfactor": 0.1,
                "data_id": "DWD_Precipitation"
            },
            "soilmoisture": {
                "url": "https://data.awi.de/rasdaman/ows/",
                "version": "2.0.1", 
                "rename_rules": {
                    "lat": "Lat", 
                    "lon": "Lon",
                    "date": "ansi",
                    "soilmoisture": "soilmoisture"
                },
                "sfactor": 1,
                "data_id": "UFZ-Soilmoisture"
            }
        }
    }
}

The file must be named config.json and exist in the current working directory. Check out the listed schema file above to see how data files are used in the configuration.

For the given example, the service under hydro requires credentials. Their are currently two options to provide them:

  1. Provide the environment variables APACHE_USER and APACHE_PASS during runtime.

  2. Provide a file .env in the working directory with the following content.

APACHE_USER=user_name
APACHE_PASS=user_pass

Usage

floodsimilarity.floodsimilarity.get_processing_options()[source]

Function that returns metadata about computed flood characteristics and the methods used to compute them.

Returns

poptions – A dictionary containing the information about possible processing options.

Return type

dict

Examples

>>> from floodsimilarity.floodsimilarity import get_processing_options

The keys of the return value lists the indicators that are available.

>>> poptions = get_processing_options()
>>> poptions.keys()
dict_keys(['api', 'ep_max', 'ep_vol', 'ed', 'epfp', 'esfp', 'eprp', 'sm'])

Lets assume we need the method to compute the indicator antecedent precipitation index (api). The method name for the given in indicator is given in the [method][name] key.

>>> poptions['api']['method']['name']
'compute_event_api'
floodsimilarity.floodsimilarity.process_event_extraction(event_dict, config_file='./config.json')[source]

Extract flood events based on direct runoff for a given gauging station and time period.

Parameters

event_dict (dict) – Dictionary with the keys (‘gid’, ‘start_date’, ‘end_date’).

Returns

event_dict

Return type

floodsimilarity.event_extraction.EventExtraction

Examples

>>> from floodsimilarity.floodsimilarity import process_event_extraction

Lets define the event were are interested in.

>>> event = {
...    'gid': 460,
...    'start_date': '2008-01-01T00:00:00.00Z',
...    'end_date': '2011-12-31T00:00:00.00Z',
... }

Call the function.

>>> ee_object = process_event_extraction(event)
>>> type(ee_object)
<class 'floodsimilarity.event_extraction.EventExtraction'>

The results a given in the results attribute, a dictionary with additional meta-data. For the given example, we have 12 events detected-so we have 12 entries where each represent a single event in the ts_json format.

>>> len(ee_object.results['events']['data']['events']['value'])
12
floodsimilarity.floodsimilarity.process_request(fe_request, parallel=True, config_file='./config.json')[source]

Extract flood events properties for a given gauging station and time period.

Parameters
  • fe_request (list) – A list of dictionaries (keys ‘gid’, ‘event_start’, ‘event_end’, ‘function_list’)

  • parallel (bool, optional) – Processing the list of requests in parallel {default: True}.

Returns

response_list – Same number of items as provided by the fe_request. Each item is of class floodsimilarity.event_container.EventContainer

Return type

list

Examples

>>> from floodsimilarity.floodsimilarity import process_request
>>> fl = [
...        {
...            'name': 'get_event_peak_properties'
...        },
...        {
...            'name': 'compute_event_api',
...            'params': {
...                         'days': 10,
...                         'k': 0.95
...                      }
...        }
... ]

The request from the front-end (fe).

>>> fe_request = [
...     {
...         'gid': 383,
...         'event_start': '2013-05-31T00:00:00.00Z',
...         'event_end': '2013-06-10T00:00:00.00Z',
...         'function_list': fl
...     }
... ]

Call the function. >>> ec_object_list = process_request(fe_request, parallel=False) >>> type(ec_object_list) <class ‘list’> >>> type(ec_object_list[0]) <class ‘floodsimilarity.event_container.EventContainer’>

>>> ec_object_list[0].results['epfp']['data']['epf']['value']
275.0