agera5tools

Tools for mirroring, manipulating and serving Global Weather for Agriculture data (AgERA5).
https://github.com/ajwdewit/agera5tools

Category: Atmosphere
Sub Category: Meteorological Observation and Forecast

Last synced: about 11 hours ago
JSON representation

Repository metadata

Tools for manipulating (exporting, extracting) AgERA5 data

README.md

AgERA5tools

Tools for mirroring, manipulating (exporting, extracting) and
serving AgERA5 data.

The agera5tools consist of a set of commandline scripts as well as the agera5tools python package
which can be used to

  • set up a mirror for AgERA5 that can automatically build a
    local copy and keep it up to date with the latest AgERA5 data.
  • Allow operations on the downloaded NetCDF files directly such as dumping, point extraction and clipping
  • Serve AgERA5 data on web API through the HTTP protocol. By providing the latitude and longitude in the
    URL, agera5tools can retrieve the corresponding data and return it as JSON.

Commandline tools

The agera5 commandline tools currently have 8 options. The first four are for setting up and managing
the local AgERA5 database:

  • init to generate a configuration file and initialize the set up.
  • build to download the relevant AgERA5 data from Copernicus Climate Data Store (CDS) and build the local database.
  • mirror to update the current database with new days from the CDS.
  • serve to serve AgERA5 data through a web API and return as JSON encoded data.

The other four tools operate directly on the NetCDF files downloaded from the CDS.

  • extract_point: this can be used to extract a time-series of variables for a given location
  • dump which can be used to dump one day of AgERA5 data to CSV, JSON or SQLite
  • clip which can be used to extract a subset of AgERA5 data which will be written to a new NetCDF file.
  • dump_grid which dumps the AgERA5 grid definition to CSV, JSON or SQLite.

Init

$ agera5tools init --help
using config from /data/agera5/agera5tools.yaml
Usage: agera5tools init [OPTIONS]

  Initializes AgERA5tools

  This implies the following:
   - Creating a template configuration file in the current directory
   - Creating a $HOME/.cdsapirc file for access to the CDS
   - Creating the database tables
   - Filling the grid table with the reference grid.

Options:
  --help  Show this message and exit.

Build

$ agera5tools build --help
using config from /data/agera5/agera5tools.yaml
Usage: agera5tools build [OPTIONS]

  Builds the AgERA5 database by bulk download from CDS

Options:
  -d, --to_database  Load AgERA5 data into the database
  -c, --to_csv       Write AgERA5 data to compressed CSV files.
  --help             Show this message and exit.

Mirror

$ agera5tools mirror --help
using config from /data/agera5/agera5tools.yaml
Usage: agera5tools mirror [OPTIONS]

  Incrementally updates the AgERA5 database by daily downloads from the CDS.

Options:
  -c, --to_csv  Write AgERA5 data to compressed CSV files.
  --help        Show this message and exit.

Serve

$ agera5tools serve --help
using config from /data/agera5/agera5tools.yaml
Usage: agera5tools serve [OPTIONS]

  Starts the http server to serve AgERA5 data through HTTP

Options:
  -p, --port INTEGER  Port to number to start listening, default=8080.
  --help              Show this message and exit.

Extract point

$ agera5tools extract_point --help
Usage: agera5tools extract_point [OPTIONS] AGERA5_PATH LONGITUDE LATITUDE
                                 STARTDATE ENDDATE
  Extracts AgERA5 data for given location and date range.

  AGERA5_PATH: path to the AgERA5 dataset
  LONGITUDE: the longitude for which to extract [dd, -180:180]
  LATITUDE: the latitude for which to extract [dd, -90:90]
  STARTDATE: the start date (yyyy-mm-dd, >=1979-01-01)
  ENDDATE: the last date (yyyy-mm-dd, <= 1 week ago)

Options:
  -o, --output PATH  output file to write to: .csv, .json and .db3 (SQLite)
                     are supported.Giving no output will write to stdout in
                     CSV format

  --tocelsius        Convert temperature values from degrees Kelvin to Celsius
  --help             Show this message and exit.

