pygridmet

Access daily climate data from GridMet over CONUS

https://github.com/hyriver/pygridmet

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: joss.theoj.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (4.3%) to scientific vocabulary

Keywords

climate conus data gridmet hydrology python webservice

Keywords from Contributors

asyncio mesh sequences networks digital-elevation-model pde interactive urban daymet hacking
Last synced: 6 months ago · JSON representation ·

Repository

Access daily climate data from GridMet over CONUS

Basic Info
  • Host: GitHub
  • Owner: hyriver
  • License: other
  • Language: Python
  • Default Branch: main
  • Homepage: https://docs.hyriver.io
  • Size: 207 KB
Statistics
  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 9
Topics
climate conus data gridmet hydrology python webservice
Created about 2 years ago · Last pushed 8 months ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Citation Authors

README.rst

.. image:: https://raw.githubusercontent.com/hyriver/HyRiver-examples/main/notebooks/_static/pygridmet_logo.png
    :target: https://github.com/hyriver/HyRiver

|

.. image:: https://joss.theoj.org/papers/b0df2f6192f0a18b9e622a3edff52e77/status.svg
    :target: https://joss.theoj.org/papers/b0df2f6192f0a18b9e622a3edff52e77
    :alt: JOSS

|

.. |pygeohydro| image:: https://github.com/hyriver/pygeohydro/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pygeohydro/actions/workflows/test.yml
    :alt: Github Actions

.. |pygeoogc| image:: https://github.com/hyriver/pygeoogc/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pygeoogc/actions/workflows/test.yml
    :alt: Github Actions

.. |pygeoutils| image:: https://github.com/hyriver/pygeoutils/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pygeoutils/actions/workflows/test.yml
    :alt: Github Actions

.. |pynhd| image:: https://github.com/hyriver/pynhd/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pynhd/actions/workflows/test.yml
    :alt: Github Actions

.. |py3dep| image:: https://github.com/hyriver/py3dep/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/py3dep/actions/workflows/test.yml
    :alt: Github Actions

.. |pydaymet| image:: https://github.com/hyriver/pydaymet/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pydaymet/actions/workflows/test.yml
    :alt: Github Actions

.. |pygridmet| image:: https://github.com/hyriver/pygridmet/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pygridmet/actions/workflows/test.yml
    :alt: Github Actions

.. |pynldas2| image:: https://github.com/hyriver/pynldas2/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/pynldas2/actions/workflows/test.yml
    :alt: Github Actions

.. |async| image:: https://github.com/hyriver/async-retriever/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/async-retriever/actions/workflows/test.yml
    :alt: Github Actions

.. |signatures| image:: https://github.com/hyriver/hydrosignatures/actions/workflows/test.yml/badge.svg
    :target: https://github.com/hyriver/hydrosignatures/actions/workflows/test.yml
    :alt: Github Actions

================ ====================================================================
Package          Description
================ ====================================================================
PyNHD_           Navigate and subset NHDPlus (MR and HR) using web services
Py3DEP_          Access topographic data through National Map's 3DEP web service
PyGeoHydro_      Access NWIS, NID, WQP, eHydro, NLCD, CAMELS, and SSEBop databases
PyDaymet_        Access daily, monthly, and annual climate data via Daymet
PyGridMET_       Access daily climate data via GridMET
PyNLDAS2_        Access hourly NLDAS-2 data via web services
HydroSignatures_ A collection of tools for computing hydrological signatures
AsyncRetriever_  High-level API for asynchronous requests with persistent caching
PyGeoOGC_        Send queries to any ArcGIS RESTful-, WMS-, and WFS-based services
PyGeoUtils_      Utilities for manipulating geospatial, (Geo)JSON, and (Geo)TIFF data
================ ====================================================================

.. _PyGeoHydro: https://github.com/hyriver/pygeohydro
.. _AsyncRetriever: https://github.com/hyriver/async-retriever
.. _PyGeoOGC: https://github.com/hyriver/pygeoogc
.. _PyGeoUtils: https://github.com/hyriver/pygeoutils
.. _PyNHD: https://github.com/hyriver/pynhd
.. _Py3DEP: https://github.com/hyriver/py3dep
.. _PyDaymet: https://github.com/hyriver/pydaymet
.. _PyGridMET: https://github.com/hyriver/pygridmet
.. _PyNLDAS2: https://github.com/hyriver/pynldas2
.. _HydroSignatures: https://github.com/hyriver/hydrosignatures

