Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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())
Exemplo n.º 4
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
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
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
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
 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!!!!!!!!"
Exemplo n.º 12
0
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
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
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]   
Exemplo n.º 16
0
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]   
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
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
Exemplo n.º 21
0
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
Exemplo n.º 22
0
# 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!
Exemplo n.º 23
0
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
Exemplo n.º 24
0
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
Exemplo n.º 25
0
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)
Exemplo n.º 26
0
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()
Exemplo n.º 27
0
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
Exemplo n.º 28
0
    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):
        
Exemplo n.º 29
0
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)