Skip to content
Snippets Groups Projects
Commit 0c70c961 authored by tomrink's avatar tomrink
Browse files

snapshot...

parent 488f4d81
No related branches found
No related tags found
No related merge requests found
......@@ -852,21 +852,20 @@ class SRCNN:
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')
cp = get_grid_values_all(h5f, 'cloud_probability')
opd = get_grid_values_all(h5f, label_param)
cld_frac = self.run_inference_(bt, refl, refl_lo, refl_hi, refl_std, cp)
cldy_frac_opd = self.run_inference_(bt, refl, refl_lo, refl_hi, refl_std, cp, opd)
cld_frac_out = np.zeros((y_len, x_len), dtype=np.int8)
cldy_frac_opd_out = np.zeros((y_len, x_len), dtype=np.int8)
border = int((KERNEL_SIZE - 1) / 2)
cld_frac_out[border:y_len - border, border:x_len - border] = cld_frac[0, :, :]
cldy_frac_opd_out[border:y_len - border, border:x_len - border] = cldy_frac_opd[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
cldy_frac_opd_out[off_earth] = -1
cldy_frac_opd_out[np.invert(off_earth) & night] = -1
# --- Make a DataArray ----------------------------------------------------
# var_names = ['cloud_fraction', 'temp_11_0um', 'refl_0_65um']
......@@ -882,10 +881,10 @@ class SRCNN:
h5f.close()
if out_file is not None:
np.save(out_file, (cld_frac_out, bt, refl, cp))
np.save(out_file, (cldy_frac_opd_out, bt, refl, cp))
else:
# return [cld_frac_out, bt, refl, cp, lons, lats]
return cld_frac_out
return cldy_frac_opd_out
def run_inference_full_disk(self, in_file, out_file):
gc.collect()
......@@ -900,7 +899,8 @@ class SRCNN:
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)
cp = get_grid_values_all(h5f, 'cloud_probability')
opd = get_grid_values_all(h5f, label_param)
t1 = time.time()
print(' read time:', (t1-t0))
......@@ -910,6 +910,7 @@ class SRCNN:
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, :]
opd_nh = opd[0:h_y_len + 1, :]
bt_sh = bt[h_y_len - 1:y_len, :]
refl_sh = refl[h_y_len - 1:y_len, :]
......@@ -917,23 +918,24 @@ class SRCNN:
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, :]
opd_sh = opd[h_y_len - 1:y_len, :]
t0 = time.time()
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)
cldy_frac_opd_nh = self.run_inference_(bt_nh, refl_nh, refl_lo_nh, refl_hi_nh, refl_std_nh, cp_nh, opd_nh)
cldy_frac_opd_sh = self.run_inference_(bt_sh, refl_sh, refl_lo_sh, refl_hi_sh, refl_std_sh, cp_sh, opd_sh)
t1 = time.time()
print(' inference time: ', (t1-t0))
cld_frac_out = np.zeros((y_len, x_len), dtype=np.int8)
cldy_frac_opd_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, :, :]
cldy_frac_opd_out[border:h_y_len, border:x_len - border] = cldy_frac_opd_nh[0, :, :]
cldy_frac_opd_out[h_y_len:y_len - border, border:x_len - border] = cldy_frac_opd_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
cldy_frac_opd_out[off_earth] = -1
cldy_frac_opd_out[np.invert(off_earth) & night] = -1
# --- Make DataArray -------------------------------------------------
# var_names = ['cloud_fraction', 'temp_11_0um', 'refl_0_65um']
......@@ -949,26 +951,26 @@ class SRCNN:
h5f.close()
if out_file is not None:
np.save(out_file, (cld_frac_out, bt, refl, cp))
np.save(out_file, (cldy_frac_opd_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)
refl_lo = normalize(refl_lo, 'refl_0_65um_nom', mean_std_dct)
refl_hi = normalize(refl_hi, 'refl_0_65um_nom', mean_std_dct)
refl_std = np.where(np.isnan(refl_std), 0, refl_std)
return cldy_frac_opd_out
def run_inference_(self, bt, refl, refl_lo, refl_hi, refl_std, cp, opd):
bt = scale(bt, 'temp_11_0um_nom', mean_std_dct)
refl = scale(refl, 'refl_0_65um_nom', mean_std_dct)
refl_lo = scale(refl_lo, 'refl_0_65um_nom', mean_std_dct)
refl_hi = scale(refl_hi, 'refl_0_65um_nom', mean_std_dct)
refl_rng = refl_hi - refl_lo
refl_std = scale2(refl_std, 0.0, 30.0)
cp = np.where(np.isnan(cp), 0, cp)
opd = scale(opd, label_param, mean_std_dct)
data = np.stack([bt, refl, refl_lo, refl_hi, refl_std, cp], axis=2)
data = np.stack([bt, cp, refl, refl_rng, refl_std, opd], axis=2)
data = np.expand_dims(data, axis=0)
probs = self.do_inference(data)
cld_frac = probs.argmax(axis=3)
cld_frac = cld_frac.astype(np.int8)
opd = self.do_inference(data)
return cld_frac
return opd
def run_restore_static(directory, ckpt_dir, out_file=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment