Esempio n. 1
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)
Esempio n. 2
0
def Ai(scatterer, h_pol=True):
    """
    Specific attenuation (A) for the current setup.

    Parameters:
        h_pol (default True): compute attenuation for the horizontal 
        polarization. If False, use vertical polarization.

    Returns:
        A [dB/km].

    NOTE: This only returns the correct value if the particle diameter and
    wavelength are given in [mm]. The scatterer object should be set to 
    forward scattering geometry before calling this function.
    """
    return 4.343e-3 * ext_xsect(scatterer, h_pol=h_pol)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
def Ai(scatterer, h_pol=True):
    """
    Specific attenuation (A) for the current setup.

    Parameters:
        h_pol (default True): compute attenuation for the horizontal 
        polarization. If False, use vertical polarization.

    Returns:
        A [dB/km].

    NOTE: This only returns the correct value if the particle diameter and
    wavelength are given in [mm]. The scatterer object should be set to 
    forward scattering geometry before calling this function.
    """
    return 4.343e-3 * ext_xsect(scatterer, h_pol=h_pol)
Esempio n. 6
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
Esempio n. 7
0
    def init_scatter_table(self, tm, angular_integration=False, verbose=False):
        """Initialize the scattering lookup tables.
        
        Initialize the scattering lookup tables for the different geometries.
        Before calling this, the following attributes must be set:
           num_points, m_func, axis_ratio_func, D_max, geometries
        and additionally, all the desired attributes of the Scatterer class
        (e.g. wavelength, aspect ratio).

        Args:
            tm: a Scatterer instance.
            angular_integration: If True, also calculate the 
                angle-integrated quantities (scattering cross section, 
                extinction cross section, asymmetry parameter). These are 
                needed to call the corresponding functions in the scatter 
                module when PSD integration is active. The default is False.
            verbose: if True, print information about the progress of the 
                calculation (which may take a while). If False (default), 
                run silently.
        """
        self._psd_D = np.linspace(self.D_max / self.num_points, self.D_max,
                                  self.num_points)

        self._S_table = {}
        self._Z_table = {}
        self._previous_psd = None
        self._m_table = np.empty(self.num_points, dtype=complex)
        if angular_integration:
            self._angular_table = {
                "sca_xsect": {},
                "ext_xsect": {},
                "asym": {}
            }
        else:
            self._angular_table = None

        (old_m, old_axis_ratio, old_radius, old_geom, old_psd_integrator) = \
            (tm.m, tm.axis_ratio, tm.radius, tm.get_geometry(),
                tm.psd_integrator)

        try:
            # temporarily disable PSD integration to avoid recursion
            tm.psd_integrator = None

            for geom in self.geometries:
                self._S_table[geom] = \
                    np.empty((2,2,self.num_points), dtype=complex)
                self._Z_table[geom] = np.empty((4, 4, self.num_points))

                if angular_integration:
                    for int_var in ["sca_xsect", "ext_xsect", "asym"]:
                        self._angular_table[int_var][geom] = \
                            np.empty(self.num_points)

            for (i, D) in enumerate(self._psd_D):
                if verbose:
                    print("Computing point {i} at D={D}...".format(i=i, D=D))
                if self.m_func != None:
                    tm.m = self.m_func(D)
                if self.axis_ratio_func != None:
                    tm.axis_ratio = self.axis_ratio_func(D)
                self._m_table[i] = tm.m
                tm.radius = D / 2.0
                for geom in self.geometries:
                    tm.set_geometry(geom)
                    (S, Z) = tm.get_SZ_orient()
                    self._S_table[geom][:, :, i] = S
                    self._Z_table[geom][:, :, i] = Z

                    if angular_integration:
                        self._angular_table["sca_xsect"][geom][i] = \
                            scatter.sca_xsect(tm)
                        self._angular_table["ext_xsect"][geom][i] = \
                            scatter.ext_xsect(tm)
                        self._angular_table["asym"][geom][i] = \
                            scatter.asym(tm)
        finally:
            #restore old values
            (tm.m, tm.axis_ratio, tm.radius, tm.psd_integrator) = \
                (old_m, old_axis_ratio, old_radius, old_psd_integrator)
            tm.set_geometry(old_geom)
