def number_density_100(habit, n0, dm): psd = D14NDmIce() from joint_flight.data import habits try: pm = getattr(habits, habit) ind = np.where(pm.dmax > 1e-4)[0][0] x = np.logspace(np.log10(pm.de[ind]), -1, 201) except: x = np.logspace(-4, -1, 201) psd.mass_weighted_diameter = dm psd.intercept_parameter = n0 data = psd.evaluate(x).data nd = np.trapz(data, x=x, axis=-1) return nd
def calculate_psds(results, mask, radar, sizes=None): """ Calculate PSDs from bulk properties. Args: results: 'xarray.Dataset' containing the retrieval results matched to in-situ measurement for all shapes. sizes: A size grid at which to evaluate the PSDs. """ if sizes is None: sizes = np.logspace(-5, -2, 41) psd = D14NDmIce() x = radar["x"].data y = radar["y"].data d = 0.25 * (x[:-1, :-1] + x[:-1, 1:] + x[1:, :-1] + x[1:, 1:]) z = 0.25 * (y[:-1, :-1] + y[:-1, 1:] + y[1:, :-1] + y[1:, 1:]) results_new = {} for s in results: try: meta_data = load_habit_meta_data(s) except FileNotFoundError as e: continue x = meta_data["d_eq"].interp(d_max=sizes).data r = results[s] dm = r["ice_dm"].data[mask] n0 = r["ice_n0"].data[mask] psd.mass_weighted_diameter = dm psd.intercept_parameter = n0 y = psd.evaluate(x) new = { "d_max": ("d_max", sizes), "psd": (("samples", "d_max"), y.data), "altitude": (("samples",), z[mask]), "d": (("samples",), d[mask]), } results_new[s] = xr.Dataset(new) return results_new
def get_results(flight, config="", group="All quantities"): """ This function loads the retrieval results from a given flight Results are automatically augmented with the retrieved iwc. Args: flight: The flight name, i.e. b984, c159 or c161 config: Name of retrieval configuration that defines from which sub-folder (if any) the data is loaded. group: The NetCDF4 group containing the results. """ flight = flight.lower() path = os.path.join(joint_flight.PATH, "data", "old") if config != "": path = os.path.join(path, config) pattern = re.compile(f"output_{flight}_([\w-]*).nc") results = {} psd = D14NDmIce() for f in glob.glob(os.path.join(path, "*")): match = re.match(pattern, os.path.basename(f)) if match is None: continue shape = match.group(1) data = xr.load_dataset(os.path.join(path, f), group=group) dm = data["ice_dm"] n0 = data["ice_n0"] psd.mass_weighted_diameter = dm psd.intercept_parameter = n0 wc = psd.get_mass_density() k = np.ones((5, 1)) / 5.0 wc_s = convolve(wc, k, mode="same") nd = psd.get_moment(0) nd.data[wc < 5e-6] = 0.0 data["ice_water_content"] = (dm.dims, wc.data) data["ice_water_content_smooth"] = (dm.dims, wc_s.data) data["number_density"] = (dm.dims, nd.data) results[shape] = data return results
"temperature", n0_a_priori, ice_covariance, mask=ice_mask, mask_value=4) ice_n0_a_priori = MaskedRegularGrid(ice_n0_a_priori, 20, ice_mask, "altitude", provide_retrieval_grid=False) # # Hydrometeor definition # ice = Hydrometeor("ice", D14NDmIce(), [ice_n0_a_priori, ice_dm_a_priori], ice_shape, ice_shape_meta) ice.transformations = [ Composition(Log10(), PiecewiseLinear(ice_n0_a_priori)), Identity() ] # Lower limits for N_0^* and m in transformed space. ice.limits_low = [2, 1e-8] ############################################################################### # Snow particles ############################################################################### snow_shape = os.path.join(scattering_data, "EvansSnowAggregate.xml") snow_shape_meta = os.path.join(scattering_data, "EvansSnowAggregate.meta.xml") snow_mask = And(AltitudeMask(0.0, 19e3), TemperatureMask(0.0, 276.0))
ip.magic("%autoreload 2") # # Load observations. # filename = os.path.join(mcrf.joint_flight.path, "data", "combined", "input.nc") data_provider = NetCDFDataProvider(filename) ice_shape = "FluffyMcSnowPhase" ice.scattering_data = "/home/simonpf/src/joint_flight/data/scattering/{}.xml".format( ice_shape) if ice_shape in psd_shapes_low: alpha, log_beta = psd_shapes_high[ice_shape] ice.psd = D14NDmIce(alpha, np.exp(log_beta)) # # Define hydrometeors and sensors. # hydrometeors = [ice, rain] sensors = [hamp_radar, hamp_passive, ismar] # # Add a priori providers. # data_provider.add(ice.a_priori[0]) data_provider.add(ice.a_priori[1]) data_provider.add(snow.a_priori[0])
def get_reference_data(scene="a", i_start=3000, i_end=3800): """ Get reference data from cloud scene. Arguments: scene: From which scene to take the values ("a", "b") i_start: Start index of the scene i_end: End index of the scene """ n = i_end - i_start ice_psd = D14NDmIce() snow_psd = D14NDmSnow() liquid_psd = D14NDmLiquid() data_provider = ModelDataProvider(99, scene=scene.upper(), ice_psd=ice_psd, snow_psd=snow_psd, hail_psd=snow_psd, graupel_psd=snow_psd, liquid_psd=liquid_psd) z = data_provider.get_altitude(i_start) iwc, swc, gwc, hwc, lwc, rwc = np.zeros((6, n, z.size)) iwc_nd, swc_nd, gwc_nd, hwc_nd, lwc_nd, rwc_nd = np.zeros((6, n, z.size)) iwc_dm, swc_dm, gwc_dm, hwc_dm, lwc_dm, rwc_dm = np.zeros((6, n, z.size)) iwc_n0, swc_n0, gwc_n0, hwc_n0, lwc_n0, rwc_n0 = np.zeros((6, n, z.size)) lats, lons = np.zeros((2, n)) h2o = np.zeros((n, z.size)) temperature = np.zeros((n, z.size)) for i in range(i_start, i_end): j = i - i_start iwc[j, :] = data_provider.get_gem_ice_mass_density(i) swc[j, :] = data_provider.get_gem_snow_mass_density(i) hwc[j, :] = data_provider.get_gem_hail_mass_density(i) gwc[j, :] = data_provider.get_gem_graupel_mass_density(i) rwc[j, :] = data_provider.get_gem_rain_mass_density(i) lwc[j, :] = data_provider.get_gem_liquid_mass_density(i) iwc_nd[j, :] = data_provider.get_gem_ice_number_density(i) swc_nd[j, :] = data_provider.get_gem_snow_number_density(i) hwc_nd[j, :] = data_provider.get_gem_hail_number_density(i) gwc_nd[j, :] = data_provider.get_gem_graupel_number_density(i) rwc_nd[j, :] = data_provider.get_gem_rain_number_density(i) lwc_nd[j, :] = data_provider.get_gem_liquid_number_density(i) iwc_dm[j, :] = data_provider.get_ice_dm(i) swc_dm[j, :] = data_provider.get_snow_dm(i) hwc_dm[j, :] = data_provider.get_hail_dm(i) gwc_dm[j, :] = data_provider.get_graupel_dm(i) rwc_dm[j, :] = data_provider.get_rain_dm(i) lwc_dm[j, :] = data_provider.get_cloud_water_dm(i) iwc_n0[j, :] = data_provider.get_ice_n0(i) swc_n0[j, :] = data_provider.get_snow_n0(i) hwc_n0[j, :] = data_provider.get_hail_n0(i) gwc_n0[j, :] = data_provider.get_graupel_n0(i) rwc_n0[j, :] = data_provider.get_rain_n0(i) lwc_n0[j, :] = data_provider.get_cloud_water_n0(i) h2o[j, :] = data_provider.get_relative_humidity(i) lats[j] = data_provider.get_latitude(i) lons[j] = data_provider.get_longitude(i) temperature[j, :] = data_provider.get_temperature(i) return { "iwc": iwc, "iwc_nd": iwc_nd, "iwc_dm": iwc_dm, "iwc_n0": iwc_n0, "swc": swc, "swc_nd": swc_nd, "swc_dm": swc_dm, "swc_n0": swc_n0, "hwc": hwc, "hwc_nd": hwc_nd, "hwc_dm": hwc_dm, "hwc_n0": hwc_n0, "gwc": gwc, "gwc_nd": gwc_nd, "gwc_dm": gwc_dm, "gwc_n0": gwc_n0, "rwc": rwc, "rwc_nd": rwc_nd, "rwc_dm": rwc_dm, "rwc_n0": rwc_n0, "lwc": lwc, "lwc_nd": lwc_nd, "lwc_dm": lwc_dm, "lwc_n0": lwc_n0, "h2o": h2o, "lat": lats, "lon": lons, "z": z, "temperature": temperature }
def number_density(n0, dm): psd = D14NDmIce() psd.mass_weighted_diameter = dm psd.intercept_parameter = n0 return psd.get_moment(0)
x2 = dy * dy / nedts ax = plt.subplot(gs[1, 0]) ax.pcolormesh(x, y, x2.T) def iwc(n0, dm): return np.pi * 917.0 * dm**4 * n0 / 4**4 def rwc(n0, dm): return np.pi * 917.0 * dm**4 * n0 / 4**4 from mcrf.psds import D14NDmIce psd = D14NDmIce() def number_density(n0, dm): psd = D14NDmIce() psd.mass_weighted_diameter = dm psd.intercept_parameter = n0 return psd.get_moment(0) def number_density_100(habit, n0, dm): psd = D14NDmIce() from joint_flight.data import habits try: pm = getattr(habits, habit)
ice_covariance = Diagonal(1, mask=ice_mask, mask_value=1e-8) ice_covariance = SpatialCorrelation(ice_covariance, 1.0e3, mask=ice_mask) ice_n0_a_priori = FunctionalAPriori("ice_n0", "temperature", n0_a_priori, ice_covariance, mask=ice_mask, mask_value=4) z_grid = np.linspace(0, 12e3, 25) ice_n0_a_priori = MaskedRegularGrid(ice_n0_a_priori, 21, ice_mask, "altitude", provide_retrieval_grid=False) ice = Hydrometeor("ice", D14NDmIce(), [ice_n0_a_priori, ice_dm_a_priori], ice_shape, ice_shape_meta) ice.radar_only = False ice.retrieve_second_moment = True ice.transformations = [ Composition(Log10(), PiecewiseLinear(ice_n0_a_priori)), Identity() ] ice.limits_low = [0, 1e-10] ################################################################################ # Snow particles ################################################################################ snow_shape = os.path.join(scattering_data, "EvansSnowAggregate.xml")