Skip to content

Commit 7a61848

Browse files
committed
use xarray for date parsing when CDO fails
1 parent 67fabaa commit 7a61848

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

nctoolkit/show.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22
from dateutil.parser import parse
3+
import xarray as xr
34

45

56
def nc_times(ff):
@@ -31,7 +32,12 @@ def nc_times(ff):
3132
cdo_result = [parse(x) for x in cdo_result]
3233
return cdo_result
3334
except:
34-
return cdo_result
35+
try:
36+
ds = xr.open_dataset(ff)
37+
times = list(ds.time.values)
38+
return times
39+
except:
40+
return cdo_result
3541

3642

3743
def nc_format(ff):

0 commit comments

Comments
 (0)