Skip to content Skip to sidebar Skip to footer

Upsample Seasonal Data To Daily Data Over 10 Years In Python Xarray

I have a netCDF file for seasonal data. When loaded into Dataset, it contains season, latitude and longitude dimensions. print(dataset_seasonal_nc) Dimensi

Solution 1:

This seems like a good candidate for xarray's advanced label-based indexing. I think something like the following should work:

import pandas as pd

times = pd.date_range('1972', '1982', freq='D', closed='left')
time = xr.DataArray(times, [('time', times)])
upsampled = dataset_seasonal_nc.sel(season=time.dt.season)

Here time.dt.season is a DataArray representing the season labels associated with each time in your upsampled Dataset:

In [16]: time.dt.season
Out[16]:
<xarray.DataArray 'season' (time: 3653)>
array(['DJF', 'DJF', 'DJF', ..., 'DJF', 'DJF', 'DJF'],
      dtype='|S3')
Coordinates:
  * time     (time) datetime64[ns] 1972-01-01 1972-01-02 1972-01-03 ...

Post a Comment for "Upsample Seasonal Data To Daily Data Over 10 Years In Python Xarray"