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/setupFunctions.py b/toargridding/setupFunctions.py new file mode 100644 index 0000000000000000000000000000000000000000..08ff791e5de05731370d17675c12c83cc2b07476 --- /dev/null +++ b/toargridding/setupFunctions.py @@ -0,0 +1,13 @@ +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 diff --git a/toargridding/static_metadata.py b/toargridding/static_metadata.py index 71789d544b62106cb41c2a3d46d22e3f39a1bafc..dfca7efc9c1ac2a99f4177071a57ed7a19f5dc1c 100644 --- a/toargridding/static_metadata.py +++ b/toargridding/static_metadata.py @@ -59,13 +59,15 @@ class TOARVariable: 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.standard_name == name or var.name== name: - return var - else: - raise ValueError(f"TOAR Database contains no variable {name}") + #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