diff --git a/modules/util/util.py b/modules/util/util.py index 730d910983e15dd9cb40a9b70d54ff8f758e0639..378c11cce641339ec48ad451b6374fc7349a260d 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -667,7 +667,15 @@ def make_for_full_domain_predict_viirs_clavrx(h5f, name_list=None, res_fac=1): for ds_name in name_list: grd_dct[ds_name] = np.stack(grd_dct_n[ds_name]) - return grd_dct, ll, cc + lats = get_grid_values(h5f, 'latitude', j_0, i_0, None, num_j=ylen, num_i=xlen, range_name=None) + lons = get_grid_values(h5f, 'longitude', j_0, i_0, None, num_j=ylen, num_i=xlen, range_name=None) + + ll, cc = np.meshgrid(ll, cc, indexing='ij') + + lats = lats[ll, cc] + lons = lons[ll, cc] + + return grd_dct, ll, cc, lats, lons def make_for_full_domain_predict2(h5f, satellite='GOES16', domain='FD', res_fac=1): @@ -1049,8 +1057,7 @@ def write_icing_file_nc4(clvrx_str_time, output_dir, preds_dct, probs_dct, rootgrp.close() -def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, - lons, lats, +def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, lons, lats, has_time=False, use_nan=False, prob_thresh=0.5, bt_10_4=None): outfile_name = output_dir + 'icing_prediction_'+clvrx_str_time+'.nc' rootgrp = Dataset(outfile_name, 'w', format='NETCDF4') @@ -1062,8 +1069,10 @@ def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, time_dim_name = 'time' geo_coords = 'time y x' - dim_0 = rootgrp.createDimension(dim_0_name, size=x.shape[0]) - dim_1 = rootgrp.createDimension(dim_1_name, size=y.shape[0]) + dim_1_len, dim_0_len = lons.shape + + dim_0 = rootgrp.createDimension(dim_0_name, size=dim_0_len) + dim_1 = rootgrp.createDimension(dim_1_name, size=dim_1_len) dim_time = rootgrp.createDimension(time_dim_name, size=1) tvar = rootgrp.createVariable('time', 'f8', time_dim_name) @@ -1086,7 +1095,7 @@ def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, #icing_pred_ds.setncattr('grid_mapping', 'Projection') icing_pred_ds.setncattr('missing', -1) if has_time: - preds = preds.reshape((1, y.shape[0], x.shape[0])) + preds = preds.reshape((1, dim_1_len, dim_0_len)) icing_pred_ds[:,] = preds for flvl in flt_lvls: @@ -1101,7 +1110,7 @@ def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, else: icing_prob_ds.setncattr('missing', np.nan) if has_time: - probs = probs.reshape((1, y.shape[0], x.shape[0])) + probs = probs.reshape((1, dim_1_len, dim_0_len)) if use_nan: probs = np.where(probs < prob_thresh, np.nan, probs) icing_prob_ds[:,] = probs @@ -1111,7 +1120,7 @@ def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, if use_nan: max_prob = np.where(max_prob < prob_thresh, np.nan, max_prob) if has_time: - max_prob = max_prob.reshape(1, y.shape[0], x.shape[0]) + max_prob = max_prob.reshape(1, dim_1_len, dim_0_len) icing_prob_ds = rootgrp.createVariable('max_icing_probability_column', 'f4', var_dim_list) icing_prob_ds.setncattr('coordinates', geo_coords) @@ -1127,7 +1136,7 @@ def write_icing_file_nc4_viirs(clvrx_str_time, output_dir, preds_dct, probs_dct, if use_nan: max_lvl = np.where(max_lvl == -1, np.nan, max_lvl) if has_time: - max_lvl = max_lvl.reshape((1, y.shape[0], x.shape[0])) + max_lvl = max_lvl.reshape((1, dim_1_len, dim_0_len)) icing_pred_ds = rootgrp.createVariable('max_icing_probability_level', 'i2', var_dim_list) icing_pred_ds.setncattr('coordinates', geo_coords)