diff --git a/modules/deeplearning/icing_cnn.py b/modules/deeplearning/icing_cnn.py index 1d6a3bef593798f92e7b64a84b61353c9f173292..c4e0103af111c5996f84006cbf39c4ffc44ef4d5 100644 --- a/modules/deeplearning/icing_cnn.py +++ b/modules/deeplearning/icing_cnn.py @@ -958,8 +958,8 @@ def run_restore_static(filename_l1b, filename_l2, ckpt_dir_s_path): return cm_avg -def run_evaluate_static(filename, ckpt_dir_s_path, prob_thresh=0.5, satellite='GOES16', domain='FD'): - data_dct, ll, cc = make_for_full_domain_predict(filename, name_list=train_params, domain=domain) +def run_evaluate_static(h5f, ckpt_dir_s_path, prob_thresh=0.5, satellite='GOES16', domain='FD'): + data_dct, ll, cc = make_for_full_domain_predict(h5f, name_list=train_params, domain=domain) ckpt_dir_s = os.listdir(ckpt_dir_s_path) prob_s = [] for ckpt in ckpt_dir_s: @@ -1000,7 +1000,7 @@ def run_evaluate_static(filename, ckpt_dir_s_path, prob_thresh=0.5, satellite='G ice_lons.append(lon) ice_lats.append(lat) - return filename, ice_lons, ice_lats + return ice_lons, ice_lats if __name__ == "__main__": diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index e31b75945390452aa9a9bedfd8cb6c0a7ab15523..e0f305a2177a8bf236d968f8ecdc87dfaacdb598 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -1826,6 +1826,7 @@ def run_make_images(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', ckpt_dir_s_pat clvrx_files = clvrx_ds.flist for fname in clvrx_files: + h5f = h5py.File(fname, 'r') dto = clvrx_ds.get_datetime(fname) ts = dto.timestamp() clvrx_str_time = dto.strftime('%Y-%m-%d_%H:%M') @@ -1836,7 +1837,7 @@ def run_make_images(clvrx_dir='/Users/tomrink/data/clavrx/RadC/', ckpt_dir_s_pat ts_0 = dto_0.timestamp() ts_1 = dto_1.timestamp() obs_times, obs_lons, obs_lats, _ = time_filter_3(ice_dict, ts_0, ts_1) - _, ice_lons, ice_lats = run_evaluate_static(filename=fname, ckpt_dir_s_path=ckpt_dir_s_path, - prob_thresh=prob_thresh, satellite=satellite, domain=domain) - make_icing_image(fname, ice_lons, ice_lats, clvrx_str_time, satellite, domain, ice_lons_vld=obs_lons, ice_lats_vld=obs_lats, extent=extent) + ice_lons, ice_lats = run_evaluate_static(h5f, ckpt_dir_s_path=ckpt_dir_s_path, prob_thresh=prob_thresh, satellite=satellite, domain=domain) + make_icing_image(h5f, ice_lons, ice_lats, clvrx_str_time, satellite, domain, ice_lons_vld=obs_lons, ice_lats_vld=obs_lats, extent=extent) print('Done: ', clvrx_str_time) + h5f.close() diff --git a/modules/util/plot.py b/modules/util/plot.py index 91bb99d93f2d29d7bd0d5ed5d149880412b3c2b6..10e8ec962fb6fd195650573d50542e554287d2f2 100644 --- a/modules/util/plot.py +++ b/modules/util/plot.py @@ -229,8 +229,7 @@ def plot_image3(image, cmap='Greys'): fig.savefig('/Users/tomrink/image') -def make_icing_image(clvrx_file, ice_lons, ice_lats, clvrx_str_time, satellite, domain, ice_lons_vld=None, ice_lats_vld=None, imagename='icing', extent=[-110, -60, 10, 55]): - h5f = h5py.File(clvrx_file, 'r') +def make_icing_image(h5f, ice_lons, ice_lats, clvrx_str_time, satellite, domain, ice_lons_vld=None, ice_lats_vld=None, imagename='icing', extent=[-110, -60, 10, 55]): image = get_grid_values_all(h5f, 'temp_10_4um_nom') geos, xlen, xmin, xmax, ylen, ymin, ymax = get_cartopy_crs(satellite, domain) @@ -252,7 +251,6 @@ def make_icing_image(clvrx_file, ice_lons, ice_lats, clvrx_str_time, satellite, plt.title(title, loc='left', fontweight='bold', fontsize=24) ImageDirAndName = os.path.join('/Users/tomrink', imagename+'_'+clvrx_str_time) fig.savefig(ImageDirAndName) - h5f.close() # values, edges in Epoch time diff --git a/modules/util/util.py b/modules/util/util.py index a71f8c08653083297f9b5d20a663e5cc5d6ca16c..095f8d8496e6cab0bb6098abc9a0a89e3a042cb3 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -399,6 +399,7 @@ def get_cartopy_crs(satellite, domain): return geos, xlen, xmin, xmax, ylen, ymin, ymax + # ------------ This code will not be needed when we implement a Fully Connected CNN ----------------------------------- # Example GOES file to retrieve GEOS parameters in MetPy form (CONUS) exmp_file_conus = '/Users/tomrink/data/OR_ABI-L1b-RadC-M6C14_G16_s20193140811215_e20193140813588_c20193140814070.nc' @@ -406,10 +407,11 @@ exmp_file_conus = '/Users/tomrink/data/OR_ABI-L1b-RadC-M6C14_G16_s20193140811215 exmp_file_fd = '/Users/tomrink/data/OR_ABI-L1b-RadF-M6C16_G16_s20212521800223_e20212521809542_c20212521809596.nc' -def make_for_full_domain_predict(clvrx_file, name_list=None, satellite='GOES16', domain='FD'): +def make_for_full_domain_predict(h5f, name_list=None, satellite='GOES16', domain='FD'): w_x = 16 w_y = 16 + # keep for reference # if domain == 'CONUS': # exmpl_ds = xr.open_dataset(exmp_file_conus) # elif domain == 'FD': @@ -422,7 +424,7 @@ def make_for_full_domain_predict(clvrx_file, name_list=None, satellite='GOES16', geos, xlen, xmin, xmax, ylen, ymin, ymax = get_cartopy_crs(satellite, domain) - h5f = h5py.File(clvrx_file, 'r') + #h5f = h5py.File(clvrx_file, 'r') grd_dct = {name: None for name in name_list} @@ -461,7 +463,7 @@ def make_for_full_domain_predict(clvrx_file, name_list=None, satellite='GOES16', for didx, ds_name in enumerate(name_list): grd_dct[ds_name] = np.stack(grd_dct_n[ds_name]) - h5f.close() + #h5f.close() return grd_dct, ll, cc # ------------------------------------------------------------------------------------------- \ No newline at end of file