YYYY-12-31 issue when selecting a period from a daily/monthly files (360Day calendar) #471
Replies: 3 comments 10 replies
-
Note that |
Beta Was this translation helpful? Give feedback.
-
I think @tomvothecoder discovered this same issue when refactor e3sm diags code, that specifying year range would result one month short with xcdat/xarray applied to e3sm data. |
Beta Was this translation helpful? Give feedback.
-
Just adding my example of working with this issue in the 360 day calendar. In this case, I'm calculating the max rolling 5-day precipitation mean for each year, and I only want days within that calendar year to be used for its average. I.E., when calculating the max for 1970, I used the 5-day rolling mean starting on Jan 5 1970 and ending on the final day of 1970. I've also run into this problem when getting the DJF max during leap years in the "noleap" calendar.
|
Beta Was this translation helpful? Give feedback.
-
Some models fail when we specify December 31st as the ending index of a time slice.
This is an issue specific to the files using a 360Days calendar.
Example:
fn=’/p/css03/esgf_publish/CMIP6/ScenarioMIP/MOHC/UKESM1-0-LL/ssp585/r3i1p1f2/day/pr/gn/v20190813/’
ds=xc.open_mfdataset(fn+'*.nc',add_bounds=True)
ds=ds.sel(time=slice('2077-01-01','2078-12-31'))
--> ValueError: invalid day number provided in cftime.Datetime360Day(2078, 12, 31, 0, 0, 0, 0, has_year_zero=True)
What we found:
For monthly files, a solution is to specify: YYYY-12: ds=ds.sel(time=slice('2077-01','2078-12'))
For daily files, there are two workaround solutions:
Solution 1: opening the next January first and drop it.
ds=ds.sel(time=slice('2077-01-01','2079-01-01'))
ds=ds.isel(time=slice(0,ds.pr.shape[0]-1))
Solution 2: select the period this way:
ds = ds.where(((ds['time.year'] >= 2076) & (ds['time.year'] < 2078)), drop=True)
Any other ideas?
Beta Was this translation helpful? Give feedback.
All reactions