2.5. floodestimation.loaders — Loading catchment data quickly

This module contains some convenience functions for quickly loading catchments (incl. annual maximum flow data) from CD3-files and to download all gauged catchments and save into a sqlite database.

floodestimation.loaders.from_file(file_path, incl_pot=True)[source]

Load catchment object from a .CD3 or .xml file.

If there is also a corresponding .AM file (annual maximum flow data) or a .PT file (peaks over threshold data) in the same folder as the CD3 file, these datasets will also be loaded.

Parameters:
  • file_path (str) – Location of CD3 or xml file
  • incl_pot (bool) – Whether to load the POT (peaks-over-threshold) data. Default: True.
Returns:

Catchment object with the amax_records and pot_dataset attributes set (if data available).

Return type:

entities.Catchment

floodestimation.loaders.to_db(catchment, session, method='create', autocommit=False)[source]

Load catchment object into the database.

A catchment/station number (catchment.id) must be provided. If method is set to update, any existing catchment in the database with the same catchment number will be updated.

Parameters:
  • catchment (entities.Catchment) – New catchment object to replace any existing catchment in the database
  • session (sqlalchemy.orm.session.Session) – Database session to use, typically floodestimation.db.Session()
  • method (str) –
    • create: only new catchments will be loaded, it must not already exist in the database.
    • update: any existing catchment in the database will be updated. Otherwise it will be created.
  • autocommit (bool) – Whether to commit the database session immediately. Default: False.
floodestimation.loaders.folder_to_db(path, session, method='create', autocommit=False, incl_pot=True)[source]

Import an entire folder (incl. sub-folders) into the database

Parameters:
  • path (str) – Folder location
  • session (sqlalchemy.orm.session.Session) – database session to use, typically floodestimation.db.Session()
  • method (str) –
    • create: only new catchments will be loaded, it must not already exist in the database.
    • update: any existing catchment in the database will be updated. Otherwise it will be created.
  • autocommit (bool) – Whether to commit the database session immediately. Default: False.
  • incl_pot (bool) – Whether to load the POT (peaks-over-threshold) data. Default: True.
floodestimation.loaders.nrfa_to_db(session, method='create', autocommit=False, incl_pot=True)[source]

Retrieves all gauged catchments (incl. catchment descriptors and annual maximum flow data) from the National River Flow Archive and saves it to a (sqlite) database.

Parameters:
  • session (sqlalchemy.orm.session.Session) – database session to use, typically floodestimation.db.Session()
  • method (str) –
    • create: only new catchments will be loaded, it must not already exist in the database.
    • update: any existing catchment in the database will be updated. Otherwise it will be created.
  • autocommit (bool) – Whether to commit the database session immediately. Default: False.
  • incl_pot (bool) – Whether to load the POT (peaks-over-threshold) data. Default: True.
floodestimation.loaders.userdata_to_db(session, method='update', autocommit=False)[source]

Add catchments from a user folder to the database.

The user folder is specified in the config.ini file like this:

[import]
folder = path/to/import/folder

If this configuration key does not exist this will be silently ignored.

Parameters:
  • session (sqlalchemy.orm.session.Session) – database session to use, typically floodestimation.db.Session()
  • method (str) –
    • create: only new catchments will be loaded, it must not already exist in the database.
    • update: any existing catchment in the database will be updated. Otherwise it will be created.
  • autocommit (bool) – Whether to commit the database session immediately. Default: False.