Esempio n. 8
0
Nc = 1
Nl = 1
xr = np.ndarray((Nc, Nl), dtype=np.float64)
mr = np.ndarray((Nc, Nl), dtype=np.complex128)
xr[:, 0] = x
mr[:, 0] = m
thetas = np.linspace(0.0, np.pi, 180)
terms, Qe, Qs, Qa, Qb, Qp, g, ssa, S1, S2 = scattnlay(xr, mr, theta=thetas)
print(S1[0, -1] / k, S2[0, -1] / k)
s1 = S1[0, 0] / k
s2 = S2[0, 0] / k
SM = 0.0 * S
SM[0, 0] = -1.0j * s2
SM[1, 1] = -1.0j * s1

print("Cext = ", scatter.ext_xsect(scatterer), Qe[0] * r * r * np.pi)
print("Csca = ", scatter.sca_xsect(scatterer), Qs[0] * r * r * np.pi)
print("Cbck = ", radar.radar_xsect(scatterer), Qb[0] * r * r * np.pi)

print(S[0, 0].real / S1[0, 0].real)
print(S[0, 0].imag / S1[0, 0].imag)

print(S[1, 1].real / S2[0, 0].real)
print(S[1, 1].imag / S2[0, 0].imag)

Z11 = 0.5 * (abs(s1)**2 + abs(s2)**2)
Z33 = 0.5 * (s1 * s2.conjugate() + s1.conjugate() * s2)

print(Z[0, 0] / Z11)
print(Z[2, 2] / Z33)
Esempio n. 9
0
    def init_scatter_table(self, tm, angular_integration=False, verbose=False):
        """Initialize the scattering lookup tables.
        
        Initialize the scattering lookup tables for the different geometries.
        Before calling this, the following attributes must be set:
           num_points, m_func, axis_ratio_func, D_max, geometries
        and additionally, all the desired attributes of the Scatterer class
        (e.g. wavelength, aspect ratio).

        Args:
            tm: a Scatterer instance.
            angular_integration: If True, also calculate the 
                angle-integrated quantities (scattering cross section, 
                extinction cross section, asymmetry parameter). These are 
                needed to call the corresponding functions in the scatter 
                module when PSD integration is active. The default is False.
            verbose: if True, print information about the progress of the 
                calculation (which may take a while). If False (default), 
                run silently.
        """
        self._psd_D = np.linspace(self.D_max/self.num_points, self.D_max, 
            self.num_points)

        self._S_table = {}
        self._Z_table = {}
        self._previous_psd = None
        self._m_table = np.empty(self.num_points, dtype=complex)
        if angular_integration:
            self._angular_table = {"sca_xsect": {}, "ext_xsect": {}, 
                "asym": {}}
        else:
            self._angular_table = None
        
        (old_m, old_axis_ratio, old_radius, old_geom, old_psd_integrator) = \
            (tm.m, tm.axis_ratio, tm.radius, tm.get_geometry(), 
                tm.psd_integrator)
        
        try:
            # temporarily disable PSD integration to avoid recursion
            tm.psd_integrator = None 

            for geom in self.geometries:
                self._S_table[geom] = \
                    np.empty((2,2,self.num_points), dtype=complex)
                self._Z_table[geom] = np.empty((4,4,self.num_points))

                if angular_integration:
                    for int_var in ["sca_xsect", "ext_xsect", "asym"]:
                        self._angular_table[int_var][geom] = \
                            np.empty(self.num_points)

            for (i,D) in enumerate(self._psd_D):
                if verbose:
                    print("Computing point {i} at D={D}...".format(i=i, D=D))
                if self.m_func != None:
                    tm.m = self.m_func(D)
                if self.axis_ratio_func != None:
                    tm.axis_ratio = self.axis_ratio_func(D)
                self._m_table[i] = tm.m
                tm.radius = D/2.0
                for geom in self.geometries:
                    tm.set_geometry(geom)
                    (S, Z) = tm.get_SZ_orient()
                    self._S_table[geom][:,:,i] = S
                    self._Z_table[geom][:,:,i] = Z

                    if angular_integration:
                        self._angular_table["sca_xsect"][geom][i] = \
                            scatter.sca_xsect(tm)
                        self._angular_table["ext_xsect"][geom][i] = \
                            scatter.ext_xsect(tm)
                        self._angular_table["asym"][geom][i] = \
                            scatter.asym(tm)
        finally:
            #restore old values
            (tm.m, tm.axis_ratio, tm.radius, tm.psd_integrator) = \
                (old_m, old_axis_ratio, old_radius, old_psd_integrator) 
            tm.set_geometry(old_geom)