Dump

$ agera5tools dump --help
Usage: agera5tools dump [OPTIONS] AGERA5_PATH DAY

  Dump AgERA5 data for a given day to CSV, JSON or SQLite

  AGERA5_PATH: Path to the AgERA5 dataset
  DAY: specifies the day to be dumped (yyyy-mm-dd)

Options:
  -o, --output PATH  output file to write to: .csv, .json and .db3 (SQLite)
                     are supported. Giving no output will write to stdout in
                     CSV format

  --tocelsius        Convert temperature values from degrees Kelvin to Celsius
  --add_gridid       Adds a grid ID instead of latitude/longitude columns.
  --bbox FLOAT...    Bounding box: <lon_min> <lon_max> <lat_min< <lat max>
  --help             Show this message and exit.

Clip

$ agera5tools clip --help
Usage: agera5tools clip [OPTIONS] AGERA5_PATH DAY

  Extracts a portion of agERA5 for the given bounding box and saves to
  NetCDF.

  AGERA5_PATH: Path to the AgERA5 dataset
  DAY: specifies the day to be dumped (yyyy-mm-dd)

Options:
  --base_fname TEXT      Base file name to use, otherwise will use
                         'agera5_clipped'

  -o, --output_dir PATH  Directory to write output to. If not provided, will
                         use current directory.

  --box FLOAT...         Bounding box: <lon_min> <lon_max> <lat_min< <lat max>
  --help                 Show this message and exit.

dump_grid

Usage: agera5tools dump_grid [OPTIONS]

  Dump the agERA5 grid to a CSV, JSON or SQLite DB.

Options:
  -o, --output PATH  output file to write to: .csv, .json and .db3 (SQLite)
                     are supported.Giving no output will write to stdout in
                     CSV format

  --help             Show this message and exit.

Python package

The shell commands described above can also be used from python directly by importing the agera5tools package.
Their working is nearly identical as the shell commands. The major difference is that the python functions
return either datasets (clip) or dataframes (extract_point, dump, dump_grid). An example for the clip function:

In [1]: import datetime as dt
   ...: import agera5tools
   ...: from agera5tools.util import BoundingBox
   ...: day = dt.date(2018,1,1)
   ...: bbox = BoundingBox(lon_min=87, lon_max=90, lat_min=24, lat_max=27)
   ...: ds = agera5tools.clip(day, bbox)
   ...: 

In [2]: ds
Out[2]: 
<xarray.Dataset>
Dimensions:                            (time: 1, lon: 30, lat: 30)
Coordinates:
  * time                               (time) datetime64[ns] 2018-01-01
  * lon                                (lon) float64 87.1 87.2 ... 89.9 90.0
  * lat                                (lat) float64 26.9 26.8 ... 24.1 24.0
