Earthkit-hydro: Getting Started¶
This notebook will show a simple demo of loading or creating a river network and how to look at some basic information about it.
import earthkit.hydro as ekhTo load a precomputed river network, ekh.river_network.load is used. For a full list of support networks, see here. As an example, we load the EFAS version 5 network.
network = ekh.river_network.load("efas", "5")River network not found in cache (/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp6w9z3pux_earthkit_hydro/1.2_0dc8123bbf944ff1cb86f41bc7506e891baaa990666d836fc0cf2edd503916db.joblib).
River network loaded, saving to cache (/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp6w9z3pux_earthkit_hydro/1.2_0dc8123bbf944ff1cb86f41bc7506e891baaa990666d836fc0cf2edd503916db.joblib).
The returned RiverNetwork repesents the connectivities between gridcells required for operations on the river network. Computationally, it is a directed acyclic graph. The size of the graph can be found by printing the network.
print(network)RiverNetwork with 7446075 nodes and 7353055 edges.
The river network lives on a computational grid. The coordinates can be found in network.coords.
print(network.coords){'lat': array([72.24166667, 72.225 , 72.20833333, ..., 22.79166667,
22.775 , 22.75833333], shape=(2970,)), 'lon': array([-25.24166667, -25.225 , -25.20833333, ..., 50.20833333,
50.225 , 50.24166667], shape=(4530,))}
Not all river networks are precomputed and available via ekh.river_network.load. For using other custom networks, the ekh.river_network.create method is used. This method supports loading data from many sources such as file, url, etc. and in PCRaster, CaMa-Flood, HydroSHEDS, MERIT-Hydro and GRIT river network formats.
As an example, we should how to recreate the hydrosheds network at 6 arcmin resolution.
network = ekh.river_network.create("https://data.hydrosheds.org/file/hydrosheds-v1-dir/hyd_glo_dir_6m.zip", "esri_d8", source="url")River network not found in cache (/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp6w9z3pux_earthkit_hydro/1.2_62771f2eab3eebdb9ec7874f5254d81debeeac5ce887325191305554e65affe1.joblib).
Unknown file type, no reader available. path=/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp35wmx4j6/url-49f06f29f0428e9e9db5949c07757622edeb9ee690d2b8d47111d7a603b9e050.d/HydroSHEDS_TechDoc_v1_4.pdf magic=b'%PDF-1.6\r%\xe2\xe3\xcf\xd3\r\n1543 0 obj\r<</Linearized 1/L 475736/O 1545/E 142' content_type=None
River network loaded, saving to cache (/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp6w9z3pux_earthkit_hydro/1.2_62771f2eab3eebdb9ec7874f5254d81debeeac5ce887325191305554e65affe1.joblib).
To save the precomputed network, it can simply be exported locally and then easily reloaded.
network.export("my_network.joblib")network = ekh.river_network.create("my_network.joblib", "precomputed")River network not found in cache (/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp6w9z3pux_earthkit_hydro/1.2_c38294f78ab838bd5e9ab139780e453377b69f3a44e867d397486b451c88b7da.joblib).
River network loaded, saving to cache (/etc/ecmwf/ssd/ssd1/jupyterhub/macw-jupyterhub/tmpdirs/macw.39412013/tmp6w9z3pux_earthkit_hydro/1.2_c38294f78ab838bd5e9ab139780e453377b69f3a44e867d397486b451c88b7da.joblib).