Skip to content
Snippets Groups Projects
Commit 3325c933 authored by tomrink's avatar tomrink
Browse files

snapshot...

parent b865ac43
Branches
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ import xarray as xr ...@@ -5,7 +5,7 @@ import xarray as xr
from util.util import get_grid_values_all 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_oper = h5py.File(oper_file, 'r')
h5f_cspp = h5py.File(cspp_file, 'r') h5f_cspp = h5py.File(cspp_file, 'r')
...@@ -29,8 +29,8 @@ def acspo_validate(oper_file, cspp_file, outfile=None): ...@@ -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, ] l2p_flags_oper = get_grid_values_all(h5f_oper, 'l2p_flags')[0, ]
# generate a ndarray of boolean # generate a ndarray of boolean
cspp_clear = (l2p_flags_cspp & (1 << 15)) != 0 cspp_clear = (l2p_flags_cspp & (1 << 15)) == 0
oper_clear = (l2p_flags_oper & (1 << 15)) != 0 oper_clear = (l2p_flags_oper & (1 << 15)) == 0
start_idx_oper = -1 start_idx_oper = -1
stop_idx_oper = -1 stop_idx_oper = -1
...@@ -54,16 +54,23 @@ def acspo_validate(oper_file, cspp_file, outfile=None): ...@@ -54,16 +54,23 @@ def acspo_validate(oper_file, cspp_file, outfile=None):
lat_cspp = lat_cspp[start_idx_cspp:stop_idx_cspp, :] lat_cspp = lat_cspp[start_idx_cspp:stop_idx_cspp, :]
lon_oper = lon_oper[start_idx_oper:stop_idx_oper, :] lon_oper = lon_oper[start_idx_oper:stop_idx_oper, :]
lat_oper = lat_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, :] oper_clear = oper_clear[start_idx_oper:stop_idx_oper, :]
overlap_shape = lon_cspp.shape overlap_shape = lon_cspp.shape
print('overlap shape, size: ', overlap_shape, np.size(lon_cspp)) 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(lon_cspp, lon_oper, rtol=0.001)))
print(np.sum(np.isclose(lat_cspp, lat_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_cspp_2d = sst_cspp[start_idx_cspp:stop_idx_cspp, :]
sst_oper = sst_oper[start_idx_oper:stop_idx_oper, :].flatten() 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() oper_clear = oper_clear.flatten()
cspp_clear = cspp_clear.flatten() cspp_clear = cspp_clear.flatten()
both_clear = oper_clear & cspp_clear both_clear = oper_clear & cspp_clear
...@@ -95,12 +102,14 @@ def acspo_validate(oper_file, cspp_file, outfile=None): ...@@ -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_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'), 'oper_lon': xr.DataArray([valid_lon_oper], coords=None, dims=None, name='oper_lon'),
}) })
if outfile is not None: if outfile_nc is not None:
xarray_data.to_netcdf('/Users/tomrink/sst_values.nc') xarray_data.to_netcdf('/Users/tomrink/outfile_nc')
print('fraction approx equal: ', print('fraction approx equal: ',
np.sum(np.isclose(valid_sst_cspp, valid_sst_oper, rtol=0.001))/np.sum(both_valid)) 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)) # print(np.histogram((sst_cspp[both_valid] - sst_oper[both_valid]), bins=10))
h5f_oper.close() h5f_oper.close()
h5f_cspp.close() h5f_cspp.close()
\ No newline at end of file
return sst_cspp_2d, sst_oper_2d
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment