I have a nc
file in which the time variable is a bit weird. It is not a gregorian calendar but a simple 365-day-a-year calendar (i.e. leap years are not included). This means the unit is also a bit off, but nothing too worrisome.
xarray.DataArray 'days' (time: 6570)>
array([730817., 730818., 730819., ..., 737384., 737385., 737386.])
Dimensions without coordinates: time
Attributes:
units: days_since_Jan11900
long_name: calendar_days
730817
represents 01-01-2001
and 737386
represents 31-12-2018
I want to obtain a certain time period of the data set for multiple years, just as you can do with cdo -seldmonth, -selday
etc. But of course, with no date, I cannot use the otherwise brilliant option. My idea was to slice the time range I need with np.slice
, but I do not know how and cannot seem to find adequate answers on SO.
In my specific case, I need to slice a range going from May 30th (150th day of the year) to Aug 18th (229th day of the year) every year. I know the first slice should be something like:
ds = ds.loc[dict(time = slice(149,229))]
But, that will only give me the range for 2001, and not the following years.
I cannot do it with cdo -ntime
as it does not recognize the time unit.
How do I make sure that I get the range for the following 17 years too? And by that skipping 285 days in between the ranges I need?