MCPcopy
hub / github.com/pydata/xarray / season_to_month_tuple

Function season_to_month_tuple

xarray/groupers.py:682–713  ·  view source on GitHub ↗

>>> season_to_month_tuple(["DJF", "MAM", "JJA", "SON"]) ((12, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)) >>> season_to_month_tuple(["DJFM", "MAMJ", "JJAS", "SOND"]) ((12, 1, 2, 3), (3, 4, 5, 6), (6, 7, 8, 9), (9, 10, 11, 12)) >>> season_to_month_tuple(["DJFM", "SOND"]) ((12,

(seasons: Sequence[str])

Source from the content-addressed store, hash-verified

680
681
682def season_to_month_tuple(seasons: Sequence[str]) -> tuple[tuple[int, ...], ...]:
683 """
684 >>> season_to_month_tuple(["DJF", "MAM", "JJA", "SON"])
685 ((12, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11))
686 >>> season_to_month_tuple(["DJFM", "MAMJ", "JJAS", "SOND"])
687 ((12, 1, 2, 3), (3, 4, 5, 6), (6, 7, 8, 9), (9, 10, 11, 12))
688 >>> season_to_month_tuple(["DJFM", "SOND"])
689 ((12, 1, 2, 3), (9, 10, 11, 12))
690 """
691 initials = "JFMAMJJASOND"
692 starts = {
693 "".join(s): i + 1
694 for s, i in zip(sliding_window(2, initials + "J"), range(12), strict=True)
695 }
696 result: list[tuple[int, ...]] = []
697 for i, season in enumerate(seasons):
698 if len(season) == 1:
699 if i < len(seasons) - 1:
700 suffix = seasons[i + 1][0]
701 else:
702 suffix = seasons[0][0]
703 else:
704 suffix = season[1]
705
706 start = starts[season[0] + suffix]
707
708 month_append = []
709 for i in range(len(season[1:])):
710 elem = start + i + 1
711 month_append.append(elem - 12 * (elem > 12))
712 result.append((start,) + tuple(month_append))
713 return tuple(result)
714
715
716def inds_to_season_string(asints: tuple[tuple[int, ...], ...]) -> tuple[str, ...]:

Callers 5

test_season_resamplerMethod · 0.90
find_independent_seasonsFunction · 0.85
__post_init__Method · 0.85

Calls 2

sliding_windowFunction · 0.90
joinMethod · 0.45

Tested by 3

test_season_resamplerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…