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 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 test_backend(): """Replicate the test run of the backend T-Matrix code. Replicates the results of the default test run of the backend code by Mishchenko. The user can use the function to manually check that the results match. Small errors may be present due to different compiler optimizations. """ scatterer = Scatterer(radius=10.0, rat=0.1, wavelength=2 * np.pi, m=complex(1.5, 0.02), axis_ratio=0.5, ddelt=1e-3, ndgs=2, np=-1) scatterer.thet0 = 56.0 scatterer.thet = 65.0 scatterer.phi0 = 114.0 scatterer.phi = 128.0 scatterer.alpha = 145.0 scatterer.beta = 52.0 print("Amplitude matrix S:") print(scatterer.get_S()) print("Phase matrix Z:") print(scatterer.get_Z())
def test_optical_theorem(self): """Optical theorem: test that for a lossless particle, Csca=Cext """ tm = Scatterer(radius=4.0, wavelength=6.5, m=complex(1.5,0.0), axis_ratio=1.0/0.6) tm.set_geometry(tmatrix_aux.geom_horiz_forw) ssa_h = scatter.ssa(tm, True) ssa_v = scatter.ssa(tm, False) test_less(self, abs(1.0-ssa_h), 1e-6) test_less(self, abs(1.0-ssa_v), 1e-6)
def test_optical_theorem(self): """Optical theorem: test that for a lossless particle, Csca=Cext """ tm = Scatterer(radius=4.0, wavelength=6.5, m=complex(1.5, 0.0), axis_ratio=1.0 / 0.6) tm.set_geometry(tmatrix_aux.geom_horiz_forw) ssa_h = scatter.ssa(tm, True) ssa_v = scatter.ssa(tm, False) test_less(self, abs(1.0 - ssa_h), 1e-6) test_less(self, abs(1.0 - ssa_v), 1e-6)
def _create_scatterer(wavelength, orientation_std): """ Create a scatterer instance that will be used later Args: wavelength: wavelength in mm orientation_std: standard deviation of the Gaussian distribution of orientations (canting angles) Returns: scatt: a pytmatrix Scatterer class instance """ scatt = Scatterer(radius=1.0, wavelength=wavelength, ndgs=10) scatt.or_pdf = orientation.gaussian_pdf(std=orientation_std) scatt.orient = orientation.orient_averaged_fixed return scatt
def scatter_off_2dvd_packed(dicc): def drop_ar(D_eq): if D_eq < 0.7: return 1.0 elif D_eq < 1.5: return 1.173 - 0.5165*D_eq + 0.4698*D_eq**2 - 0.1317*D_eq**3 - \ 8.5e-3*D_eq**4 else: return 1.065 - 6.25e-2*D_eq - 3.99e-3*D_eq**2 + 7.66e-4*D_eq**3 - \ 4.095e-5*D_eq**4 d_diameters = dicc['1'] d_densities = dicc['2'] mypds = interpolate.interp1d(d_diameters, d_densities, bounds_error=False, fill_value=0.0) scatterer = Scatterer(wavelength=tmatrix_aux.wl_C, m=refractive.m_w_10C[tmatrix_aux.wl_C]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / drop_ar(D) scatterer.psd_integrator.D_max = 10.0 scatterer.psd_integrator.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(20.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) scatterer.psd = mypds # GammaPSD(D0=2.0, Nw=1e3, mu=4) radar.refl(scatterer) zdr = radar.Zdr(scatterer) z = radar.refl(scatterer) scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) kdp = radar.Kdp(scatterer) A = radar.Ai(scatterer) return z, zdr, kdp, A
def _setup_scattering(self, wavelength, dsr_func): """ Internal Function to create scattering tables. This internal function sets up the scattering table. It takes a wavelength as an argument where wavelength is one of the pytmatrix accepted wavelengths. Parameters: ----------- wavelength : tmatrix wavelength PyTmatrix wavelength. dsr_func : function Drop Shape Relationship function. Several built-in are available in the `DSR` module. """ self.scatterer = Scatterer(wavelength=wavelength, m=self.m_w) self.scatterer.psd_integrator = PSDIntegrator() self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / dsr_func( D) self.dsr_func = dsr_func self.scatterer.psd_integrator.D_max = 10.0 self.scatterer.psd_integrator.geometries = ( tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) self.scatterer.or_pdf = orientation.gaussian_pdf(20.0) self.scatterer.orient = orientation.orient_averaged_fixed self.scatterer.psd_integrator.init_scatter_table(self.scatterer)
def _setup_scattering(self, wavelength, dsr_func, max_diameter): """ Internal Function to create scattering tables. This internal function sets up the scattering table. It takes a wavelength as an argument where wavelength is one of the pytmatrix accepted wavelengths. Parameters: wavelength : tmatrix wavelength PyTmatrix wavelength. dsr_func : function Drop Shape Relationship function. Several built-in are available in the `DSR` module. max_diameter: float Maximum drop diameter to generate scattering table for. """ self.scatterer = Scatterer(wavelength=wavelength, m=self.scattering_params["m_w"]) self.scatterer.psd_integrator = PSDIntegrator() self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / dsr_func( D) self.dsr_func = dsr_func self.scatterer.psd_integrator.D_max = max_diameter self.scatterer.psd_integrator.geometries = ( tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) self.scatterer.or_pdf = orientation.gaussian_pdf( self.scattering_params["canting_angle"]) self.scatterer.orient = orientation.orient_averaged_fixed self.scatterer.psd_integrator.init_scatter_table(self.scatterer) self.scattering_table_consistent = True
def test_rayleigh(self): """Test match with Rayleigh scattering for small spheres """ wl = 100.0 r = 1.0 eps = 1.0 m = complex(1.5,0.5) tm = Scatterer(wavelength=wl, radius=r, axis_ratio=eps, m=m) S = tm.get_S() k = 2*np.pi/wl S_ray = k**2 * (m**2-1)/(m**2+2) * r test_relative(self, S[0,0], S_ray, limit=1e-3) test_relative(self, S[1,1], -S_ray, limit=1e-3) test_less(self, abs(S[0,1]), 1e-25) test_less(self, abs(S[1,0]), 1e-25)
def test_rayleigh(self): """Test match with Rayleigh scattering for small spheres """ wl = 100.0 r = 1.0 eps = 1.0 m = complex(1.5, 0.5) tm = Scatterer(wavelength=wl, radius=r, axis_ratio=eps, m=m) S = tm.get_S() k = 2 * np.pi / wl S_ray = k**2 * (m**2 - 1) / (m**2 + 2) * r test_relative(self, S[0, 0], S_ray, limit=1e-3) test_relative(self, S[1, 1], -S_ray, limit=1e-3) test_less(self, abs(S[0, 1]), 1e-25) test_less(self, abs(S[1, 0]), 1e-25)
def _compute_gautschi_canting(list_of_std): """ Computes the quadrature points and weights for a list of standard deviations for the Gaussian distribution of canting angles Args: list_of_std: list of standard deviations for which a quadrature rule must be computed (one set of points and weights per standard deviation) Returns: A tuple, containing two lists, one with the quadrature points for every stdev, one with the quadrature weights for every stdev """ scatt = Scatterer(radius=5.0) gautschi_pts = [] gautschi_w = [] for l in list_of_std: scatt.or_pdf = orientation.gaussian_pdf(std=l) scatt.orient = orientation.orient_averaged_fixed scatt._init_orient() gautschi_pts.append(scatt.beta_p) # Check if sum of weights if 1, if not set it to 1 scatt.beta_w /= np.sum(scatt.beta_w) gautschi_w.append(scatt.beta_w) return (gautschi_pts, gautschi_w)
def compute(i): s = res.loc[i, 'Dmax'] start = time.time() print(res.loc[i]) if res.loc[i].hasnans(): print('computing') density = rho(s) m = refractive.mi(wl, density) scatterer = Scatterer(radius=0.5 * s, wavelength=wl, m=m, axis_ratio=1.0 / ar, radius_type=Scatterer.RADIUS_MAXIMUM) scatterer.set_geometry(tmatrix_aux.geom_vert_back) scatterer.orient = orientation.orient_averaged_fixed scatterer.or_pdf = orientation.uniform_pdf() res.loc[i, 'f'] = f res.loc[i, 'wl'] = wl res.loc[i, 'rho'] = density res.loc[i, 'mr'] = m.real res.loc[i, 'mi'] = m.imag res.loc[i, 'Dmax'] = s res.loc[i, 'Csca'] = scatter.sca_xsect(scatterer) res.loc[i, 'Cbk'] = scatter.sca_intensity(scatterer) res.loc[i, 'sigmabk'] = radar.radar_xsect(scatterer) res.loc[i, 'Cext'] = scatter.ext_xsect(scatterer) res.loc[i, 'g'] = scatter.asym(scatterer) res.to_csv(savename) end = time.time() print(s, end - start)
def __init__(self, wl=tmatrix_aux.wl_X, dr =1, shape='bc'): DSR_list = {'tb':DSR.tb, 'bc': DSR.bc, 'pb': DSR.pb} self.scatterer = Scatterer(wavelength=wl, m=refractive.m_w_10C[wl]) self.scatterer.psd_integrator = PSDIntegrator() self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/DSR_list[shape](D) self.scatterer.psd_integrator.D_max = 10.0 self.scatterer.psd_integrator.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) self.scatterer.or_pdf = orientation.gaussian_pdf(20.0) self.scatterer.orient = orientation.orient_averaged_fixed self.scatterer.psd_integrator.init_scatter_table(self.scatterer) self.dr=dr
def test_asymmetry(self): """Test calculation of the asymmetry parameter """ tm = Scatterer(radius=4.0, wavelength=6.5, m=complex(1.5, 0.5), axis_ratio=1.0) tm.set_geometry(tmatrix_aux.geom_horiz_forw) asym_horiz = scatter.asym(tm) tm.set_geometry(tmatrix_aux.geom_vert_forw) asym_vert = scatter.asym(tm) # Is the asymmetry parameter the same for a sphere in two directions? test_less(self, abs(1 - asym_horiz / asym_vert), 1e-6) # Is the asymmetry parameter zero for small particles? tm.radius = 0.0004 tm.set_geometry(tmatrix_aux.geom_horiz_forw) asym_horiz = scatter.asym(tm) test_less(self, abs(asym_horiz), 1e-8)
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)
def _setup_scattering(self, wavelength): self.scatterer = Scatterer(wavelength=wavelength, m=refractive.m_w_10C[wavelength]) self.scatterer.psd_integrator = PSDIntegrator() self.scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0 / \ axis_ratio.axis_ratio_THBRS07(D) self.scatterer.psd_integrator.D_max = 8.0 self.scatterer.psd_integrator.geometries = ( tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) self.scatterer.or_pdf = orientation.gaussian_pdf(20.0) self.scatterer.orient = orientation.orient_averaged_fixed print "MADE IT CC!!!!!!!!" self.scatterer.psd_integrator.init_scatter_table(self.scatterer) print "MADE IT HERE!!!!!!!!"
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)
def test_asymmetry(self): """Test calculation of the asymmetry parameter """ tm = Scatterer(radius=4.0, wavelength=6.5, m=complex(1.5,0.5), axis_ratio=1.0) tm.set_geometry(tmatrix_aux.geom_horiz_forw) asym_horiz = scatter.asym(tm) tm.set_geometry(tmatrix_aux.geom_vert_forw) asym_vert = scatter.asym(tm) # Is the asymmetry parameter the same for a sphere in two directions? test_less(self, abs(1-asym_horiz/asym_vert), 1e-6) # Is the asymmetry parameter zero for small particles? tm.radius = 0.0004 tm.set_geometry(tmatrix_aux.geom_horiz_forw) asym_horiz = scatter.asym(tm) test_less(self, abs(asym_horiz), 1e-8)
def test_backend(): """Replicate the test run of the backend T-Matrix code. Replicates the results of the default test run of the backend code by Mishchenko. The user can use the function to manually check that the results match. Small errors may be present due to different compiler optimizations. """ scatterer = Scatterer(radius=10.0, rat=0.1, wavelength=2*np.pi, m=complex(1.5,0.02), axis_ratio=0.5, ddelt=1e-3, ndgs=2, np=-1) scatterer.thet0 = 56.0 scatterer.thet = 65.0 scatterer.phi0 = 114.0 scatterer.phi = 128.0 scatterer.alpha = 145.0 scatterer.beta = 52.0 print("Amplitude matrix S:") print(scatterer.get_S()) print("Phase matrix Z:") print(scatterer.get_Z())
def test_against_mie(self): """Test scattering parameters against Mie results """ # Reference values computed with the Mie code of Maetzler sca_xsect_ref = 4.4471684294079958 ext_xsect_ref = 7.8419745883848435 asym_ref = 0.76146646088675629 sca = Scatterer(wavelength=1, radius=1, m=complex(3.0, 0.5)) sca_xsect = scatter.sca_xsect(sca) ext_xsect = scatter.ext_xsect(sca) asym = scatter.asym(sca) test_less(self, abs(1 - sca_xsect / sca_xsect_ref), 1e-6) test_less(self, abs(1 - ext_xsect / ext_xsect_ref), 1e-6) test_less(self, abs(1 - asym / asym_ref), 1e-6)
def _compute_single_size(self, d): ar = self.aspect_ratio_func(d) rain = Scatterer(radius=0.5 * d, wavelength=self.wl, m=self.n, axis_ratio=1.0 / ar) rain.Kw_sqr = self.K2 if self.canting is not None: rain.or_pdf = orientation.gaussian_pdf(std=self.canting) rain.orient = orientation.orient_averaged_fixed # Set backward scattering for reflectivity calculations rain.set_geometry((self._theta0, self._theta0, 0., 180., 0., 0.)) rxsh = radar.radar_xsect(rain, h_pol=True) rxsv = radar.radar_xsect(rain, h_pol=False) # Set forward scattering for attenuation and phase computing rain.set_geometry((self._theta0, self._theta0, 0., 0., 0., 0.)) ext = scatter.ext_xsect(rain) skdp = radar.Kdp(rain) # Calculate Rayleigh approximation for reference ray = self.prefactor * d**6 #print(d, rxsh, rxsv, ext, ray, skdp, ar) return rxsh, rxsv, ext, ray, skdp, ar
def compute_gautschi_canting(list_of_std): scatt = Scatterer(radius = 5.0) gautschi_pts = [] gautschi_w = [] for l in list_of_std: scatt.or_pdf = orientation.gaussian_pdf(std=l) scatt.orient = orientation.orient_averaged_fixed scatt._init_orient() gautschi_pts.append(scatt.beta_p) gautschi_w.append(scatt.beta_w) return(gautschi_pts,gautschi_w)
def calcKdpPropOneFreq(wl, radii, as_ratio, rho, elv, ndgs=2, canting=False, cantingStd=1, meanAngle=0): """ Calculation of the KDP of one particle Parameters ---------- wl: wavelength [mm] (single value) radii: radius [mm] of the particle (array[n]) as_ratio: aspect ratio of the super particle (array[n]) rho: density [g/mmˆ3] of the super particle (array[n]) elv: elevation angle [°] ndgs: number of division points used to integrate over the particle surface (default= 30 it is already high) canting: boolean (default = False) cantingStd: standard deviation of the canting angle [°] (default = 1) meanAngle: mean value of the canting angle [°] (default = 0) Returns ------- kdp: calculated kdp from each particle (array[n]) """ scatterer = Scatterer(wavelength=wl) #, axis_ratio=1./as_ratio) scatterer.radius_type = Scatterer.RADIUS_MAXIMUM scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) scatterer.ndgs = ndgs if canting == True: scatterer.or_pdf = orientation.gaussian_pdf(std=cantingStd, mean=meanAngle) #scatterer.orient = orientation.orient_averaged_adaptive scatterer.orient = orientation.orient_averaged_fixed # geometric parameters scatterer.thet0 = 90. - elv scatterer.phi0 = 0. # geometric parameters scatterer.thet = scatterer.thet0 scatterer.phi = (scatterer.phi0) % 360. #KDP geometry sMat = np.ones_like(radii) * np.nan for i, radius in enumerate(radii): scatterer.axis_ratio = 1. / as_ratio[i] scatterer.radius = radius scatterer.m = refractive.mi(wl, rho[i]) S = scatterer.get_S() sMat[i] = (S[1, 1] - S[0, 0]).real kdp = 1e-3 * (180.0 / np.pi) * scatterer.wavelength * (sMat) return kdp
def calcScatPropOneFreq(wl, radii, as_ratio, rho, elv, ndgs=30, canting=False, cantingStd=1, meanAngle=0, safeTmatrix=False): """ Calculates the Ze at H and V polarization, Kdp for one wavelength TODO: LDR??? Parameters ---------- wl: wavelength [mm] (single value) radii: radius [mm] of the particle (array[n]) as_ratio: aspect ratio of the super particle (array[n]) rho: density [g/mmˆ3] of the super particle (array[n]) elv: elevation angle [°] ndgs: division points used to integrate over the particle surface canting: boolean (default = False) cantingStd: standard deviation of the canting angle [°] (default = 1) meanAngle: mean value of the canting angle [°] (default = 0) Returns ------- reflect_h: super particle horizontal reflectivity[mm^6/m^3] (array[n]) reflect_v: super particle vertical reflectivity[mm^6/m^3] (array[n]) refIndex: refractive index from each super particle (array[n]) kdp: calculated kdp from each particle (array[n]) """ #---pyTmatrix setup # initialize a scatterer object scatterer = Scatterer(wavelength=wl) scatterer.radius_type = Scatterer.RADIUS_MAXIMUM scatterer.ndgs = ndgs scatterer.ddelta = 1e-6 if canting == True: scatterer.or_pdf = orientation.gaussian_pdf(std=cantingStd, mean=meanAngle) # scatterer.orient = orientation.orient_averaged_adaptive scatterer.orient = orientation.orient_averaged_fixed # geometric parameters - incident direction scatterer.thet0 = 90. - elv scatterer.phi0 = 0. # parameters for backscattering refIndex = np.ones_like(radii, np.complex128) * np.nan reflect_h = np.ones_like(radii) * np.nan reflect_v = np.ones_like(radii) * np.nan # S matrix for Kdp sMat = np.ones_like(radii) * np.nan for i, radius in enumerate(radii[::5]): #TODO remove [::5] # A quick function to save the distribution of values used in the test #with open('/home/dori/table_McRadar.txt', 'a') as f: # f.write('{0:f} {1:f} {2:f} {3:f} {4:f} {5:f} {6:f}\n'.format(wl, elv, # meanAngle, # cantingStd, # radius, # rho[i], # as_ratio[i])) # scattering geometry backward # radius = 100.0 # just a test to force nans scatterer.thet = 180. - scatterer.thet0 scatterer.phi = (180. + scatterer.phi0) % 360. scatterer.radius = radius scatterer.axis_ratio = 1. / as_ratio[i] scatterer.m = refractive.mi(wl, rho[i]) refIndex[i] = refractive.mi(wl, rho[i]) if safeTmatrix: inputs = [ str(scatterer.radius), str(scatterer.wavelength), str(scatterer.m), str(scatterer.axis_ratio), str(int(canting)), str(cantingStd), str(meanAngle), str(ndgs), str(scatterer.thet0), str(scatterer.phi0) ] arguments = ' '.join(inputs) a = subprocess.run( ['spheroidMcRadar'] + inputs, # this script should be installed by McRadar capture_output=True) # print(str(a)) try: back_hh, back_vv, sMatrix, _ = str( a.stdout).split('Results ')[-1].split() back_hh = float(back_hh) back_vv = float(back_vv) sMatrix = float(sMatrix) except: back_hh = np.nan back_vv = np.nan sMatrix = np.nan # print(back_hh, radar.radar_xsect(scatterer, True)) # print(back_vv, radar.radar_xsect(scatterer, False)) reflect_h[i] = scatterer.wavelength**4 / ( np.pi**5 * scatterer.Kw_sqr ) * back_hh # radar.radar_xsect(scatterer, True) # Kwsqrt is not correct by default at every frequency reflect_v[i] = scatterer.wavelength**4 / ( np.pi**5 * scatterer.Kw_sqr ) * back_vv # radar.radar_xsect(scatterer, False) # scattering geometry forward # scatterer.thet = scatterer.thet0 # scatterer.phi = (scatterer.phi0) % 360. #KDP geometry # S = scatterer.get_S() sMat[i] = sMatrix # (S[1,1]-S[0,0]).real # print(sMatrix, sMat[i]) # print(sMatrix) else: reflect_h[i] = scatterer.wavelength**4 / ( np.pi**5 * scatterer.Kw_sqr) * radar.radar_xsect( scatterer, True ) # Kwsqrt is not correct by default at every frequency reflect_v[i] = scatterer.wavelength**4 / ( np.pi**5 * scatterer.Kw_sqr) * radar.radar_xsect( scatterer, False) # scattering geometry forward scatterer.thet = scatterer.thet0 scatterer.phi = (scatterer.phi0) % 360. #KDP geometry S = scatterer.get_S() sMat[i] = (S[1, 1] - S[0, 0]).real kdp = 1e-3 * (180.0 / np.pi) * scatterer.wavelength * sMat del scatterer # TODO: Evaluate the chance to have one Scatterer object already initiated instead of having it locally return reflect_h, reflect_v, refIndex, kdp
def calcScatPropOneFreq(wl, radii, as_ratio, rho, elv, ndgs=30, canting=False, cantingStd=1, meanAngle=0): """ Calculates the Ze of one particle Parameter --------- wl: wavelenght [mm] (single value) radii: radius [mm] of the particle (array[n]) as_ratio: aspect ratio of the super particle (array[n]) rho: density [g/mmˆ3] of the super particle (array[n]) elv: elevation angle [°] ndgs: number of division points used to integrate over the particle surface (default= 30 it is already high) canting: boolean (default = False) cantingStd: standard deviation of the canting angle [°] (default = 1) meanAngle: mean value of the canting angle [°] (default = 0) Returns ------- reflect: horizontal reflectivity[mm^6/m^3] from each super particle (array[n]) reflect_v: vertical reflectivity[mm^6/m^3] from each super particle (array[n]) refIndex: refractive index from each super particle (array[n]) """ #---pyTmatrix setup # initialize a scatterer object scatterer = Scatterer(wavelength=wl) scatterer.radius_type = Scatterer.RADIUS_MAXIMUM scatterer.ndgs = ndgs scatterer.ddelta = 1e-6 if canting==True: scatterer.or_pdf = orientation.gaussian_pdf(std=cantingStd, mean=meanAngle) # scatterer.orient = orientation.orient_averaged_adaptive scatterer.orient = orientation.orient_averaged_fixed # geometric parameters scatterer.thet0 = 90. - elv scatterer.phi0 = 0. # geometric parameters scatterer.thet = 180. - scatterer.thet0 scatterer.phi = (180. + scatterer.phi0) % 360. refIndex = np.ones_like(radii, np.complex128)*np.nan reflect = np.ones_like(radii)*np.nan reflect_v = np.ones_like(radii)*np.nan for i, radius in enumerate(radii): scatterer.radius = radius scatterer.axis_ratio = 1./as_ratio[i] scatterer.m = refractive.mi(wl, rho[i]) refIndex[i] = refractive.mi(wl, rho[i]) reflect[i] = scatterer.wavelength**4/(np.pi**5*scatterer.Kw_sqr) * radar.radar_xsect(scatterer, True) reflect_v[i] = scatterer.wavelength**4/(np.pi**5*scatterer.Kw_sqr) * radar.radar_xsect(scatterer, False) del scatterer return reflect, reflect_v, refIndex
if __name__ == "__main__": TIME_UNIT = "seconds since 1970-01-01 00:00" OUTDIR = "." # Radar band in mm. flist = glob.glob( "/g/data/kl02/vhl548/data_for_others/disdro2/*psd_na.txt") for infile in flist: for RADAR_BAND in [ tmatrix_aux.wl_S, tmatrix_aux.wl_C, tmatrix_aux.wl_X, tmatrix_aux.wl_Ku, tmatrix_aux.wl_Ka, tmatrix_aux.wl_W ]: print("Looking at wavelength {} mm.".format(RADAR_BAND)) SCATTERER = Scatterer(wavelength=RADAR_BAND, m=refractive.m_w_10C[RADAR_BAND]) SCATTERER.psd_integrator = PSDIntegrator() SCATTERER.psd_integrator.axis_ratio_func = lambda D: drop_axis_ratio( D) SCATTERER.psd_integrator.D_max = 8 SCATTERER.psd_integrator.geometries = ( tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw, ) SCATTERER.or_pdf = orientation.gaussian_pdf(10.0) SCATTERER.orient = orientation.orient_averaged_fixed SCATTERER.psd_integrator.init_scatter_table(SCATTERER) main(infile, RADAR_BAND)
A = backscatter.createDimension('Mass Parameter a', len(a.tolist())) D = backscatter.createDimension('Maximum Diameter', len(d.tolist())) WAVE = backscatter.createDimension('Wavelength', len(wave)) xsections = backscatter.createVariable( 'backscat', 'f4', ('Area Ratio', 'Mass Parameter b', 'Mass Parameter a', 'Maximum Diameter', 'Wavelength')) for i in range(len(a)): print(a[i]) for j in range(len(b)): print(b[j]) for k in range(len(ar)): print(ar[k]) for l in range(len(d)): for n in range(len(wave)): if wave[n] / d[l] > 0.15: dmod = d[l] * (ar[k]**(1. / 3.)) newm = mix(a[i], b[j], d[l] * 0.1, ar[k]) oblate = Scatterer(radius=dmod / 2., wavelength=wave[n], m=newm, axis_ratio=1 / ar[k]) xsection = 10 * np.log10(radar.refl(oblate)) xsections[i, j, k, l, n] = 10 * np.log10(radar.refl(oblate)) else: xsections[i, j, k, l, n] = np.nan backscatter.close()
plt.figure() plt.plot(D,a1.a*D**a1.b) plt.plot(D,a2.a*D**a2.b) # plt.figure() plt.plot(D,diel1(D),D,diel2(D)) from pytmatrix import orientation from pytmatrix.tmatrix import Scatterer f=9.41 wavelength=constants.C/(f*1E09)*1000 # in mm scatt = Scatterer(radius = 1.0, wavelength = wavelength) scatt.or_pdf = orientation.gaussian_pdf(std=20) scatt.orient = orientation.orient_averaged_fixed list_SZ_1=[] list_SZ_2=[] elevation = 5 m_func1= a1.get_m_func(270,f) m_func2= a2.get_m_func(270,f) geom_back=(90-elevation, 180-(90-elevation), 0., 180, 0.0,0.0) geom_forw=(90-elevation, 90-elevation, 0., 0.0, 0.0,0.0) for i,d in enumerate(D):
if ptype == 'rain': rads = np.linspace(0.1, 4.0, nr) else: rads = np.linspace(1, nr, nr) sv = np.zeros((nr, niZe, nsZe, nsAz)) sh = np.zeros((nr, niZe, nsZe, nsAz)) # zdr = np.zeros((nr,niZe,nsZe,nsAz)) for n, r in enumerate(rads): print(r) if ptype == 'rain': ar = 1.0 / drop_ar(2 * r) else: ar = 1.0 / hail_ar(2 * r) scatterer = Scatterer(radius=r, axis_ratio=0.6, wavelength=Lambda, m=m, ndgs=3) #scatterer.psd_integrator = PSDIntegrator() #scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/drop_ar(D) #scatterer.psd_integrator.axis_ratio_func = lambda D: 0.8 #scatterer.psd_integrator.D_max = 100.0 #scatterer.psd_integrator.num_points = 16 #scatterer.psd_integrator.geometries = () geometries = () ize = np.linspace(0, 90, niZe) + 90 sze = np.linspace(0, 180, nsZe) saz = np.linspace(0, 180, nsAz) sze, ize, saz = np.meshgrid(sze, ize, saz)
def create_scatterer(wavelength,orientation_std): scatt = Scatterer(radius = 1.0, wavelength = wavelength) scatt.or_pdf = orientation.gaussian_pdf(std=orientation_std) scatt.orient = orientation.orient_averaged_fixed return scatt
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]
# and/or phase matrices. So, initialize a scatterer object for RAIN # INFO ON GEOMETRY: geom_tuple = (thet0, thet, phi0, phi, alpha, beta) where, # The Euler angle alpha of the scatterer orientation (alpha) # The Euler angle beta of the scatterer orientation (beta) # The zenith angle of the incident beam (thet0) # The zenith angle of the scattered beam (thet) # The azimuth angle of the incident beam (phi0) # The azimuth angle of the scattered beam (phi) # e.g. geom_horiz_back is (90.0, 90.0, 0.0, 180.0, 0.0, 0.0) ref_indices_rain = [ complex(8.983, 0.989), complex(8.590, 1.670), complex(7.718, 2.473) ] scatterer = Scatterer() theta_radar = (0.5, 0.9, 1.3, 1.9, 2.3, 3, 3.5, 5, 6.9, 9.1, 11.8, 15.1 ) # The angles for the radar are: scatterer.alpha = 0.0 scatterer.beta = 0.0 scatterer.phi0 = 0.0 scatterer.thet = 90.0 - theta_radar[0] scatterer.thet0 = 90.0 - theta_radar[0] scatterer.phi = 180.0 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!
def calcScatPropOneFreq(wl, radii, as_ratio, rho, elv, ndgs=30, canting=False, cantingStd=1, meanAngle=0): """ Calculates the Ze at H and V polarization, Kdp for one wavelength TODO: LDR??? Parameters ---------- wl: wavelenght [mm] (single value) radii: radius [mm] of the particle (array[n]) as_ratio: aspect ratio of the super particle (array[n]) rho: density [g/mmˆ3] of the super particle (array[n]) elv: elevation angle [°] ndgs: division points used to integrate over the particle surface canting: boolean (default = False) cantingStd: standard deviation of the canting angle [°] (default = 1) meanAngle: mean value of the canting angle [°] (default = 0) Returns ------- reflect_h: super particle horizontal reflectivity[mm^6/m^3] (array[n]) reflect_v: super particle vertical reflectivity[mm^6/m^3] (array[n]) refIndex: refractive index from each super particle (array[n]) kdp: calculated kdp from each particle (array[n]) """ #---pyTmatrix setup # initialize a scatterer object scatterer = Scatterer(wavelength=wl) scatterer.radius_type = Scatterer.RADIUS_MAXIMUM scatterer.ndgs = ndgs scatterer.ddelta = 1e-6 if canting == True: scatterer.or_pdf = orientation.gaussian_pdf(std=cantingStd, mean=meanAngle) # scatterer.orient = orientation.orient_averaged_adaptive scatterer.orient = orientation.orient_averaged_fixed # geometric parameters - incident direction scatterer.thet0 = 90. - elv scatterer.phi0 = 0. # parameters for backscattering refIndex = np.ones_like(radii, np.complex128) * np.nan reflect_h = np.ones_like(radii) * np.nan reflect_v = np.ones_like(radii) * np.nan # S matrix for Kdp sMat = np.ones_like(radii) * np.nan for i, radius in enumerate(radii): # A quick function to save the distribution of values used in the test #with open('/home/dori/table_McRadar.txt', 'a') as f: # f.write('{0:f} {1:f} {2:f} {3:f} {4:f} {5:f} {6:f}\n'.format(wl, elv, # meanAngle, # cantingStd, # radius, # rho[i], # as_ratio[i])) # scattering geometry backward scatterer.thet = 180. - scatterer.thet0 # Is it???? scatterer.phi = (180. + scatterer.phi0) % 360. scatterer.radius = radius scatterer.axis_ratio = 1. / as_ratio[i] scatterer.m = refractive.mi(wl, rho[i]) refIndex[i] = refractive.mi(wl, rho[i]) reflect_h[i] = scatterer.wavelength**4 / ( np.pi**5 * scatterer.Kw_sqr) * radar.radar_xsect( scatterer, True) # Kwsqrt is not correct by default at every frequency reflect_v[i] = scatterer.wavelength**4 / ( np.pi**5 * scatterer.Kw_sqr) * radar.radar_xsect(scatterer, False) # scattering geometry forward scatterer.thet = scatterer.thet0 scatterer.phi = (scatterer.phi0) % 360. #KDP geometry S = scatterer.get_S() sMat[i] = (S[1, 1] - S[0, 0]).real kdp = 1e-3 * (180.0 / np.pi) * scatterer.wavelength * sMat del scatterer # TODO: Evaluate the chance to have one Scatterer object already initiated instead of having it locally return reflect_h, reflect_v, refIndex, kdp
def fun(main_dir,input_data,output_data): os.chdir(main_dir+input_data) print 'loading data...', QRAIN =np.load('QRAIN.npy') QNRAIN =np.load('QNRAIN.npy') QHAIL =np.load('QHAIL.npy') QNHAIL =np.load('QNHAIL.npy') QSNOW =np.load('QSNOW.npy') QNSNOW =np.load('QNSNOW.npy') QICE =np.load('QICE.npy') QNICE =np.load('QNICE.npy') QGRAUP =np.load('QGRAUP.npy') QNGRAUPEL=np.load('QNGRAUPEL.npy') QCLOUD =np.load('QCLOUD.npy') QNCLOUD =np.load('QNCLOUD.npy') RHO =np.load('RHO.npy') REFL_10CM=np.load('REFL_10CM.npy') Pa =np.load('Pa.npy') Tem =np.load('Tem.npy') print 'finished' #------------------------------------------------------------------------- print 'start using T-matrix tools...' Qr = QRAIN Qh = QHAIL Qs = QSNOW Qi = QICE Qg = QGRAUP Qc = QCLOUD Qnr = QNRAIN*RHO Qnh = QNHAIL*RHO Qns = QNSNOW*RHO Qni = QNICE*RHO Qng = QNGRAUPEL*RHO Qnc = QNCLOUD*RHO print 'Q>=1e-10' Qr=funlib.data_process(Qr) Qh=funlib.data_process(Qh) Qs=funlib.data_process(Qs) Qi=funlib.data_process(Qi) Qg=funlib.data_process(Qg) Qc=funlib.data_process(Qc) print 'finished' print ' ' #problem 20151010 print 'Nt>=0.1' Qnr=funlib.num_process(Qnr) Qnh=funlib.num_process(Qnh) Qns=funlib.num_process(Qns) Qni=funlib.num_process(Qni) Qng=funlib.num_process(Qng) Qnc=funlib.num_process(Qnc) print 'finished' print ' ' #------------------------------------------------------------------------- # global gamma_u #------------------------------------------------------------------------- gamma_u = 0 #------------------------------------------------------------------------- # starting polar calculation #------------------------------------------------------------------------- #------------------------------------------------------------------------- # setup rain #------------------------------------------------------------------------- [aaa,bbb,ccc]=Qr.shape print('-'*60) print ' ' print 'start rain...' start_time = datetime.datetime.now() #------------------------------------------------------------------------- # choice= 1,2,3 select rain,hail,snow density #------------------------------------------------------------------------- [n0,lamda]=funlib.setup_tmatrix(Qr,Qnr,gamma_u,RHO,1) scatterer = Scatterer(wavelength=tmatrix_aux.wl_X,m=refractive.m_w_10C[tmatrix_aux.wl_X]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/funlib.drop_ar(D) scatterer.psd_integrator.D_max=10.0 scatterer.psd_integrator.geometries=(tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(5.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) #-------------------------------------------------------------------------- # start tmatrix #-------------------------------------------------------------------------- print('start tmatrix...') os.chdir(main_dir+output_data) print('start calculate...zh,zdr,zv,ldr,rhv') #-------------------------------------------------------------------------- n0=n0.reshape(-1) lamda=lamda.reshape(-1) r_zh,r_zdr,r_zv,r_ldr,r_rhv=apply(funlib.cal_tm4,(n0,lamda,gamma_u,scatterer)) r_zh= r_zh.reshape(aaa,bbb,ccc) r_zdr = r_zdr.reshape(aaa,bbb,ccc) r_zv = r_zv.reshape(aaa,bbb,ccc) r_ldr = r_ldr.reshape(aaa,bbb,ccc) r_rhv = r_rhv.reshape(aaa,bbb,ccc) print('finished') print 'saving data...', np.save('r_zh.npy',r_zh) np.save('r_zdr.npy',r_zdr) np.save('r_zv.npy',r_zv) np.save('r_ldr.npy',r_ldr) np.save('r_rhv.npy',r_rhv) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------------------ # cal kdp,ai #------------------------------------------------------------------------------ print('start calculate...kdp,ai') scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) r_kdp,r_ai=apply(funlib.cal_tm2,(n0,lamda,gamma_u,scatterer)) r_kdp = r_kdp.reshape(aaa,bbb,ccc) r_ai = r_ai.reshape(aaa,bbb,ccc) print 'finished' print 'saving data...', np.save('r_kdp.npy',r_kdp) np.save('r_ai.npy',r_ai) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------ # setup cloud #------------------------------------------------------------------ [aaa,bbb,ccc]=Qc.shape print('-'*60) print ' ' print 'start cloud...' #------------------------------------------------------------------------- # choice= 1,2,3 select rain,hail,snow density #------------------------------------------------------------------------- [n0,lamda]=funlib.setup_tmatrix(Qc,Qnc,gamma_u,RHO,1) scatterer = Scatterer(wavelength=tmatrix_aux.wl_X,m=refractive.m_w_10C[tmatrix_aux.wl_X]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/funlib.drop_ar(D) scatterer.psd_integrator.D_max=2.0 scatterer.psd_integrator.geometries=(tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(10.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) #-------------------------------------------------------------------------- # start tmatrix #-------------------------------------------------------------------------- print('start tmatrix...') os.chdir(main_dir+output_data) print('start calculate...zh,zdr,zv,ldr,rhv') #-------------------------------------------------------------------------- n0=n0.reshape(-1) lamda=lamda.reshape(-1) c_zh,c_zdr,c_zv,c_ldr,c_rhv=apply(funlib.cal_tm4,(n0,lamda,gamma_u,scatterer)) c_zh= c_zh.reshape(aaa,bbb,ccc) c_zdr = c_zdr.reshape(aaa,bbb,ccc) c_zv = c_zv.reshape(aaa,bbb,ccc) c_ldr = c_ldr.reshape(aaa,bbb,ccc) c_rhv = c_rhv.reshape(aaa,bbb,ccc) print('finished') print 'saving data...', np.save('c_zh.npy',c_zh) np.save('c_zdr.npy',c_zdr) np.save('c_zv.npy',c_zv) np.save('c_ldr.npy',c_ldr) np.save('c_rhv.npy',c_rhv) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------------------ # cal kdp,ai #------------------------------------------------------------------------------ print('start calculate...kdp,ai') scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) c_kdp,c_ai=apply(funlib.cal_tm2,(n0,lamda,gamma_u,scatterer)) c_kdp = c_kdp.reshape(aaa,bbb,ccc) c_ai = c_ai.reshape(aaa,bbb,ccc) print 'finished' print 'saving data...', np.save('c_kdp.npy',c_kdp) np.save('c_ai.npy',c_ai) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------ # setup snow #------------------------------------------------------------------ [aaa,bbb,ccc]=Qs.shape print('-'*60) print ' ' print 'start snow...' #------------------------------------------------------------------------- # choice= 1,2,3 select rain,hail,snow density #------------------------------------------------------------------------- [n0,lamda]=funlib.setup_tmatrix(Qs,Qns,gamma_u,RHO,3) scatterer = Scatterer(wavelength=tmatrix_aux.wl_X,m=refractive.m_w_10C[tmatrix_aux.wl_X]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/funlib.drop_ar(D) scatterer.psd_integrator.D_max=2.0 scatterer.psd_integrator.geometries=(tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(20.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) #-------------------------------------------------------------------------- # start tmatrix #-------------------------------------------------------------------------- print('start tmatrix...') os.chdir(main_dir+output_data) print('start calculate...zh,zdr,zv,ldr,rhv') #-------------------------------------------------------------------------- n0=n0.reshape(-1) lamda=lamda.reshape(-1) s_zh,s_zdr,s_zv,s_ldr,s_rhv=apply(funlib.cal_tm4,(n0,lamda,gamma_u,scatterer)) s_zh= s_zh.reshape(aaa,bbb,ccc) s_zdr = s_zdr.reshape(aaa,bbb,ccc) s_zv = s_zv.reshape(aaa,bbb,ccc) s_ldr = s_ldr.reshape(aaa,bbb,ccc) s_rhv = s_rhv.reshape(aaa,bbb,ccc) print('finished') print 'saving data...', np.save('s_zh.npy',s_zh) np.save('s_zdr.npy',s_zdr) np.save('s_zv.npy',s_zv) np.save('s_ldr.npy',s_ldr) np.save('s_rhv.npy',s_rhv) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------------------ # cal kdp,ai #------------------------------------------------------------------------------ print('start calculate...kdp,ai') scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) s_kdp,s_ai=apply(funlib.cal_tm2,(n0,lamda,gamma_u,scatterer)) s_kdp = s_kdp.reshape(aaa,bbb,ccc) s_ai = s_ai.reshape(aaa,bbb,ccc) print 'finished' print 'saving data...', np.save('s_kdp.npy',s_kdp) np.save('s_ai.npy',s_ai) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------ # setup ice #------------------------------------------------------------------ [aaa,bbb,ccc]=Qi.shape print('-'*60) print ' ' print 'start ice...' #------------------------------------------------------------------------- # choice= 1,2,3 select rain,hail,snow density #------------------------------------------------------------------------- [n0,lamda]=funlib.setup_tmatrix(Qs,Qns,gamma_u,RHO,2) scatterer = Scatterer(wavelength=tmatrix_aux.wl_X,m=refractive.m_w_0C[tmatrix_aux.wl_X]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/funlib.drop_ar(D) scatterer.psd_integrator.D_max=2.0 scatterer.psd_integrator.geometries=(tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(2.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) #-------------------------------------------------------------------------- # start tmatrix #-------------------------------------------------------------------------- print('start tmatrix...') os.chdir(main_dir+output_data) print('start calculate...zh,zdr,zv,ldr,rhv') #-------------------------------------------------------------------------- n0=n0.reshape(-1) lamda=lamda.reshape(-1) i_zh,i_zdr,i_zv,i_ldr,i_rhv=apply(funlib.cal_tm4,(n0,lamda,gamma_u,scatterer)) i_zh= i_zh.reshape(aaa,bbb,ccc) #i_zh= lg_zh(i_zh) i_zdr = i_zdr.reshape(aaa,bbb,ccc) i_zv = i_zv.reshape(aaa,bbb,ccc) i_ldr = i_ldr.reshape(aaa,bbb,ccc) i_rhv = i_rhv.reshape(aaa,bbb,ccc) print('finished') print 'saving data...', np.save('i_zh.npy',i_zh) np.save('i_zdr.npy',i_zdr) np.save('i_zv.npy',i_zv) np.save('i_ldr.npy',i_ldr) np.save('i_rhv.npy',i_rhv) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------------------ # cal kdp,ai #------------------------------------------------------------------------------ print('start calculate...kdp,ai') scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) i_kdp,i_ai=apply(funlib.cal_tm2,(n0,lamda,gamma_u,scatterer)) i_kdp = i_kdp.reshape(aaa,bbb,ccc) i_ai = i_ai.reshape(aaa,bbb,ccc) print 'finished' print 'saving data...', np.save('i_kdp.npy',i_kdp) np.save('i_ai.npy',i_ai) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------ # setup graupel #------------------------------------------------------------------ [aaa,bbb,ccc]=Qg.shape print('-'*60) print ' ' print 'start graupel...' #------------------------------------------------------------------------- # choice= 1,2,3 select rain,hail,snow density #------------------------------------------------------------------------- [n0,lamda]=funlib.setup_tmatrix(Qg,Qng,gamma_u,RHO,2) scatterer = Scatterer(wavelength=tmatrix_aux.wl_X,m=refractive.m_w_10C[tmatrix_aux.wl_X]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/funlib.drop_ar(D) scatterer.psd_integrator.D_max=2.0 scatterer.psd_integrator.geometries=(tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(2.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) #-------------------------------------------------------------------------- # start tmatrix #-------------------------------------------------------------------------- print('start tmatrix...') os.chdir(main_dir+output_data) print('start calculate...zh,zdr,zv,ldr,rhv') #-------------------------------------------------------------------------- n0=n0.reshape(-1) lamda=lamda.reshape(-1) g_zh,g_zdr,g_zv,g_ldr,g_rhv=apply(funlib.cal_tm4,(n0,lamda,gamma_u,scatterer)) g_zh= g_zh.reshape(aaa,bbb,ccc) #g_zh= lg_zh(g_zh) g_zdr = g_zdr.reshape(aaa,bbb,ccc) g_zv = g_zv.reshape(aaa,bbb,ccc) g_ldr = g_ldr.reshape(aaa,bbb,ccc) g_rhv = g_rhv.reshape(aaa,bbb,ccc) print('finished') print 'saving data...', np.save('g_zh.npy',g_zh) np.save('g_zdr.npy',g_zdr) np.save('g_zv.npy',g_zv) np.save('g_ldr.npy',g_ldr) np.save('g_rhv.npy',g_rhv) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------------------ # cal kdp,ai #------------------------------------------------------------------------------ print('start calculate...kdp,ai') scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) g_kdp,g_ai=apply(funlib.cal_tm2,(n0,lamda,gamma_u,scatterer)) g_kdp = g_kdp.reshape(aaa,bbb,ccc) g_ai = g_ai.reshape(aaa,bbb,ccc) print 'finished' print 'saving data...', np.save('g_kdp.npy',g_kdp) np.save('g_ai.npy',g_ai) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------ # setup hail #------------------------------------------------------------------ [aaa,bbb,ccc]=Qh.shape print('-'*60) print ' ' print 'start hail...' #------------------------------------------------------------------------- # choice= 1,2,3 select rain,hail,snow density #------------------------------------------------------------------------- [n0,lamda]=funlib.setup_tmatrix(Qh,Qnh,gamma_u,RHO,2) scatterer = Scatterer(wavelength=tmatrix_aux.wl_X,m=refractive.m_w_10C[tmatrix_aux.wl_X]) scatterer.psd_integrator = PSDIntegrator() scatterer.psd_integrator.axis_ratio_func = lambda D: 1.0/funlib.drop_ar(D) scatterer.psd_integrator.D_max=5.0 scatterer.psd_integrator.geometries=(tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw) scatterer.or_pdf = orientation.gaussian_pdf(5.0) scatterer.orient = orientation.orient_averaged_fixed scatterer.psd_integrator.init_scatter_table(scatterer) #-------------------------------------------------------------------------- # start tmatrix #-------------------------------------------------------------------------- print('start tmatrix...') os.chdir(main_dir+output_data) print('start calculate...zh,zdr,zv,ldr,rhv') #-------------------------------------------------------------------------- n0=n0.reshape(-1) lamda=lamda.reshape(-1) h_zh,h_zdr,h_zv,h_ldr,h_rhv=apply(funlib.cal_tm4,(n0,lamda,gamma_u,scatterer)) h_zh= h_zh.reshape(aaa,bbb,ccc) #g_zh= lg_zh(g_zh) h_zdr = h_zdr.reshape(aaa,bbb,ccc) h_zv = h_zv.reshape(aaa,bbb,ccc) h_ldr = h_ldr.reshape(aaa,bbb,ccc) h_rhv = h_rhv.reshape(aaa,bbb,ccc) print('finished') print 'saving data...', np.save('h_zh.npy',h_zh) np.save('h_zdr.npy',h_zdr) np.save('h_zv.npy',h_zv) np.save('h_ldr.npy',h_ldr) np.save('h_rhv.npy',h_rhv) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' #------------------------------------------------------------------------------ # cal kdp,ai #------------------------------------------------------------------------------ print('start calculate...kdp,ai') scatterer.set_geometry(tmatrix_aux.geom_horiz_forw) h_kdp,h_ai=apply(funlib.cal_tm2,(n0,lamda,gamma_u,scatterer)) h_kdp = h_kdp.reshape(aaa,bbb,ccc) h_ai = h_ai.reshape(aaa,bbb,ccc) print 'finished' print 'saving data...', np.save('h_kdp.npy',h_kdp) np.save('h_ai.npy',h_ai) print 'finished' print 'used time:'+str((datetime.datetime.now()-start_time).seconds)+' s' print('-'*60) return
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]