gdptools CONUS404 Spatial Aggregation over DRB-extent HUC12s#
This tutorial demonstrates the use of gdptools, a python package for area-weighted interpolation of source gridded datasets, such as conus404, to target polygonal geospatial fabrics. Source datasets can be any gridded dataset that can be opened in XArray. However it’s important to note that gdptools, operations on XArray Datasets or DataArrays with dimensions of (Y,X,Time) generally. As such climate datasets that have ensemble dimensions will require subsetting by ensemble to obtain the a dataset with the proper dimensions. The target dataset can be any polygonal dataset that can be read by GeoPandas. GDPtools also has capabilities of interpolating gridded data to lines as well, but our focus here is interpolating to polygons.
In this workflow, CONUS404 is aggregated to Deleware River Basin (DRB) HUC12s. The spatial polygons used in this notebook come from the NHDPlusV2 snapshot of the Watershed Boundary Dataset HUC12 boundaries provided through the PyGeoHydro python package.
We use the HyTest intake catalog to access CONUS404 from the OSN pod. This notebook provides a relatively simple and efficient workflow that can be easily run on a local computer.
# Common python packages
import xarray as xr
import hvplot.xarray
import hvplot.pandas
import hvplot.dask
import intake
import warnings
import intake_xarray
import datetime
import holoviews as hv
import geoviews as gv
from holoviews import opts
import cartopy.crs as ccrs
import panel as pn
import numpy as np
import pandas as pd
import geopandas as gpd
# HyRiver packages
from pynhd import NLDI, WaterData
import pygeohydro as gh
# GDPTools packages
from gdptools import AggGen, UserCatData, WeightGen
import os
# Until gdptools updates it's numpy dependency to v2, the environment statement below is required
os.environ["HYRIVER_CACHE_DISABLE"] = "true"
hv.extension("bokeh")
pn.extension()
warnings.filterwarnings('ignore')
Here we setup a variable the sets our local context, working on the HPC or working locally on your Desktop. This just modifies the access point of the conus404 data, using the Hovenweep access for HPC and the OSN pod access for the Desktop.
t_sys = "Desktop" # "HPC" # or "Desktop"
We can use a subset of the HyRiver Python packages to access HUC12 geometries representing the Delaware River Basin. The process involves several steps:
Select the HUC4 Mid-Atlantic Region:
This region encompasses the Delaware River Basin (HUC4 code: 0204).
Retrieve HUC12 Basins within the Selected HUC4:
Obtain all HUC12 basins that fall within the HUC4 Mid-Atlantic region.
Filter HUC12 Basins:
Focus on the HUC12 basins within the two HUC6 regions whose drainages terminate in the Delaware River Basin (DRB).
Exclude basins with drainages that terminate at the coast.
We used Science in Your Watershed to help identify the HUC6 regions that drain directly into the DRB.
wbd = gh.WBD("huc4")
del_huc4 = wbd.byids(field="huc4", fids="0204")
huc12_basins = WaterData('wbd12').bygeom(del_huc4.geometry[0])
filtered_gdf = huc12_basins[huc12_basins['huc12'].str.startswith(('020401', '020402'))]
filtered_gdf
geometry | tnmid | metasourceid | sourcedatadesc | sourceoriginator | sourcefeatureid | loaddate | gnis_id | areaacres | areasqkm | states | huc12 | name | hutype | humod | tohuc | noncontributingareaacres | noncontributingareasqkm | globalid | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | MULTIPOLYGON (((-75.02421 39.44397, -75.02353 ... | {001055CD-7B5E-4F96-ABB1-22923FD2B454} | None | None | None | None | 2013-01-18T07:08:41Z | None | 16178.10 | 65.47 | NJ | 020402060505 | White Marsh Run-Maurice River | S | NM | 020402060507 | 0 | 0 | {A70A97FA-E29C-11E2-8094-0021280458E6} |
1 | MULTIPOLYGON (((-74.62113 41.00565, -74.62139 ... | {009DA440-393A-46A0-BBA3-C38139823414} | {ED602145-9201-4827-9CE1-05D252484579} | None | None | None | 2017-10-03T20:11:06Z | None | 29107.93 | 117.80 | NJ | 020401050502 | Lubbers Run-Musconetcong River | S | NM | 020401050503 | 0 | 0 | {B830B4F8-E29C-11E2-8094-0021280458E6} |
2 | MULTIPOLYGON (((-75.75805 40.65996, -75.75783 ... | {00F73634-FA00-464F-93F0-F0BCCB464567} | {ED602145-9201-4827-9CE1-05D252484579} | None | None | None | 2017-10-03T20:10:58Z | None | 35229.84 | 142.57 | PA | 020402030305 | Upper Maiden Creek | S | NM | 020402030307 | 0 | 0 | {BAF5E77A-E29C-11E2-8094-0021280458E6} |
3 | MULTIPOLYGON (((-75.13279 39.88601, -75.13439 ... | {017B8A58-E959-4600-B212-8EB921F0F9F7} | {E9F5C988-2313-440E-A05E-C5871E2773A6} | None | None | None | 2017-10-03T20:11:04Z | None | 24920.90 | 100.85 | NJ,PA | 020402020507 | Woodbury Creek-Delaware River | S | TF | 020402020607 | 0 | 0 | {B122D6B7-E29C-11E2-8094-0021280458E6} |
4 | MULTIPOLYGON (((-74.92817 40.55256, -74.92833 ... | {01B4598B-0623-407F-9133-3040D99A8D1A} | {ED602145-9201-4827-9CE1-05D252484579} | None | None | None | 2017-10-03T20:10:52Z | None | 15086.80 | 61.05 | NJ | 020401050905 | Lockatong Creek | S | NM | 020401050908 | 0 | 0 | {A6AB04BE-E29C-11E2-8094-0021280458E6} |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
656 | MULTIPOLYGON (((-75.12376 40.12389, -75.12455 ... | {FE1811B2-B495-4065-8624-913739AF724E} | {ED602145-9201-4827-9CE1-05D252484579} | None | None | None | 2017-10-03T20:11:07Z | None | 23146.21 | 93.67 | PA | 020402030902 | Lower Wissahickon Creek | S | NM | 020402031007 | 0 | 0 | {BB87766E-E29C-11E2-8094-0021280458E6} |
659 | MULTIPOLYGON (((-75.75805 40.65996, -75.75893 ... | {FF44E71D-0E10-4CEF-ACB5-A148FCC1D201} | None | None | None | None | 2013-01-18T07:08:53Z | None | 18124.40 | 73.35 | PA | 020402030301 | Ontelaunee Creek | S | NM | 020402030305 | 0 | 0 | {BAD53EAD-E29C-11E2-8094-0021280458E6} |
660 | MULTIPOLYGON (((-75.19691 40.5796, -75.19719 4... | {FF630558-25A7-462F-9E12-F4166478902C} | {ED602145-9201-4827-9CE1-05D252484579} | None | None | None | 2017-10-03T20:10:58Z | None | 18929.21 | 76.60 | PA | 020401050604 | Cooks Creek | S | NM | 020401050605 | 0 | 0 | {BA28799D-E29C-11E2-8094-0021280458E6} |
661 | MULTIPOLYGON (((-75.53503 39.11019, -75.53441 ... | {FF6AB0DD-4B75-40D8-81D9-7AC2F0ACE65E} | None | None | None | None | 2013-01-18T07:08:10Z | None | 6290.20 | 25.46 | DE | 020402070303 | Tidbury Creek | S | NM | 020402070304 | 0 | 0 | {963110E8-E29C-11E2-8094-0021280458E6} |
662 | MULTIPOLYGON (((-74.85144 41.01532, -74.8516 4... | {FF9C7C31-4BE0-426E-9CEA-FC14A0F526C7} | {ED602145-9201-4827-9CE1-05D252484579} | None | None | None | 2017-10-03T20:10:56Z | None | 21760.30 | 88.06 | NJ | 020401050103 | Middle Paulins Kill | S | NM | 020401050104 | 0 | 0 | {B82FC756-E29C-11E2-8094-0021280458E6} |
427 rows × 19 columns
from holoviews.element.tiles import OSM
drb = filtered_gdf.hvplot(
geo=True, coastline='50m', alpha=0.2, frame_width=300,
xlabel="longitude", ylabel="latitude",
title="Delaware River HUC12 basins", aspect='equal'
)
OSM() * drb