Lyra is a Python library for parsing and transforming JSON-based forms into Python code. It provides tools to parse form definitions and generate corresponding Python code, facilitating the handling of data from the Climate Data Store (CDS) in Python applications.
To install Lyra, clone the repository and install the required dependencies:
git clone https://github.com/joangq/lyra
cd lyra
pip install -r requirements.txt
Here's a simple example of how to use Lyra to download data using the cds_collections
module:
from lyra import cds_collections
cds_collections.reanalysis_era5_single_levels.download(
product_type = "reanalysis",
data_format = "netcdf",
variable = "2m_temperature",
year = "2020",
month = "01",
day = "01",
time = "12:00",
)
This example demonstrates how to use the generated functions in cds_collections
to request data directly from the CDS and save it to a file.
Lyra processes JSON form definitions from the CDS and transforms them into Python code that can be used to interact with the CDS API. The process involves three main components:
-
Parser: The parser, implemented in
lyra.parser
, reads the JSON form definitions and creates an abstract syntax tree (AST) representation. -
Transformer: The transformer, found in
lyra.transformer
, takes the AST and transforms it into an intermediate representation suitable for code generation. -
Translator: The translator, located in
lyra.translator
, generates Python code from the intermediate representation, producing a set of functions that mirror the data request forms on the CDS.
This automated process allows users to interact with the CDS programmatically, without having to manually construct API requests.
The Lyra repository is organized as follows:
Lyra/
├── src/ # Main code (notebooks + library)
│ └── lyra/ # Library code
│ ├── parser/ # - JSON Form to AST parser
│ ├── transformer/ # - AST to intermediate representation
│ ├── translator/ # - IR to Python code (target cds_collections/)
│ ├── cds_collections/ # - Autogenerated target
│ └── auth/ # - Wrapper for dotenv-based authentication
├── data/ # Example forms from the CDS.
├── tests/ # Unit tests
├── assets/ # Graphical assets
└── .env # Expected environament variables file.
lyra by Joan Gonzalez is licensed under CC BY 4.0