diff --git a/modules/util/acspo_validate.py b/modules/util/acspo_validate.py index a503e78d3cc407f057dfee264e1ce3af008fed7b..e3ae56222efb0740bb01c4dddb0bec6449290137 100644 --- a/modules/util/acspo_validate.py +++ b/modules/util/acspo_validate.py @@ -1,5 +1,6 @@ import numpy as np import h5py +import xarray as xr from util.util import get_grid_values_all @@ -68,13 +69,37 @@ def acspo_validate(oper_file, cspp_file): both_clear = oper_clear & cspp_clear sst_cspp = sst_cspp[both_clear] sst_oper = sst_oper[both_clear] + lon_cspp = lon_cspp.flatten() + lat_cspp = lat_cspp.flatten() + lon_oper = lon_oper.flatten() + lat_oper = lat_oper.flatten() + lon_cspp = lon_cspp[both_clear] + lat_cspp = lat_cspp[both_clear] + lon_oper = lon_oper[both_clear] + lat_oper = lat_oper[both_clear] both_valid = np.invert(np.isnan(sst_cspp)) & np.invert(np.isnan(sst_oper)) print('number of clear and valid SSTs in both: ', np.sum(both_valid)) + valid_sst_cspp = sst_cspp[both_valid] + valid_sst_oper = sst_oper[both_valid] + valid_lon_cspp = lon_cspp[both_valid] + valid_lat_cspp = lat_cspp[both_valid] + valid_lon_oper = lon_oper[both_valid] + valid_lat_oper = lat_oper[both_valid] + + xarray_data = xr.Dataset({ + 'sst_cspp': xr.DataArray([valid_sst_cspp], coords=None, dims=None, name='sst_cspp'), + 'sst_oper': xr.DataArray([valid_sst_oper], coords=None, dims=None, name='sst_oper'), + 'cspp_lat': xr.DataArray([valid_lat_cspp], coords=None, dims=None, name='cspp_lat'), + 'cspp_lon': xr.DataArray([valid_lon_cspp], coords=None, dims=None, name='cspp_lon'), + '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'), + }) + xarray_data.to_netcdf('/Users/tomrink/sst_values.nc') print('fraction approx equal: ', - np.sum(np.isclose(sst_cspp[both_valid], sst_oper[both_valid], 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)) - - + h5f_oper.close() + h5f_cspp.close() \ No newline at end of file