Data variables:
    Precipitation_Flux                 (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
    Solar_Radiation_Flux               (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
    Temperature_Air_2m_Max_Day_Time    (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
    Temperature_Air_2m_Mean_24h        (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
    Temperature_Air_2m_Min_Night_Time  (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
    Vapour_Pressure_Mean               (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
    Wind_Speed_10m_Mean                (time, lat, lon) float32 dask.array<chunksize=(1, 30, 30), meta=np.ndarray>
Attributes:
    CDI:          Climate Data Interface version 1.9.2 (http://mpimet.mpg.de/...
    history:      Fri Mar 12 15:04:43 2021: cdo splitday /archive/ESG/wit015/...
    Conventions:  CF-1.7
    CDO:          Climate Data Operators version 1.9.2 (http://mpimet.mpg.de/...

It works in a very similar way for the extract_point function:

In[6]: from agera5tools.util import Point

In[7]: pnt = Point(latitude=26, longitude=89)
In[8]: df = agera5tools.extract_point(pnt, startday=dt.date(2018, 1, 1), endday=dt.date(2018, 1, 31)),
In [7]: df.head(5)
Out[7]: 
          day  precipitation_flux  solar_radiation_flux  ...  temperature_air_2m_min_night_time  vapour_pressure_mean  wind_speed_10m_mean
0  2018-01-01                0.31              13282992  ...                          12.156799             11.809731             1.317589
1  2018-01-02                1.91              13646220  ...                          12.342041             11.711860             1.416075
2  2018-01-03                0.14              14817991  ...                          11.064514             11.198871             1.524268
3  2018-01-04                0.03              14131904  ...                          10.861877             11.413278             1.566405
4  2018-01-05                0.07              14315206  ...                          12.292969             10.984181             1.597181

[5 rows x 8 columns]

Note that extracting point data for a long timeseries can be time-consuming because all netCDF files have to be opened, decompressed and the point extracted.

Installing agera5tools

Requirements

The agera5tools package requires python >=3.8 and has a number of dependencies:

  • pandas == 1.4.1
  • PyYAML >= 6.0
  • Pandas >= 1.5
  • SQLAlchemy >= 1.4
  • PyYAML >= 6.0
  • xarray >= 2022.12.0
  • dask >= 2022.7.0
  • click >= 8.1
  • flask >= 2.2
  • cdsapi >= 0.5.1
  • dotmap >= 1.3
  • netCDF4 >= 1.6
  • requests >= 2.28
  • wsgiserver >= 1.3
  • duckdb >= 1.1.3
  • duckdb_engine >= 0.13.6

Lower versions of dependencies may work, but have not been tested.

Installing

Installing agera5tools can be done through the github repository to get the latest version:

pip install https://github.com/ajwdewit/agera5tools/archive/refs/heads/main.zip

or directory from PyPI:

pip install agera5tools

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 1 day ago

Total Commits: 68
Total Committers: 1
Avg Commits per committer: 68.0
Development Distribution Score (DDS): 0.0

Commits in past year: 29
Committers in past year: 1
Avg Commits per committer in past year: 29.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Wit, Allard de a****t@w****l 68

Committer domains:


Issue and Pull Request metadata

Last synced: 1 day ago

Total issues: 5
Total pull requests: 0
Average time to close issues: 2 months
Average time to close pull requests: N/A
Total issue authors: 4
Total pull request authors: 0
Average comments per issue: 1.6
Average comments per pull request: 0
Merged pull request: 0
Bot issues: 0
Bot pull requests: 0

Past year issues: 2
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 1
Past year pull request authors: 0
Past year average comments per issue: 0.0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/ajwdewit/agera5tools

Top Issue Authors

  • braza2 (2)
  • frank0434 (1)
  • lwq-star (1)
  • krsnapaudel (1)

Top Pull Request Authors


Top Issue Labels

Top Pull Request Labels


Package metadata

pypi.org: agera5tools

AgERA5 is a tool for handling AgERA5 data from the Copernicus Climate Data Store.

  • Homepage: https://github.com/ajwdewit/agera5tools
  • Documentation: https://agera5tools.readthedocs.io/
  • Licenses: MIT License Copyright (c) 2021 Allard de Wit Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 2.1.1 (published 2 months ago)
  • Last Synced: 2025-04-29T14:30:38.643Z (1 day ago)
  • Versions: 17
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 969 Last month
  • Rankings:
    • Dependent packages count: 10.118%
    • Downloads: 15.172%
    • Average: 16.747%
    • Stargazers count: 17.743%
    • Forks count: 19.152%
    • Dependent repos count: 21.552%
  • Maintainers (1)

Dependencies

pyproject.toml pypi
requirements.txt pypi
  • Flask >=2.2
  • PyYAML >=6.0
  • SQLAlchemy >=1.4,<2.0
  • WSGIserver >=1.3
  • cdsapi >=0.5
  • click >=8.0
  • dotmap >=1.3
  • pandas >=1.3
  • requests >=2.28
  • xarray >=2022.11
doc/requirements.txt pypi
  • sphinx *
  • sphinx_rtd_theme *

Score: 9.711539812347542