import requests
import folium
import folium.plugins
from pystac.client import Client
Comparing NLDAS-2 and NLDAS-3 Precipitation Forcing Data
Run this notebook
You can launch this notebook in VEDA JupyterHub by clicking the link below.
Launch in VEDA JupyterHub (requires access)
Learn more
Inside the Hub
This notebook was written on the VEDA JupyterHub and as such is designed to be run on a jupyterhub which is associated with an AWS IAM role which has been granted permissions to the VEDA data store via its bucket policy. The instance used provided 16GB of RAM.
See (VEDA Analytics JupyterHub Access)[https://nasa-impact.github.io/veda-docs/veda-jh-access.html] for information about how to gain access.
Outside the Hub
The data is in a protected bucket. Please request access by emailng aimee@developmentseed.org or alexandra@developmentseed.org and providing your affiliation, interest in or expected use of the dataset and an AWS IAM role or user Amazon Resource Name (ARN). The team will help you configure the cognito client.
You should then run:
%run -i 'cognito_login.py'
About the Data
NLDAS is a widely used land modeling environment that generates estimates of land surface fluxes and states such as soil moisture, snow, and streamflow. These estimates are critical for drought and flood monitoring, water availability and water resource management, climate assessments, and other uses. NLDAS-3 is the next generation version of NLDAS-2, and offers significant improvements such as improved spatial resolution (12.5km to 1km), expanded domain (CONUS to North and Central America), reduced data latency (3.5 days to near real-time), and assimilation of NASA remote sensing data, among others. (see Earthdata VEDA Data Story). Please note that the NLDAS-3 precipitation data provided here is a sample dataset still in development, and will not be the final NLDAS-3 product when it is released.
This notebook is intended to visualize and compare the NLDAS-2 and sample NLDAS-3 monthly-averaged precipitation forcing.
Approach
- Query metadata from the VEDA STAC API
- Get tiles representing NLDAS-2 and NLDAS-3 from the VEDA Raster API
- Display the data side-by-side for comparison
Querying the STAC API
The metadata and derived data products can be accessed without credentials via STAC API and Raster API respectively.
= "https://openveda.cloud/api/stac"
STAC_API_URL = "https://openveda.cloud/api/raster" RASTER_API_URL
Next we will define our collections of interest. You can discover available collections via the STAC Browser: http://openveda.cloud
= "nldas3"
collection_id3 = "nldas2" collection_id2
Now we can use those collection ids along with a particular datetime to search the STAC for items that match our criteria.
= Client.open(STAC_API_URL).search(
search =[collection_id3, collection_id2],
collections="2021-02-01",
datetime
)
= search.item_collection()
item_collection print(f"Found {len(item_collection)} items")
Found 2 items
Lets take a closer look at each of these items:
0] item_collection[
- type "Feature"
- stac_version "1.1.0"
stac_extensions[] 2 items
- 0 "https://stac-extensions.github.io/raster/v1.1.0/schema.json"
- 1 "https://stac-extensions.github.io/projection/v2.0.0/schema.json"
- id "nldas3_LIS_HIST_202102"
geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
1[] 2 items
- 0 -51.93999145246978
- 1 7.019999961559591
2[] 2 items
- 0 -51.93999145246978
- 1 72.06000091582078
3[] 2 items
- 0 -168.98000671647551
- 1 72.06000091582078
4[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
bbox[] 4 items
- 0 -168.98000671647551
- 1 7.019999961559591
- 2 -51.93999145246978
- 3 72.06000091582078
properties
- end_datetime "2021-02-28T00:00:00+00:00"
- start_datetime "2021-02-01T00:00:00+00:00"
- datetime None
links[] 5 items
0
- rel "collection"
- href "https://openveda.cloud/api/stac/collections/nldas3"
- type "application/json"
1
- rel "parent"
- href "https://openveda.cloud/api/stac/collections/nldas3"
- type "application/json"
2
- rel "root"
- href "https://openveda.cloud/api/stac"
- type "application/json"
- title "VEDA (Visualization, Exploration, and Data Analysis) STAC API"
3
- rel "self"
- href "https://openveda.cloud/api/stac/collections/nldas3/items/nldas3_LIS_HIST_202102"
- type "application/geo+json"
4
- rel "preview"
- href "https://openveda.cloud/api/raster/collections/nldas3/items/nldas3_LIS_HIST_202102/map?assets=cog_default&rescale=0%2C200&colormap_name=magma"
- type "text/html"
- title "Map of Item"
assets
cog_default
- href "s3://veda-data-store/nldas3/nldas3_LIS_HIST_202102.tif"
- type "image/tiff; application=geotiff"
- title "Default COG Layer"
- description "Cloud optimized default layer to display on map"
proj:bbox[] 4 items
- 0 -168.98000671647551
- 1 7.019999961559591
- 2 -51.93999145246978
- 3 72.06000091582078
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 1626
- 1 2926
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 428.0843200683594
- min -0.022795898839831352
- count 11
buckets[] 10 items
- 0 217417
- 1 29857
- 2 15254
- 3 7576
- 4 3011
- 5 1122
- 6 488
- 7 77
- 8 9
- 9 2
statistics
- mean 30.96841488575868
- stddev 41.008411449510426
- maximum 428.0843200683594
- minimum -0.022795898839831352
- valid_percent 47.08281935307018
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
1[] 2 items
- 0 -51.93999145246978
- 1 7.019999961559591
2[] 2 items
- 0 -51.93999145246978
- 1 72.06000091582078
3[] 2 items
- 0 -168.98000671647551
- 1 72.06000091582078
4[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.04000000521668002
- 1 0.0
- 2 -168.98000671647551
- 3 0.0
- 4 -0.0400000005868765
- 5 72.06000091582078
- 6 0.0
- 7 0.0
- 8 1.0
- proj:code "EPSG:4326"
roles[] 2 items
- 0 "data"
- 1 "layer"
rendered_preview
- href "https://openveda.cloud/api/raster/collections/nldas3/items/nldas3_LIS_HIST_202102/preview.png?assets=cog_default&rescale=0%2C200&colormap_name=magma"
- type "image/png"
- title "Rendered preview"
- rel "preview"
roles[] 1 items
- 0 "overview"
- collection "nldas3"
1] item_collection[
- type "Feature"
- stac_version "1.1.0"
stac_extensions[] 2 items
- 0 "https://stac-extensions.github.io/raster/v1.1.0/schema.json"
- 1 "https://stac-extensions.github.io/projection/v2.0.0/schema.json"
- id "nldas2_LIS_HIST_202102"
geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
1[] 2 items
- 0 -51.93999145246978
- 1 7.019999961559591
2[] 2 items
- 0 -51.93999145246978
- 1 72.06000091582078
3[] 2 items
- 0 -168.98000671647551
- 1 72.06000091582078
4[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
bbox[] 4 items
- 0 -168.98000671647551
- 1 7.019999961559591
- 2 -51.93999145246978
- 3 72.06000091582078
properties
- end_datetime "2021-02-28T00:00:00+00:00"
- start_datetime "2021-02-01T00:00:00+00:00"
- datetime None
links[] 5 items
0
- rel "collection"
- href "https://openveda.cloud/api/stac/collections/nldas2"
- type "application/json"
1
- rel "parent"
- href "https://openveda.cloud/api/stac/collections/nldas2"
- type "application/json"
2
- rel "root"
- href "https://openveda.cloud/api/stac"
- type "application/json"
- title "VEDA (Visualization, Exploration, and Data Analysis) STAC API"
3
- rel "self"
- href "https://openveda.cloud/api/stac/collections/nldas2/items/nldas2_LIS_HIST_202102"
- type "application/geo+json"
4
- rel "preview"
- href "https://openveda.cloud/api/raster/collections/nldas2/items/nldas2_LIS_HIST_202102/map?assets=cog_default&rescale=0%2C200&colormap_name=magma"
- type "text/html"
- title "Map of Item"
assets
cog_default
- href "s3://veda-data-store/nldas2/nldas2_LIS_HIST_202102.tif"
- type "image/tiff; application=geotiff"
- title "Default COG Layer"
- description "Cloud optimized default layer to display on map"
proj:bbox[] 4 items
- 0 -168.98000671647551
- 1 7.019999961559591
- 2 -51.93999145246978
- 3 72.06000091582078
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 1626
- 1 2926
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 574.3709106445312
- min -4.244315147399902
- count 11
buckets[] 10 items
- 0 75701
- 1 14093
- 2 5868
- 3 2149
- 4 419
- 5 204
- 6 128
- 7 63
- 8 36
- 9 12
statistics
- mean 40.024527986379255
- stddev 50.011235463160766
- maximum 574.3709106445312
- minimum -4.244315147399902
- valid_percent 16.90532483552632
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
1[] 2 items
- 0 -51.93999145246978
- 1 7.019999961559591
2[] 2 items
- 0 -51.93999145246978
- 1 72.06000091582078
3[] 2 items
- 0 -168.98000671647551
- 1 72.06000091582078
4[] 2 items
- 0 -168.98000671647551
- 1 7.019999961559591
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.04000000521668002
- 1 0.0
- 2 -168.98000671647551
- 3 0.0
- 4 -0.0400000005868765
- 5 72.06000091582078
- 6 0.0
- 7 0.0
- 8 1.0
- proj:code "EPSG:4326"
roles[] 2 items
- 0 "data"
- 1 "layer"
rendered_preview
- href "https://openveda.cloud/api/raster/collections/nldas2/items/nldas2_LIS_HIST_202102/preview.png?assets=cog_default&rescale=0%2C200&colormap_name=magma"
- type "image/png"
- title "Rendered preview"
- rel "preview"
roles[] 1 items
- 0 "overview"
- collection "nldas2"
Notice that each of these items has an asset called cog_default
. That is the one we are interested in. That asset includes statistics about the raster band:
= item_collection[0]
nldas3_item = nldas3_item.assets["cog_default"].ext.raster.bands[0].statistics
nldas3_band_statistics nldas3_band_statistics.properties
{'mean': 30.96841488575868,
'stddev': 41.008411449510426,
'maximum': 428.0843200683594,
'minimum': -0.022795898839831352,
'valid_percent': 47.08281935307018}
Get tiles with the Raster API
We’ll use those statistics to make a Raster API query for the NLDAS-3 tile:
= requests.get(
response f"{RASTER_API_URL}/collections/{collection_id3}/items/{nldas3_item.id}/WebMercatorQuad/tilejson.json?"
"&assets=cog_default"
"&color_formula=gamma+r+1.05&colormap_name=rdbu_r"
f"&rescale={nldas3_band_statistics.minimum},{nldas3_band_statistics.maximum}",
)
# If anything goes wrong with this request, output error contents
assert response.ok, response.text
= response.json()
tiles3 tiles3
{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://openveda.cloud/api/raster/collections/nldas3/items/nldas3_LIS_HIST_202102/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog_default&color_formula=gamma+r+1.05&colormap_name=rdbu_r&rescale=-0.022795898839831352%2C428.0843200683594'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-168.98000671647551,
7.019999961559591,
-51.93999145246978,
72.06000091582078],
'center': [-110.45999908447266, 39.540000438690186, 0]}
Let’s do the same for the nldas2 item
= item_collection[1]
nldas2_item = nldas2_item.assets["cog_default"].ext.raster.bands[0].statistics
nldas2_band_statistics
= requests.get(
response f"{RASTER_API_URL}/collections/{collection_id2}/items/{nldas2_item.id}/WebMercatorQuad/tilejson.json?"
"&assets=cog_default"
"&color_formula=gamma+r+1.05&colormap_name=rdbu_r"
f"&rescale={nldas2_band_statistics.minimum},{nldas2_band_statistics.maximum}",
)
# If anything goes wrong with this request, output error contents
assert response.ok, response.text
= response.json()
tiles2 tiles2
{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://openveda.cloud/api/raster/collections/nldas2/items/nldas2_LIS_HIST_202102/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog_default&color_formula=gamma+r+1.05&colormap_name=rdbu_r&rescale=-4.244315147399902%2C574.3709106445312'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-168.98000671647551,
7.019999961559591,
-51.93999145246978,
72.06000091582078],
'center': [-110.45999908447266, 39.540000438690186, 0]}
Visualize NLDAS-2 and NLDAS-3
Create and display a DualMap to visualize NLDAS-2 and NLDAS-3 data side-by-side. Notice the differences in extent and resolution between the two versions.
= folium.TileLayer(
map_layer2 =tiles2["tiles"][0],
tiles="VEDA",
attr
)= folium.TileLayer(
map_layer3 =tiles3["tiles"][0],
tiles="VEDA",
attr
)= folium.plugins.DualMap(location=[39,-110], zoom_start=3,)
m
map_layer2.add_to(m.m1)
map_layer3.add_to(m.m2) m