-
Is there a similar function to cf_xarray resample using dataset.cf.resample(T="Y").mean() |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
I don't have much detailed knowledge of xarray (I assume this is 'really' an xarray operation?) As a general development point, I think we should probably get around to providing a 'groupby' ? BTW it this is "just a question", then it might be more friendly to put this type of query on StackOverflow (though I must admit there isn't much specifically about Iris there). |
Beta Was this translation helpful? Give feedback.
-
You are probably right, I created the question: Group_by in iris using mean calculation. To reply your post, (thanks for the help) that indeed pointed me to the direction. iris.coord_categorisation.add_year(cube, 'time', name='year')
result = cube.aggregated_by(['year'], iris.analysis.MEAN) That produced the following output: print(result)
atmosphere_mole_content_of_ozone / (mol m-2) (time: 1; latitude: 18; longitude: 36)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
Auxiliary coordinates:
year x - -
Attributes:
...
Cell methods:
mean: area
maximum: time (interval: 1 day)
mean: year Although, if interesting, I was expecting something more like: atmosphere_mole_content_of_ozone / (mol m-2) (time: 1; latitude: 18; longitude: 36)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
Attributes:
...
Cell methods:
mean: area
maximum: time (interval: 1 day)
mean: time (interval: 1 year) Although probably both are CF valid. |
Beta Was this translation helpful? Give feedback.
-
Ok that is worrying. |
Beta Was this translation helpful? Give feedback.
-
That I think would not in fact be correct : the "interval" should record the original spacing of the observations (which is lost when forming a statistical measure). So e.g. "mean: time (interval: 1 day) " would mean that it is an average of daily values. As to Iris, I suspect that probably the result of the statistical aggregation never adds a stated interval, because the aggregation operation itself is a generalised thing -- so the original data sampling interval would not always be regular, so we probably don't specially check for that. Certainly if you had monthly or yearly values, for instance, that wouldn't be straightforward because it is only 'regular' with respect to a calendar (not in the actual numberic intervals). Actually, looking at the code, Iris has only a very generic and minimal approach to adding cell-methods on aggregation. |
Beta Was this translation helpful? Give feedback.
-
@pp-mo thanks for the comments. I am sorry to write again this late, I am new to this CF conventions and I find it quite complicated, however I earn experience each day. I have read your point and you are correct, the interval is for the original spacing. Here is the example metioned:
So it applies a statistical calculation over the atmosphere_mole_content_of_ozone / (mol m-2) (time: 1; latitude: 18; longitude: 36)
Dimension coordinates:
time x - -
latitude - x -
longitude - - x
Attributes:
...
Cell methods:
mean: area
maximum within days: time
mean over years: time |
Beta Was this translation helpful? Give feedback.
-
Archiving "answered" Q+As |
Beta Was this translation helpful? Give feedback.
I don't have much detailed knowledge of xarray (I assume this is 'really' an xarray operation?)
So I'm not entirely sure what this exact operation involves. Certainly the cf-xarray docs don't help much !
But ...
the exisiting "Iris way" of performing aggregated statistics (equivalent to a 'groupby') is to first create an auxiliary 'categorised coordinate' and then use Cube.aggregated_by
So, there is already a User Guide section on it, here : https://scitools-iris.readthedocs.io/en/latest/userguide/cube_statistics.html#partially-reducing-data-dimensions
Can you confirm whether that is what you were looking for ?
As a general development point, I think we should probably get around to provi…