PyGridMET: Daily climate data through GridMET
---------------------------------------------

.. image:: https://img.shields.io/pypi/v/pygridmet.svg
    :target: https://pypi.python.org/pypi/pygridmet
    :alt: PyPi

.. image:: https://img.shields.io/conda/vn/conda-forge/pygridmet.svg
    :target: https://anaconda.org/conda-forge/pygridmet
    :alt: Conda Version

.. image:: https://codecov.io/gh/hyriver/pygridmet/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/hyriver/pygridmet
    :alt: CodeCov

.. image:: https://img.shields.io/pypi/pyversions/pygridmet.svg
    :target: https://pypi.python.org/pypi/pygridmet
    :alt: Python Versions

.. image:: https://static.pepy.tech/badge/pygridmet
    :target: https://pepy.tech/project/pygridmet
    :alt: Downloads

|

.. image:: https://www.codefactor.io/repository/github/hyriver/pygridmet/badge
   :target: https://www.codefactor.io/repository/github/hyriver/pygridmet
   :alt: CodeFactor

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
    :target: https://github.com/astral-sh/ruff
    :alt: Ruff

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
    :target: https://github.com/pre-commit/pre-commit
    :alt: pre-commit

.. image:: https://mybinder.org/badge_logo.svg
    :target: https://mybinder.org/v2/gh/hyriver/HyRiver-examples/main?urlpath=lab/tree/notebooks
    :alt: Binder

|

Features
--------

PyGridMET is a part of `HyRiver `__ software stack that
is designed to aid in hydroclimate analysis through web services. This package provides
access to daily climate data over contermonious US (CONUS) from
`GridMET `__ database using NetCDF
Subset Service (NCSS). Both single pixel (using ``get_bycoords`` function) and gridded data (using
``get_bygeom``) are supported which are returned as
``pandas.DataFrame`` and ``xarray.Dataset``, respectively.

Both ``get_bygeom`` and ``get_bycoords`` functions save the intermediate files
returned by the web service in a local cache folder (``./cache`` in the current
directory). The cache folder is created automatically when the functions are
called for the first time. The cache folder is used to store the intermediate
files to avoid re-downloading them. These two functions allow modifying the
web service calls via two options:

- ``conn_timeout``: Sets the connection timeout in seconds. The default value
  is 5 minutes. This can be increaseed for larger requests. If running these
  functions fails with a connection timeout error, try increasing this value.
- ``validate_filesize``: If ``True``, the functions compares the file size
  of the previously cached files in the ``./cache`` folder, if they exist, with
  their size on the remote server. If the sizes do not match, the cached files are
  removed and they will be re-download. By default this is set to ``False`` since
  the files on the server rarely change. So, if a request has already been cached
  there shouldn't be a need for re-donwloading them from scratch. However, if you
  suspect that the files on the server have changed or the functions fails to process
  the cached files, you can set this to ``True`` or manually delete the cached
  files in the ``./cache`` folder.

