Skip to main content

Access USGS 3DEP database and get data such as elevation in the US

Project description

https://raw.githubusercontent.com/cheginit/hydrodata/develop/docs/_static/py3dep_logo.png

PyPi Conda Version CodeCov Github Actions Binder

CodeFactor black pre-commit

🚨 This package is under heavy development and breaking changes are likely to happen. 🚨

Features

Hydrodata is a stack of Python libraries designed to aid in watershed analysis through web services. Currently, it only includes hydrology and climatology data within the US. Hydrodata software stack is shown in the table below.

Package

Description

Hydrodata

Access NWIS, HCDN 2009, NLCD, and SSEBop databases

PyGeoOGC

Query data from any ArcGIS RESTful-, WMS-, and WFS-based services

PyGeoUtils

Convert responses from PyGeoOGC’s supported web services to datasets

PyNHD

Access NLDI and WaterData web services for navigating the NHDPlus database

Py3DEP

Access topographic data through the 3D Elevation Program (3DEP) web service

PyDaymet

Access the Daymet database for daily climate data

Py3DEP provides access to the 3DEP database which is a part the National Map services. The 3DEP service has multi-resolution sources and depending on the user provided resolution, the data is resampled on the server-side based on all the available data sources. Py3DEP returns the requestes as xarray dataset. The 3DEP includes the following layers:

  • DEM

  • Hillshade Gray

  • Aspect Degrees

  • Aspect Map

  • GreyHillshade Elevation Fill

  • Hillshade Multidirectional

  • Slope Map

  • Slope Degrees

  • Hillshade Elevation Tinted

  • Height Ellipsoidal

  • Contour 25

  • Contour Smoothed 25

Moreover, Py3DEP offers some additonal utilities:

  • elevation_bygrid: For getting elevations of all the grid points in a 2D grid.

  • elevation_byloc: For getting elevation of a single point which is based on the National Map’s Elevation Point Query Service.

  • deg2mpm: For converting slope dataset from degree to meter per meter.

You can try using Py3DEP without installing it on you system by clicking on the binder badge below the Py3DEP banner. A Jupyter notebook instance with the Hydrodata software stack pre-installed will be launched in your web browser and you can start coding!

Moreover, requests for additional functionalities can be submitted via issue tracker.

Installation

You can install Py3DEP using pip after installing libgdal on your system (for example, in Ubuntu run sudo apt install libgdal-dev):

$ pip install py3dep

Alternatively, Py3DEP can be installed from the conda-forge repository using Conda:

$ conda install -c conda-forge py3dep

Quickstart

Py3DEP accepts Shapely’s Polygon or a bounding box (a tuple of length four) as an input geometry. We can use Hydrodata to get a watershed’s geometry, then use it to get DEM and slope data in meters/meters from Py3DEP using get_map function.

The get_map has a resolution argument that sets the target resolution in meters. Note that the highest available resolution throughout the CONUS is about 10 m, though higher resolutions are available in limited parts of the US. Note that the input geometry can be in any valid spatial reference (geo_crs argument). The crs argument, however, is limited to CRS:84, EPSG:4326, and EPSG:3857 since 3DEP only supports these spatial references.

import py3dep
from hydrodata import NLDI

geom = NLDI().getfeature_byid("nwissite", "USGS-01031500", basin=True).geometry[0]
dem = py3dep.get_map("DEM", geom, resolution=30, geo_crs="epsg:4326", crs="epsg:3857")
slope = py3dep.get_map("Slope Degrees", geom, resolution=30)
slope = py3dep.deg2mpm(slope)
https://raw.githubusercontent.com/cheginit/hydrodata/develop/docs/_static/example_plots_py3dep.png

We can get the elevation for a single point within the US:

elev = py3dep.elevation_byloc((-7766049.665, 5691929.739), "epsg:3857")

Additionally, we can get the elevations of set of x- and y- coordinates of a grid. For example, let’s get the minimum temperature data within the watershed from Daymet using Hydrodata then add the elevation as a new variable to the dataset:

import hydrodata.datasets as hds
import xarray as xr
import numpy as np

clm = hds.daymet_bygeom(geom, dates=("2005-01-01", "2005-01-31"), variables="tmin")
gridxy = (clm.x.values, clm.y.values)
elev = py3dep.elevation_bygrid(gridxy, clm.crs, clm.res[0] * 1000)
clm = xr.merge([clm, elev], combine_attrs="override")
clm["elevation"] = clm.elevation.where(~np.isnan(clm.isel(time=0).tmin), drop=True)

Contributing

Contributions are very welcomed. Please read CONTRIBUTING.rst file for instructions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py3dep-0.1.5.tar.gz (21.9 kB view hashes)

Uploaded Source

Built Distribution

py3dep-0.1.5-py2.py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page