def test_psd(self): """Test a case that integrates over a particle size distribution """ tm = Scatterer(wavelength=6.5, m=complex(1.5, 0.5), axis_ratio=1.0 / 0.6) tm.psd_integrator = psd.PSDIntegrator() tm.psd_integrator.num_points = 500 tm.psd = psd.GammaPSD(D0=1.0, Nw=1e3, mu=4) tm.psd_integrator.D_max = 10.0 tm.psd_integrator.init_scatter_table(tm) (S, Z) = tm.get_SZ() S_ref = np.array([[ complex(1.02521928e+00, 6.76066598e-01), complex(6.71933838e-24, 6.83819665e-24) ], [ complex(-6.71933678e-24, -6.83813546e-24), complex(-1.10464413e+00, -1.05571494e+00) ]]) Z_ref = np.array([ [7.20540295e-02, -1.54020475e-02, -9.96222107e-25, 8.34246458e-26], [-1.54020475e-02, 7.20540295e-02, 1.23279391e-25, 1.40049088e-25], [9.96224596e-25, -1.23291269e-25, -6.89739108e-02, 1.38873290e-02], [8.34137617e-26, 1.40048866e-25, -1.38873290e-02, -6.89739108e-02] ]) test_relative(self, S, S_ref) test_relative(self, Z, Z_ref)
def tmatrix(self, wl, pluvio_filter=True, pip_filter=False, density=None): """Calculate radar reflectivity at requested wavelength wl [mm] using T-matrix""" name = switch_wl(wl) + "reflTM" if density is None: density = self.density(pluvio_filter=pluvio_filter, pip_filter=pip_filter) z_serie = pd.Series(density) dBin = self.instr['dsd'].bin_width() edges = self.instr['dsd'].bin_cen() + 0.5 * dBin grp = self.instr['dsd'].grouped(rule=self.rule, varinterval=self.varinterval, col=self.dsd.bin_cen()) psd_values = grp.mean() for item in density.iteritems(): if item[1] > 0.0: ref = refractive.mi(wl, 0.001 * item[1]) print(ref) flake = tmatrix.Scatterer(wavelength=wl, m=ref, axis_ratio=1.0 / 1.0) flake.psd_integrator = psd.PSDIntegrator() flake.psd_integrator.D_max = 35.0 flake.psd = psd.BinnedPSD( bin_edges=edges, bin_psd=psd_values.loc[item[0]].values) flake.psd_integrator.init_scatter_table(flake) Z = 10.0 * np.log10(radar.refl(flake)) else: Z = np.nan z_serie.loc[item[0]] = Z z_serie.name = name return z_serie
def setup_scatterer_rain(elev_radar): scatterer = Scatterer() scatterer.psd_integrator = psd.PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/drop_ar(D) scatterer.alpha = 0.0 scatterer.beta = 0.0 scatterer.phi0 = 0.0 scatterer.thet = 90.0 - elev_radar[0] scatterer.thet0 = 90.0 - elev_radar[0] scatterer.phi = 0.0 geom_forw = scatterer.get_geometry() scatterer.phi = 180.0 geom_back = scatterer.get_geometry() scatterer.or_pdf = orientation.gaussian_pdf(7.0) # orientation PDF according to Bringi and Chandrasekar (2001) scatterer.orient = orientation.orient_averaged_fixed # averaging method return [scatterer, geom_forw, geom_back]
def setup_scatterer_grau(elev_radar): scatterer = Scatterer() scatterer.psd_integrator = psd.PSDIntegrator() scatterer.axis_ratio = 1. # 1./0.8 (original); scatterer.alpha = 0.0 scatterer.beta = 0.0 scatterer.phi0 = 0.0 scatterer.thet = 90.0 - elev_radar[0] scatterer.thet0 = 90.0 - elev_radar[0] scatterer.phi = 0.0 geom_forw = scatterer.get_geometry() scatterer.phi = 180.0 geom_back = scatterer.get_geometry() # set up orientation averaging, Gaussian PDF with mean=0 and std=7 deg scatterer.or_pdf = orientation.gaussian_pdf(1) # orientation PDF according to Bringi and Chandrasekar (2001) scatterer.orient = orientation.orient_averaged_fixed # averaging method return [scatterer, geom_forw, geom_back]
def tmatrix_stuffses(dsd): drops = tmatrix.Scatterer(wavelength=aux.wl_C, m=ref.m_w_10C[aux.wl_C]) drops.Kw_sqr = aux.K_w_sqr[aux.wl_C] drops.or_pdf = ori.gaussian_pdf(std=7.0) drops.orient = ori.orient_averaged_fixed drops.psd_integrator = psd.PSDIntegrator() drops.psd_integrator.D_max = 10.0 drops.psd_integrator.axis_ratio_func = read.ar back = aux.geom_horiz_back forw = aux.geom_horiz_forw drops.psd_integrator.geometries = (back, forw) drops.psd_integrator.init_scatter_table(drops) psds = dsd.to_tm_series(resample=None) drops.set_geometry(back) zh = [] zv = [] zdr = [] rho_hv = [] ldr = [] for tm_psd in psds: drops.psd = tm_psd zh.append(db(radar.refl(drops))) zv.append(db(radar.refl(drops, False))) zdr.append(db(radar.Zdr(drops))) rho_hv.append(radar.rho_hv(drops)) ldr.append(db(radar.ldr(drops))) d = { 'R': dsd.intensity(), 'Zh': zh, 'Zv': zv, 'Zdr': zdr, 'rho_hv': rho_hv, 'LDR': ldr } return pd.DataFrame(data=d, index=psds.index)
def test_integrated_x_sca(self): """Test Rayleigh scattering cross section integrated over sizes. """ m = complex(3.0, 0.5) K = (m**2 - 1) / (m**2 + 2) N0 = 10 Lambda = 1e4 sca = Scatterer(wavelength=1, m=m) sca.psd_integrator = psd.PSDIntegrator() sca.psd = psd.ExponentialPSD(N0=N0, Lambda=Lambda) sca.psd.D_max = 0.002 sca.psd_integrator.D_max = sca.psd.D_max # 256 is quite low, but we want to run the test reasonably fast sca.psd_integrator.num_points = 256 sca.psd_integrator.init_scatter_table(sca, angular_integration=True) # This size-integrated scattering cross section has an analytical value. # Check that we can reproduce it. sca_xsect_ref = 480 * N0 * np.pi**5 * abs(K)**2 / Lambda**7 sca_xsect = scatter.sca_xsect(sca) test_less(self, abs(1 - sca_xsect / sca_xsect_ref), 1e-3)
geom_back = scatterer.get_geometry() scatterer.phi = 0.0 geom_forw = scatterer.get_geometry() # so assuming perfect backscattering (no gaussian function) # geom_tuple = (theta_radar, theta_radar, 0.0, 180.0, 0.0, 0.0) # Set geometry to backscattering! # CAREFUL: for Kdp need forward scattering. <------------------------------------------------- scatterer.set_geometry(geom_back) # set up orientation averaging, Gaussian PDF with mean=0 and std=7 deg scatterer.or_pdf = orientation.gaussian_pdf(7.0) # orientation PDF scatterer.orient = orientation.orient_averaged_fixed # averaging method # set up PSD integration scatterer.psd_integrator = psd.PSDIntegrator() scatterer.psd_integrator.D_max = 5. # maximum diameter considered scatterer.psd_integrator.geometries = (geom_forw, geom_back) #scatterer.psd_integrator.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) # ????????? scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / drop_ar( 2. * D) # This only for rain maybe (?) scatterer.wavelength = wavelengths[1] scatterer.m = ref_indices_rain[1] # initialize lookup table scatterer.psd_integrator.init_scatter_table(scatterer) Zh_RAIN = np.zeros([dim, dim]) Zdr_RAIN = np.zeros([dim, dim])
Ai = 0.0 * D0s wl = tmatrix_aux.wl_W el = 0. scatterer = tmatrix.Scatterer( wavelength=wl, m=refractive.m_w_10C[wl], #kw_sqr=tmatrix_aux.K_w_sqr[wl], radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM, #or_pdf=orientation.gaussian_pdf(std=1.0), #orient=orientation.orient_averaged_fixed, thet0=90.0 - el, thet=90.0 + el) Nw = 8000.0 # mm-2 m-3 mu = 5 scatterer.psd_integrator = psd.PSDIntegrator( D_max=8.0, geometries=(tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw)) scatterer.psd_integrator.init_scatter_table(scatterer) for i, D0 in enumerate(D0s): scatterer.psd = genGamma(Nw, D0, mu) #psd.GammaPSD(D0=D0, mu=mu, Nw=Nw) scatterer.set_geometry(tmatrix_aux.geom_horiz_back) Zhh[i] = 10.0 * np.log10(radar.refl(scatterer)) scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) Ai[i] = radar.Ai(scatterer) plt.plot(D0s, Zhh) plt.plot(D0s, Zhh - 2.0 * Ai * 0.25) plt.ylim([11, 26]) plt.grid()