0

Is there a similar function at iris to cf_xarray resample using mean?

dataset.cf.resample(T="Y").mean()
BorjaEst
  • 390
  • 2
  • 11

1 Answers1

0

Although not very elegant, I found a way to make it possible for year:

import iris
import iris.coord_categorisation

def year_mean(dataset):
    # 1st step: Create an auxialiary coordinate
    iris.coord_categorisation.add_year(dataset, "time", name="year")
    # 2nd step: Mean over the auxiliary coordinate  
    result = dataset.aggregated_by(["year"], iris.analysis.MEAN)
    # 3rd step: Fix cell_methods   
    method = iris.coords.CellMethod('mean', coords=['time'], intervals='1 year')
    result.cell_methods = result.cell_methods[:-1]
    result.add_cell_method(method)
    # 4rd step: Remove the auxiliary coordinate
    result.remove_coord("year")
    return result

I think this produces the most CF standard output.

BorjaEst
  • 390
  • 2
  • 11