def sz_lut(scheme, hydrom_type, list_frequencies, list_elevations, list_temperatures, quad_pts): """ Computes and saves a scattering lookup table for a given hydrometeor type (non melting) and various frequencies, elevations, etc. Args: scheme: microphysical scheme, '1mom' or '2mom' hydrom_type: the hydrometeor type, either 'mS' (melt. snow) or 'mG' (melt. graup) list_frequencies: list of frequencies for which to obtain the lookup tables, in GHz list_elevations: list of incident elevation angles for which to obtain the lookup tables, in degrees list_temperatures: list of temperatures for which to obtain the lookup tables, in K quad_pts: the quadrature points computed with the calculate_quadrature_points function (see below) Returns: No output but saves a lookup table """ if np.isscalar(list_frequencies): list_frequencies = [list_frequencies] hydrom = create_hydrometeor(hydrom_type, scheme) if hydrom_type != 'R': hydrom.radius_type = Scatterer.RADIUS_EQUAL_VOLUME else: hydrom.radius_type = Scatterer.RADIUS_MAXIMUM list_D = np.linspace(hydrom.d_min, hydrom.d_max, NUM_DIAMETERS).astype('float32') num_cores = multiprocessing.cpu_count() for f in list_frequencies: global SCATTERER wavelength = constants.C / (f * 1E09) * 1000 # in mm SCATTERER = _create_scatterer(wavelength, hydrom.canting_angle_std) SZ_matrices = np.zeros( (len(list_elevations), len(list_temperatures), len(list_D), 12)) for i, e in enumerate(list_elevations): print('Running elevation : ' + str(e)) results = (Parallel(n_jobs=num_cores)( delayed(_compute_sz_with_quad)(hydrom, f, e, t, quad_pts[0], quad_pts[1], list_D) for t in list_temperatures)) arr_SZ = _flatten_matrices(results) SZ_matrices[i, :, :, :] = arr_SZ # Create lookup table for a given frequency lut_SZ = Lookup_table() lut_SZ.add_axis('e', list_elevations) lut_SZ.add_axis('t', list_temperatures) lut_SZ.add_axis('d', list_D) lut_SZ.add_axis('sz', np.arange(12)) lut_SZ.set_value_table(SZ_matrices) # The name of the lookup table is lut_SZ_<hydro_name>_<freq>_<scheme>.lut filename = (FOLDER_LUT + "lut_SZ_" + hydrom_type + '_' + str(f).replace('.', '_') + '_' + scheme + ".lut") save_lut(lut_SZ, filename)
def sz_lut_melting(scheme, hydrom_type, list_frequencies, list_elevations, list_wcontent, quad_pts): """ Computes and saves a scattering lookup table for a given melting hydrometeortype and various frequencies, elevations, etc. Args: scheme: microphysical scheme, '1mom' or '2mom' hydrom_type: the hydrometeor type, either 'mS' (melt. snow) or 'mG' (melt. graup) list_frequencies: list of frequencies for which to obtain the lookup tables, in GHz list_elevations: list of incident elevation angles for which to obtain the lookup tables, in degrees list_wcontent: list of water contents for which to obtain the lookup tables, unitless, from 0 to 1 quad_pts: the quadrature points computed with the calculate_quadrature_points function (see below) Returns: No output but saves a lookup table """ if np.isscalar(list_frequencies): list_frequencies = [list_frequencies] hydrom = create_hydrometeor(hydrom_type, scheme) hydrom.radius_type = Scatterer.RADIUS_MAXIMUM array_D = [] for wc in W_CONTENTS: hydrom.f_wet = wc list_D = np.linspace(hydrom.d_min, hydrom.d_max, NUM_DIAMETERS).astype('float32') array_D.append(list_D) array_D = np.array(array_D) num_cores = multiprocessing.cpu_count() for f in list_frequencies: global SCATTERER wavelength = constants.C / (f * 1E09) * 1000 # in mm # The 40 here is the orientation std, but it doesn't matter since # we integrate "manually" over the distributions, we just have # to set something to start SCATTERER = _create_scatterer(wavelength, 40) SZ_matrices = np.zeros( (len(list_elevations), len(list_wcontent), len(list_D), 12)) for i, e in enumerate(list_elevations): print('Running elevation : ' + str(e)) results = (Parallel(n_jobs=num_cores)( delayed(_compute_sz_with_quad_melting)( hydrom, f, e, wc, quad_pts[j][0], quad_pts[j][1]) for j, wc in enumerate(list_wcontent))) arr_SZ = _flatten_matrices(results) SZ_matrices[i, :, :, :] = arr_SZ # Create lookup table for a given frequency lut_SZ = Lookup_table() lut_SZ.add_axis('e', list_elevations) lut_SZ.add_axis('wc', list_wcontent) lut_SZ.add_axis('d', array_D) lut_SZ.add_axis('sz', np.arange(12)) lut_SZ.set_value_table(SZ_matrices) # The name of the lookup table is lut_SZ_<hydro_name>_<freq>_<scheme>.lut filename = (FOLDER_LUT + "lut_SZ_" + hydrom_type + '_' + str(f).replace('.', '_') + '_' + scheme + ".lut") save_lut(lut_SZ, filename)