Skip to content

Commit

Permalink
mfdataset preprocessing: cftime to datetimeindex before casting to int
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed Nov 9, 2024
1 parent ece79e7 commit f3b6b04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion sup3r/utilities/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def preprocess_datasets(dset):
"""Standardization preprocessing applied before datasets are concatenated
by ``xr.open_mfdataset``"""
if 'time' in dset and dset.time.size > 1:
ti = dset.time.astype(int)
if 'time' in dset.indexes and hasattr(
dset.indexes['time'], 'to_datetimeindex'
):
dset['time'] = dset.indexes['time'].to_datetimeindex()
ti = dset['time'].astype(int)
dset['time'] = ti
if 'latitude' in dset.dims:
dset = dset.swap_dims({'latitude': 'south_north'})
Expand Down
6 changes: 5 additions & 1 deletion tests/utilities/test_era_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def test_era_dl_year(tmpdir_factory):
yearly_file_pattern=yearly_file_pattern,
max_workers=1,
combine_all_files=True,
res_kwargs={'compat': 'override', 'engine': 'netcdf4'},
res_kwargs={
'compat': 'override',
'engine': 'netcdf4',
'concat_dim': 'time',
},
)

combined_file = yearly_file_pattern.replace('_{var}_', '').format(
Expand Down

0 comments on commit f3b6b04

Please sign in to comment.