Example #1
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 get_radar_variables_cloudPSD(N0=None, Lambda=None, D_max=None):
    scatterer.psd = NEWhybridPSD(N0=N0, Lambda=Lambda, D_max=D_max)
    #return [10.*np.log10(radar.refl(scatterer)), 10.*np.log10(radar.Zdr(scatterer)), radar.Kdp(scatterer), radar.Ai(scatterer)]
    return [
        10. * np.log10(radar.refl(scatterer)),
        10. * np.log10(radar.Zdr(scatterer))
    ]
Example #3
0
def get_radar_variables_unnormalizedGamma(N0=None,
                                          Lambda=None,
                                          mu=None,
                                          D_max=None):
    scatterer.psd = psd.UnnormalizedGammaPSD(N0=N0,
                                             Lambda=Lambda,
                                             mu=mu,
                                             D_max=D_max)
    return [radar.refl(scatterer), radar.Zdr(scatterer), radar.ldr(scatterer)]
def get_radar_variables_ThomPSD(N1=None,
                                N2=None,
                                Lambda1=None,
                                Lambda2=None,
                                mu=None,
                                D_max=None):
    scatterer.psd = ThomPSD(N1=N1,
                            N2=N2,
                            Lambda1=Lambda1,
                            Lambda2=Lambda2,
                            mu=mu,
                            D_max=D_max)
    return [radar.refl(scatterer), radar.Zdr(scatterer), radar.ldr(scatterer)]
Example #5
0
    def calcParameters(self,D0, Nw, mu):
        self.moments = {}
        self.scatterer.psd = GammaPSD(D0=D0, Nw=10**(Nw), mu=mu)
        self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back)
        self.moments['Zh']       = 10*np.log10(radar.refl(self.scatterer))
        self.moments['Zdr']      = 10*np.log10(radar.Zdr(self.scatterer))
        self.moments['delta_hv'] = radar.delta_hv(self.scatterer)
        self.moments['ldr_h']    = radar.ldr(self.scatterer)
        self.moments['ldr_v']    = radar.ldr(self.scatterer, h_pol=False)

        self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)
        self.moments['Kdp']      = radar.Kdp(self.scatterer)
        self.moments['Ah']       = radar.Ai(self.scatterer)
        self.moments['Adr']      = self.moments['Ah']-radar.Ai(self.scatterer, h_pol=False)
        return self.moments
Example #6
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)
def scatter_off_2dvd_packed(d_diameters, d_densities, scatterer):
    """
    Computing the scattering properties of homogeneous nonspherical scatterers with the T-Matrix method.
    
    Parameters:
    ===========
        d_diameters: array
            Drop diameters in mm! (or else returns values won't be with proper units.)
        d_densities: array
            Drop densities.
            
    Returns:
    ========
        dbz: array
            Horizontal reflectivity.
        zdr: array 
            Differential reflectivity.
        kdp: array
            Specific differential phase (deg/km).
        atten_spec: array
            Specific attenuation (dB/km).
    """
    # Function interpolation.
    mypds = interpolate.interp1d(d_diameters,
                                 d_densities,
                                 bounds_error=False,
                                 fill_value=0.0)
    scatterer.psd = mypds  # GammaPSD(D0=2.0, Nw=1e3, mu=4)

    # Obtaining reflectivity and ZDR.
    print(scatterer)
    print(np.shape(mypds))
    print(d_diameters)
    print(d_densities)
    dbz = 10 * np.log10(radar.refl(scatterer))  # in dBZ
    zdr = radar.Zdr(scatterer)  # in dB

    # Specific attenuation and KDP.
    scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)
    atten_spec = radar.Ai(scatterer)  # in dB/km
    kdp = radar.Kdp(scatterer)  # in deg/km

    return dbz, zdr, kdp, atten_spec
Example #8
0
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 calc_radar_parameters(self, wavelength=tmatrix_aux.wl_X):
        '''
        Calculates the radar parameters and stores them in the object.
        Defaults to X-Band wavelength and Thurai et al. 2007 axis ratio setup.
        Sets object radar parameters:
        Zh, Zdr, Kdp, Ai

        Parameter:
        wavelength = tmatrix supported wavelength.
        '''
        self._setup_scattering(wavelength)
        print self.bin_edges/1000.
        print self.Nt.min(),self.Nt.max()

        for t in range(0, len(self.time)):
            BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges/1000., self.Nt[t]/1E9)
            self.scatterer.psd = BinnedDSD
            self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back)
            self.Zdr[t] = 10 * np.log10(radar.Zdr(self.scatterer))
            self.Zh[t] = 10 * np.log10(radar.refl(self.scatterer))
            self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)
            self.Kdp[t] = radar.Kdp(self.scatterer)
            self.Ai[t] = radar.Ai(self.scatterer)
