@@ -71,13 +71,16 @@ def extractData(nc, details, key=['',], debug=False):
7171 return np .ma .array (xd )
7272
7373
74+
7475####
7576# Some functions for maniulating data:
7677def NoChange (nc ,keys ):
7778 """
7879 Loads keys[0] from the netcdf, but applies no change.
7980 """
80- return nc .variables [keys [0 ]][:]
81+ arr = nc .variables [keys [0 ]][:]
82+ arr = np .ma .masked_where (arr == 0. + arr .mask , arr )
83+ return arr
8184
8285
8386def N2Biomass (nc ,keys ):
@@ -126,7 +129,9 @@ def applymask(nc,keys):
126129 """
127130 Loads keys[0] from the netcdf, but applies a mask.
128131 """
129- return np .ma .masked_where (nc .variables [keys [1 ]][:] == 0. , nc .variables [keys [0 ]][:])
132+ arr = np .ma .array (nc .variables [keys [0 ]][:])
133+ arr = np .ma .masked_invalid (arr )
134+ return np .ma .masked_where (arr .mask + (nc .variables [keys [1 ]][:] == 0. ), arr )
130135
131136
132137def maskzeroes (nc , keys ):
@@ -147,6 +152,7 @@ def sums(nc,keys):
147152 a = nc .variables [keys [0 ]][:]
148153 for k in keys [1 :]:
149154 a += nc .variables [k ]
155+ a = np .ma .masked_where (a == 0. + a .mask , a )
150156 return a
151157
152158
@@ -172,9 +178,12 @@ def choose_best_var(nc, keys):
172178 for key in keys :
173179 if key not in nc .variables .keys ():
174180 continue
175- return nc .variables [key ][:]
181+ arr = nc .variables [key ][:]
182+ arr = np .ma .masked_where (arr == 0. + arr .mask , arr )
183+ return arr
176184 raise KeyError (f'choose_best_var: unable to find any variable in { keys } in { nc .filename } ' )
177185
186+
178187def find_best_var (nc , keys ):
179188 """
180189 Takes the list of keys and returns the first one that exists in the input file.
@@ -194,7 +203,9 @@ def multiplyBy(nc,keys, **kwargs):
194203 """
195204 if 'factor' not in kwargs :
196205 raise KeyError (f"std_functions: multiplyBy: Did not get key word argument, 'factor' in kwargs: { kwargs } " )
197- return nc .variables [keys [0 ]][:] * float (kwargs ['factor' ])
206+ arr = nc .variables [keys [0 ]][:] * float (kwargs ['factor' ])
207+ arr = np .ma .masked_where (arr == 0. + arr .mask , arr )
208+ return arr
198209
199210
200211def addValue (nc ,keys , ** kwargs ):
0 commit comments