How to change or reorder grouping by 'time.season'? #5134
Unanswered
hafez-ahmad
asked this question in
Q&A
Replies: 1 comment 2 replies
-
How about import numpy as np
import xarray as xr
ds = xarray.tutorial.open_dataset("air_temperature")
months = ds.time.dt.month
seasons = xr.full_like(months, fill_value="none", dtype="U4")
seasons.name = "season"
# set values
seasons[months.isin([12, 1, 2, 3])] = "DJFM"
seasons[months.isin([4, 5])] = "AM"
seasons[months.isin([6, 7, 8])] = "JJA"
seasons[months.isin([9, 10, 11])] = "SON"
# seasonal mean, then reindex to get nicely ordered seasons
ds.groupby(seasons).mean().reindex(season=["DJFM", "AM", "JJA", "SON"])
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone!
is there any way to change or reorder month names [
'DJF' 'JJA' 'MAM' 'SON'] during seasonal grouping? I like to change
'DJF' 'JJA' 'MAM' 'SON' combination and find out winter season Dec+Jan+Feb+Mar=winter season.
Your assistant highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions