Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iris.coord_categorisation.add_season_year_preceding() #4877

Closed
kaedonkers opened this issue Jul 26, 2022 · 5 comments · Fixed by #5573
Closed

iris.coord_categorisation.add_season_year_preceding() #4877

kaedonkers opened this issue Jul 26, 2022 · 5 comments · Fixed by #5573
Assignees
Milestone

Comments

@kaedonkers
Copy link
Member

✨ Feature Request

Add an alternative to iris.coord_categorisation.add_season_year() which assigns seasons which span two years to the preceding year instead of the following year.

Motivation

iris.coord_categorisation.add_season_year() is an excellent feature and very handy for comparing multiple timeseries datasets. However, it has an inherent assumption that a season which spans two years (i.e. includes December and January) will be assigned to the later rather than the earlier year. We have had a usecase where we want to compare the effects of monthly climate indices to several months of meteorological data after the climate index month (since we know that specific climate indices affect the weather variables we are analysing).

Proposed change

Proposed change/addition to iris.coord_categorisation (which essentially just removes the use of _month_year_adjusts()):

def add_season_year_preceding(
    cube, coord, name="season_year", seasons=("djf", "mam", "jja", "son")
):
    """
    Add a categorical year-of-season coordinate, with user specified
    seasons. Any season spanning two years will be assigned the preceding year.
    Args:
    * cube (:class:`iris.cube.Cube`):
        The cube containing 'coord'. The new coord will be added into
        it.
    * coord (:class:`iris.coords.Coord` or string):
        Coordinate in 'cube', or its name, representing time.
    Kwargs:
    * name (string):
        Name of the created coordinate. Defaults to "season_year".
    * seasons (:class:`list` of strings):
        List of seasons defined by month abbreviations. Each month must
        appear once and only once. Defaults to standard meteorological
        seasons ('djf', 'mam', 'jja', 'son').
    """
    # Check that the seasons are valid.
    _validate_seasons(seasons)

    # Define a categorisation function.
    def _season_year(coord, value):
        dt = _pt_date(coord, value)
        year = dt.year
        return year

    # Apply the categorisation.
    add_categorised_coord(cube, name, coord, _season_year)
@rcomer
Copy link
Member

rcomer commented Jul 26, 2022

I think you still need some form of _month_year_adjusts, otherwise it's the same as add_year.

def add_year(cube, coord, name="year"):
"""Add a categorical calendar-year coordinate."""
add_categorised_coord(
cube, name, coord, lambda coord, x: _pt_date(coord, x).year
)

@trexfeathers
Copy link
Contributor

trexfeathers commented Jul 27, 2022

@kaedonkers how would you feel about an example in the docs, rather than more API? I'm assuming that this could be achieved with a few more lines of user code, but do correct me if I'm wrong.

@kaedonkers
Copy link
Member Author

Hmm, good spot @rcomer. I'll need to give that a little more testing then.
@trexfeathers Yes we achieved it with user code. I'll add it to my todo list.

@trexfeathers
Copy link
Contributor

@kaedonkers any thoughts on this? It's OK to not be OK assigned! ♥

@kaedonkers
Copy link
Member Author

Sorry, I never picked this up again. Is this something someone else can make happen?

@trexfeathers trexfeathers added this to the v3.8 milestone Oct 11, 2023
@stephenworsley stephenworsley moved this to 🆕 New - potential tasks in 🐙Iris v3.8.0 Oct 11, 2023
@stephenworsley stephenworsley moved this from 🆕 New - potential tasks to Candidate for next sprint in 🐙Iris v3.8.0 Oct 11, 2023
@trexfeathers trexfeathers moved this from Candidate for next sprint to 📋 Backlog in 🐙Iris v3.8.0 Nov 2, 2023
@trexfeathers trexfeathers moved this from 📋 Backlog to 🔖Assigned in 🐙Iris v3.8.0 Nov 8, 2023
@trexfeathers trexfeathers moved this from 🔖Assigned to 🏗 In progress in 🐙Iris v3.8.0 Nov 9, 2023
@trexfeathers trexfeathers moved this from 🏗 In progress to 👀 In review in 🐙Iris v3.8.0 Nov 9, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to 🏁 Done in 🐙Iris v3.8.0 Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: 🏁 Done
Development

Successfully merging a pull request may close this issue.

4 participants