Exemplo n.º 1
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
Exemplo n.º 2
0
def cal_tm4(n0,lamda,u,scatterer):
    rain_zdr=[]
    rain_zv=[]
    rain_ldr=[]
    rain_rhv=[]
    rain_zh=[]
    length=len(n0)
    for i in range(length):
        scatterer.psd=UnnormalizedGammaPSD(N0=n0[i],Lambda=lamda[i],mu=u)
        rain_zh.append(radar.refl(scatterer))
        rain_zdr.append(radar.Zdr(scatterer))
        rain_zv.append(radar.refl(scatterer,h_pol=False))
        rain_ldr.append(radar.ldr(scatterer))
        rain_rhv.append(radar.rho_hv(scatterer))
        if i%1000==0:
            print '\r|'+'='*(50*i/length)+' '*(50-50*i/length)+'|'+'%1.2f%%' %(100.0*i/length),
    print ' '

    rain_zh = np.array(rain_zh)
    rain_zdr  = np.array(rain_zdr)
    rain_zv   = np.array(rain_zv)
    rain_ldr  = np.array(rain_ldr)
    rain_rhv  = np.array(rain_rhv)

    return rain_zh,rain_zdr,rain_zv,rain_ldr,rain_rhv
Exemplo n.º 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)]
Exemplo n.º 4
0
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)]
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)
Exemplo n.º 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)
Exemplo n.º 7
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)
Exemplo n.º 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)
Exemplo n.º 9
0
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)] 
Exemplo n.º 10
0
    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'])