Unsorted time coordinate
When I load 52 files of monthly data (from VIKING20X) with load_xorca_dataset
, the resulting time coordinate is not sorted.
ds = load_xorca_dataset(data_files=glob('/gfs2/work/shkifmjr/VIKING20X/VIKING20X.L46-KKG36013H/'
+ '1_VIKING20X.L46-KKG36013H_1m_????0101_????1231_grid_T.nc'),
aux_files=meshmask2,
...
ds.t.data
array(['2005-01-16T00:00:00.000000000', '2005-02-12T11:58:55.000000000',
'2005-03-11T23:57:52.000000000', '2005-04-16T00:00:00.000000000',
'2005-05-16T00:00:00.000000000', '2005-06-15T00:00:00.000000000',
'2005-07-15T00:00:00.000000000', '2005-08-14T00:00:00.000000000',
'2005-09-13T00:00:00.000000000', '2005-10-13T00:00:00.000000000',
'2005-11-12T00:00:00.000000000', '2005-12-12T00:00:00.000000000',
'2004-01-15T23:57:52.000000000', '2004-02-12T12:01:04.000000000',
'2004-03-12T00:00:00.000000000', '2004-04-16T00:02:07.000000000',
'2004-05-15T23:57:52.000000000', '2004-06-15T00:02:07.000000000',
'2004-07-14T23:57:52.000000000', '2004-08-14T00:02:07.000000000',
'2004-09-12T23:57:52.000000000', '2004-10-13T00:02:07.000000000',
'2004-11-11T23:57:52.000000000', '2004-12-12T00:02:07.000000000',
'1994-01-16T00:02:07.000000000', '1994-02-12T12:01:04.000000000',
'1994-03-12T00:00:00.000000000', '1994-04-15T23:57:52.000000000',
'1994-05-16T00:02:07.000000000', '1994-06-14T23:57:52.000000000',
'1994-07-15T00:02:07.000000000', '1994-08-13T23:57:52.000000000',
'1994-09-13T00:02:07.000000000', '1994-10-12T23:57:52.000000000',
'1994-11-12T00:02:07.000000000', '1994-12-11T23:57:52.000000000',
'1972-01-15T23:57:52.000000000', '1972-02-12T12:01:04.000000000',
'1972-03-12T00:00:00.000000000', '1972-04-16T00:02:07.000000000',
...
This leads to problems when selecting based on the time dimension afterwards
ds.sel(t=slice('1990-01-01','1999-12-31'))
...
KeyError: "cannot represent labeled-based slice indexer for dimension 't' with a slice over integer positions; the index is unsorted or non-unique"
This is easily overcome by sorting the time coordinate
ds['t'] = np.sort(ds['t'].values)
Maybe this can be incorporated into the open_xorca_dataset
process at some point.
edit: of course, all the data needs to be sorted accordingly... so maybe it is not that easy. Unless there is a way to combine the files in the right order in open_xorca_dataset
...
Edited by Jan Klaus Rieck