From 709e9bf035b3ac1fbb41dfb30c7648654b80c9f8 Mon Sep 17 00:00:00 2001 From: thorbjoernl <51087536+thorbjoernl@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:02:28 +0200 Subject: [PATCH] . --- setup.cfg | 2 +- src/pyaro/csvreader/CSVTimeseriesReader.py | 2 +- tests/test_CSVTimeSeriesReader.py | 71 +++++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 0cdc8d5..812b8b7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ install_requires = importlib-metadata >= 3.6; python_version < "3.10" xarray netcdf4 - cfunits + cf-units package_dir = =src packages = pyaro, pyaro.timeseries, pyaro.csvreader diff --git a/src/pyaro/csvreader/CSVTimeseriesReader.py b/src/pyaro/csvreader/CSVTimeseriesReader.py index 4b0833c..07120f8 100644 --- a/src/pyaro/csvreader/CSVTimeseriesReader.py +++ b/src/pyaro/csvreader/CSVTimeseriesReader.py @@ -180,7 +180,7 @@ def col_keys(cls): """ return cls._col_keys - def metadata(self) -> dict(): + def metadata(self) -> dict: return self._metadata def _unfiltered_data(self, varname) -> Data: diff --git a/tests/test_CSVTimeSeriesReader.py b/tests/test_CSVTimeSeriesReader.py index 912e346..81f14e7 100644 --- a/tests/test_CSVTimeSeriesReader.py +++ b/tests/test_CSVTimeSeriesReader.py @@ -534,7 +534,7 @@ def test_relaltitude_filter_emep_2(self): "flag": "0", } ) as ts: - # At rdiff = 0.89, only the first station should be included. + # At rdiff = 90, only the first station should be included. self.assertEqual(len(ts.stations()), 1) def test_relaltitude_filter_emep_3(self): @@ -557,9 +557,76 @@ def test_relaltitude_filter_emep_3(self): "flag": "0", } ) as ts: - # Since rdiff=1, all stations should be included. + # Since rdiff=300, all stations should be included. self.assertEqual(len(ts.stations()), 3) + def test_relaltitude_filter_1(self): + engines = pyaro.list_timeseries_engines() + with engines["csv_timeseries"].open( + filename=self.elevation_file, + filters=[pyaro.timeseries.filters.get("relaltitude", topo_file = "./tests/testdata/datadir_elevation/topography.nc", rdiff=0)], + columns={ + "variable": 0, + "station": 1, + "longitude": 2, + "latitude": 3, + "value": 4, + "units": 5, + "start_time": 6, + "end_time": 7, + "altitude": 9, + "country": "NO", + "standard_deviation": "NaN", + "flag": "0", + } + ) as ts: + self.assertEqual(len(ts.stations()), 0) + + def test_relaltitude_filter_2(self): + engines = pyaro.list_timeseries_engines() + with engines["csv_timeseries"].open( + filename=self.elevation_file, + filters=[pyaro.timeseries.filters.get("relaltitude", topo_file = "./tests/testdata/datadir_elevation/topography.nc", rdiff=90)], + columns={ + "variable": 0, + "station": 1, + "longitude": 2, + "latitude": 3, + "value": 4, + "units": 5, + "start_time": 6, + "end_time": 7, + "altitude": 9, + "country": "NO", + "standard_deviation": "NaN", + "flag": "0", + } + ) as ts: + # At rdiff = 90, only the first station should be included. + self.assertEqual(len(ts.stations()), 1) + + def test_relaltitude_filter_3(self): + engines = pyaro.list_timeseries_engines() + with engines["csv_timeseries"].open( + filename=self.elevation_file, + filters=[pyaro.timeseries.filters.get("relaltitude", topo_file = "./tests/testdata/datadir_elevation/topography.nc", rdiff=300)], + columns={ + "variable": 0, + "station": 1, + "longitude": 2, + "latitude": 3, + "value": 4, + "units": 5, + "start_time": 6, + "end_time": 7, + "altitude": 9, + "country": "NO", + "standard_deviation": "NaN", + "flag": "0", + } + ) as ts: + # Since rdiff=300, all stations should be included. + self.assertEqual(len(ts.stations()), 3)