diff --git a/pet-wrapper-api.py b/pet-wrapper-api.py index 94c4ef635997a544afda111f2ccced7d4217cdd8..02a390b865db01eceabdb347d7f69ed49fb6e992 100644 --- a/pet-wrapper-api.py +++ b/pet-wrapper-api.py @@ -139,9 +139,34 @@ class PET(plugin.PluginAbstract): name="debug", default=False, help="Turn on to get better detailed debug information in case you face any issue." - ) + ), ) + def find_orog(self, config_dict): + ''' + Retrieves a list of orographic files based on given facets and returns first entry as suggestion + + Parameters: + config_dict (dict): Dictionary containing facet values to search database + Returns: + orog_files[0] (string): First entry of list of found files + ''' + facets = ["product", "institute", "model", "experiment", "ensemble"] + #search_args = {"project": config_dict["project"], "variable": "orog"} for later if project facte is given + search_args = {"project": "nukleus", "variable": "orog"} + orog_files = list(freva.databrowser(**search_args)) + + for facet in facets: + search_args[facet] = config_dict[facet] + file_number = freva.count_values(**search_args) + + # if there are results, keep them and the facet + if (file_number > 0): + orog_files = list(freva.databrowser(**search_args)) + else: + del search_args[facet] + + return orog_files[0] def find_files(self, config_dict, variables: List[str], time_frequency: str, time: Optional[str] = None): ''' @@ -157,7 +182,7 @@ class PET(plugin.PluginAbstract): ''' search_keys = ( - # "project", + #"project", "product", "institute", "model", @@ -173,8 +198,6 @@ class PET(plugin.PluginAbstract): file_dict = {} for variable in variables: search_args["variable"] = variable - if variable == "orog": - del search_args["ensemble"] ## orog files are part of another ensemble than the other variables files = list(freva.databrowser(**search_args)) file_dict[variable] = files @@ -317,7 +340,7 @@ class PET(plugin.PluginAbstract): def run_tool(self, config_dict=None): config_dict["files"] = self.find_files(config_dict, ["tasmax", "tasmin", "sfcWind", "pvap", "rsds"], "day", config_dict["start_date"] + " to " + config_dict["end_date"]) - config_dict["alti_file"] = self.find_files(config_dict, ["orog"], "fx")["orog"] + config_dict["alti_file"] = self.find_orog(config_dict) if "alti_file" not in config_dict or not config_dict["alti_file"]: logger.error("Can't find altitude file")