[1]:
import earthkit.hydro as ekh
Loading/creating river networks¶
This notebooks goes through all of the different options for loading a river network.
There are two methods
ekh.river_network.load(recommended)ekh.river_network.create(advanced use only)
Loading river networks¶
A chosen network can then be loaded easily using river_network.load. For example, loading the EFAS v5 network is done with
[3]:
network = ekh.river_network.load("efas", "5")
River network not found in cache (/var/folders/td/yqnxcqpx39dc855vwjtv5hj40000gn/T/tmp75g6_e5n_earthkit_hydro/0.2_c3b54d239de177b0e6b8abf8b506b79bc227f3d173ad1e346c9cc89471cad1e0.joblib).
River network loaded, saving to cache (/var/folders/td/yqnxcqpx39dc855vwjtv5hj40000gn/T/tmp75g6_e5n_earthkit_hydro/0.2_c3b54d239de177b0e6b8abf8b506b79bc227f3d173ad1e346c9cc89471cad1e0.joblib).
Creating river networks¶
Obviously not all river networks will be available. In advanced cases therefore, users may need to create their own river network with river_network.create.
Many river network formats are supported, as are many filetypes and data sources. As an example, we can load a local netCDF file using the PCRaster river network format via
[4]:
network = ekh.river_network.create("local_pcraster_efas_network_file.nc", "pcr_d8", "file")
River network not found in cache (/var/folders/td/yqnxcqpx39dc855vwjtv5hj40000gn/T/tmp75g6_e5n_earthkit_hydro/0.2_d49eb4193bdab4aa653eac88fc0d9dea6c7ecbe5ae64cf639230e2c2fdf612e4.joblib).
River network loaded, saving to cache (/var/folders/td/yqnxcqpx39dc855vwjtv5hj40000gn/T/tmp75g6_e5n_earthkit_hydro/0.2_d49eb4193bdab4aa653eac88fc0d9dea6c7ecbe5ae64cf639230e2c2fdf612e4.joblib).
This creation step can be expensive, particularly for large network since it involves finding the topological ordering of the graph. Therefore, if the network will be reused for further analyses, it is recommended to save it explicitly somewhere.
[5]:
network.export("my_river_network.joblib")
The saved network can then be cheaply reloaded in later analyses via
[6]:
network = ekh.river_network.create("my_river_network.joblib", "precomputed", "file")
River network not found in cache (/var/folders/td/yqnxcqpx39dc855vwjtv5hj40000gn/T/tmp75g6_e5n_earthkit_hydro/0.2_cd239cb18e6e841065a4fed044c6ac667853b385ef8406da2c1cf86471f003a8.joblib).
River network loaded, saving to cache (/var/folders/td/yqnxcqpx39dc855vwjtv5hj40000gn/T/tmp75g6_e5n_earthkit_hydro/0.2_cd239cb18e6e841065a4fed044c6ac667853b385ef8406da2c1cf86471f003a8.joblib).
Caching¶
Networks are automatically cached to temporary storage for faster reloading within the same script. This temporary storage is however still only temporary, which is why exporting and saving explicitly is required if one wants to ensure the availability of the precomputed network.
The cache can however be modified. To disable it, the use_cache=False flag can be passed
[7]:
network = ekh.river_network.load("efas", "5", use_cache=False)
Cache disabled.
The cache can also be set to a non-temporary storage location, in which case it becomes permanent.
[8]:
network = ekh.river_network.load("efas", "5", cache_dir=".")
River network not found in cache (./0.2_c3b54d239de177b0e6b8abf8b506b79bc227f3d173ad1e346c9cc89471cad1e0.joblib).
River network loaded, saving to cache (./0.2_c3b54d239de177b0e6b8abf8b506b79bc227f3d173ad1e346c9cc89471cad1e0.joblib).
For further customisation options, view the API reference.