Example #10
0
    def calculate_radar_parameters(self,
                                   dsr_func=DSR.bc,
                                   scatter_time_range=None,
                                   max_diameter=9.0):
        """ Calculates radar parameters for the Drop Size Distribution.

        Calculates the radar parameters and stores them in the object.
        Defaults to X-Band,Beard and Chuang 10C setup.

        Sets the dictionary parameters in fields dictionary:
            Zh, Zdr, Kdp, Ai(Attenuation)

        Parameters:
        ----------
            wavelength: optional, pytmatrix wavelength
                Wavelength to calculate scattering coefficients at.
            dsr_func: optional, function
                Drop Shape Relationship function. Several are availab le in the `DSR` module.
                Defaults to Beard and Chuang
            scatter_time_range: optional, tuple
                Parameter to restrict the scattering to a time interval. The first element is the start time,
                while the second is the end time.
        """
        if self.scattering_table_consistent is False:
            self._setup_scattering(
                SPEED_OF_LIGHT / self.scattering_params["scattering_freq"] *
                1000.0,
                dsr_func,
                max_diameter,
            )
        self._setup_empty_fields()

        if scatter_time_range is None:
            self.scatter_start_time = 0
            self.scatter_end_time = self.numt
        else:
            if scatter_time_range[0] < 0:
                print("Invalid Start time specified, aborting")
                return
            self.scatter_start_time = scatter_time_range[0]
            self.scatter_end_time = scatter_time_range[1]

            if scatter_time_range[1] > self.numt:
                print("End of Scatter time is greater than end of file." +
                      "Scattering to end of included time.")
                self.scatter_end_time = self.numt

        self.scatterer.set_geometry(
            tmatrix_aux.geom_horiz_back
        )  # We break up scattering to avoid regenerating table.

        for t in range(self.scatter_start_time, self.scatter_end_time):
            if np.sum(self.Nd["data"][t]) is 0:
                continue
            BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges["data"],
                                                self.Nd["data"][t])
            self.scatterer.psd = BinnedDSD
            self.fields["Zh"]["data"][t] = 10 * np.log10(
                radar.refl(self.scatterer))
            self.fields["Zdr"]["data"][t] = 10 * np.log10(
                radar.Zdr(self.scatterer))

        self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)

        for t in range(self.scatter_start_time, self.scatter_end_time):
            BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges["data"],
                                                self.Nd["data"][t])
            self.scatterer.psd = BinnedDSD
            self.fields["Kdp"]["data"][t] = radar.Kdp(self.scatterer)
            self.fields["Ai"]["data"][t] = radar.Ai(self.scatterer)
            self.fields["Adr"]["data"][t] = radar.Ai(
                self.scatterer) - radar.Ai(self.scatterer, h_pol=False)
def get_radar_variables_Exponential(N0=None, Lambda=None, D_max=None):
    scatterer.psd = psd.ExponentialPSD(N0=N0, Lambda=Lambda, D_max=D_max)
    return [
        10. * np.log10(radar.refl(scatterer)),
        10. * np.log10(radar.Zdr(scatterer))
    ]
Example #12
0
Zdr_array = []
Z_array = []
for wl in wavelengths:
    ref_func = m_rho_func(wl)
    for lamb in lambdas:
        scatterer = tmatrix.Scatterer(wavelength=wl,
                              axis_ratio=1.0/ar,
                              Kw_sqr=tmatrix_aux.K_w_sqr[wl])
        scatterer.psd_integrator = psd.PSDIntegrator()
        scatterer.psd_integrator.m_func = ref_func
        scatterer.psd_integrator.geometries=[tmatrix_aux.geom_horiz_back,tmatrix_aux.geom_horiz_forw,]
        scatterer.set_geometry(tmatrix_aux.geom_horiz_back)
        scatterer.psd = psd.ExponentialPSD(N0=1.0,Lambda=lamb,D_max=20.0)
        scatterer.psd_integrator.D_max = 20.0
        scatterer.psd_integrator.init_scatter_table(scatterer)
        Zdr = 10.0*np.log10(radar.Zdr(scatterer))
        scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)
        W = np.pi*1e3*(1.0/lamb)**4
        Kdp = 1.0e6*radar.Kdp(scatterer)/W
        Zdr_array.append(Zdr)
        Z_array.append(Kdp)
    ax1.plot(D0s,Zdr_array,label=wl)
    ax2.plot(D0s,Z_array,label=wl)
    Zdr_array = []
    Z_array = []
