1

I hope you're well --

I have multiple files all having one month of hourly data.

Wind = Jun1.variables['wind'][:,:,:]
Wind = Jun2.variables['winds'][:,:,:]
etc

Below shows the dimensions

I want to average each individual files in a way to calculate the hourly average to get the diurnal cycle for each month with array shape (time, lon, lat) of 24 steps.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • I rephrased the question according to our interpretation for clarity, but please change if my edits have changed the nature of your question. – ClimateUnboxed Feb 20 '21 at 10:51

2 Answers2

1

If I understand your question correctly, you want to compute the mean diurnal cycle from a month of hourly data. NCO's ncra does this with a feature called "interleaving":

ncra -d time,,,,720,24 in.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19
1

If Charlie's interpretation is correct (I think it is from your desired array shape) then you can work out the diurnal cycle over a multi day period with CDO using

cdo dhourmean in.nc out.nc 

I think you need to make sure you have a recent version of cdo for this. v1.9.5 should be okay.

EDIT Oct 2021: I've just launched a video on this topic on my climate unboxed channel to provide more details on calculating diurnal cycles.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
  • I was about to suggest a way to chain this with mergetime, but surprisingly CDO does not seem to have a method for this. Though I guess people rarely deal with hourly stats – Robert Wilson Feb 19 '21 at 15:52
  • Ah I see ok I'm working on other data currently. I looked into http://xarray.pydata.org/en/stable/indexing.html too. it seems NCO or CDO. I also need to convert UTC to local time to then do this calculation since its over an entire US map –  Feb 19 '21 at 18:45
  • well that's another question, but you can use **cdo shifttime** – ClimateUnboxed Feb 20 '21 at 10:53