Closed slharris closed 5 years ago
This is a good idea, but it's not currently supported. You could do something like this, though:
hourofyear = (ds['time.dayofyear'] * 24 + ds['time.hourofday']).rename('hourofyear')
result = ds['TEMP'].groupby(hourofyear).mean('time')
thank you
On 30 December 2015 at 15:01, Stephan Hoyer notifications@github.com wrote:
This is a good idea, but it's not currently supported. You could do something like this, though:
hourofyear = (ds['time.dayofyear'] * 24 + ds['time.hourofday']).rename('hourofyear') result = ds['TEMP'].groupby(hourofyear).mean('time')
— Reply to this email directly or view it on GitHub https://github.com/xray/xray/issues/690#issuecomment-167932904.
Dr Sarah Harris Research Fellow School of Earth, Atmosphere and Environment Room 227, 9 Rainforest Walk Faculty of Science Monash University Ph: 03 9902 4243 Email: sarah.harris@monash.edu Email%3Asarah.harris@monash.edu
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here; otherwise it will be marked as closed automatically
This was very helpful, thanks. Minor tweak (maybe due to source change since previous comments in 2015?):
hourofyear = ((da.time.dt.dayofyear-1) * 24 + da.time.dt.hour).rename('hourofyear')
result = da.groupby(hourofyear).mean('time')
Is there a way to use 'hourofyear' in the same way 'dayofyear' works? I want the calculate the mean temperature value for a 2d dataset for each hour of the year based on 40 years of hourly data. I realise this might be a pandas question but if I receive an answer from a pandas forum I don't know if I would be able to work out how to apply it to an xray dataset.
Below is the code I would use to calculate 'dayofyear' but with the word 'hour' used to replace 'day'. Obviously it does not work! Any feedback will be greatly appreciated
ds=xray.open_mfdataset('/DATA/*TEMP.nc') ds_variable=ds['TEMP'] hourofyear=ds_variable.groupby('time.hourofyear').mean('time')