Skip to content

Commit

Permalink
Updates units
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Heinesen committed Sep 13, 2024
1 parent a6d13d6 commit acb3ed5
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 275 deletions.
17 changes: 16 additions & 1 deletion src/pyaro_readers/eeareader/EEATimeseriesReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
Station,
)

try:
import tomllib
except ImportError: # python <3.11
import tomli as tomllib

FLAGS_VALID = {-99: False, -1: False, 1: True, 2: False, 3: False, 4: True}
VERIFIED_LVL = [1, 2, 3]
DATA_TOML = Path(__file__).parent / "data.toml"
Expand Down Expand Up @@ -73,6 +78,7 @@ def __init__(
self._set_filters(filters)

self.metadata = self._read_metadata(filename)
self.datafile = self._read_data()

self._read_polars(filters, filename)

Expand Down Expand Up @@ -167,7 +173,7 @@ def _read_polars(self, filters, filename) -> None:
except:
continue

file_unit = df.row(0)[df.get_column_index("Unit")]
file_unit = self._convert_unit(df.row(0)[df.get_column_index("Unit")])

for key in PARQUET_FIELDS:
array[key][
Expand Down Expand Up @@ -248,6 +254,15 @@ def _read_metadata(self, folder: str) -> dict:
}

return metadata

def _read_data(self) -> dict:
with open(DATA_TOML, "rb") as f:
data = tomllib.load(f)
return data

def _convert_unit(self, unit: str) -> str:
return self.datafile["units"][unit]


def _unfiltered_data(self, varname) -> Data:
return self._data[varname]
Expand Down
Loading

0 comments on commit acb3ed5

Please sign in to comment.