iris add all quarterly season coordinate

40 views
Skip to first unread message

Roger Bodman

unread,
Sep 3, 2020, 11:40:33 PM9/3/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
How to add a season coordinate for all combinations of months in sequence:

quarters = ['jfm', 'fma', 'mam', 'amj', 'mjj', 'jja', 'jas', 'aso', 'son', 'ond', 'ndj', 'djf']

iris.coord_categorisation.add_season_membership(tmin, 'time', quarters, name='all_quarters')

produces error:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-54-03c816a954fc> in <module>
      6 quarters = ['jfm', 'fma', 'mam', 'amj', 'mjj', 'jja', 'jas', 'aso', 'son', 'ond', 'ndj', 'djf']
      7 
----> 8 iris.coord_categorisation.add_season_membership(tmin, 'time', quarters, name='all_quarters')

/g/data3/hh5/public/apps/miniconda3/envs/analysis3-20.01/lib/python3.7/site-packages/iris/coord_categorisation.py in add_season_membership(cube, coord, season, name)
    438 
    439     """
--> 440     months = _months_in_season(season)
    441 
    442     def _season_membership(coord, value):

/g/data3/hh5/public/apps/miniconda3/envs/analysis3-20.01/lib/python3.7/site-packages/iris/coord_categorisation.py in _months_in_season(season)
    229     """
    230     cyclic_months = 'jfmamjjasondjfmamjjasond'
--> 231     m0 = cyclic_months.find(season.lower())
    232     if m0 < 0:
    233         # Can't match the season, raise an error.

AttributeError: 'list' object has no attribute 'lower'

How else might I achieve this?

Simon Peatman

unread,
Sep 4, 2020, 6:23:57 AM9/4/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Roger,

The season argument needs to be a string, not a list.  The add_season_membership() function creates a coordinate with values of either True or False, telling you whether a date is within the given season.  Therefore, it doesn't make sense to do this for more than one season simultaneously.  If you want to do this for all the different seasons, you could call the same function repeatedly:

for season in ['jfm', 'fma', 'mam', 'amj', 'mjj', 'jja', 'jas', 'aso', 'son', 'ond', 'ndj', 'djf']:
    iris
.coord_categorisation.add_season_membership(tmin, 'time', season, name=season+'_membership')

Simon
Reply all
Reply to author
Forward
0 new messages