-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: Add async_retriever and more example notebooks openjournals/joss…
- Loading branch information
cheginit
committed
May 27, 2021
1 parent
be9d1db
commit c484af3
Showing
22 changed files
with
628 additions
and
304 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
docs/source/autoapi/async_retriever/async_retriever/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
:mod:`async_retriever.async_retriever` | ||
====================================== | ||
|
||
.. py:module:: async_retriever.async_retriever | ||
.. autoapi-nested-parse:: | ||
|
||
Core async functions. | ||
|
||
|
||
|
||
Module Contents | ||
--------------- | ||
|
||
.. function:: retrieve(urls: List[str], read: str, request_kwds: Optional[List[Dict[str, Any]]] = None, request: str = 'GET', max_workers: int = 8, cache_name: Optional[Union[Path, str]] = None) -> List[Union[str, Dict[str, Any], bytes]] | ||
|
||
Send async requests. | ||
|
||
This function is based on | ||
`this <https://github.com/HydrologicEngineeringCenter/data-retrieval-scripts/blob/master/qpe_async_download.py>`__ | ||
script. | ||
|
||
:Parameters: * **urls** (:class:`list` of :class:`str`) -- A list of URLs. | ||
* **read** (:class:`str`) -- The method for returning the request; binary, json, and text. | ||
* **request_kwds** (:class:`list` of :class:`dict`, *optional*) -- A list of requests kwds corresponding to input URLs (1 on 1 mapping), defaults to None. | ||
For example, [{"params": {...}, "headers": {...}}, ...]. | ||
* **request** (:class:`str`, *optional*) -- The request type; GET or POST, defaults to GET. | ||
* **max_workers** (:class:`int`, *optional*) -- The maximum number of async processes, defaults to 8. | ||
* **cache_name** (:class:`str`, *optional*) -- Path to a file for caching the session, default to None which uses a file | ||
called aiohttp_cache.sqlite under the systems' cache directory: ~/.cache | ||
for Linux and MacOS, and %Temp% for Windows. | ||
|
||
:returns: :class:`list` -- A list of responses which are not in the order of input requests. | ||
|
||
.. rubric:: Examples | ||
|
||
>>> import async_retriever as ar | ||
>>> stations = ["01646500", "08072300", "11073495"] | ||
>>> base = "https://waterservices.usgs.gov/nwis/site" | ||
>>> urls, kwds = zip( | ||
... *[ | ||
... (base, {"params": {"format": "rdb", "sites": s, "siteStatus": "all"}}) | ||
... for s in stations | ||
... ] | ||
... ) | ||
>>> resp = ar.retrieve(urls, "text", request_kwds=kwds) | ||
>>> resp[0].split('\n')[-2].split('\t')[1] | ||
'01646500' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
:mod:`async_retriever` | ||
====================== | ||
|
||
.. py:module:: async_retriever | ||
.. autoapi-nested-parse:: | ||
|
||
Top-level package. | ||
|
||
|
||
|
||
Submodules | ||
---------- | ||
.. toctree:: | ||
:titlesonly: | ||
:maxdepth: 1 | ||
|
||
async_retriever/index.rst | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,108 @@ | ||
Reference | ||
========= | ||
API References | ||
============== | ||
|
||
Versions | ||
-------- | ||
.. panels:: | ||
:container: container-lg pb-3 | ||
:body: text-center | ||
:column: col-lg-3 col-md-3 col-sm-4 col-xs-6 p-2 | ||
|
||
- |pygeoogc| | ||
- |pygeoutils| | ||
- |pynhd| | ||
- |pygeohydro| | ||
- |py3dep| | ||
- |pydaymet| | ||
.. link-button:: /autoapi/pynhd/index | ||
:type: ref | ||
:text: PyNHD | ||
:classes: stretched-link | ||
|
||
APIs | ||
---- | ||
|pynhd| | ||
|
||
--- | ||
|
||
.. link-button:: /autoapi/pygeohydro/index | ||
:type: ref | ||
:text: PyGeoHydro | ||
:classes: stretched-link | ||
|
||
|pygeohydro| | ||
|
||
--- | ||
|
||
.. link-button:: /autoapi/py3dep/index | ||
:type: ref | ||
:text: Py3DEP | ||
:classes: stretched-link | ||
|
||
|py3dep| | ||
|
||
--- | ||
|
||
.. link-button:: /autoapi/pydaymet/index | ||
:type: ref | ||
:text: PyDaymet | ||
:classes: stretched-link | ||
|
||
|pydaymet| | ||
|
||
--- | ||
|
||
.. link-button:: /autoapi/pygeoogc/index | ||
:type: ref | ||
:text: PyGeoOGC | ||
:classes: stretched-link | ||
|
||
|pygeoogc| | ||
|
||
--- | ||
|
||
.. link-button:: /autoapi/pygeoutils/index | ||
:type: ref | ||
:text: PyGeoUtils | ||
:classes: stretched-link | ||
|
||
|pygeoutils| | ||
|
||
--- | ||
|
||
.. link-button:: /autoapi/async_retriever/index | ||
:type: ref | ||
:text: AsyncRetriever | ||
:classes: stretched-link | ||
|
||
|async| | ||
|
||
.. toctree:: | ||
:titlesonly: | ||
:hidden: | ||
|
||
/autoapi/pygeoogc/index | ||
/autoapi/pygeoutils/index | ||
/autoapi/pynhd/index | ||
/autoapi/py3dep/index | ||
/autoapi/pygeohydro/index | ||
/autoapi/pydaymet/index | ||
PyNHD </autoapi/pynhd/index> | ||
PyGeoHydro </autoapi/pygeohydro/index> | ||
Py3DEP </autoapi/py3dep/index> | ||
PyDaymet </autoapi/pydaymet/index> | ||
PyGeoOGC </autoapi/pygeoogc/index> | ||
PyGeoUtils </autoapi/pygeoutils/index> | ||
AsyncRetriever </autoapi/async_retriever/index> | ||
|
||
.. |pygeohydro| image:: https://img.shields.io/pypi/v/pygeohydro?label=PyGeoHydro&color=blue | ||
.. |pygeohydro| image:: https://img.shields.io/pypi/v/pygeohydro?label=%20&color=blue | ||
:target: https://github.com/cheginit/pygeohydro | ||
:alt: PyPi Version | ||
|
||
.. |pygeoogc| image:: https://img.shields.io/pypi/v/pygeoogc?label=PyGeoOGC&color=blue | ||
.. |pygeoogc| image:: https://img.shields.io/pypi/v/pygeoogc?label=%20&color=blue | ||
:target: https://github.com/cheginit/pygeoogc | ||
:alt: PyPi Version | ||
|
||
.. |pygeoutils| image:: https://img.shields.io/pypi/v/pygeoutils?label=PyGeoUtils&color=blue | ||
.. |pygeoutils| image:: https://img.shields.io/pypi/v/pygeoutils?label=%20&color=blue | ||
:target: https://github.com/cheginit/pygeoutils | ||
:alt: PyPi Version | ||
|
||
.. |pynhd| image:: https://img.shields.io/pypi/v/pynhd?label=PyNHD&color=blue | ||
.. |pynhd| image:: https://img.shields.io/pypi/v/pynhd?label=%20&color=blue | ||
:target: https://github.com/cheginit/pynhd | ||
:alt: PyPi Version | ||
|
||
.. |py3dep| image:: https://img.shields.io/pypi/v/py3dep?label=Py3DEP&color=blue | ||
.. |py3dep| image:: https://img.shields.io/pypi/v/py3dep?label=%20&color=blue | ||
:target: https://github.com/cheginit/py3dep | ||
:alt: PyPi Version | ||
|
||
.. |pydaymet| image:: https://img.shields.io/pypi/v/pydaymet?label=PyDaymet&color=blue | ||
.. |pydaymet| image:: https://img.shields.io/pypi/v/pydaymet?label=%20&color=blue | ||
:target: https://github.com/cheginit/pydaymet | ||
:alt: PyPi Version | ||
|
||
.. |async| image:: https://img.shields.io/pypi/v/async_retriever?label=%20&color=blue | ||
:target: https://github.com/cheginit/async_retriever | ||
:alt: PyPi Version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
:mod:`py3dep.cli` | ||
================= | ||
|
||
.. py:module:: py3dep.cli | ||
.. autoapi-nested-parse:: | ||
|
||
Command-line interface for Py3DEP. | ||
|
||
|
||
|
||
Module Contents | ||
--------------- | ||
|
||
.. function:: from_coords(coords: List[Tuple[float, float]], crs: str, csv_path: Union[str, Path]) -> None | ||
|
||
Get elevations of a set of coordinates in meter from airmap. | ||
|
||
|
||
.. function:: from_geometry(layer: str, geometry: Union[Polygon, MultiPolygon, Tuple[float, float, float, float]], res: float, crs: str, nc_path: Union[str, Path]) -> None | ||
|
||
Get topographic data from 3DEP for a geometry. | ||
|
||
|
||
.. function:: get_target_df(tdf: Union[pd.DataFrame, gpd.GeoDataFrame], req_cols: List[str]) -> Union[pd.DataFrame, gpd.GeoDataFrame] | ||
|
||
Check if all required columns exists in the dataframe. | ||
|
||
It also re-orders the columns based on req_cols order. | ||
|
||
|
||
.. function:: main(target: Path, target_type: str, crs: str, layer: Optional[str] = None, save_dir: Union[str, Path] = 'topo_3dep') | ||
|
||
Retrieve topographic data within geometries or elevations for a list of coordinates. | ||
|
||
TARGET: Path to a geospatial file (any file that geopandas.read_file can open) or a csv file. | ||
|
||
The geospatial file should have three columns: | ||
|
||
- id: Feature identifiers that py3dep uses as the output netcdf/csv filenames. | ||
|
||
- res: Target resolution in meters. | ||
|
||
- geometry: A Polygon or MultiPloygon. | ||
|
||
The csv file should have two column: x and y. | ||
|
||
TARGET_TYPE: Type of input file: "coords" for csv and "geometry" for geospatial. | ||
|
||
CRS: CRS of the input data. | ||
|
||
Examples: | ||
|
||
$ py3dep ny_coords.csv coords epsg:4326 | ||
|
||
$ py3dep ny_geom.gpkg geometry epsg:3857 --layer "Slope Map" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Submodules | |
:titlesonly: | ||
:maxdepth: 1 | ||
|
||
cli/index.rst | ||
py3dep/index.rst | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
:mod:`pydaymet.cli` | ||
=================== | ||
|
||
.. py:module:: pydaymet.cli | ||
.. autoapi-nested-parse:: | ||
|
||
Command-line interface for PyDaymet. | ||
|
||
|
||
|
||
Module Contents | ||
--------------- | ||
|
||
.. function:: get_target_df(tdf: Union[pd.DataFrame, gpd.GeoDataFrame], req_cols: List[str]) -> Union[pd.DataFrame, gpd.GeoDataFrame] | ||
|
||
Check if all required columns exists in the dataframe. | ||
|
||
It also re-orders the columns based on req_cols order. | ||
|
||
|
||
.. function:: main(target: Path, target_type: str, crs: str, variables: Optional[Union[List[str], str]] = None, time_scale: str = 'daily', pet: bool = False, save_dir: Union[str, Path] = 'clm_daymet') | ||
|
||
Retrieve cliamte data within geometries or elevations for a list of coordinates. | ||
|
||
TARGET: Path to a geospatial file (any file that geopandas.read_file can open) or a csv file. | ||
|
||
The input files should have three columns: | ||
|
||
- id: Feature identifiers that daymet uses as the output netcdf filenames. | ||
|
||
- start: Starting time. | ||
|
||
- end: Ending time. | ||
|
||
- region: Target region (na for CONUS, hi for Hawaii, and pr for Puerto Rico. | ||
|
||
If target_type is geometry, an additional geometry column is required. | ||
If it is coords, two additional columns are needed: x and y. | ||
|
||
TARGET_TYPE: Type of input file: "coords" for csv and "geometry" for geospatial. | ||
|
||
CRS: CRS of the input data. | ||
|
||
Examples: | ||
|
||
$ pydaymet ny_coords.csv coords epsg:4326 -v prcp -v tmin -p -t monthly | ||
|
||
$ pydaymet ny_geom.gpkg geometry epsg:3857 -v prcp | ||
|
||
|
Oops, something went wrong.