diff --git a/modules/util/acspo_validate.py b/modules/util/acspo_validate.py index 4569e426a2e4c61dd537da75d1fe1b34ea252dbf..335b3b793cfdaff7c6089b61179de4a7261d1968 100644 --- a/modules/util/acspo_validate.py +++ b/modules/util/acspo_validate.py @@ -5,7 +5,7 @@ import xarray as xr from util.util import get_grid_values_all -def acspo_validate(oper_file, cspp_file, rel_tol=0.001, deg_tol=0.0002, outfile_nc=None): +def acspo_validate(oper_file, cspp_file, rel_tol=0.01, deg_tol=0.0002, outfile_nc=None): h5f_oper = h5py.File(oper_file, 'r') h5f_cspp = h5py.File(cspp_file, 'r') @@ -107,28 +107,28 @@ def acspo_validate(oper_file, cspp_file, rel_tol=0.001, deg_tol=0.0002, outfile_ overlap_shape = lon_cspp.shape print('overlap shape, size: ', overlap_shape, np.size(lon_cspp)) - # sst_cspp_2d = np.where(cspp_clear, sst_cspp_2d, np.nan) - # sst_oper_2d = np.where(oper_clear, sst_oper_2d, np.nan) + both_valid = np.invert(np.isnan(sst_cspp_2d)) & np.invert(np.isnan(sst_oper_2d)) + sst_cspp_2d = np.where(both_valid, sst_cspp_2d, np.nan) + sst_oper_2d = np.where(both_valid, sst_oper_2d, np.nan) - sst_cspp = sst_cspp_2d.flatten() - sst_oper = sst_oper_2d.flatten() - oper_clear = oper_clear.flatten() - cspp_clear = cspp_clear.flatten() - lon_cspp = lon_cspp.flatten() - lat_cspp = lat_cspp.flatten() - lon_oper = lon_oper.flatten() - lat_oper = lat_oper.flatten() + both_valid = both_valid.flatten() + sst_cspp = sst_cspp_2d.flatten()[both_valid] + sst_oper = sst_oper_2d.flatten()[both_valid] + oper_clear = oper_clear.flatten()[both_valid] + cspp_clear = cspp_clear.flatten()[both_valid] + lon_cspp = lon_cspp.flatten()[both_valid] + lat_cspp = lat_cspp.flatten()[both_valid] + lon_oper = lon_oper.flatten()[both_valid] + lat_oper = lat_oper.flatten()[both_valid] - both_valid = np.invert(np.isnan(sst_cspp)) & np.invert(np.isnan(sst_oper)) both_clear = oper_clear & cspp_clear - keep = both_valid & both_clear - valid_sst_cspp = sst_cspp[keep] - valid_sst_oper = sst_oper[keep] - valid_lon_cspp = lon_cspp[keep] - valid_lat_cspp = lat_cspp[keep] - valid_lon_oper = lon_oper[keep] - valid_lat_oper = lat_oper[keep] + valid_sst_cspp = sst_cspp[both_clear] + valid_sst_oper = sst_oper[both_clear] + valid_lon_cspp = lon_cspp[both_clear] + valid_lat_cspp = lat_cspp[both_clear] + valid_lon_oper = lon_oper[both_clear] + valid_lat_oper = lat_oper[both_clear] xarray_data = xr.Dataset({ 'sst_cspp': xr.DataArray(valid_sst_cspp, coords=None, dims=None, name='sst_cspp'), @@ -142,7 +142,7 @@ def acspo_validate(oper_file, cspp_file, rel_tol=0.001, deg_tol=0.0002, outfile_ xarray_data.to_netcdf(outfile_nc) print('fraction SSTs approx equal: ', - np.sum(np.isclose(valid_sst_cspp, valid_sst_oper, rtol=rel_tol))/np.sum(keep)) + np.sum(np.isclose(valid_sst_cspp, valid_sst_oper, rtol=rel_tol))/np.sum(both_clear)) h5f_oper.close() h5f_cspp.close()