From 3325c9333efd537563f7368291d8075983f5cc0c Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Thu, 14 Nov 2024 12:05:51 -0600 Subject: [PATCH] snapshot... --- modules/util/acspo_validate.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/modules/util/acspo_validate.py b/modules/util/acspo_validate.py index 0627c836..fba92dc0 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, outfile=None): +def acspo_validate(oper_file, cspp_file, outfile_nc=None): h5f_oper = h5py.File(oper_file, 'r') h5f_cspp = h5py.File(cspp_file, 'r') @@ -29,8 +29,8 @@ def acspo_validate(oper_file, cspp_file, outfile=None): l2p_flags_oper = get_grid_values_all(h5f_oper, 'l2p_flags')[0, ] # generate a ndarray of boolean - cspp_clear = (l2p_flags_cspp & (1 << 15)) != 0 - oper_clear = (l2p_flags_oper & (1 << 15)) != 0 + cspp_clear = (l2p_flags_cspp & (1 << 15)) == 0 + oper_clear = (l2p_flags_oper & (1 << 15)) == 0 start_idx_oper = -1 stop_idx_oper = -1 @@ -54,16 +54,23 @@ def acspo_validate(oper_file, cspp_file, outfile=None): lat_cspp = lat_cspp[start_idx_cspp:stop_idx_cspp, :] lon_oper = lon_oper[start_idx_oper:stop_idx_oper, :] lat_oper = lat_oper[start_idx_oper:stop_idx_oper, :] - cspp_clear = cspp_clear[start_idx_oper:stop_idx_oper, :] + cspp_clear = cspp_clear[start_idx_cspp:stop_idx_cspp, :] oper_clear = oper_clear[start_idx_oper:stop_idx_oper, :] overlap_shape = lon_cspp.shape print('overlap shape, size: ', overlap_shape, np.size(lon_cspp)) + # check lon/lat arrays print(np.sum(np.isclose(lon_cspp, lon_oper, rtol=0.001))) print(np.sum(np.isclose(lat_cspp, lat_oper, rtol=0.001))) - sst_cspp = sst_cspp[start_idx_cspp:stop_idx_cspp, :].flatten() - sst_oper = sst_oper[start_idx_oper:stop_idx_oper, :].flatten() + sst_cspp_2d = sst_cspp[start_idx_cspp:stop_idx_cspp, :] + sst_oper_2d = sst_oper[start_idx_oper:stop_idx_oper, :] + + sst_cspp_2d = np.where(cspp_clear, sst_cspp_2d, np.nan) + sst_oper_2d = np.where(oper_clear, 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() both_clear = oper_clear & cspp_clear @@ -95,12 +102,14 @@ def acspo_validate(oper_file, cspp_file, outfile=None): 'oper_lat': xr.DataArray([valid_lat_oper], coords=None, dims=None, name='oper_lat'), 'oper_lon': xr.DataArray([valid_lon_oper], coords=None, dims=None, name='oper_lon'), }) - if outfile is not None: - xarray_data.to_netcdf('/Users/tomrink/sst_values.nc') + if outfile_nc is not None: + xarray_data.to_netcdf('/Users/tomrink/outfile_nc') print('fraction approx equal: ', np.sum(np.isclose(valid_sst_cspp, valid_sst_oper, rtol=0.001))/np.sum(both_valid)) # print(np.histogram((sst_cspp[both_valid] - sst_oper[both_valid]), bins=10)) h5f_oper.close() - h5f_cspp.close() \ No newline at end of file + h5f_cspp.close() + + return sst_cspp_2d, sst_oper_2d -- GitLab