Skip to content

Commit

Permalink
stations() to return correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusuMET committed Nov 1, 2024
1 parent 69917b7 commit 80ff3f1
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/pyaro_readers/eeareader/EEATimeseriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Data,
Reader,
Engine,
Filter,
Station,
)
import pyaro.timeseries

Expand Down Expand Up @@ -326,18 +326,32 @@ def variables(self) -> list[str]:
common = set(pollutants).intersection(pollutants_metadata)
return list(sorted(common))

# TODO: Should return dict[str, Station]
def stations(self) -> list[str]:
stations = self._metadata.with_columns(
def stations(self) -> dict[str, Station]:
stations = self._metadata.with_columns((
(
polars.col("Country").map_elements(
_country_code_eea, return_dtype=str
)
+ "/"
+ polars.col("Sampling Point Id")
).alias("selector")
)["selector"]
return list(stations)
).alias("station"),
polars.col("Latitude").alias("latitude"),
polars.col("Longitude").alias("longitude"),
polars.col("Altitude").alias("altitude"),
polars.col("Country").map_elements(_country_code, return_dtype=str).alias("country"),
polars.col("Source Data URL").alias("url"),
(
polars.col("Country").map_elements(
_country_code_eea, return_dtype=str
)
+ "/"
+ polars.col("Sampling Point Id")
).alias("long_name"),
polars.col("Air Quality Station Area").alias("station_area"),
polars.col("Air Quality Station Type").alias("station_type"),
)).select(["station", "latitude", "longitude", "altitude", "country", "url", "station_area", "station_type", "long_name"])
station_dicts = {s["station"]: Station(s) for s in stations.to_dicts()}
return station_dicts

def close(self) -> None:
pass
Expand Down

0 comments on commit 80ff3f1

Please sign in to comment.