From 10ba648a4a1c6f24fd8afac0ddadeaf45018e96a Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Tue, 18 Apr 2023 13:23:49 -0500 Subject: [PATCH] snapshot... --- modules/util/abi_surfrad.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/util/abi_surfrad.py b/modules/util/abi_surfrad.py index aaac9b72..7f0bb523 100644 --- a/modules/util/abi_surfrad.py +++ b/modules/util/abi_surfrad.py @@ -10,6 +10,7 @@ group_name_i = 'super/' group_name_m = 'orig/' solzen_name = group_name_m + 'solar_zenith' +snow_class_name = group_name_m + 'snow_class' params_i = [group_name_i+'temp_ch38', group_name_i+'refl_ch01', group_name_i+target_param] params_m = [group_name_m+'temp_ch38', group_name_m+'refl_ch01', group_name_m+'refl_submin_ch01', @@ -19,6 +20,10 @@ param_idx_m = params_m.index(group_name_m + target_param) param_idx_i = params_i.index(group_name_i + target_param) +def snow_covered(tile): + return np.any(tile > 1) + + def is_missing(p_idx, tile): keep = np.invert(np.isnan(tile[p_idx, ])) if np.sum(keep) / keep.size < 0.98: @@ -64,7 +69,7 @@ def process_cld_opd(grd_k): return grd_k -def run_all(directory, out_directory, day_night='ANY', pattern='clavrx_*.nc', start=10): +def run_all(directory, out_directory, day_night='ANY', pattern='clavrx_*.nc', start=10, is_snow_covered=None): cnt = start total_num_train_samples = 0 total_num_valid_samples = 0 @@ -95,7 +100,8 @@ def run_all(directory, out_directory, day_night='ANY', pattern='clavrx_*.nc', st try: num_not_missing = run(h5f, params_m, data_tiles_m, params_i, data_tiles_i, - num_keep_x_tiles=num_keep_x_tiles, tile_width=16, kernel_size=4, factor=4, day_night=day_night) + num_keep_x_tiles=num_keep_x_tiles, tile_width=16, kernel_size=4, factor=4, + day_night=day_night, is_snow_covered=is_snow_covered) except Exception as e: print(e) h5f.close() @@ -208,7 +214,8 @@ def run_all(directory, out_directory, day_night='ANY', pattern='clavrx_*.nc', st # tile_width: Must be even! # kernel_size: Must be odd! -def run(h5f, params_m, data_tiles_m, params_i, data_tiles_i, num_keep_x_tiles=8, tile_width=64, kernel_size=3, factor=2, day_night='ANY'): +def run(h5f, params_m, data_tiles_m, params_i, data_tiles_i, num_keep_x_tiles=8, tile_width=64, kernel_size=3, factor=2, + day_night='ANY', is_snow_covered=None): border = int((kernel_size - 1)/2) + 1 # Need to add for interpolation with no edge effects @@ -220,6 +227,9 @@ def run(h5f, params_m, data_tiles_m, params_i, data_tiles_i, num_keep_x_tiles=8, if day_night != 'ANY': solzen = get_grid_values(h5f, solzen_name, 0, 0, None, num_lines, num_pixels) + if is_snow_covered is not None: + snow = get_grid_values(h5f, snow_class_name, 0, 0, None, num_lines, num_pixels) + grd_s = [] for param in params_m: try: @@ -259,6 +269,14 @@ def run(h5f, params_m, data_tiles_m, params_i, data_tiles_i, num_keep_x_tiles=8, i_a = i_start + i * i_skip i_b = i_a + tile_width + if is_snow_covered is not None: + if is_snow_covered: + if not snow_covered(snow[j_a:j_b, i_a:i_b]): + continue + else: + if snow_covered(snow[j_a:j_b, i_a:i_b]): + continue + if day_night == 'DAY' and not is_day(solzen[j_a:j_b, i_a:i_b]): continue elif day_night == 'NIGHT' and is_day(solzen[j_a:j_b, i_a:i_b]): -- GitLab