ax1.legend()
ax1.grid()
ax2.grid()

ax2.set_xlabel('D0   [mm]')
ax1.set_ylabel('Zdr  [dB]')
    def calculate_radar_parameters(self,
                                   wavelength=tmatrix_aux.wl_X,
                                   dsr_func=DSR.bc,
                                   scatter_time_range=None):
        ''' Calculates radar parameters for the Drop Size Distribution.

        Calculates the radar parameters and stores them in the object.
        Defaults to X-Band,Beard and Chuang 10C setup.

        Sets the dictionary parameters in fields dictionary:
            Zh, Zdr, Kdp, Ai(Attenuation)

        Parameters:
        ----------
            wavelength: optional, pytmatrix wavelength
                Wavelength to calculate scattering coefficients at.
            dsr_func: optional, function
                Drop Shape Relationship function. Several are availab le in the `DSR` module.
                Defaults to Beard and Chuang
            scatter_time_range: optional, tuple
                Parameter to restrict the scattering to a time interval. The first element is the start time,
                while the second is the end time. 
        '''
        self._setup_scattering(wavelength, dsr_func)
        self._setup_empty_fields()

        if scatter_time_range is None:
            self.scatter_start_time = 0
            self.scatter_end_time = len(self.time)
        else:
            if scatter_time_range[0] < 0:
                print("Invalid Start time specified, aborting")
                return
            self.scatter_start_time = scatter_time_range[0]
            self.scatter_end_time = scatter_time_range[1]

            if scatter_time_range[1] > len(self.time):
                print(
                    "End of Scatter time is greater than end of file. Scattering to end of included time."
                )
                self.scatter_end_time = len(self.time)

        self.scatterer.set_geometry(
            tmatrix_aux.geom_horiz_back
        )  # We break up scattering to avoid regenerating table.

        for t in range(self.scatter_start_time, self.scatter_end_time):
            if np.sum(self.Nd[t]) is 0:
                continue
            BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges, self.Nd[t])
            self.scatterer.psd = BinnedDSD
            self.fields['Zh']['data'][t] = 10 * \
                np.log10(radar.refl(self.scatterer))
            self.fields['Zdr']['data'][t] = 10 * \
                np.log10(radar.Zdr(self.scatterer))

        self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)

        for t in range(self.scatter_start_time, self.scatter_end_time):
            self.fields['Kdp']['data'][t] = radar.Kdp(self.scatterer)
            self.fields['Ai']['data'][t] = radar.Ai(self.scatterer)
            self.fields['Ad']['data'][t] = radar.Ai(self.scatterer) - radar.Ai(
                self.scatterer, h_pol=False)
