8000 GitHub - ecmwf/polytope-mars: High level interface to polytope for meteorological feature extraction using the MARS language · GitHub
[go: up one dir, main page]

Skip to content

About

High level interface to polytope for meteorological feature extraction using the MARS language

Topics

Resources

Stars

4 stars

Watchers

11 watching

Forks

Repository files navigation


Polytope-mars

ci Project Maturity

Concept • Installation • Example • Testing

Concept

Repository for high level API of polytope feature extraction such as vertical profile and time series.

Current features include:

Important

This software is Incubating and subject to ECMWF's guidelines on Software Maturity.

Installation

pip install polytope-mars

Or clone the repo and install locally

git clone git@github.com:ecmwf/polytope-mars.git
cd polytope-mars

pip install -e .

Example

Create time series request: Create a request for a time series request using the time series feature, set options for use by polytope feature extraction. "gribjump" indicates the type of data in this case. NB: Assumes data is in a local FDB or or environment variables have been set up to point to a gribjump server.

from polytope_mars.api import PolytopeMars

request = {
    "class": "od",
    "stream" : "enfo",
    "type" : "pf",
    "date" : "20231205",
    "time" : "00:00:00",
    "levtype" : "sfc",
    "expver" : "0001",
    "domain" : "g",
    "param" : "228/49/164/165/166/167",
    "number" : "1/to/5",
    "step" : "0/1"
    "feature" : {
        "type" : "timeseries",
        "points" : [[51.5073219, 2.1]],
        "axis" : "step",
    },
}

result = PolytopeMars().extract(request)

If the user provides no arguments to PolytopeMars then a config is loaded from the default locations:

  1. System-wide configuration in /etc/polytope_mars/config.json (and yaml)
  2. User configuration in ~/.polytope_mars.json (and yaml)

The user can also pass in a config as a python dictionary to PolytopeMars for a custom config at runtime.

from polytope_mars.api import PolytopeMars
from conflator import Conflator
from polytope_mars.config import PolytopeMarsConfig

conf = Conflator(app_name="polytope_mars", model=PolytopeMarsConfig).load()
cf = conf.model_dump()
cf["options"] = options

request = {
    "class": "od",
    "stream" : "enfo",
    "type" : "pf",
    "date" : "20231205",
    "time" : "00:00:00",
    "levtype" : "sfc",
    "expver" : "0001",
    "domain" : "g",
    "param" : "228/49/164/165/166/167",
    "number" : "1/to/5",
    "step" : "0/1"
    "feature" : {
        "type" : "timeseries",
        "points" : [[51.5073219, 2.1]],
        "axis" : "step",
    },
}

result = PolytopeMars(cf).extract(request)

A context dictionary can also be passed to PolytopeMars for logging.

Result will be a coverageJSON file with the requested data if it is available, further manipulation of the coverage can be made using covjsonkit.

Config

An example config can be found here example_config.json. This can be edited to change any of the fields. The config is made up of four main components.

  1. datacube: This option is used to set up what type of datacube is being used at the moment, currently only gribjump is supported.
  2. options These are the options used by polytope for interpreting the data available.
  3. encoders Settings of the output encoders: covjson.param_db, the parameter database names and units come from, covjson.max_fragment_bytes, and tensogram (fragment size, compression). See the configuration reference.
  4. limits What a request may cost: max_polygon_points, and the memory bounds of an extraction (memory_budget_bytes, which plans the units of area features, and max_tree_bytes, max_points_per_field, which refuse requests). See the configuration reference.

Streaming

Results are produced as a stream. For area features (bounding box, polygon, circle, frame, shapefile) the memory a request needs then depends on the size of one extraction unit, planned against limits.memory_budget_bytes, and not on the size of the answer; the same holds for trajectories over hdate; point features (time series, position, vertical profile, other trajectories) are fetched with one call that the budget does not split, and CovJSON holds those collections until the end. Use PolytopeMars.extract_stream(request) to get the output as bytes fragments (extract(request) still returns the whole CoverageJSON as a dict), and the format key (covjson, the default, or tensogram with pip install polytope-mars[tensogram]) to choose the output format. See Streaming for how it works, the errors and the output changes, and the developer guide.

Acknowledgements

Past and current funding and support is listed in the adjoining Acknowledgements.

About

High level interface to polytope for meteorological feature extraction using the MARS language

Topics

Resources

Stars

4 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0