From ae0f9f719808156426300e2856044149237ddc7e Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Wed, 14 Jun 2023 12:33:11 -0500 Subject: [PATCH] snapshot... --- .../deeplearning/cloud_fraction_fcn_abi.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/modules/deeplearning/cloud_fraction_fcn_abi.py b/modules/deeplearning/cloud_fraction_fcn_abi.py index c140172a..4614aaf6 100644 --- a/modules/deeplearning/cloud_fraction_fcn_abi.py +++ b/modules/deeplearning/cloud_fraction_fcn_abi.py @@ -822,6 +822,70 @@ class SRCNN: # return [cld_frac_out, bt, refl, cp, lons, lats] return cld_frac_out + def run_inference_full_disk(self, in_file, out_file): + gc.collect() + + h5f = h5py.File(in_file, 'r') + + bt = get_grid_values_all(h5f, 'temp_11_0um_nom') + y_len, x_len = bt.shape + h_y_len = int(y_len / 2) + refl = get_grid_values_all(h5f, 'refl_0_65um_nom') + refl_lo = get_grid_values_all(h5f, 'refl_0_65um_nom_min_sub') + refl_hi = get_grid_values_all(h5f, 'refl_0_65um_nom_max_sub') + refl_std = get_grid_values_all(h5f, 'refl_0_65um_nom_stddev_sub') + cp = get_grid_values_all(h5f, label_param) + # lons = get_grid_values_all(h5f, 'longitude') + # lats = get_grid_values_all(h5f, 'latitude') + + bt_nh = bt[0:h_y_len + 1, :] + refl_nh = refl[0:h_y_len + 1, :] + refl_lo_nh = refl_lo[0:h_y_len + 1, :] + refl_hi_nh = refl_hi[0:h_y_len + 1, :] + refl_std_nh = refl_std[0:h_y_len + 1, :] + cp_nh = cp[0:h_y_len + 1, :] + + bt_sh = bt[h_y_len - 1:y_len, :] + refl_sh = refl[h_y_len - 1:y_len, :] + refl_lo_sh = refl_lo[h_y_len - 1:y_len, :] + refl_hi_sh = refl_hi[h_y_len - 1:y_len, :] + refl_std_sh = refl_std[h_y_len - 1:y_len, :] + cp_sh = cp[h_y_len - 1:y_len, :] + + cld_frac_nh = self.run_inference_(bt_nh, refl_nh, refl_lo_nh, refl_hi_nh, refl_std_nh, cp_nh) + + cld_frac_sh = self.run_inference_(bt_sh, refl_sh, refl_lo_sh, refl_hi_sh, refl_std_sh, cp_sh) + + cld_frac_out = np.zeros((y_len, x_len), dtype=np.int8) + border = int((KERNEL_SIZE - 1) / 2) + cld_frac_out[border:h_y_len, border:x_len - border] = cld_frac_nh[0, :, :] + cld_frac_out[h_y_len:y_len - border, border:x_len - border] = cld_frac_sh[0, :, :] + + # Use this hack for now. + off_earth = (bt <= 161.0) + night = np.isnan(refl) + cld_frac_out[off_earth] = -1 + cld_frac_out[np.invert(off_earth) & night] = -1 + + # --- Make DataArray ------------------------------------------------- + # var_names = ['cloud_fraction', 'temp_11_0um', 'refl_0_65um'] + # dims = ['num_params', 'y', 'x'] + # da = xr.DataArray(np.stack([cld_frac_out, bt, refl], axis=0), dims=dims) + # da.assign_coords({ + # 'num_params': var_names, + # 'lat': (['y', 'x'], lats), + # 'lon': (['y', 'x'], lons) + # }) + # ------------------------------------------------------------------------ + + h5f.close() + + if out_file is not None: + np.save(out_file, (cld_frac_out, bt, refl, cp)) + else: + # return [cld_frac_out, bt, refl, cp, lons, lats] + return cld_frac_out + def run_inference_(self, bt, refl, refl_lo, refl_hi, refl_std, cp): bt = normalize(bt, 'temp_11_0um_nom', mean_std_dct) refl = normalize(refl, 'refl_0_65um_nom', mean_std_dct) -- GitLab