From d4abd2acc6fff35d204c1eb8b4bc94ac6bd88c59 Mon Sep 17 00:00:00 2001 From: lukas leufen <l.leufen@fz-juelich.de> Date: Thu, 28 Nov 2019 12:17:30 +0100 Subject: [PATCH] add station_type check for local stored data --- src/data_preparation.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/data_preparation.py b/src/data_preparation.py index 3030acfb..061eddc4 100644 --- a/src/data_preparation.py +++ b/src/data_preparation.py @@ -80,12 +80,20 @@ class DataPrep(object): data = self._slice_prep(xr.open_dataarray(file_name)) self.data = self.check_for_negative_concentrations(data) self.meta = pd.read_csv(meta_file, index_col=0) + if self.station_type is not None: + self.check_station_type() except FileNotFoundError as e: logging.warning(e) data, self.meta = self.download_data_from_join(file_name, meta_file) data = self._slice_prep(data) self.data = self.check_for_negative_concentrations(data) + def check_station_type(self): + if self.meta.at["station_type", self.station[0]] != self.station_type: + self.data = None + self.meta = None + raise join.EmptyQueryResult + def download_data_from_join(self, file_name: str, meta_file: str) -> [xr.DataArray, pd.DataFrame]: """ Download data from TOAR database using the JOIN interface. @@ -114,7 +122,7 @@ class DataPrep(object): def __repr__(self): return f"Dataprep(path='{self.path}', network='{self.network}', station={self.station}, " \ - f"variables={self.variables}, **{self.kwargs})" + f"variables={self.variables}, station_type='{self.station_type}', **{self.kwargs})" def interpolate(self, dim: str, method: str = 'linear', limit: int = None, use_coordinate: Union[bool, str] = True, **kwargs): -- GitLab