From 9f81985da3b6648d08c7ac98334b08c73d3522de Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 17 Jan 2025 12:47:34 +0100 Subject: [PATCH 1/2] check if units are equivalent --- src/pyaro_readers/eeareader/EEATimeseriesReader.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pyaro_readers/eeareader/EEATimeseriesReader.py b/src/pyaro_readers/eeareader/EEATimeseriesReader.py index 3be04b6..faa84e3 100644 --- a/src/pyaro_readers/eeareader/EEATimeseriesReader.py +++ b/src/pyaro_readers/eeareader/EEATimeseriesReader.py @@ -8,6 +8,7 @@ from tqdm import tqdm import numpy as np +import cf_units import polars from pyaro.timeseries.AutoFilterReaderEngine import ( AutoFilterReader, @@ -39,7 +40,13 @@ def units(self) -> str: if len(units) == 0: raise EEAReaderException("No units present in this dataset") elif len(units) != 1: - raise EEAReaderException("Multiple different units present in this dataset") + base_unit = cf_units.Unit(units[0]) + for unit in units[1:]: + if base_unit.convert(1, unit) != 1.0: + raise EEAReaderException( + f"Multiple different units present in this dataset ({units[0]} and {unit})" + ) + return units[0] def keys(self): From 848d21dcff8a157e3da5b2e7ca1ff8c5fa366407 Mon Sep 17 00:00:00 2001 From: Daniel Heinesen Date: Fri, 17 Jan 2025 12:15:46 +0000 Subject: [PATCH 2/2] Adds correct version of cf units to setup --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 8f6034d..d43e43f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,6 +29,7 @@ install_requires = numpy xarray cfunits + cf-units polars[pyarrow] tomli>=2.0.1; python_version < "3.11"