Skip to content

Commit

Permalink
Adds possiblity to add unit conversion in data toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Heinesen committed Sep 13, 2024
1 parent acb3ed5 commit 1cfdf6d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pyaro_readers/eeareader/EEATimeseriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def _read_polars(self, filters, filename) -> None:
continue

file_unit = self._convert_unit(df.row(0)[df.get_column_index("Unit")])
if s in self.datafile["changeunit"]:
file_unit = self.datafile["changeunit"][s]["unit"]
df.with_columns((polars.col(PARQUET_FIELDS["values"]) * self.datafile["changeunit"][s]["factor"]).alias(PARQUET_FIELDS["values"]))

for key in PARQUET_FIELDS:
array[key][
Expand Down
2 changes: 2 additions & 0 deletions src/pyaro_readers/eeareader/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"ugso2.m-3" = "µg SO2/m3"
"nm" = "nm"

[changeunit]
"SO4--" = { unit = "µg /m3", factor = 2995.82 }

[pollutant]
1 = "SO2"
Expand Down
9 changes: 9 additions & 0 deletions src/pyaro_readers/eeareader/utils/generate_data_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"HNO3",
]

changeunit = {
"SO4--" : '{ unit = "µg /m3", factor = 2995.82 }'
}

with open("response.json", "r") as f:
properties = {}
data = json.load(f)
Expand All @@ -56,6 +60,11 @@
target.write(f'"{poll}",\n')
target.write("]\n\n")

target.write('[changeunits]\n')
for s in changeunit:
target.write(f'"{s}" = {changeunit[s]}\n')
target.write("]\n\n")

target.write("[units]\n")
for key in response:
target.write(f'"{key.lower()}" = {response[key]}\n')
Expand Down

0 comments on commit 1cfdf6d

Please sign in to comment.