Skip to content

Commit

Permalink
WIP: adjust readers to new read method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Griesfeller committed Oct 30, 2024
1 parent 6a8b53b commit f54f9d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pyaro_readers/ascii2netcdf/Ascii2NetcdfTimeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(
:param filters: list of filters, defaults to []
"""
self._set_filters(filters)
self._revision = datetime.datetime.now()
if os.path.isdir(filename):
self._directory = filename
else:
Expand All @@ -70,6 +71,9 @@ def __init__(
if self._is_year_in_filters(year):
self._years.add(year)

self._metadata = self.metadata()

def read(self):
self._variables = self._read_file_variables()
station_file = "StationList.csv"
station_filepath = os.path.join(self._directory, station_file)
Expand All @@ -79,7 +83,7 @@ def __init__(
dirname = os.path.basename(self._directory)
station_file = dirname + station_file # e.g. AirbaseStationList.csv
station_filepath = os.path.join(self._directory, station_file)
if os.exists(station_filepath):
if os.path.exists(station_filepath):
self._stations = self._read_station_list(station_filepath)
else:
raise Ascii2NetcdfTimeseriesReaderException(
Expand Down Expand Up @@ -283,3 +287,7 @@ def description(self) -> str:

def url(self):
return "https://github.com/metno/pyaro-readers"

def read(self):
return self.reader_class().read()

3 changes: 3 additions & 0 deletions tests/test_Ascii2NetcdfTimeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_1open(self):
with pyaro.open_timeseries(
self.engine, EBAS_URL, resolution="daily", filters=[]
) as ts:
ts.read()
self.assertGreater(len(ts.variables()), 70)
self.assertGreater(len(ts.stations()), 300)

Expand All @@ -29,6 +30,7 @@ def test_2read(self):
with pyaro.open_timeseries(
self.engine, EBAS_URL, resolution="daily", filters=[]
) as ts:
ts.read()
data = ts.data("sulphur_dioxide_in_air")
self.assertIn("AM0001", data.stations)
self.assertGreater(np.sum(data.values), 10000)
Expand All @@ -45,6 +47,7 @@ def test_3read(self):
"stations": {"include": ["NO0002"]},
}, # Birkenes2
) as ts:
ts.read()
data = ts.data("sulphur_dioxide_in_air")
self.assertIn("NO0002", data.stations)
self.assertGreater(len(data), 360)
Expand Down

0 comments on commit f54f9d0

Please sign in to comment.