Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select an inter-year period with xarray?

The context: I have a netCDF with 30 years of (daily) data. I would like to select data across years for specific months, e.g. every May to March period.

I could do it with a separate function for selection, but I'm hoping there's a straightforward way to do it with xarray. The version I have installed is 0.9.6

like image 975
ConnectedSystems Avatar asked Sep 27 '18 09:09

ConnectedSystems


1 Answers

If your time dimension is a datetime object, you can use the DatetimeAccessor object to select only the months you'd like:

# select only daily data from June, July, and August
da_jja_only = ds.sel(time=ds.time.dt.month.isin([6, 7, 8]))
like image 172
Michael Delgado Avatar answered Nov 04 '22 10:11

Michael Delgado