def get_radar_variables_Exponential(N0=None,Lambda=None,D_max=None):
    scatterer.psd = psd.ExponentialPSD(N0=N0, Lambda=Lambda, D_max=D_max)
    return [radar.refl(scatterer), radar.Zdr(scatterer), radar.ldr(scatterer)] 
    def calculate_radar_parameters(self,
                                   dsr_func=DSR.bc,
                                   scatter_time_range=None):
        ''' Calculates radar parameters for the Drop Size Distribution.

        Calculates the radar parameters and stores them in the object.
        Defaults to X-Band,Beard and Chuang 10C setup.

        Sets the dictionary parameters in fields dictionary:
            Zh, Zv, Zdr, Kdp, Ai, Av(hor. and vert. Attenuation),
            Adr (diff. attenuation), cross_correlation_ratio_hv (rhohv),
            LDR, Kdp

        Parameters:
        ----------
            wavelength: optional, pytmatrix wavelength
                Wavelength to calculate scattering coefficients at.
            dsr_func: optional, function
                Drop Shape Relationship function. Several are available
                in the `DSR` module.
                Defaults to Beard and Chuang
            scatter_time_range: optional, tuple
                Parameter to restrict the scattering to a time interval.
                The first element is the start time,
                while the second is the end time.
        '''
        self._setup_scattering(SPEED_OF_LIGHT / self.scattering_freq * 1000.0,
                               dsr_func)
        self._setup_empty_fields()

        if scatter_time_range is None:
            self.scatter_start_time = 0
            self.scatter_end_time = self.numt
        else:
            if scatter_time_range[0] < 0:
                print("Invalid Start time specified, aborting")
                return
            self.scatter_start_time = scatter_time_range[0]
            self.scatter_end_time = scatter_time_range[1]

            if scatter_time_range[1] > self.numt:
                print("End of Scatter time is greater than end of file. " +
                      "Scattering to end of included time.")
                self.scatter_end_time = self.numt

        # We break up scattering to avoid regenerating table.
        self.scatterer.set_geometry(tmatrix_aux.geom_horiz_back)

        print('Calculating backward scattering parameters ...')
        for t in range(self.scatter_start_time, self.scatter_end_time):
            if np.sum(self.Nd['data'][t]) is 0:
                continue
            BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges['data'],
                                                self.Nd['data'][t])
            self.scatterer.psd = BinnedDSD
            self.fields['Zh']['data'][t] = 10 * \
                np.log10(radar.refl(self.scatterer))
            self.fields['Zv']['data'][t] = 10 * \
                np.log10(radar.refl(self.scatterer, h_pol=False))
            self.fields['Zdr']['data'][t] = 10 * \
                np.log10(radar.Zdr(self.scatterer))
            self.fields['cross_correlation_ratio_hv']['data'][t] = \
                radar.rho_hv(self.scatterer)
            self.fields['specific_differential_phase_hv']['data'][t] = \
                radar.delta_hv(self.scatterer)
            self.fields['LDR']['data'][t] = 10 * \
                np.log10(radar.ldr(self.scatterer))

        self.scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)

        print('Calculating forward scattering parameters ...')
        for t in range(self.scatter_start_time, self.scatter_end_time):
            BinnedDSD = pytmatrix.psd.BinnedPSD(self.bin_edges['data'],
                                                self.Nd['data'][t])
            self.scatterer.psd = BinnedDSD
            self.fields['Kdp']['data'][t] = radar.Kdp(self.scatterer)
            self.fields['Ai']['data'][t] = radar.Ai(self.scatterer)
            self.fields['Av']['data'][t] = radar.Ai(self.scatterer,
                                                    h_pol=False)
            self.fields['Adr']['data'][t] = radar.Ai(self.scatterer) - \
                radar.Ai(self.scatterer, h_pol=False)

        # Mask all values where no precipitation present or when ice present
        params_list = [
            'Zh', 'Zv', 'Zdr', 'Kdp', 'Ai', 'Av', 'Adr',
            'cross_correlation_ratio_hv', 'LDR',
            'specific_differential_phase_hv'
        ]
        l = np.empty(len(self.fields['Precip_Code']['data']), dtype=bool)
        j = 0
        for i in self.fields['Precip_Code']['data']:
            l[j] = 'N' in i or 'G' in i
            j += 1
        for param in params_list:
            self.fields[param]['data'] = \
                np.ma.masked_where(l, self.fields[param]['data'])
Example #16
0
el = 0.
m = refractive.m_w_10C[wl]
scatterer = tmatrix.Scatterer(wavelength=wl,
                              m=m,
                              axis_ratio=1.0,
                              radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM,
                              thet0=90.0 - el,
                              thet=90.0 + el)

Dmax = np.linspace(0.1, 2.7, 100)
Zhh = 0.0 * Dmax
Zvv = 0.0 * Dmax
Zdr = 0.0 * Dmax
for i, D in enumerate(Dmax):
    scatterer.radius = 0.5 * D
    Zdr[i] = 10.0 * np.log10(radar.Zdr(scatterer))
    Zhh[i] = 10.0 * np.log10(radar.refl(scatterer, h_pol=True))
    Zvv[i] = 10.0 * np.log10(radar.refl(scatterer, h_pol=False))

plt.figure()
ax0 = plt.gca()
ax0.plot(Dmax, Zhh, label='Zhh')
ax0.plot(Dmax, Zvv, label='Zvv')
ax0.vlines(wl * 0.5, ymin=-14, ymax=0)
ax0.legend()
ax0.grid()
ax0.set_ylabel('Z  [dbZ]')
ax0.set_xlabel('Dmax   [mm]')
ax1 = ax0.twinx()
ax1.plot(Dmax, Zdr, c='C3', label='Zdr')
ax1.legend()