diff --git a/README.md b/README.md index dbd1511a8aecc86f89d823201b7751bed318d56c..97bc4cfb6ff8ff79957dfec3a13782c4efb0c237 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,8 @@ The first supported grid is a regular grid with longitude and latitude. # 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 diff --git a/toargridding/gridding.py b/toargridding/gridding.py index 5523c9e84779adacfcbe1967c039e12f654d99bc..1d645a29439844a51c11270f3d9ba8b7be51487a 100644 --- a/toargridding/gridding.py +++ b/toargridding/gridding.py @@ -41,7 +41,7 @@ def get_gridded_toar_data( """ metadatas = [ - Metadata.construct(standart_name=var, time=time, stat=stat, moreOptions=kwargs) for var, stat in product(variables, stats) + Metadata.construct(standard_name=var, time=time, stat=stat, moreOptions=kwargs) for var, stat in product(variables, stats) ] datasets = [] diff --git a/toargridding/metadata.py b/toargridding/metadata.py index af46d09a75a1508fda8989d34ba2c81610a04b8c..627f1167ceca07b351c8f12058c3c52a5c817755 100644 --- a/toargridding/metadata.py +++ b/toargridding/metadata.py @@ -111,7 +111,7 @@ class Metadata: moreOptions : Dict = field(default_factory=lambda: {}) @staticmethod - def construct(standart_name: str, time: TimeSample, stat: str, moreOptions : Dict = {}): + def construct(standard_name: str, time: TimeSample, stat: str, moreOptions : Dict = {}): """constructor Parameters: @@ -126,7 +126,7 @@ class Metadata: collection of additional query options for the REST API. """ - variable = TOARVariable.get(standart_name) + variable = TOARVariable.get(standard_name) return Metadata(variable, time, stat, moreOptions) @property diff --git a/toargridding/setupFunctions.py b/toargridding/setupFunctions.py new file mode 100644 index 0000000000000000000000000000000000000000..1348f4950900bfa743da4152faba98ec00f46d56 --- /dev/null +++ b/toargridding/setupFunctions.py @@ -0,0 +1,14 @@ +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") + response.raise_for_status()#check, for errors. + varList = response.json() + with open(TOAR_VARIABLES_METADATA_PATH, "w") as f: + json.dump(varList, f, indent=2) \ No newline at end of file diff --git a/toargridding/static_metadata.py b/toargridding/static_metadata.py index adf6566a301795d1e71f90c9d983442f2fc36137..dfca7efc9c1ac2a99f4177071a57ed7a19f5dc1c 100644 --- a/toargridding/static_metadata.py +++ b/toargridding/static_metadata.py @@ -47,22 +47,65 @@ class TOARVariable: cls.vars = [TOARVariable(**var) for var in variables] @classmethod - def get(cls, standart_name: str) -> "TOARVariable": + def get(cls, name: str) -> "TOARVariable": """searches the known variables for the requested variable Parameters: ---------- - standart_name: + name: name of the variable following the CF convention. + For each variable first, the cf_standardname is checked and afterwards the name field. return: provides direct access to the meta data of the selected variable """ + #TODO: update README + try: + return cls.get_from_cf_standardname(standard_name=name) + except ValueError as e: + pass + try: + 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 + def get_from_cf_standardname(cls, standard_name: str) -> "TOARVariable": + """searches the known variables for the given cf_standardname + + Parameters: + ---------- + standard_name: + name of the variable following the CF convention. + + return: + provides direct access to the meta data of the selected variable + """ + if standard_name == "" or standard_name == None: + raise ValueError("No name provided for variable.") + for var in cls.vars: + if var.standard_name == standard_name: + return var + else: + raise ValueError(f"TOAR Database contains no variable with cf_standardname {standard_name}") + @classmethod + def get_from_name(cls, name: str) -> "TOARVariable": + """searches the known variables for the given name + + Parameters: + ---------- + name: + name of the variable according to the TOAR database config + + return: + provides direct access to the meta data of the selected variable + """ + if name == "" or name == None: + raise ValueError("No name provided for variable.") for var in cls.vars: - if var.standart_name == standart_name: + if var.name==name: return var else: - raise ValueError(f"TOAR Database contains no variable {standart_name}") + raise ValueError(f"TOAR Database contains no variable {name}") @property def toar_id(self): @@ -71,7 +114,7 @@ class TOARVariable: return self.id @property - def standart_name(self): + def standard_name(self): """alias to get cf_standardname """ return self.cf_standardname