Exemple #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_Exponential_fwScattering(N0=None,
                                                 Lambda=None,
                                                 D_max=None):
    scatterer.psd = psd.ExponentialPSD(N0=N0, Lambda=Lambda, D_max=D_max)
    return [
        radar.Ai(scatterer, h_pol=True),
        radar.Ai(scatterer, h_pol=False),
        radar.Kdp(scatterer)
    ]
Exemple #3
0
def get_radar_variables_unnormalizedGamma_fwScattering(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.Ai(scatterer, h_pol=True),
        radar.Ai(scatterer, h_pol=False),
        radar.Kdp(scatterer)
    ]
Exemple #4
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
def get_radar_variables_ThomPSD_fwScattering(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.Ai(scatterer, h_pol=True),
        radar.Ai(scatterer, h_pol=False),
        radar.Kdp(scatterer)
    ]
Exemple #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
Exemple #8
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
    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)
Exemple #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)
Exemple #11
0
    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]')
ax2.set_ylabel('Kdp  [deg]')
ax1.set_title('m-D Brown and Francis 95 --- constant ar = 0.6')
    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 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'])