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)
    ]
Example #2
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)
    ]
Example #3
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 #4
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_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)
    ]
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)
Example #7
0
def scatter_off_2dvd_packed(d_diameters, d_densities):
    """
    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.
    dbz = 10 * np.log10(radar.refl(SCATTERER))  # in dBZ
    zdr = 10 * np.log10(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
    atten_spec_v = radar.Ai(SCATTERER, h_pol=False)  # in dB/km
    kdp = radar.Kdp(SCATTERER)  # in deg/km

    return dbz, zdr, kdp, atten_spec, atten_spec_v
    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 #9
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 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'])
Ai = 0.0 * D0s

wl = tmatrix_aux.wl_W
el = 0.

scatterer = tmatrix.Scatterer(
    wavelength=wl,
    m=refractive.m_w_10C[wl],
    #kw_sqr=tmatrix_aux.K_w_sqr[wl],
    radius_type=tmatrix.Scatterer.RADIUS_MAXIMUM,
    #or_pdf=orientation.gaussian_pdf(std=1.0),
    #orient=orientation.orient_averaged_fixed,
    thet0=90.0 - el,
    thet=90.0 + el)
Nw = 8000.0  # mm-2 m-3
mu = 5
scatterer.psd_integrator = psd.PSDIntegrator(
    D_max=8.0,
    geometries=(tmatrix_aux.geom_horiz_back, tmatrix_aux.geom_horiz_forw))
scatterer.psd_integrator.init_scatter_table(scatterer)
for i, D0 in enumerate(D0s):
    scatterer.psd = genGamma(Nw, D0, mu)  #psd.GammaPSD(D0=D0, mu=mu, Nw=Nw)
    scatterer.set_geometry(tmatrix_aux.geom_horiz_back)
    Zhh[i] = 10.0 * np.log10(radar.refl(scatterer))
    scatterer.set_geometry(tmatrix_aux.geom_horiz_forw)
    Ai[i] = radar.Ai(scatterer)

plt.plot(D0s, Zhh)
plt.plot(D0s, Zhh - 2.0 * Ai * 0.25)
plt.ylim([11, 26])
plt.grid()