Exemplo 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)
Exemplo n.º 2
0
def tm_reflectivity(size, wl, n, ar=1.0):  # Takes size and wl in meters
    scatt = tmatrix.Scatterer(
        radius=0.5e3 * size,  # conversion to millimeter radius
        radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM,
        wavelength=wl * 1.0e3,  # conversion to millimeters
        m=n,
        axis_ratio=1.0 / ar)
    scatt.set_geometry(tmatrix_aux.geom_vert_back)
    return radar.radar_xsect(
        scatt
    )  # mm**2 ... need just to integrate and multiply by Rayleigh factor
Exemplo n.º 3
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.º 4
0
    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)
Exemplo n.º 5
0
    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)
ones = np.ones_like(volume_fractions)
ref_soft = snowScatt.refractiveIndex.mixing.eps(
    [ref_index**2 * ones, complex(1.0, 0.0) * ones],
    [volume_fractions, 1.0 - volume_fractions])
ref_soft = np.sqrt(ref_soft)

for iD, D in enumerate(Dmax):
    spheroid = tmatrix.Scatterer(radius=0.5 * D,
                                 radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM,
                                 wavelength=wavelength,
                                 m=ref_soft[iD],
                                 axis_ratio=1.0 / aspect_ratio)
    spheroid.set_geometry(tmatrix_aux.geom_vert_back)
    spheroidCs[iD] = scatter.sca_xsect(spheroid)
    spheroidCb[iD] = radar.radar_xsect(spheroid)

spheroidQb = spheroidCb / (np.pi * reff_sph**2)
spheroidQs = spheroidCs / (np.pi * reff_sph**2)
spheroid_x = 2.0 * np.pi * reff_sph / wavelength

axs[0].plot(spheroid_x, spheroidQb, c='m', label='soft-spheroid')
axs[1].plot(spheroid_x, spheroidQs, c='m', label='soft-spheroid')
###############################################################################

for ipt, (particle_type, ssrga_particle) in enumerate(
        zip(particle_types, ssrga_particle_names)):
    part_sel = [
        str(v.values) for v in Cext.particle_name
        if str(v.values).startswith(particle_type)
    ]
Exemplo n.º 7
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.º 8
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.º 9
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)
Exemplo n.º 10
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