diff --git a/ecml_tools/data.py b/ecml_tools/data.py index ba4f1e1..737b10b 100644 --- a/ecml_tools/data.py +++ b/ecml_tools/data.py @@ -119,6 +119,7 @@ def __init__(self, path): self.z = path else: self.path = path + print(path) self.z = zarr.convenience.open(path, "r") def __len__(self): @@ -137,11 +138,19 @@ def dates(self): @property def latitudes(self): - return self.z.latitudes[:] + try: + return self.z.latitudes[:] + except AttributeError: + LOG.warning("No 'latitudes' in %r, trying 'latitude'", self) + return self.z.latitude[:] @property def longitudes(self): - return self.z.longitudes[:] + try: + return self.z.longitudes[:] + except AttributeError: + LOG.warning("No 'longitudes' in %r, trying 'longitude'", self) + return self.z.longitude[:] @property def statistics(self): @@ -153,7 +162,13 @@ def resolution(self): @property def frequency(self): - return self.z.attrs["frequency"] + try: + return self.z.attrs["frequency"] + except KeyError: + LOG.warning("No 'frequency' in %r, computing from 'dates'", self) + dates = self.dates + delta = dates[1].astype(object) - dates[0].astype(object) + return delta.total_seconds() // 3600 @property def name_to_index(self): diff --git a/test.py b/test.py index 55254f3..da4d496 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,6 @@ from ecml_tools.data import open_dataset -name = "aifs-od-an-oper-0001-mars-o96-2021-6h-v2" +name = "aifs-ea-an-oper-0001-mars-o96-2021-6h-v2-only-z" # aifs-od-an-oper-0001-mars-o96-2021-6h-v2" z = open_dataset(name)