This page was generated from nldas.ipynb. Interactive online version: Binder badge

NLDAS2 Forcing#

[1]:
from pathlib import Path

import pynldas2 as nldas

from pygeohydro import WBD

The NLDAS2 database provides forcing data at 1/8th-degree grid spacing and range from 01 Jan 1979 to present. Let’s take a look at NLDAS2 grid mask that includes land, water, soil, and vegetation masks:

[2]:
grid = nldas.get_grid_mask()
grid
[2]:
<xarray.Dataset>
Dimensions:      (lon: 464, lat: 224, time: 1, bnds: 2)
Coordinates:
  * lon          (lon) float32 -124.9 -124.8 -124.7 ... -67.31 -67.19 -67.06
  * lat          (lat) float32 25.06 25.19 25.31 25.44 ... 52.69 52.81 52.94
  * time         (time) datetime64[ns] 2000-01-01
    spatial_ref  int64 0
Dimensions without coordinates: bnds
Data variables:
    time_bnds    (time, bnds) datetime64[ns] ...
    NLDAS_mask   (time, lat, lon) float32 ...
    CONUS_mask   (time, lat, lon) float32 ...
    NLDAS_veg    (time, lat, lon) float32 ...
    NLDAS_soil   (time, lat, lon) float32 ...
Attributes: (12/13)
    missing_value:          -9999.0
    time_definition:        constant
    title:                  NLDAS masks and predominant vegetation/soil
    institution:            NASA GSFC
    history:                created on date: Fri Mar  8 15:58:50 2019
    references:             Mitchell_etal_JGR_2004; Xia_etal_JGR_2012
    ...                     ...
    website:                https://ldas.gsfc.nasa.gov/nldas/
    MAP_PROJECTION:         EQUIDISTANT CYLINDRICAL
    SOUTH_WEST_CORNER_LAT:  25.0625
    SOUTH_WEST_CORNER_LON:  -124.9375
    DX:                     0.125
    DY:                     0.125

For example, let’s plot the vegetation mask.

[3]:
ax = grid.NLDAS_veg.plot()
ax.figure.savefig(Path("_static", "nldas_grid.png"), facecolor="w", bbox_inches="tight")
../../_images/examples_notebooks_nldas_5_0.png

Next, we use PyGeoHydro to get the geometry of a HUC8 with ID of 1306003:

[4]:
huc8 = WBD("huc8")
geometry = huc8.byids("huc8", "13060003").geometry[0]

PyNLDAS2 allows us to get the data for a list of coordinates using pynldas2.get_bycoords or for a region as gridded data using pynldas2.get_bygeom. Here, we use the latter. Note that if we don’t pass any variables, all variables will be downloaded.

[5]:
clm = nldas.get_bygeom(geometry, "2010-01-01", "2010-01-31", 4326)
[6]:
clm
[6]:
<xarray.Dataset>
Dimensions:      (time: 744, y: 11, x: 15)
Coordinates:
  * time         (time) datetime64[ns] 2010-01-01 ... 2010-01-31T23:00:00
  * y            (y) float64 33.56 33.69 33.81 33.94 ... 34.44 34.56 34.69 34.81
  * x            (x) float64 -105.6 -105.4 -105.3 ... -104.1 -103.9 -103.8
    spatial_ref  int64 0
Data variables:
    prcp         (time, y, x) float64 nan nan nan nan nan ... 0.0 0.0 nan nan
    pet          (time, y, x) float64 nan nan nan nan ... 0.0143 0.0145 nan nan
    temp         (time, y, x) float64 nan nan nan nan ... 275.6 275.1 nan nan
    wind_u       (time, y, x) float64 nan nan nan nan nan ... 0.69 0.79 nan nan
    wind_v       (time, y, x) float64 nan nan nan nan nan ... 4.03 4.15 nan nan
    rlds         (time, y, x) float64 nan nan nan nan ... 241.8 239.1 nan nan
    rsds         (time, y, x) float64 nan nan nan nan ... 208.7 208.5 nan nan
    humidity     (time, y, x) float64 nan nan nan nan ... 0.004118 nan nan
Attributes:
    tz:       UTC
[7]:
ax = clm.humidity.isel(time=slice(10, 16)).plot(col="time", col_wrap=3)
ax.fig.savefig(Path("_static", "nldas_humidity.png"), facecolor="w", bbox_inches="tight")
../../_images/examples_notebooks_nldas_11_0.png