diff --git a/modules/icing/pirep_goes.py b/modules/icing/pirep_goes.py index 3ab7a1a4883bd7a7000a1d2677a883faf10491a1..685a012195241497510730487dd02dc493afeed1 100644 --- a/modules/icing/pirep_goes.py +++ b/modules/icing/pirep_goes.py @@ -87,9 +87,13 @@ def get_goes_datasource(timestamp): return ds -def get_grid_values(h5f, grid_name, j_c, i_c, half_width, scale_factor_name='scale_factor', add_offset_name='add_offset'): +def get_grid_values(h5f, grid_name, j_c, i_c, half_width, scale_factor_name='scale_factor', add_offset_name='add_offset', + fill_value_name='_FillValue', range_name='actual_range'): hfds = h5f[grid_name] attrs = hfds.attrs + if attrs is None: + raise GenericException('No attributes object for: '+grid_name) + ylen, xlen = hfds.shape j_l = j_c-half_width @@ -103,21 +107,36 @@ def get_grid_values(h5f, grid_name, j_c, i_c, half_width, scale_factor_name='sca return None grd_vals = hfds[j_l:j_r, i_l:i_r] - grd_vals = np.where(grd_vals == -999, np.nan, grd_vals) - grd_vals = np.where(grd_vals == -127, np.nan, grd_vals) - grd_vals = np.where(grd_vals == -32768, np.nan, grd_vals) - - if attrs is None: - return grd_vals if scale_factor_name is not None: - scale_factor = attrs.get(scale_factor_name)[0] + attr = attrs.get(scale_factor_name) + if attr is None: + raise GenericException('Attribute: '+scale_factor_name+' not found for variable: '+grid_name) + scale_factor = attr[0] grd_vals = grd_vals * scale_factor if add_offset_name is not None: - add_offset = attrs.get(add_offset_name)[0] + attr = attrs.get(add_offset_name) + if attr is None: + raise GenericException('Attribute: '+add_offset_name+' not found for variable: '+grid_name) + add_offset = attr[0] grd_vals = grd_vals + add_offset + if range_name is not None: + attr = attrs.get(range_name) + if attr is None: + raise GenericException('Attribute: '+range_name+' not found for variable: '+grid_name) + low = attr[0] + high = attr[1] + grd_vals = np.where(grd_vals < low, np.nan, grd_vals) + grd_vals = np.where(grd_vals > high, np.nan, grd_vals) + elif fill_value_name is not None: + attr = attrs.get(fill_value_name) + if attr is None: + raise GenericException('Attribute: '+fill_value_name+' not found for variable: '+grid_name) + fill_value = attr[0] + grd_vals = np.where(grd_vals == fill_value, np.nan, grd_vals) + return grd_vals