Skip to content
Snippets Groups Projects
Commit ed44723b authored by Carsten Hinz's avatar Carsten Hinz
Browse files

Changed functions and how to use

added an utility function to update the list of available variables.
Updated get function to reduce the number of repetitions

updated README
parent 8f2e6bce
No related branches found
No related tags found
2 merge requests!11Creation of first beta release version,!3fixed typo in standard name
...@@ -153,7 +153,8 @@ The first supported grid is a regular grid with longitude and latitude. ...@@ -153,7 +153,8 @@ The first supported grid is a regular grid with longitude and latitude.
# Supported Variables # Supported Variables
At the moment only a limited number of variables from the TOAR database is supported. This module supports all variables of the TOAR database (Extraction: 2024-05-27). They can be identified by their "cf_standardname" or their name as stored in the TOAR database.
The full list can be accesses by querying the TOAR database, e.g. with https://toar-data.fz-juelich.de/api/v2/variables/?limit=None
# Supported Time intervals # Supported Time intervals
......
from toargridding.static_metadata import TOAR_VARIABLES_METADATA_PATH
import requests
import json
def updateTOARVariables():
"""Download the most recent list of variables from the TOAR database
This overwrites the current static file
"""
response = requests.get("https://toar-data.fz-juelich.de/api/v2/variables/?limit=None")
varList = response.json()
with open(TOAR_VARIABLES_METADATA_PATH, "w") as f:
json.dump(varList, f, indent=2)
\ No newline at end of file
...@@ -59,13 +59,15 @@ class TOARVariable: ...@@ -59,13 +59,15 @@ class TOARVariable:
return: return:
provides direct access to the meta data of the selected variable provides direct access to the meta data of the selected variable
""" """
if name == "" or name == None: #TODO: update README
raise ValueError("No name provided for variable.") try:
for var in cls.vars: return cls.get_from_cf_standardname(standard_name=name)
if var.standard_name == name or var.name== name: except ValueError as e:
return var pass
else: try:
raise ValueError(f"TOAR Database contains no variable {name}") return cls.get_from_name(name=name)
except ValueError as e:
raise ValueError(f"TOAR Database contains no variable with cf_standardname or name '{name}'")
@classmethod @classmethod
def get_from_cf_standardname(cls, standard_name: str) -> "TOARVariable": def get_from_cf_standardname(cls, standard_name: str) -> "TOARVariable":
"""searches the known variables for the given cf_standardname """searches the known variables for the given cf_standardname
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment