Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
climix
climix
Commits
c3e5c17a
Commit
c3e5c17a
authored
Jul 22, 2021
by
Klaus Zimmermann
Browse files
Fix handling of seasonal periods that straddle years (fixes #226)
parent
2572e947
Changes
1
Hide whitespace changes
Inline
Side-by-side
climix/period.py
View file @
c3e5c17a
...
...
@@ -55,16 +55,28 @@ class Season(Period):
]
def
__init__
(
self
,
specifier
):
super
().
__init__
(
"year"
,
"sem"
)
super
().
__init__
(
"
season_
year"
,
"sem"
)
self
.
specifier
=
specifier
.
upper
()
self
.
first_month_number
=
(
self
.
YEAR
*
2
).
find
(
self
.
specifier
)
+
1
self
.
length
=
len
(
self
.
specifier
)
self
.
last_month_number
=
self
.
first_month_number
+
self
.
length
-
1
self
.
constraint
=
iris
.
Constraint
(
time
=
lambda
cell
:
self
.
first_month_number
<=
cell
.
point
.
month
<=
self
.
last_month_number
)
last_month_number
=
self
.
first_month_number
+
self
.
length
-
1
if
last_month_number
>
12
:
last_month_number
%=
12
def
selector
(
cell
):
m
=
cell
.
point
.
month
return
(
self
.
first_month_number
<=
m
<=
12
)
|
(
1
<=
m
<=
last_month_number
)
else
:
def
selector
(
cell
):
m
=
cell
.
point
.
month
return
self
.
first_month_number
<=
m
<=
last_month_number
self
.
constraint
=
iris
.
Constraint
(
time
=
selector
)
self
.
last_month_number
=
last_month_number
def
long_label
(
self
):
first_month
=
self
.
MONTHS
[
self
.
first_month_number
-
1
]
...
...
@@ -73,7 +85,7 @@ class Season(Period):
return
long_label
def
add_coord_categorisation
(
self
,
cube
):
iris
.
coord_categorisation
.
add_year
(
iris
.
coord_categorisation
.
add_
season_
year
(
cube
,
self
.
input_coord
,
name
=
self
.
output_coord
)
return
self
.
output_coord
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment