0

I'm loading an annual dataset with xarray. I'd like to create 35-year means of the data (not a rolling average, just chunked into 35 year means). Right now I do the following:

filename = '/glade/scratch/mberdahl/127kaH11/MOC/MOC_only_127kaH11_AnnMeans.nc' # read 127ka H11 run, 1-1749 years only
ds = xr.open_dataset(filename)
ds

Which shows

Dimensions:
d2: 2lat_aux_grid: 395 moc_comp: 3 moc_z: 61 time: 1750 transport_reg: 2

With 1750 annual time entries, I should be able to calculate 50 means, each accounting for 35 years of time. However, when I do the following:

MOC_35yr = ds.resample(time="35A").mean()
MOC_35yr

I get 51 times:

Dimensions:
lat_aux_grid: 395 moc_z: 61 time: 51 

As a sanity check, I've also calculated the 35 year means with nco commands, and the results are identical to the xarray.resample.mean method for only the 0th time entry. After that the results are different.

Can anyone see what I'm doing wrong?

Thanks, Mira

  • Actually, I found that perhaps I have to specify also the S for 'start' . so: MOC_35yr = ds.resample(time="35AS").mean() This seems to work just fine, but I don't know if I exactly understand why. – user14771692 Oct 01 '21 at 19:15
  • I think this is just to avoid the default which is 'start_day’: origin is the first day at midnight of the timeseries. Hope this might help someone else! – user14771692 Oct 01 '21 at 19:37
  • If this is the answer, feel free to answer your own question! – Michael Delgado Oct 03 '21 at 05:27

1 Answers1

0

I believe the answer is that I had to specify S for 'start'. so: MOC_35yr = ds.resample(time="35AS").mean().

Similarly in this post: xarray and 5 year averages from monthly or yearly avarges

This is just to avoid the default which is 'start_day’: origin is the first day at midnight of the timeseries.

Hoping this helps someone else.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 04 '21 at 17:13