Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Sep 21, 2023
1 parent e75da3f commit 95b8898
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions ecml_tools/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down

0 comments on commit 95b8898

Please sign in to comment.