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 test_fixed_orient(self): """Test a fixed-point orientation averaging case """ tm = TMatrix(axi=2.0, lam=6.5, m=complex(1.5, 0.5), eps=1.0 / 0.6, suppress_warning=True) tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_fixed (S, Z) = tm.get_SZ() S_ref = np.array([[ complex(6.49006090e-02, -2.42487917e-01), complex(1.20257317e-11, -5.23022168e-11) ], [ complex(6.21754594e-12, 2.95662844e-11), complex(-9.54177082e-02, 2.84758158e-01) ]]) Z_ref = np.array([[ 7.89748116e-02, -1.37649947e-02, -1.58053610e-11, -4.56295798e-12 ], [-1.37649947e-02, 7.82237468e-02, -2.85105399e-11, -3.43475094e-12], [ 2.42108565e-11, -3.92054806e-11, -7.73426425e-02, 5.14654926e-03 ], [ 4.56792369e-12, -3.77838854e-12, -5.14654926e-03, -7.65915776e-02 ]]) test_relative(self, S, S_ref) test_relative(self, Z, Z_ref)
def test_fixed_orient(self): """Test a fixed-point orientation averaging case """ tm = TMatrix(axi=2.0, lam=6.5, m=complex(1.5,0.5), eps=1.0/0.6, suppress_warning=True) tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_fixed (S, Z) = tm.get_SZ() S_ref = np.array( [[complex(6.49006090e-02, -2.42487917e-01), complex(1.20257317e-11, -5.23022168e-11)], [complex(6.21754594e-12, 2.95662844e-11), complex(-9.54177082e-02, 2.84758158e-01)]]) Z_ref = np.array( [[7.89748116e-02, -1.37649947e-02, -1.58053610e-11, -4.56295798e-12], [-1.37649947e-02, 7.82237468e-02, -2.85105399e-11, -3.43475094e-12], [2.42108565e-11, -3.92054806e-11, -7.73426425e-02, 5.14654926e-03], [4.56792369e-12, -3.77838854e-12, -5.14654926e-03, -7.65915776e-02]]) test_relative(self, S, S_ref) test_relative(self, Z, Z_ref)
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 _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 test_adaptive_orient(self): """Test an adaptive orientation averaging case """ tm = TMatrix(axi=2.0, lam=6.5, m=complex(1.5,0.5), eps=1.0/0.6, suppress_warning=True) tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_adaptive (S, Z) = tm.get_SZ() S_ref = np.array( [[complex(6.49005717e-02, -2.42488000e-01), complex(-6.12697676e-16, -4.10602248e-15)], [complex(-1.50048180e-14, -1.64195485e-15), complex(-9.54176591e-02, 2.84758322e-01)]]) Z_ref = np.array( [[7.89677648e-02, -1.37631854e-02, -7.45412599e-15, -9.23979111e-20], [-1.37631854e-02, 7.82165256e-02, 5.61975938e-15, -1.32888054e-15], [8.68047418e-15, 3.52110917e-15, -7.73358177e-02, 5.14571155e-03], [1.31977116e-19, -3.38136420e-15, -5.14571155e-03, -7.65845784e-02]]) test_relative(self, S, S_ref) test_relative(self, Z, Z_ref)
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 _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 test_adaptive_orient(self): """Test an adaptive orientation averaging case """ tm = TMatrix(axi=2.0, lam=6.5, m=complex(1.5, 0.5), eps=1.0 / 0.6, suppress_warning=True) tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_adaptive (S, Z) = tm.get_SZ() S_ref = np.array([[ complex(6.49005717e-02, -2.42488000e-01), complex(-6.12697676e-16, -4.10602248e-15) ], [ complex(-1.50048180e-14, -1.64195485e-15), complex(-9.54176591e-02, 2.84758322e-01) ]]) Z_ref = np.array([[ 7.89677648e-02, -1.37631854e-02, -7.45412599e-15, -9.23979111e-20 ], [-1.37631854e-02, 7.82165256e-02, 5.61975938e-15, -1.32888054e-15], [ 8.68047418e-15, 3.52110917e-15, -7.73358177e-02, 5.14571155e-03 ], [ 1.31977116e-19, -3.38136420e-15, -5.14571155e-03, -7.65845784e-02 ]]) test_relative(self, S, S_ref) test_relative(self, Z, Z_ref)
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 _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 / \ DSR.bc(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)
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 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 _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 _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 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 test_radar(self): """Test that the radar properties are computed correctly """ tm = TMatrixPSD(lam=tmatrix_aux.wl_C, m=refractive.m_w_10C[tmatrix_aux.wl_C], suppress_warning=True) tm.psd = psd.GammaPSD(D0=2.0, Nw=1e3, mu=4) tm.psd_eps_func = lambda D: 1.0/drop_ar(D) tm.D_max = 10.0 tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_fixed tm.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) tm.init_scatter_table() radar_xsect_h = radar.radar_xsect(tm) Z_h = radar.refl(tm) Z_v = radar.refl(tm, False) ldr = radar.ldr(tm) Zdr = radar.Zdr(tm) delta_hv = radar.delta_hv(tm) rho_hv = radar.rho_hv(tm) tm.set_geometry(tmatrix_aux.geom_horiz_forw) Kdp = radar.Kdp(tm) A_h = radar.Ai(tm) A_v = radar.Ai(tm, False) radar_xsect_h_ref = 0.22176446239750278 Z_h_ref = 6383.7337897299258 Z_v_ref = 5066.721040036321 ldr_ref = 0.0021960626647629547 Zdr_ref = 1.2599339374097778 delta_hv_ref = -0.00021227778705544846 rho_hv_ref = 0.99603080460983828 Kdp_ref = 0.19334678024367824 A_h_ref = 0.018923976733777458 A_v_ref = 0.016366340549483317 for (val, ref) in zip( (radar_xsect_h, Z_h, Z_v, ldr, Zdr, delta_hv, rho_hv, Kdp, A_h, A_v), (radar_xsect_h_ref, Z_h_ref, Z_v_ref, ldr_ref, Zdr_ref, delta_hv_ref, rho_hv_ref, Kdp_ref, A_h_ref, A_v_ref)): test_relative(self, val, ref)
def test_radar(self): """Test that the radar properties are computed correctly """ tm = TMatrixPSD(lam=tmatrix_aux.wl_C, m=refractive.m_w_10C[tmatrix_aux.wl_C], suppress_warning=True) tm.psd = psd.GammaPSD(D0=2.0, Nw=1e3, mu=4) tm.psd_eps_func = lambda D: 1.0 / drop_ar(D) tm.D_max = 10.0 tm.or_pdf = orientation.gaussian_pdf(20.0) tm.orient = orientation.orient_averaged_fixed tm.geometries = (tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw) tm.init_scatter_table() radar_xsect_h = radar.radar_xsect(tm) Z_h = radar.refl(tm) Z_v = radar.refl(tm, False) ldr = radar.ldr(tm) Zdr = radar.Zdr(tm) delta_hv = radar.delta_hv(tm) rho_hv = radar.rho_hv(tm) tm.set_geometry(tmatrix_aux.geom_horiz_forw) Kdp = radar.Kdp(tm) A_h = radar.Ai(tm) A_v = radar.Ai(tm, False) radar_xsect_h_ref = 0.22176446239750278 Z_h_ref = 6383.7337897299258 Z_v_ref = 5066.721040036321 ldr_ref = 0.0021960626647629547 Zdr_ref = 1.2599339374097778 delta_hv_ref = -0.00021227778705544846 rho_hv_ref = 0.99603080460983828 Kdp_ref = 0.19334678024367824 A_h_ref = 0.018923976733777458 A_v_ref = 0.016366340549483317 for (val, ref) in zip( (radar_xsect_h, Z_h, Z_v, ldr, Zdr, delta_hv, rho_hv, Kdp, A_h, A_v), (radar_xsect_h_ref, Z_h_ref, Z_v_ref, ldr_ref, Zdr_ref, delta_hv_ref, rho_hv_ref, Kdp_ref, A_h_ref, A_v_ref)): test_relative(self, val, ref)
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 __init__(self, **kwargs): self.radius = 1.0 self.radius_type = Scatterer.RADIUS_EQUAL_VOLUME self.wavelength = 1.0 self.m = complex(2, 0) self.axis_ratio = 1.0 self.shape = Scatterer.SHAPE_SPHEROID self.ddelt = 1e-3 self.ndgs = 2 self.alpha = 0.0 self.beta = 0.0 self.thet0 = 90.0 self.thet = 90.0 self.phi0 = 0.0 self.phi = 180.0 self.Kw_sqr = 0.93 self.orient = orientation.orient_single self.or_pdf = orientation.gaussian_pdf() self.n_alpha = 5 self.n_beta = 10 self._tm_signature = () self._scatter_signature = () self._orient_signature = () self._psd_signature = () self.psd_integrator = None self.psd = None self.suppress_warning = kwargs["suppress_warning"] if \ "suppress_warning" in kwargs else False for attr in self.__class__._deprecated_aliases: if attr in kwargs: self._warn_deprecation(attr) self.__dict__[self._deprecated_aliases[attr]] = kwargs[attr] for attr in self._attr_list: if attr in kwargs: self.__dict__[attr] = kwargs[attr]
def __init__(self, **kwargs): self.radius = 1.0 self.radius_type = Scatterer.RADIUS_EQUAL_VOLUME self.wavelength = 1.0 self.m = complex(2,0) self.axis_ratio = 1.0 self.shape = Scatterer.SHAPE_SPHEROID self.ddelt = 1e-3 self.ndgs = 2 self.alpha = 0.0 self.beta = 0.0 self.thet0 = 90.0 self.thet = 90.0 self.phi0 = 0.0 self.phi = 180.0 self.Kw_sqr = 0.93 self.orient = orientation.orient_single self.or_pdf = orientation.gaussian_pdf() self.n_alpha = 5 self.n_beta = 10 self._tm_signature = () self._scatter_signature = () self._orient_signature = () self._psd_signature = () self.psd_integrator = None self.psd = None self.suppress_warning = kwargs["suppress_warning"] if \ "suppress_warning" in kwargs else False for attr in self.__class__._deprecated_aliases: if attr in kwargs: self._warn_deprecation(attr) self.__dict__[self._deprecated_aliases[attr]] = kwargs[attr] for attr in self._attr_list: if attr in kwargs: self.__dict__[attr] = kwargs[attr]
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 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 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
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! # 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)
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 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 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
#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) # for i in range(nsAz): # for j in range(nsZe): # for k in range(niZe): # print(i,j,k) # #scatterer.psd_integrator.geometries += ((k*22.5+90, j, 0.0, i, 0.0, 0.0),) # geometries += ((k*22.5+90, j, 0.0, i, 0.0, 0.0),) scatterer.or_pdf = orientation.gaussian_pdf(std=30.0) # scatterer.orient = orientation.orient_averaged_fixed # start = timer() # scatterer.psd_integrator.init_scatter_table(scatterer,verbose=True) # end = timer() # time = end-start # print(time) #scatterer.psd = ExponentialPSD(N0 = 1e2,Lambda= 0.025,D_max=100.0) it = np.nditer(sze, flags=['multi_index']) for x in it: geom = (ize[it.multi_index], sze[it.multi_index], 0.0, saz[it.multi_index], 0.0, 0.0) scatterer.set_geometry(geom) idx = (n, ) + it.multi_index # refh[it.multi_index] = 10*np.log10(radar.refl(scatterer))
for index, row in data.iterrows(): coords = Z11.sel(wavelength=row.wl, size=row.radius, aspect=row.as_ratio, density=row.rho, elevation=row.elv, canting=row.cantingStd, method='nearest').coords if np.isnan(Z11.loc[coords]): print(index, i) i = i + 1 scatterer.wavelength = row.wl scatterer.radius = row.radius scatterer.axis_ratio = 1. / row.as_ratio scatterer.m = refractive.mi(row.wl, row.rho) scatterer.or_pdf = orientation.gaussian_pdf( std=row.cantingStd, mean=int(row.as_ratio > 1) * 90.0) # scatterer.orient = orientation.orient_averaged_adaptive scatterer.orient = orientation.orient_averaged_fixed scatterer.thet0 = 90. - row.elv scatterer.phi0 = 0. # First, backward scatterer.thet = 180.0 - scatterer.thet0 scatterer.phi = (180. + scatterer.phi0) % 360. Zmat = scatterer.get_Z() Z11.load().loc[coords] = Zmat[0, 0] Z22.load().loc[coords] = Zmat[1, 1] Z21.load().loc[coords] = Zmat[1, 0] Z12.load().loc[coords] = Zmat[0, 1] Z33.load().loc[coords] = Zmat[2, 2] Z34.load().loc[coords] = Zmat[2, 3]
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
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): ar = a1.get_axis_ratio(d)
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)
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