Skip to content

Commit

Permalink
add testdata for elevation with third station, and test for both min …
Browse files Browse the repository at this point in the history
…and max elevation
  • Loading branch information
thorbjoernl committed Sep 4, 2024
1 parent 469c76e commit 8de1f82
Show file tree
Hide file tree
Showing 4 changed files with 554 additions and 215 deletions.
7 changes: 3 additions & 4 deletions src/pyaro/timeseries/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,10 @@ class AltitudeFilter(StationReductionFilter):

def __init__(self, min_altitude: float | None = None, max_altitude: float | None = None):
"""
:param min_altitude : float of minimum altitude in meters required to keep the station.
:param max_altitude : float of maximum altitude in meters required to keep the station.
:param min_altitude : float of minimum altitude in meters required to keep the station (inclusive).
:param max_altitude : float of maximum altitude in meters required to keep the station (inclusive).
Stations will be kept if min_altitude ≤ x ≤ max_altitude where x is the elevation of the
station. If station elevation is nan, it is always excluded.
If station elevation is nan, it is always excluded.
"""
if min_altitude is not None and max_altitude is not None:
if min_altitude > max_altitude:
Expand Down
34 changes: 31 additions & 3 deletions tests/test_CSVTimeSeriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class TestCSVTimeSeriesReader(unittest.TestCase):
"datadir",
"csvReader_testdata.csv",
)
elevation_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"testdata",
"datadir_elevation",
"csvReader_testdata_elevation.csv",
)
multifile = "glob:" + os.path.join(
os.path.dirname(os.path.realpath(__file__)), "testdata", "datadir", "**/*.csv"
)
Expand Down Expand Up @@ -417,7 +423,7 @@ def test_country_lookup(self):
def test_altitude_filter_1(self):
engines = pyaro.list_timeseries_engines()
with engines["csv_timeseries"].open(
filename=self.file,
filename=self.elevation_file,
filters=[pyaro.timeseries.filters.get("altitude", max_altitude=150)],
columns={
"variable": 0,
Expand All @@ -439,8 +445,30 @@ def test_altitude_filter_1(self):
def test_altitude_filter_2(self):
engines = pyaro.list_timeseries_engines()
with engines["csv_timeseries"].open(
filename=self.file,
filters=[pyaro.timeseries.filters.get("altitude", min_altitude=150)],
filename=self.elevation_file,
filters=[pyaro.timeseries.filters.get("altitude", min_altitude=250)],
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()), 1)

def test_altitude_filter_3(self):
engines = pyaro.list_timeseries_engines()
with engines["csv_timeseries"].open(
filename=self.elevation_file,
filters=[pyaro.timeseries.filters.get("altitude", min_altitude=150, max_altitude=250)],
columns={
"variable": 0,
"station": 1,
Expand Down
Loading

0 comments on commit 8de1f82

Please sign in to comment.