Skip to content
Snippets Groups Projects
Commit 5dd597d9 authored by lukas leufen's avatar lukas leufen
Browse files

Merge branch 'lukas_issue444_feat_choose-interp-method-cams' into...

Merge branch 'lukas_issue444_feat_choose-interp-method-cams' into 'lukas_issue442_feat_bias-free-evaluation'

use different interp methods for cams

See merge request !505
parents 43efa786 f8ed17e5
Branches
Tags
5 merge requests!522filter can now combine obs, forecast, and apriori for first iteration. Further...,!521Resolve "release v2.4.0",!505use different interp methods for cams,!504Draft: Resolve "choose interp method in CAMS competitor",!503Resolve "bias free evaluation"
Pipeline #128587 passed
...@@ -11,7 +11,16 @@ import pandas as pd ...@@ -11,7 +11,16 @@ import pandas as pd
class CAMSforecast(AbstractReferenceModel): class CAMSforecast(AbstractReferenceModel):
def __init__(self, ref_name: str, ref_store_path: str = None, data_path: str = None): def __init__(self, ref_name: str, ref_store_path: str = None, data_path: str = None, interp_method: str = None):
"""
Use parameters `cams_data_path` to set `data_path` and `cams_interp_method` to set `interp_method` in MLAir
run script.
:param ref_name:
:param ref_store_path:
:param data_path:
:param interp_method:
"""
super().__init__() super().__init__()
self.ref_name = ref_name self.ref_name = ref_name
...@@ -22,6 +31,7 @@ class CAMSforecast(AbstractReferenceModel): ...@@ -22,6 +31,7 @@ class CAMSforecast(AbstractReferenceModel):
self.data_path = os.path.abspath(".") self.data_path = os.path.abspath(".")
else: else:
self.data_path = os.path.abspath(data_path) self.data_path = os.path.abspath(data_path)
self.interp_method = interp_method
self.file_pattern = "forecasts_%s_test.nc" self.file_pattern = "forecasts_%s_test.nc"
self.time_dim = "index" self.time_dim = "index"
self.ahead_dim = "ahead" self.ahead_dim = "ahead"
...@@ -36,7 +46,11 @@ class CAMSforecast(AbstractReferenceModel): ...@@ -36,7 +46,11 @@ class CAMSforecast(AbstractReferenceModel):
darray = dataset.to_array().sortby(["longitude", "latitude"]) darray = dataset.to_array().sortby(["longitude", "latitude"])
for station, coords in missing_stations.items(): for station, coords in missing_stations.items():
lon, lat = coords["lon"], coords["lat"] lon, lat = coords["lon"], coords["lat"]
if self.interp_method is None:
station_data = darray.sel(longitude=lon, latitude=lat, method="nearest", drop=True).squeeze(drop=True) station_data = darray.sel(longitude=lon, latitude=lat, method="nearest", drop=True).squeeze(drop=True)
else:
station_data = darray.interp(**{"longitude": lon, "latitude": lat}, method=self.interp_method)
station_data = station_data.drop_vars(["longitude", "latitude"]).squeeze(drop=True)
station_data = station_data.expand_dims(dim={self.type_dim: [self.ref_name]}).compute() station_data = station_data.expand_dims(dim={self.type_dim: [self.ref_name]}).compute()
station_data.coords[self.time_dim] = station_data.coords[self.time_dim] - pd.Timedelta(days=1) station_data.coords[self.time_dim] = station_data.coords[self.time_dim] - pd.Timedelta(days=1)
station_data.coords[self.ahead_dim] = station_data.coords[self.ahead_dim] + 1 station_data.coords[self.ahead_dim] = station_data.coords[self.ahead_dim] + 1
......
...@@ -378,13 +378,23 @@ class PreProcessing(RunEnvironment): ...@@ -378,13 +378,23 @@ class PreProcessing(RunEnvironment):
elif competitor_name.lower() == "CAMS".lower(): elif competitor_name.lower() == "CAMS".lower():
logging.info("Prepare CAMS forecasts") logging.info("Prepare CAMS forecasts")
from mlair.reference_models.reference_model_cams import CAMSforecast from mlair.reference_models.reference_model_cams import CAMSforecast
interp_method = self.data_store.get_default("cams_interp_method", default=None)
data_path = self.data_store.get_default("cams_data_path", default=None) data_path = self.data_store.get_default("cams_data_path", default=None)
path = os.path.join(self.data_store.get("competitor_path"), competitor_name) path = os.path.join(self.data_store.get("competitor_path"), competitor_name)
stations = {} stations = {}
for subset in ["train", "val", "test"]: for subset in ["train", "val", "test"]:
data_collection = self.data_store.get("data_collection", subset) data_collection = self.data_store.get("data_collection", subset)
stations.update({str(s): s.get_coordinates() for s in data_collection if s not in stations}) stations.update({str(s): s.get_coordinates() for s in data_collection if s not in stations})
CAMSforecast("CAMS", ref_store_path=path, data_path=data_path).make_reference_available_locally(stations) if interp_method is None:
CAMSforecast("CAMS", ref_store_path=path, data_path=data_path, interp_method=None
).make_reference_available_locally(stations)
else:
competitors = remove_items(competitors, "CAMS")
for method in to_list(interp_method):
CAMSforecast(f"CAMS{method}", ref_store_path=path + method, data_path=data_path,
interp_method=method).make_reference_available_locally(stations)
competitors.append(f"CAMS{method}")
self.data_store.set("competitors", competitors)
else: else:
logging.info(f"No preparation required for competitor {competitor_name} as no specific instruction " logging.info(f"No preparation required for competitor {competitor_name} as no specific instruction "
f"is provided.") f"is provided.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment