1

I have a new project on, calculating some seasonal climate metrics. As part of this, I need to identify, eg the wettest quarter in a set of climatological monthly data:

print(pr_cube)
 
Precipitation / (mm)                (time: 12; latitude: 125; longitude: 211) 
     Dimension coordinates:
          time                           x             -               -
          latitude                       -             x               -
          longitude                      -             -               x
 

where time is every month, averaged across 30-years with coord('time) =

DimCoord([2030-01-01 00:00:00, 2030-02-01 00:00:00, 2030-03-01 00:00:00, 
       2030-04-01 00:00:00, 2030-05-01 00:00:00, 2030-06-01 00:00:00,
       2030-07-01 00:00:00, 2030-08-01 00:00:00, 2030-09-01 00:00:00,
       2030-10-01 00:00:00, 2030-11-01 00:00:00, 2030-12-01 00:00:00]

I was wondering if I could add a seasons coordinate for all sets of consecutive 3 months, including 'wrapping around', something like this:

iris.coord_categorisation.add_season(cube, coord, name='season', 
       seasons=(''jfm', 'fma', 'mam', 'amj', 'mjj', 'jja', 'jas', 'aso', 'son', 'ond', 'ndj', 'djf'))
   

or

season = ('jfm', 'fma', 'mam', 'amj', 'mjj', 'jja', 'jas', 'aso', 'son', 'ond', 'ndj', 'djf')
iris.coord_categorisation.add_season_membership(cube, coord, season, name='all_quarters')
 

Not tested this yet, just wondered if about suggestions or a recommendation?

And then, get the season with the max rainfall?

Qtr_max_rain = pr_cube.collapsed('season', iris.analysis.MAX)

Would that work correctly ?

Chris Maggiulli
  • 3,375
  • 26
  • 39
RBodman
  • 13
  • 4

1 Answers1

2

There may be a way to achieve this using coord_categorisation, but I believe the simplest way is to instead use iris.cube.Cube.rolling_window(). There's no native way to wrap around in the way you need, so you can hack it by duplicating Jan and Feb on the end of the existing data.

I've tested the below and it seems to work as intended. Hopefully it works for you.

# Create extra cube based on Jan and Feb from pr_cube.
extra_months_cube = pr_cube[:2, ...]
# Replace time coordinate with another that is advanced by a year - ensures correct sorting.
# Adjust addition depending on the unit of the time coordinate.
extra_months_coord = extra_months_cube.coord("time") + (24 * 365)
extra_months_cube.remove_coord("time")
extra_months_cube.add_dim_coord(extra_months_coord, 0)

# Combine original cube with extra cube.
both_cubes = iris.cube.CubeList([pr_cube, extra_months_cube])
fourteen_month_cube = both_cubes.concatenate_cube()

# Generate cube of 3-month MAX aggregations.
rolling_cube = fourteen_month_cube.rolling_window("time", iris.analysis.MAX, 3)

Once done, you would of course be free to add your suggested three month labels using iris.cube.Cube.add_aux_coord().

Martin Yeo
  • 21
  • 3