7
7
# nor does it submit to any jurisdiction.
8
8
#
9
9
10
+ import warnings
10
11
import climetlab as cml
11
12
import numpy as np
12
13
import tqdm
@@ -42,8 +43,11 @@ def normalise_number(number):
42
43
def ensembles_perturbations (ensembles , center , mean , remapping = {}, patches = {}):
43
44
n_ensembles = len (normalise_number (ensembles ["number" ]))
44
45
46
+ print (f"Retrieving ensemble data with { ensembles } " )
45
47
ensembles = cml .load_source (** ensembles )
48
+ print (f"Retrieving center data with { center } " )
46
49
center = cml .load_source (** center )
50
+ print (f"Retrieving mean data with { mean } " )
47
51
mean = cml .load_source (** mean )
48
52
49
53
assert len (mean ) * n_ensembles == len (ensembles ), (
@@ -82,6 +86,8 @@ def ensembles_perturbations(ensembles, center, mean, remapping={}, patches={}):
82
86
83
87
for field in tqdm .tqdm (center ):
84
88
param = field .metadata ("param" )
89
+ grid = field .metadata ("grid" )
90
+
85
91
selection = dict (
86
92
valid_datetime = field .metadata ("valid_datetime" ),
87
93
param = field .metadata ("param" ),
@@ -91,20 +97,25 @@ def ensembles_perturbations(ensembles, center, mean, remapping={}, patches={}):
91
97
step = field .metadata ("step" ),
92
98
)
93
99
mean_field = get_unique_field (mean , selection )
100
+ assert mean_field .metadata ("grid" ) == grid , (mean_field .metadata ("grid" ), grid )
94
101
95
102
m = mean_field .to_numpy ()
96
103
c = field .to_numpy ()
97
104
assert m .shape == c .shape , (m .shape , c .shape )
98
105
99
106
for number in ensembles_coords ["number" ]:
100
107
ensembles_field = get_unique_field (ensembles .sel (number = number ), selection )
108
+ assert ensembles_field .metadata ("grid" ) == grid , (ensembles_field .metadata ("grid" ), grid )
109
+
101
110
e = ensembles_field .to_numpy ()
102
111
assert c .shape == e .shape , (c .shape , e .shape )
103
112
104
113
x = c + m - e
105
114
if param == "q" :
106
- print ("Clipping q" )
107
- x = np .max (x , 0 )
115
+ warnings .warn ("Clipping q" )
116
+ x = np .maximum (x , 0 )
117
+
118
+ assert x .shape == c .shape , (x .shape , c .shape )
108
119
109
120
check_data_values (x , name = param )
110
121
out .write (x , template = ensembles_field )
0 commit comments