@@ -1163,7 +1163,7 @@ function _check_sim_obs_units_consistent(sim::OutputVar, obs::OutputVar)
1163
1163
end
1164
1164
1165
1165
"""
1166
- bias(sim::OutputVar, obs::OutputVar)
1166
+ bias(sim::OutputVar, obs::OutputVar; mask = nothing )
1167
1167
1168
1168
Return a `OutputVar` whose data is the bias (`sim.data - obs.data`) and compute the global
1169
1169
bias of `data` in `sim` and `obs` over longitude and latitude. The result is stored in
@@ -1175,10 +1175,13 @@ for longitude and latitude should be degrees. Resampling is done automatically b
1175
1175
`obs` on `sim`. Attributes in `sim` and `obs` will be thrown away. The long name and short
1176
1176
name of the returned `OutputVar` will be updated to reflect that a bias is computed.
1177
1177
1178
+ The parameter `mask` is a function that masks a `OutputVar`. See [`apply_landmask`](@ref)
1179
+ and [`apply_oceanmask`](@ref).
1180
+
1178
1181
See also [`global_bias`](@ref), [`squared_error`](@ref), [`global_mse`](@ref),
1179
1182
[`global_rmse`](@ref).
1180
1183
"""
1181
- function bias (sim:: OutputVar , obs:: OutputVar )
1184
+ function bias (sim:: OutputVar , obs:: OutputVar ; mask = nothing )
1182
1185
_check_sim_obs_units_consistent (sim, obs)
1183
1186
1184
1187
# Resample obs on sim to ensure the size of data in sim and obs are the same and the
@@ -1203,24 +1206,24 @@ function bias(sim::OutputVar, obs::OutputVar)
1203
1206
end
1204
1207
1205
1208
# Compute global bias and store it as an attribute
1209
+ ! isnothing (mask) && (bias = mask (bias))
1206
1210
integrated_bias = integrate_lonlat (bias). data
1207
- normalization =
1208
- integrate_lonlat (
1209
- OutputVar (
1210
- bias. attributes,
1211
- bias. dims,
1212
- bias. dim_attributes,
1213
- ones (size (bias. data)),
1214
- ),
1215
- ). data
1211
+ ones_var = OutputVar (
1212
+ bias. attributes,
1213
+ bias. dims,
1214
+ bias. dim_attributes,
1215
+ ones (size (bias. data)),
1216
+ )
1217
+ ! isnothing (mask) && (ones_var = mask (ones_var))
1218
+ normalization = integrate_lonlat (ones_var). data
1216
1219
# Do ./ instead of / because we are dividing between zero dimensional arrays
1217
1220
global_bias = integrated_bias ./ normalization
1218
1221
ret_attributes[" global_bias" ] = global_bias
1219
1222
return OutputVar (ret_attributes, bias. dims, bias. dim_attributes, bias. data)
1220
1223
end
1221
1224
1222
1225
"""
1223
- global_bias(sim::OutputVar, obs::OutputVar)
1226
+ global_bias(sim::OutputVar, obs::OutputVar; mask = nothing )
1224
1227
1225
1228
Return the global bias of `data` in `sim` and `obs` over longitude and latitude.
1226
1229
@@ -1229,16 +1232,19 @@ longitude and latitude. Units must be supplied for data and dimensions in `sim`
1229
1232
The units for longitude and latitude should be degrees. Resampling is done automatically by
1230
1233
resampling `obs` on `sim`.
1231
1234
1235
+ The parameter `mask` is a function that masks a `OutputVar`. See [`apply_landmask`](@ref)
1236
+ and [`apply_oceanmask`](@ref).
1237
+
1232
1238
See also [`bias`](@ref), [`squared_error`](@ref), [`global_mse`](@ref),
1233
1239
[`global_rmse`](@ref).
1234
1240
"""
1235
- function global_bias (sim:: OutputVar , obs:: OutputVar )
1236
- bias_var = bias (sim, obs)
1241
+ function global_bias (sim:: OutputVar , obs:: OutputVar ; mask = nothing )
1242
+ bias_var = bias (sim, obs, mask = mask )
1237
1243
return bias_var. attributes[" global_bias" ]
1238
1244
end
1239
1245
1240
1246
"""
1241
- squared_error(sim::OutputVar, obs::OutputVar)
1247
+ squared_error(sim::OutputVar, obs::OutputVar; mask = nothing )
1242
1248
1243
1249
Return a `OutputVar` whose data is the squared error (`(sim.data - obs.data)^2`) and compute
1244
1250
the global mean squared error (MSE) and global root mean squared error (RMSE) of `data` in
@@ -1251,9 +1257,12 @@ for longitude and latitude should be degrees. Resampling is done automatically b
1251
1257
`obs` on `sim`. Attributes in `sim` and `obs` will be thrown away. The long name and short
1252
1258
name of the returned `OutputVar` will be updated to reflect that a squared error is computed.
1253
1259
1260
+ The parameter `mask` is a function that masks a `OutputVar`. See [`apply_landmask`](@ref)
1261
+ and [`apply_oceanmask`](@ref).
1262
+
1254
1263
See also [`global_mse`](@ref), [`global_rmse`](@ref), [`bias`](@ref), [`global_bias`](@ref).
1255
1264
"""
1256
- function squared_error (sim:: OutputVar , obs:: OutputVar )
1265
+ function squared_error (sim:: OutputVar , obs:: OutputVar ; mask = nothing )
1257
1266
_check_sim_obs_units_consistent (sim, obs)
1258
1267
1259
1268
# Resample obs on sim to ensure the size of data in sim and obs are the same and the
@@ -1282,16 +1291,16 @@ function squared_error(sim::OutputVar, obs::OutputVar)
1282
1291
end
1283
1292
1284
1293
# Compute global mse and global rmse and store it as an attribute
1294
+ ! isnothing (mask) && (squared_error = mask (squared_error))
1285
1295
integrated_squared_error = integrate_lonlat (squared_error). data
1286
- normalization =
1287
- integrate_lonlat (
1288
- OutputVar (
1289
- squared_error. attributes,
1290
- squared_error. dims,
1291
- squared_error. dim_attributes,
1292
- ones (size (squared_error. data)),
1293
- ),
1294
- ). data
1296
+ ones_var = OutputVar (
1297
+ squared_error. attributes,
1298
+ squared_error. dims,
1299
+ squared_error. dim_attributes,
1300
+ ones (size (squared_error. data)),
1301
+ )
1302
+ ! isnothing (mask) && (ones_var = mask (ones_var))
1303
+ normalization = integrate_lonlat (ones_var). data
1295
1304
# Do ./ instead of / because we are dividing between zero dimensional arrays
1296
1305
mse = integrated_squared_error ./ normalization
1297
1306
ret_attributes[" global_mse" ] = mse
@@ -1305,7 +1314,7 @@ function squared_error(sim::OutputVar, obs::OutputVar)
1305
1314
end
1306
1315
1307
1316
"""
1308
- global_mse(sim::OutputVar, obs::OutputVar)
1317
+ global_mse(sim::OutputVar, obs::OutputVar; mask = nothing )
1309
1318
1310
1319
Return the global mean squared error (MSE) of `data` in `sim` and `obs` over longitude and
1311
1320
latitude.
@@ -1315,15 +1324,18 @@ and latitude. Units must be supplied for data and dimensions in `sim` and `obs`.
1315
1324
for longitude and latitude should be degrees. Resampling is done automatically by resampling
1316
1325
`obs` on `sim`.
1317
1326
1327
+ The parameter `mask` is a function that masks a `OutputVar`. See [`apply_landmask`](@ref)
1328
+ and [`apply_oceanmask`](@ref).
1329
+
1318
1330
See also [`squared_error`](@ref), [`global_rmse`](@ref), [`bias`](@ref), [`global_bias`](@ref).
1319
1331
"""
1320
- function global_mse (sim:: OutputVar , obs:: OutputVar )
1321
- squared_error_var = squared_error (sim, obs)
1332
+ function global_mse (sim:: OutputVar , obs:: OutputVar ; mask = nothing )
1333
+ squared_error_var = squared_error (sim, obs, mask = mask )
1322
1334
return squared_error_var. attributes[" global_mse" ]
1323
1335
end
1324
1336
1325
1337
"""
1326
- global_rmse(sim::OutputVar, obs::OutputVar)
1338
+ global_rmse(sim::OutputVar, obs::OutputVar; mask = nothing )
1327
1339
1328
1340
Return the global root mean squared error (RMSE) of `data` in `sim` and `obs` over longitude
1329
1341
and latitude.
@@ -1333,10 +1345,13 @@ and latitude. Units must be supplied for data and dimensions in `sim` and `obs`.
1333
1345
for longitude and latitude should be degrees. Resampling is done automatically by resampling
1334
1346
`obs` on `sim`.
1335
1347
1348
+ The parameter `mask` is a function that masks a `OutputVar`. See [`apply_landmask`](@ref)
1349
+ and [`apply_oceanmask`](@ref).
1350
+
1336
1351
See also [`squared_error`](@ref), [`global_mse`](@ref), [`bias`](@ref), [`global_bias`](@ref).
1337
1352
"""
1338
- function global_rmse (sim:: OutputVar , obs:: OutputVar )
1339
- squared_error_var = squared_error (sim, obs)
1353
+ function global_rmse (sim:: OutputVar , obs:: OutputVar ; mask = nothing )
1354
+ squared_error_var = squared_error (sim, obs, mask = mask )
1340
1355
return squared_error_var. attributes[" global_rmse" ]
1341
1356
end
1342
1357
0 commit comments