manually fix incorrect times #475
-
I am trying to read in a file that apparently has incorrect times. Is it possible for me to define what I believe to be the correct times and assign those corrected times to this dataset? If I read this in with decoding: ds = xc.open_mfdataset('/p/user_pub/climate_work/zelinka1/pattern-effectMIP/Vaccaro_et_al_2021/vaccaro_et_al_2021_T63_bil_absolute_TS_values01.nc')
Reading it in without decoding: ds = xc.open_mfdataset(
'/p/user_pub/climate_work/zelinka1/pattern-effectMIP/Vaccaro_et_al_2021/vaccaro_et_al_2021_T63_bil_absolute_TS_values01.nc',
decode_times = False)
Clearly this should instead be Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@mzelinka - there is some ambiguity here (read about # import xarray which has encoding / decoding functionality
import xarray
# define / open dataset
fn = '/p/user_pub/climate_work/zelinka1/pattern-effectMIP/Vaccaro_et_al_2021/vaccaro_et_al_2021_T63_bil_absolute_TS_values01.nc'
ds = xc.open_dataset(fn, decode_times=False)
# decode options (first one is probably what you want?)
time = xarray.coding.times.decode_cf_datetime(ds.time, 'day since 0000-01-01', use_cftime=True, calendar='proleptic_gregorian')
time_360 = xarray.coding.times.decode_cf_datetime(ds.time, 'day since 0000-01-01', use_cftime=True, calendar='360_day')
time_standard = xarray.coding.times.decode_cf_datetime(ds.time, 'day since 0001-01-01', use_cftime=True)
# put in dataset
ds['time'] = time |
Beta Was this translation helpful? Give feedback.
One other option that comes to mind (via pandas):
This yields
numpy.Datetime64
time objects, which I think should work fine with xcdat utilities.