def __init__(self, **kwargs): super(TMatrixPSD, self).__init__(**kwargs) if not kwargs.get("suppress_warning", False): warnings.simplefilter("always") warnings.warn("TMatrixPSD is deprecated and may be removed in " + "a future version. Use the PSDIntegrator class and the " + \ "psd_integrator property of the Scatterer class instead.", DeprecationWarning) warnings.filters.pop(0) self.num_points = 500 self.m_func = None self.axis_ratio_func = None self.D_max = None self.geometries = (tmatrix_aux.geom_horiz_back, ) self.psd_integrator = PSDIntegrator() for attr in self._aliases: if attr in kwargs: self.__dict__[self._aliases[attr]] = kwargs[attr] for attr in self.__class__._psd_attr_list: if attr in kwargs: self.__dict__[attr] = kwargs[attr] self.set_geometry(self.geometries[0])
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 __init__(self, **kwargs): super(TMatrixPSD, self).__init__(**kwargs) if not kwargs.get("suppress_warning", False): warnings.simplefilter("always") warnings.warn("TMatrixPSD is deprecated and may be removed in " + "a future version. Use the PSDIntegrator class and the " + \ "psd_integrator property of the Scatterer class instead.", DeprecationWarning) warnings.filters.pop(0) self.num_points = 500 self.m_func = None self.axis_ratio_func = None self.D_max = None self.geometries = (tmatrix_aux.geom_horiz_back,) self.psd_integrator = PSDIntegrator() for attr in self._aliases: if attr in kwargs: self.__dict__[self._aliases[attr]] = kwargs[attr] for attr in self.__class__._psd_attr_list: if attr in kwargs: self.__dict__[attr] = kwargs[attr] self.set_geometry(self.geometries[0])
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 __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 _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!!!!!!!!"
class TMatrixPSD(Scatterer): """T-matrix class to perform computations over PSDs. This class derives from TMatrix to perform computations on particle ensembles given by a particle size distribution (PSD). Most class attributes can be set as in the TMatrix class, and there are several additional attributes. However, note that unlike with TMatrix, the results are based on lookup tables that are initialized with init_scatter_table. This means that after initializing (init_scatter_table) or loading (load_scatter_table) the lookup tables, only changes to the PSD will have an effect on the results. To change other properties of the scattering problem (e.g. the refractive index m), you must rerun init_scatter_table. Initialize the class and set the attributes as described below. Call init_scatter_table to compute the lookup table for scattering values at different scatterer geometries. The scattering properties can now be retrieved multiple times without re-initializing. Use set_geometry to select the geometry you need. After this, you can call the same functions as with the TMatrix class to retrieve the scattering/radar parameters. Attributes: psd: set to a callable object giving the PSD value for a given diameter (for example a GammaPSD instance); default GammaPSD(D0=1.0) n_psd: the number of points for which to sample the PSD and scattering properties for; default n_psd=500 should be good for most purposes psd_m_func: set to a callable object giving the refractive index as a function of diameter, or None to use the "m" attribute for all sizes; default None psd_eps_func: set to a callable object giving the aspect ratio (horizontal to rotational) as a function of diameter, or None to use the "eps" attribute for all sizes; default None D_max: set to the maximum single scatterer size that is desired to be used (usually the D_max corresponding to the largest PSD you intend to use) geoms: tuple containing the scattering geometry tuples that are initialized (thet0, thet, phi0, phi, alpha, beta); default horizontal backscatter """ _psd_attr_list = set( ["num_points", "m_func", "axis_ratio_func", "D_max", "geometries"]) _aliases = { "n_psd": "num_points", "psd_eps_func": "axis_ratio_func", "psd_m_func": "m_func" } def __init__(self, **kwargs): super(TMatrixPSD, self).__init__(**kwargs) if not kwargs.get("suppress_warning", False): warnings.simplefilter("always") warnings.warn("TMatrixPSD is deprecated and may be removed in " + "a future version. Use the PSDIntegrator class and the " + \ "psd_integrator property of the Scatterer class instead.", DeprecationWarning) warnings.filters.pop(0) self.num_points = 500 self.m_func = None self.axis_ratio_func = None self.D_max = None self.geometries = (tmatrix_aux.geom_horiz_back, ) self.psd_integrator = PSDIntegrator() for attr in self._aliases: if attr in kwargs: self.__dict__[self._aliases[attr]] = kwargs[attr] for attr in self.__class__._psd_attr_list: if attr in kwargs: self.__dict__[attr] = kwargs[attr] self.set_geometry(self.geometries[0]) def __setattr__(self, name, value): name = self._aliases.get(name, name) super(TMatrixPSD, self).__setattr__(name, value) def __getattr__(self, name): if name == "_aliases": raise AttributeError name = self._aliases.get(name, name) return super(TMatrixPSD, self).__getattr__(name) def _copy_attrs(self): for attr in self._psd_attr_list: if attr in self.__dict__: self.psd_integrator.__dict__[attr] = self.__dict__[attr] def init_scatter_table(self): self._copy_attrs() self.psd_integrator.init_scatter_table(self) def save_scatter_table(self, fn, description=""): self._copy_attrs() self.psd_integrator.save_scatter_table(fn, description=description) def load_scatter_table(self, fn): self.psd_integrator.load_scatter_table(fn)
class TMatrixPSD(Scatterer): """T-matrix class to perform computations over PSDs. This class derives from TMatrix to perform computations on particle ensembles given by a particle size distribution (PSD). Most class attributes can be set as in the TMatrix class, and there are several additional attributes. However, note that unlike with TMatrix, the results are based on lookup tables that are initialized with init_scatter_table. This means that after initializing (init_scatter_table) or loading (load_scatter_table) the lookup tables, only changes to the PSD will have an effect on the results. To change other properties of the scattering problem (e.g. the refractive index m), you must rerun init_scatter_table. Initialize the class and set the attributes as described below. Call init_scatter_table to compute the lookup table for scattering values at different scatterer geometries. The scattering properties can now be retrieved multiple times without re-initializing. Use set_geometry to select the geometry you need. After this, you can call the same functions as with the TMatrix class to retrieve the scattering/radar parameters. Attributes: psd: set to a callable object giving the PSD value for a given diameter (for example a GammaPSD instance); default GammaPSD(D0=1.0) n_psd: the number of points for which to sample the PSD and scattering properties for; default n_psd=500 should be good for most purposes psd_m_func: set to a callable object giving the refractive index as a function of diameter, or None to use the "m" attribute for all sizes; default None psd_eps_func: set to a callable object giving the aspect ratio (horizontal to rotational) as a function of diameter, or None to use the "eps" attribute for all sizes; default None D_max: set to the maximum single scatterer size that is desired to be used (usually the D_max corresponding to the largest PSD you intend to use) geoms: tuple containing the scattering geometry tuples that are initialized (thet0, thet, phi0, phi, alpha, beta); default horizontal backscatter """ _psd_attr_list = set(["num_points", "m_func", "axis_ratio_func", "D_max", "geometries"]) _aliases = {"n_psd": "num_points", "psd_eps_func": "axis_ratio_func", "psd_m_func": "m_func" } def __init__(self, **kwargs): super(TMatrixPSD, self).__init__(**kwargs) if not kwargs.get("suppress_warning", False): warnings.simplefilter("always") warnings.warn("TMatrixPSD is deprecated and may be removed in " + "a future version. Use the PSDIntegrator class and the " + \ "psd_integrator property of the Scatterer class instead.", DeprecationWarning) warnings.filters.pop(0) self.num_points = 500 self.m_func = None self.axis_ratio_func = None self.D_max = None self.geometries = (tmatrix_aux.geom_horiz_back,) self.psd_integrator = PSDIntegrator() for attr in self._aliases: if attr in kwargs: self.__dict__[self._aliases[attr]] = kwargs[attr] for attr in self.__class__._psd_attr_list: if attr in kwargs: self.__dict__[attr] = kwargs[attr] self.set_geometry(self.geometries[0]) def __setattr__(self, name, value): name = self._aliases.get(name, name) super(TMatrixPSD, self).__setattr__(name, value) def __getattr__(self, name): if name == "_aliases": raise AttributeError name = self._aliases.get(name, name) return super(TMatrixPSD, self).__getattr__(name) def _copy_attrs(self): for attr in self._psd_attr_list: if attr in self.__dict__: self.psd_integrator.__dict__[attr] = self.__dict__[attr] def init_scatter_table(self): self._copy_attrs() self.psd_integrator.init_scatter_table(self) def save_scatter_table(self, fn, description=""): self._copy_attrs() self.psd_integrator.save_scatter_table(fn, description=description) def load_scatter_table(self, fn): self.psd_integrator.load_scatter_table(fn)
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)