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
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]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With