Concept • Installation • Example • Testing
Covjsonkit is an ECMWF library for encoding and decoding coverageJSON files/objects of meteorlogical features such as vertical profiles and time series.
- Encodes and decodes CoverageJSON objects
- Convert CoverageJSON files to and from xarray
- Works in conjunction with ECMWFs Polytope feature extraction library
Current features implemented:
- Time Series
- Vertical Profile
- Bounding Box
- Frame
- Path
- Wkt Polygons
- Shapefiles
Install the covjsonkit with Python 3 (>=3.7) from GitHub directly with the command
python3 -m pip install git+ssh://git@github.com/ecmwf/covjsonkit.git@develop
or from PyPI with the command
python3 -m pip install covjsonkit
The library consists of an encoder and a decoder element. The decoder can be used to decode valid coverageJSON files that can be then be edited and accessed via the api. It can also be used to convert to ther formats such as xarray.
from covjsonkit.api import Covjsonkit
decoder = Covjsonkit().decode(coverage.covjson)
print(decoder.type)
print(decoder.parameters)
print(decoder.get_referencing())
ds = decoder.to_xarray()
The following example encodes data output from the polytope feature extraction library assuming polytope_output is a valid output from polytope.
from covjsonkit.api import Covjsonkit
encoder = Covjsonkit().encode("CoverageCollection", "BoundingBox")
res = encoder.from_polytope(polytope_output)
Covjsonkit uses a config to determine what parameter metadata to use, an example can be found in example_config.json. This will automatically be loaded at runtime to point to the correct parameter metadata files.
The example config has to be stored in one of the following places:
- System-wide configuration in /etc/covjsonkit/config.json (and yaml)
- User configuration in ~/.covjsonkit.json (and yaml)
Users can add their own parameter metadata in the data directory by add ing a new directory containing a param.json, param_id.json, and units.json in a format the same as can be found in ecmwf directory. Then edit the config to point to your newly named directory.
If users want to pass in their own config tehy can do this as a python dictioanry in the following way:
encoder = Covjsonkit(cf).encode("CoverageCollection", "BoundingBox")
Where cf
is a valid covjsonkit config.
Python unit tests can be run with pytest:
python -m pytest
When a pull request is merged into develop or main a github actions CI pipeline is triggered to test formatting and unit tests.