diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index 8d4439cb23122a24733e096101b37d3c3bb25deb..a7548fe475a4e7aca1b14d55af512edc74a68f0c 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -4,7 +4,8 @@ import pickle import matplotlib.pyplot as plt import os from util.util import get_time_tuple_utc, GenericException, add_time_range_to_filename, is_night, is_day, \ - get_grid_values_all, check_oblique, make_times, find_bin_index, get_timestamp, homedir + check_oblique, make_times, find_bin_index, get_timestamp, homedir +from util.plot import make_icing_image from aeolus.datasource import CLAVRx, CLAVRx_VIIRS, GOESL1B import h5py import re @@ -12,7 +13,7 @@ import datetime from datetime import timezone import glob from skyfield import api, almanac -import xarray as xr +from deeplearning.icing_cnn import run_evaluate_static goes_date_format = '%Y%j%H' goes16_directory = '/arcdata/goes/grb/goes16' # /year/date/abi/L1b/RadC @@ -1815,68 +1816,24 @@ def tiles_info(filename): print('Icing 5: ', np.sum(iint == 5)) print('Icing 6: ', np.sum(iint == 6)) -# ------------ 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' -# Full Disk -exmp_file_fd = '/Users/tomrink/data/OR_ABI-L1b-RadF-M6C16_G16_s20212521800223_e20212521809542_c20212521809596.nc' +def run_make_images(ckpt_dir_s_path='/Users/tomrink/tf_model/', prob_thresh=0.5, domain='CONUS', extent=[-105, -70, 15, 50]): + ice_dict, no_ice_dict, neg_ice_dict = setup('/Users/tomrink/data/pirep/pireps_202109140000_202109142359.csv') -def make_for_full_domain_predict(clvrx_file, name_list=l1b_ds_list, domain='FD'): - w_x = 16 - w_y = 16 + clvrx_ds = CLAVRx('/Users/tomrink/data/clavrx/RadC/265/') + clvrx_files = clvrx_ds.flist - if domain == 'CONUS': - exmpl_ds = xr.open_dataset(exmp_file_conus) - elif domain == 'FD': - exmpl_ds = xr.open_dataset(exmp_file_fd) - mdat = exmpl_ds.metpy.parse_cf('Rad') - geos = mdat.metpy.cartopy_crs - xlen = mdat.x.values.size - ylen = mdat.y.values.size - exmpl_ds.close() - - h5f = h5py.File(clvrx_file, 'r') - - grd_dct = {name: None for name in name_list} - - cnt_a = 0 - for didx, ds_name in enumerate(name_list): - gvals = get_grid_values_all(h5f, ds_name) - if gvals is not None: - grd_dct[ds_name] = gvals - cnt_a += 1 - - if cnt_a > 0 and cnt_a != len(name_list): - raise GenericException('weirdness') - - grd_dct_n = {name: [] for name in name_list} - - n_x = int(xlen/w_x) - n_y = int(ylen/w_y) - - i_0 = 0 - j_0 = 0 - - cc = [] - ll = [] - - for didx, ds_name in enumerate(name_list): - for j in range(4, n_y-4, 1): - j_ul = j_0 + j * w_y - for i in range(4, n_x-4, 1): - i_ul = i_0 + i * w_x - if didx == 0: - ll.append(j_ul) - cc.append(i_ul) - grd_dct_n[ds_name].append(grd_dct[ds_name][j_ul:j_ul+w_y, i_ul:i_ul+w_x]) - - grd_dct = {name: None for name in name_list} - for didx, ds_name in enumerate(name_list): - grd_dct[ds_name] = np.stack(grd_dct_n[ds_name]) - - h5f.close() - - return grd_dct, ll, cc -# ------------------------------------------------------------------------------------------- + for fname in clvrx_files: + dto = clvrx_ds.get_datetime(fname) + ts = dto.timestamp() + clvrx_str_time = dto.strftime('%Y-%m-%d_%H:%M') + dto, _ = get_time_tuple_utc(ts) + dto_0 = dto - datetime.timedelta(minutes=60) + dto_1 = dto + datetime.timedelta(minutes=60) + 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, domain=domain) + make_icing_image(fname, ice_lons, ice_lats, clvrx_str_time, ice_lons_vld=obs_lons, ice_lats_vld=obs_lats, extent=extent) + print('Done: ', clvrx_str_time)