You can find some example notebooks
`here `__.
You can also try using PyGridMET without installing
it on your system by clicking on the binder badge. A Jupyter Lab
instance with the HyRiver 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 `__.

Citation
--------
If you use any of HyRiver packages in your research, we appreciate citations:

.. code-block:: bibtex

    @article{Chegini_2021,
        author = {Chegini, Taher and Li, Hong-Yi and Leung, L. Ruby},
        doi = {10.21105/joss.03175},
        journal = {Journal of Open Source Software},
        month = {10},
        number = {66},
        pages = {1--3},
        title = {{HyRiver: Hydroclimate Data Retriever}},
        volume = {6},
        year = {2021}
    }

Installation
------------

You can install PyGridMET using ``pip`` as follows:

.. code-block:: console

    $ pip install pygridmet

Alternatively, PyGridMET can be installed from the ``conda-forge`` repository
using `Conda `__:

.. code-block:: console

    $ conda install -c conda-forge pygridmet

Quick start
-----------

You can use PyGridMET using command-line or as a Python library. The commanda-line
provides access to two functionality:

- Getting gridded climate data: You must create a ``geopandas.GeoDataFrame`` that contains
  the geometries of the target locations. This dataframe must have four columns:
  ``id``, ``start``, ``end``, ``geometry``. The ``id`` column is used as
  filenames for saving the obtained climate data to a NetCDF (``.nc``) file. The ``start``
  and ``end`` columns are starting and ending dates of the target period. Then,
  you must save the dataframe as a shapefile (``.shp``) or geopackage (``.gpkg``) with
  CRS attribute.
- Getting single pixel climate data: You must create a CSV file that
  contains coordinates of the target locations. This file must have at four columns:
  ``id``, ``start``, ``end``, ``lon``, and ``lat``. The ``id`` column is used as filenames
  for saving the obtained climate data to a CSV (``.csv``) file. The ``start`` and ``end``
  columns are the same as the ``geometry`` command. The ``lon`` and ``lat`` columns are
  the longitude and latitude coordinates of the target locations.

.. code-block:: console

    $ pygridmet -h
    Usage: pygridmet [OPTIONS] COMMAND [ARGS]...

    Command-line interface for PyGridMET.

    Options:
    -h, --help  Show this message and exit.

    Commands:
    coords    Retrieve climate data for a list of coordinates.
    geometry  Retrieve climate data for a dataframe of geometries.

The ``coords`` sub-command is as follows:

.. code-block:: console

    $ pygridmet coords -h
    Usage: pygridmet coords [OPTIONS] FPATH

    Retrieve climate data for a list of coordinates.

    FPATH: Path to a csv file with four columns:
        - ``id``: Feature identifiers that gridmet uses as the output netcdf filenames.
        - ``start``: Start time.
        - ``end``: End time.
        - ``lon``: Longitude of the points of interest.
        - ``lat``: Latitude of the points of interest.
        - ``snow``: (optional) Separate snowfall from precipitation, default is ``False``.

    Examples:
        $ cat coords.csv
        id,lon,lat,start,end
        california,-122.2493328,37.8122894,2012-01-01,2014-12-31
        $ pygridmet coords coords.csv -v pr -v tmmn

    Options:
    -v, --variables TEXT  Target variables. You can pass this flag multiple
                            times for multiple variables.
    -s, --save_dir PATH   Path to a directory to save the requested files.
                            Extension for the outputs is .nc for geometry and .csv
                            for coords.
    --disable_ssl         Pass to disable SSL certification verification.
    -h, --help            Show this message and exit.

And, the ``geometry`` sub-command is as follows:

.. code-block:: console

    $ pygridmet geometry -h
    Usage: pygridmet geometry [OPTIONS] FPATH

    Retrieve climate data for a dataframe of geometries.

    FPATH: Path to a shapefile (.shp) or geopackage (.gpkg) file.
    This file must have four columns and contain a ``crs`` attribute:
        - ``id``: Feature identifiers that gridmet uses as the output netcdf filenames.
        - ``start``: Start time.
        - ``end``: End time.
        - ``geometry``: Target geometries.
        - ``snow``: (optional) Separate snowfall from precipitation, default is ``False``.

    Examples:
        $ pygridmet geometry geo.gpkg -v pr -v tmmn

    Options:
    -v, --variables TEXT  Target variables. You can pass this flag multiple
                            times for multiple variables.
    -s, --save_dir PATH   Path to a directory to save the requested files.
                            Extension for the outputs is .nc for geometry and .csv
                            for coords.
    --disable_ssl         Pass to disable SSL certification verification.
    -h, --help            Show this message and exit.

Now, let's see how we can use PyGridMET as a library.

PyGridMET offers two functions for getting climate data; ``get_bycoords`` and ``get_bygeom``.
The arguments of these functions are identical except the first argument where the latter
should be polygon and the former should be a coordinate (a tuple of length two as in (x, y)).
The input geometry or coordinate can be in any valid CRS (defaults to ``EPSG:4326``). The
``dates`` argument can be either a tuple of length two like ``(start_str, end_str)`` or a list of
years like ``[2000, 2005]``. It is noted that both functions have a ``snow`` flag for separating
snow from precipitation using
`Martinez and Gupta (2010) `__ method.

We can get a dataframe of available variables and their info by calling
``GridMET().gridmet_table``:

+----------------------------------------+------------+------------------------------+
| Variable                               | Abbr       | Unit                         |
+========================================+============+==============================+
| Precipitation                          | ``pr``     | mm                           |
+----------------------------------------+------------+------------------------------+
| Maximum Relative Humidity              | ``rmax``   | %                            |
+----------------------------------------+------------+------------------------------+
| Minimum Relative Humidity              | ``rmin``   | %                            |
+----------------------------------------+------------+------------------------------+
| Specific Humidity                      | ``sph``    | kg/kg                        |
+----------------------------------------+------------+------------------------------+
| Surface Radiation                      | ``srad``   | W/m2                         |
+----------------------------------------+------------+------------------------------+
| Wind Direction                         | ``th``     | Degrees Clockwise from north |
+----------------------------------------+------------+------------------------------+
| Minimum Air Temperature                | ``tmmn``   | K                            |
+----------------------------------------+------------+------------------------------+
| Maximum Air Temperature                | ``tmmx``   | K                            |
+----------------------------------------+------------+------------------------------+
| Wind Speed                             | ``vs``     | m/s                          |
+----------------------------------------+------------+------------------------------+
| Burning Index                          | ``bi``     | Dimensionless                |
+----------------------------------------+------------+------------------------------+
| Fuel Moisture (100-hr)                 | ``fm100``  | %                            |
+----------------------------------------+------------+------------------------------+
| Fuel Moisture (1000-hr)                | ``fm1000`` | %                            |
+----------------------------------------+------------+------------------------------+
| Energy Release Component               | ``erc``    | Dimensionless                |
+----------------------------------------+------------+------------------------------+
| Reference Evapotranspiration (Alfalfa) | ``etr``    | mm                           |
+----------------------------------------+------------+------------------------------+
| Reference Evapotranspiration (Grass)   | ``pet``    | mm                           |
+----------------------------------------+------------+------------------------------+
| Vapor Pressure Deficit                 | ``vpd``    | kPa                          |
+----------------------------------------+------------+------------------------------+

.. code-block:: python

    from pynhd import NLDI
    import pygridmet as gridmet

    geometry = NLDI().get_basins("01031500").geometry[0]

    var = ["pr", "tmmn"]
    dates = ("2000-01-01", "2000-06-30")

    daily = gridmet.get_bygeom(geometry, dates, variables=var, snow=True)

.. image:: https://raw.githubusercontent.com/hyriver/HyRiver-examples/main/notebooks/_static/gridmet_grid.png
    :target: https://github.com/hyriver/HyRiver-examples/blob/main/notebooks/gridmet.ipynb

If the input geometry (or coordinate) is in a CRS other than ``EPSG:4326``, we should pass
it to the functions.

.. code-block:: python

    coords = (-1431147.7928, 318483.4618)
    crs = 3542
    dates = ("2000-01-01", "2006-12-31")
    data = gridmet.get_bycoords(coords, dates, variables=var, loc_crs=crs)

.. image:: https://raw.githubusercontent.com/hyriver/HyRiver-examples/main/notebooks/_static/gridmet_loc.png
    :target: https://github.com/hyriver/HyRiver-examples/blob/main/notebooks/gridmet.ipynb

Additionally, the ``get_bycoords`` function accepts a list of coordinates and by setting the
``to_xarray`` flag to ``True`` it can return the results as a ``xarray.Dataset`` instead of
a ``pandas.DataFrame``:

.. code-block:: python

    coords = [(-94.986, 29.973), (-95.478, 30.134)]
    idx = ["P1", "P2"]
    clm_ds = gridmet.get_bycoords(coords, range(2000, 2021), coords_id=idx, to_xarray=True)

Contributing
------------

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

Owner

  • Name: HyRiver
  • Login: hyriver
  • Kind: organization
  • Location: United States of America

A suite of Python packages that provides a unified API for retrieving geospatial/temporal data from various web services

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Chegini"
  given-names: "Taher"
  orcid: "https://orcid.org/0000-0002-5430-6000"
- family-names: "Li"
  given-names: "Hong-Yi"
  orcid: "https://orcid.org/0000-0002-9807-3851"
- family-names: "Leung"
  given-names: "L. Ruby"
  orcid: "https://orcid.org/0000-0002-3221-9467"
title: "HyRiver: Hydroclimate Data Retriever"
version: 0.11
doi: 10.21105/joss.03175
date-released: 2021-10-27
url: "https://github.com/cheginit/HyRiver"
preferred-citation:
  type: article
  authors:
  - family-names: "Chegini"
    given-names: "Taher"
    orcid: "https://orcid.org/0000-0002-5430-6000"
  - family-names: "Li"
    given-names: "Hong-Yi"
    orcid: "https://orcid.org/0000-0002-9807-3851"
  - family-names: "Leung"
    given-names: "L. Ruby"
    orcid: "https://orcid.org/0000-0002-3221-9467"
  doi: "10.21105/joss.03175"
  journal: "Journal of Open Source Software"
  month: 10
  start: 1
  end: 3
  title: "HyRiver: Hydroclimate Data Retriever"
  issue: 66
  volume: 6
  year: 2021

GitHub Events

Total
  • Create event: 7
  • Issues event: 5
  • Release event: 4
  • Watch event: 2
  • Delete event: 1
  • Issue comment event: 6
  • Push event: 12
  • Pull request event: 4
Last Year
  • Create event: 7
  • Issues event: 5
  • Release event: 4
  • Watch event: 2
  • Delete event: 1
  • Issue comment event: 6
  • Push event: 12
  • Pull request event: 4

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 31
  • Total Committers: 3
  • Avg Commits per committer: 10.333
  • Development Distribution Score (DDS): 0.097
Past Year
  • Commits: 31
  • Committers: 3
  • Avg Commits per committer: 10.333
  • Development Distribution Score (DDS): 0.097
Top Committers
Name Email Commits
Taher Chegini c****t@g****m 28
dependabot[bot] 4****] 2
Taher Chegini t****i@g****m 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 2
  • Total pull requests: 9
  • Average time to close issues: N/A
  • Average time to close pull requests: 2 days
  • Total issue authors: 2
  • Total pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.78
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 9
Past Year
  • Issues: 2
  • Pull requests: 3
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 1.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
  • nhahnepr (1)
  • j-tenny (1)
Pull Request Authors
  • dependabot[bot] (16)
Top Labels
Issue Labels
bug (2)
Pull Request Labels
dependencies (16)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 177 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 9
  • Total maintainers: 1
pypi.org: pygridmet

Access daily, monthly, and annual climate data via the Daymet web service.

  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 177 Last month
Rankings
Dependent packages count: 10.1%
Average: 38.3%
Dependent repos count: 66.5%
Maintainers (1)
Last synced: 7 months ago

Dependencies

.github/workflows/codeql-analysis.yml actions
  • actions/checkout v4 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/pre-commit.yml actions
  • actions/checkout v4 composite
  • excitedleigh/setup-nox v2.1.0 composite
.github/workflows/release.yml actions
  • actions/checkout v4 composite
  • actions/setup-python master composite
  • docker://pandoc/core * composite
  • pypa/gh-action-pypi-publish v1.8.10 composite
  • softprops/action-gh-release v1 composite
.github/workflows/test.yml actions
  • actions/checkout v4 composite
  • codecov/codecov-action v3 composite
  • mamba-org/setup-micromamba v1 composite
ci/requirements/environment.yml pypi
pyproject.toml pypi
  • async-retriever <0.16,>=0.15.2
  • click >=0.7
  • geopandas >=0.10
  • numpy >=1.21
  • pandas >=1
  • pygeoogc <0.16,>=0.15.2
  • pygeoutils <0.16,>=0.15.2
  • pyproj >=3.0.1
  • shapely >=2
  • xarray >=2023.01