Downloading data
This notebooks demonstrates how to download data needed by rabpro to delineate watersheds and create a flowline elevation profile.
There are two methods available for delineating watersheds:
HydroBasins: easier as all the data can be downloaded in one simple call, but the smallest basins are ~230 km^2. Also faster delineations. Useful for large basins.
MERIT-Hydro: MERIT-Hydro data is provided as 30 degree by 30 degree tiled chunks. See http://hydro.iis.u-tokyo.ac.jp/~yamadai/MERIT_Hydro/. You must ensure that you download sufficient area to fully cover your target watershed. you must identify the tile(s) needed to download. You must also register at the above site to receive the username and password for downloads. rabpro uses four of the layers provided by MERIT-Hydro: flow directions, adjusted elevations, upstream drainage area, and river width.
Download HydroBasins
[4]:
from rabpro import data_utils
data_utils.download_hydrobasins()
# If you are behind a proxy, you can provide the proxy argument, e.g.
# data_utils.download_hydrobasins(proxy='proxy_address:port')
Downloading HydroBasins zip file (562 MB)...
Unzipping HydroBasins zip file...
Done.
If the download fails, ensure you’re not behind a proxy. If so, provide the proxy as a keyword argument. If not, often simply retrying the download will work. You may also manually download HydroBasins here. You will need to place it in the correct directory, which you can find with the following code:
[11]:
# Where will rabpro look for the HydroBasins data?
from rabpro import utils
print(utils.get_datapaths()['HydroBasins_root'])
One or more MERIT layers have no data. Use rabro.data_utils.download_merit_hydro() to fetch a MERIT tile.
C:\Users\318596\AppData\Local\rabpro\rabpro\HydroBasins
Within the HydroBasins directory, there should be two subdirectores: level_one and level_twelve.
Downloading MERIT tiles
For demonstration purposes, we will download a fairly sparse MERIT tile that has a relatively small filesize. Let’s say that our watershed falls in the ‘s30e150’ tile. Additionally, the username and password are hidden here–you must first request access at the MERIT-Hydro page.
[4]:
from rabpro import data_utils
merit_tile = 's30e150'
username = hidden
password = hidden
data_utils.download_merit_hydro(merit_tile, username, password) # Can also add proxy argument.
Downloading 'http://hydro.iis.u-tokyo.ac.jp/~yamadai/MERIT_Hydro/distribute/v1.0/dir_s30e150.tar' into 'C:\Users\318596\AppData\Local\rabpro\rabpro\MERIT_Hydro\MERIT_FDR\dir_s30e150.tar'
100%|█████████████████████████████████████████████████████████████████████████████| 23.9M/23.9M [00:07<00:00, 3.26MB/s]
Downloading 'http://hydro.iis.u-tokyo.ac.jp/~yamadai/MERIT_Hydro/distribute/v1.0/elv_s30e150.tar' into 'C:\Users\318596\AppData\Local\rabpro\rabpro\MERIT_Hydro\MERIT_ELEV_HP\elv_s30e150.tar'
100%|███████████████████████████████████████████████████████████████████████████████| 169M/169M [00:29<00:00, 5.76MB/s]
Downloading 'http://hydro.iis.u-tokyo.ac.jp/~yamadai/MERIT_Hydro/distribute/v1.0/upa_s30e150.tar' into 'C:\Users\318596\AppData\Local\rabpro\rabpro\MERIT_Hydro\MERIT_UDA\upa_s30e150.tar'
100%|███████████████████████████████████████████████████████████████████████████████| 112M/112M [00:18<00:00, 6.13MB/s]
Downloading 'http://hydro.iis.u-tokyo.ac.jp/~yamadai/MERIT_Hydro/distribute/v1.0/wth_s30e150.tar' into 'C:\Users\318596\AppData\Local\rabpro\rabpro\MERIT_Hydro\MERIT_WTH\wth_s30e150.tar'
100%|█████████████████████████████████████████████████████████████████████████████| 15.3M/15.3M [00:05<00:00, 2.67MB/s]
rabpro automatically unzips and stores the MERIT-Hydro tiles in the proper locations.
MERIT-Hydro tiles are collections of 5x5 degree geotiffs. rabpro “stitches” these geotiffs together in virtual rasters. Each time you call download_merit_hydro()
, rabpro will automatically rebuild the virtual rasters to ensure that the new geotiffs are available. We can check that these virtual rasters have been built.
[1]:
# We can check that the virtual rasters were built
from rabpro import utils
import os
datapaths = utils.get_datapaths()
if os.path.isfile(datapaths['DEM_fdr']) is True:
print('Flow directions virtual raster was built.')
if os.path.isfile(datapaths['DEM_uda']) is True:
print('Drainage area virtual raster was built.')
if os.path.isfile(datapaths['DEM_elev_hp']) is True:
print('Elevations virtual raster was built.')
if os.path.isfile(datapaths['DEM_width']) is True:
print('Width virtual raster was built.')
Flow directions virtual raster was built.
Drainage area virtual raster was built.
Elevations virtual raster was built.
Width virtual raster was built.