コード例 #1
0
ファイル: test_zr.py プロジェクト: zhatin/wradlib
    def test_z_to_r_enhanced(self):
        res_rr, res_si = zr.z_to_r_enhanced(trafo.idecibel(self.img))
        res_rr2, res_si2 = zr.z_to_r_enhanced(trafo.idecibel(self.img),
                                              algo='mdfilt', mode='mirror')
        res_rr3, res_si3 = zr.z_to_r_enhanced(trafo.idecibel(self.img),
                                              algo='mdcorr', xmode='mirror',
                                              ymode='mirror')

        rr = np.array([[3.64633237e-02, 1.77564547e-01, 1.77564547e-01,
                        3.17838962e-02, 3.17838962e-02, 1.62407903e-02,
                        2.37427600e+01, 2.37427600e+01, 2.37427600e+01,
                        1.62407903e-02, 3.17838962e-02],
                       [1.62407903e-02, 1.62407903e-02, 1.62407903e-02,
                        1.62407903e-02, 3.17838962e-02, 1.62407903e-02,
                        1.62407903e-02, 1.62407903e-02, 1.62407903e-02,
                        1.62407903e-02, 3.17838962e-02],
                       [1.62407903e-02, 8.64681611e+00, 8.64681611e+00,
                        1.62407903e-02, 3.17838962e-02, 3.17838962e-02,
                        4.41635812e-02, 4.41635812e-02, 4.41635812e-02,
                        3.17838962e-02, 3.17838962e-02],
                       [1.62407903e-02, 3.69615367e-02, 3.69615367e-02,
                        3.69615367e-02, 7.23352513e-02, 7.23352513e-02,
                        7.23352513e-02, 3.17838962e-02, 3.17838962e-02,
                        3.17838962e-02, 3.17838962e-02],
                       [3.64633237e-02, 3.64633237e-02, 3.64633237e-02,
                        3.17838962e-02, 3.17838962e-02, 1.62407903e-02,
                        1.62407903e-02, 1.62407903e-02, 1.62407903e-02,
                        1.62407903e-02, 3.17838962e-02]])
        si = np.array([[4.71428575, 4.58333337, 4.58333337, 2.75000002,
                        0., 11.25000003, -1., -1.,
                        -1., 11.25000003, 0.],
                       [13.99999989, 12.2499999, 12.2499999, 8.1666666,
                        0., 7.83333337, 11.75000005, 11.75000005,
                        11.75000005, 7.83333337, 0.],
                       [16.28571408, -1., -1., 9.91666655,
                        1.25000001, 1.41666669, 1.75000004, 1.50000004,
                        0.83333337, 0.50000002, 0.],
                       [11.57142844, 9.91666655, 10.33333322, 7.99999994,
                        2.50000003, 2.50000003, 2.25000003, 1.41666669,
                        0.50000002, 0.33333335, 0.],
                       [4.57142861, 4.00000004, 4.00000004, 3.08333336,
                        1.25000001, 8.75000003, 12.50000004, 12.08333337,
                        11.25000003, 7.50000002, 0.]])
        np.testing.assert_allclose(rr, res_rr)
        np.testing.assert_allclose(rr, res_rr2)
        np.testing.assert_allclose(rr, res_rr3)

        self.assertTrue(np.allclose(si, res_si))
コード例 #2
0
ファイル: atten.py プロジェクト: wradlib/wradlib-old
def calc_attenuation_backward(gateset, a, b, gate_length,
                              a_ref, tdiff, maxiter):
    """Gate-by-Gate backward correction as described in
    :cite:`Kraemer2008`"""
    k = np.zeros(gateset.shape)
    k[..., -1] = a_ref
    for gate in range(gateset.shape[-1] - 2, 0, -1):
        kright = np.zeros(gateset.shape[:-1]) + a_ref / gateset.shape[-1]
        toprocess = np.ones(gateset.shape[:-1], dtype=np.bool)
        for j in range(maxiter):
            kleft = a * (idecibel(gateset[..., gate][toprocess] +
                                  k[..., gate + 1][toprocess] -
                                  kright[toprocess])) ** b * 2.0 * gate_length
            diff = np.abs(kleft - kright)
            kright[toprocess] = kleft
            toprocess[diff < tdiff] = False
            if ~np.any(toprocess):
                break

        if j == maxiter - 1:
            raise AttenuationIterationError

        k[..., gate] = k[..., gate + 1] - kright
    # k = np.cumsum(k, axis=-1)
    return k
コード例 #3
0
def depolarization(zdr, rho):
    """Compute the depolarization ration.

    Compute the depolarization ration using differential
    reflectivity :math:`Z_{DR}` and crosscorrelation coefficient
    :math:`Rho_{HV}` of a radar sweep (:cite:`Kilambi2018`,
    :cite:`Melnikov2013`, :cite:`Ryzhkov2017`).

    Parameters
    ----------
    zdr : float or :class:`numpy:numpy.ndarray`
        differential reflectivity
    rho : float or :class:`numpy:numpy.ndarray`
        crosscorrelation coefficient

    Returns
    ------
    depolarization : :class:`numpy:numpy.ndarray`
        array of depolarization ratios with the same shape as input data,
        numpy broadcasting rules apply
    """
    zdr = trafo.idecibel(np.asanyarray(zdr))
    m = 2 * np.asanyarray(rho) * zdr**0.5

    return trafo.decibel((1 + zdr - m) / (1 + zdr + m))
コード例 #4
0
def calc_attenuation_forward(gateset, a=1.67e-4, b=0.7, l=1.):
    """Gate-by-Gate forward correction as described in Kraemer :cite:`Kraemer2008`"""
    pia = np.zeros(gateset.shape)
    for gate in range(gateset.shape[-1] - 1):
        k = a * idecibel(gateset[..., gate] + pia[..., gate])**b  * 2.0 * l
        pia[..., gate + 1] = pia[..., gate] + k
    return pia
コード例 #5
0
ファイル: atten.py プロジェクト: tooowzh/wradlib
def calc_attenuation_forward(gateset, a=1.67e-4, b=0.7, gate_length=1.):
    """Gate-by-Gate forward correction as described in :cite:`Kraemer2008`

    Parameters
    ----------
    gateset : :class:`numpy:numpy.ndarray`
        Multidimensional array, where the range gates (over which iteration has
        to be performed) are supposed to vary along the last array-dimension.

        Data has to be provided in decibel representation of reflectivity
        [dBZ].
    a : float
        proportionality factor of the k-Z relation (:math:`k=a \\cdot Z^{b}`).
        Per default set to 1.67e-4.
    b : float
        exponent of the k-Z relation ( :math:`k=a \\cdot Z^{b}` ). Per default
        set to 0.7.
    gate_length : float
        length of a range gate [km]. Per default set to 1.0.

    Returns
    -------
    pia : :class:`numpy:numpy.ndarray`
        Array with the same shape as ``gateset`` containing the calculated path
        integrated attenuation [dB] for each range gate.
    """
    pia = np.zeros(gateset.shape)
    for gate in range(gateset.shape[-1] - 1):
        k = a * trafo.idecibel(gateset[..., gate] + pia[..., gate]) ** b \
            * 2.0 * gate_length
        pia[..., gate + 1] = pia[..., gate] + k
    return pia
コード例 #6
0
    def test_z_to_r_enhanced(self):
        res_rr, res_si = zr.z_to_r_enhanced(trafo.idecibel(self.img),
                                            polar=True)
        res_rr2, res_si2 = zr.z_to_r_enhanced(trafo.idecibel(self.img[0]),
                                              polar=True)

        rr = np.array([[3.64633237e-02, 1.77564547e-01, 1.77564547e-01,
                        3.17838962e-02, 3.17838962e-02, 1.62407903e-02,
                        2.37427600e+01, 2.37427600e+01, 2.37427600e+01,
                        1.62407903e-02, 3.17838962e-02],
                       [1.62407903e-02, 1.62407903e-02, 1.62407903e-02,
                        1.62407903e-02, 3.17838962e-02, 1.62407903e-02,
                        1.62407903e-02, 1.62407903e-02, 1.62407903e-02,
                        1.62407903e-02, 3.17838962e-02],
                       [1.62407903e-02, 8.64681611e+00, 8.64681611e+00,
                        1.62407903e-02, 3.17838962e-02, 3.17838962e-02,
                        4.41635812e-02, 4.41635812e-02, 4.41635812e-02,
                        3.17838962e-02, 3.17838962e-02],
                       [1.62407903e-02, 3.69615367e-02, 3.69615367e-02,
                        3.69615367e-02, 7.23352513e-02, 7.23352513e-02,
                        7.23352513e-02, 3.17838962e-02, 3.17838962e-02,
                        3.17838962e-02, 3.17838962e-02],
                       [3.64633237e-02, 3.64633237e-02, 3.64633237e-02,
                        3.17838962e-02, 3.17838962e-02, 1.62407903e-02,
                        1.62407903e-02, 1.62407903e-02, 1.62407903e-02,
                        1.62407903e-02, 3.17838962e-02]])
        si = np.array([[4.71428575, 4.58333337, 4.58333337, 2.75000002,
                        0., 11.25000003, -1., -1.,
                        -1., 11.25000003, 0.],
                       [13.99999989, 12.2499999, 12.2499999, 8.1666666,
                        0., 7.83333337, 11.75000005, 11.75000005,
                        11.75000005, 7.83333337, 0.],
                       [16.28571408, -1., -1., 9.91666655,
                        1.25000001, 1.41666669, 1.75000004, 1.50000004,
                        0.83333337, 0.50000002, 0.],
                       [11.57142844, 9.91666655, 10.33333322, 7.99999994,
                        2.50000003, 2.50000003, 2.25000003, 1.41666669,
                        0.50000002, 0.33333335, 0.],
                       [4.57142861, 4.00000004, 4.00000004, 3.08333336,
                        1.25000001, 8.75000003, 12.50000004, 12.08333337,
                        11.25000003, 7.50000002, 0.]])

        np.testing.assert_almost_equal(si, res_si[0], decimal=6)
        np.testing.assert_array_almost_equal(rr, res_rr[0], decimal=6)
        np.testing.assert_almost_equal(si, res_si2, decimal=6)
        np.testing.assert_array_almost_equal(rr, res_rr2, decimal=6)
コード例 #7
0
ファイル: atten.py プロジェクト: Maxima86/wradlib
def calc_attenuation_backward(gateset, a, b, l, a_ref, tdiff, maxiter):
    """Gate-by-Gate backward correction as described in Kraemer :cite:`Kraemer2008`"""
    k = np.zeros(gateset.shape)
    k[...,-1] = a_ref
    for gate in range(gateset.shape[-1]-2, 0, -1):
        kright = np.zeros(gateset.shape[:-1])+a_ref/gateset.shape[-1]
        toprocess = np.ones(gateset.shape[:-1], dtype=np.bool)
        for j in range(maxiter):
            kleft = a * (idecibel(gateset[...,gate][toprocess]
                                  + k[...,gate+1][toprocess]
                                  - kright[toprocess]))**b * 2.0 * l
            diff = np.abs(kleft-kright)
            kright[toprocess] = kleft
            toprocess[diff<tdiff] = False
            if ~np.any(toprocess):
                break

        if j == maxiter-1:
            raise AttenuationIterationError

        k[...,gate] = k[...,gate+1] - kright
    #k = np.cumsum(k, axis=-1)
    return k
コード例 #8
0
ファイル: test_zr.py プロジェクト: Maxima86/wradlib
 def test_z2r(self):
     self.assertEqual(zr.z2r(trafo.idecibel(10.)), 0.1537645610180688)
コード例 #9
0
 def test_z_to_r(self):
     self.assertEqual(zr.z_to_r(trafo.idecibel(10.)), 0.1537645610180688)
コード例 #10
0
ファイル: test_trafo.py プロジェクト: egouden/wradlib
 def test_idecibel(self):
     assert np.allclose(trafo.idecibel(self.dec), self.lin)
コード例 #11
0
 def test_z_to_r(self):
     assert zr.z_to_r(trafo.idecibel(10.0)) == 0.1537645610180688
コード例 #12
0
 def test_idecibel(self):
     self.assertTrue(np.allclose(trafo.idecibel(self.dec), self.lin))
コード例 #13
0
                blon, blat, dpr_typ_b = cut_the_swath(gprof_lon,gprof_lat,dpr_typ,eu=0)
                blon, blat, dpr_top_b = cut_the_swath(gprof_lon,gprof_lat,dpr_top,eu=0)

                proj_stereo = wrl.georef.create_osr("dwd-radolan")
                proj_wgs = osr.SpatialReference()
                proj_wgs.ImportFromEPSG(4326)

                gpm_x, gpm_y = wradlib.georef.reproject(blon, blat, projection_target=proj_stereo , projection_source=proj_wgs)
                grid_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()


                ####################################### Neu
                #rwdata2[rwdata2 <= 15] = -9999


                rwdata2 = idecibel(rwdata2)



                ############################################## INTERLOLATION RY

                gk3 = wradlib.georef.epsg_to_osr(31467)

                grid_gpm_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()

                xy = np.vstack((x.ravel(), y.ravel())).transpose()

                #mask = ~np.isnan(rwdata)

                result = wrl.ipol.interpolate(xy, grid_gpm_xy, rwdata.reshape(900*900,1), wrl.ipol.Idw, nnearest=8)
コード例 #14
0
ファイル: atten.py プロジェクト: zhaopingsun/wradlib
def correctRadomeAttenuationEmpirical(gateset,
                                      frequency=5.64,
                                      hydrophobicity=0.165,
                                      n_r=2,
                                      stat=np.mean):
    """Estimate two-way wet radome losses as an empirical
    function of frequency and rainfall rate for both standard and
    hydrophobic radomes based on the approach of :cite:`Merceret2000`.



    Parameters
    ----------
    gateset : array
        Multidimensional array, where the range gates (over which
        iteration has to be performed) are supposed to vary along the
        last array-dimension and the azimuths are supposed to vary
        along the next to last array-dimension. Data has to be provided
        in decibel representation of reflectivity [dBZ].
    frequency : float
        Radar-frequency [GHz]:

            Standard frequencies in X-band range between 8.0 and 12.0 GHz,

            Standard frequencies in C-band range between 4.0 and 8.0 GHz,

            Standard frequencies in S-band range between 2.0 and 4.0 GHz.

            Be aware that the empirical fit of the formula was just
            done for C- and S-band. The use for X-band is probably an
            undue extrapolation.

            Per default set to 5.64 as used by the German Weather
            Service radars.
    hydrophobicity : float
        Empirical parameter based on the hydrophobicity of the radome
        material.

            - 0.165 for standard radomes,
            - 0.0575 for hydrophobic radomes.

            Per default set to 0.165.
    n_r : integer
        The radius of rangebins within the rain-intensity is
        statistically evaluated as the representative rain-intensity
        over radome.
    stat : class
        A name of a numpy function for statistical aggregation of the
        central rangebins defined by n_r.

        Potential options: np.mean, np.median, np.max, np.min.

    Returns
    -------
    k : array
        Array with the same shape as ``gateset`` containing the
        calculated two-way transmission loss [dB] for each range gate.
        In case the input array (gateset) contains NaNs the
        corresponding beams of the output array (k) will be set as NaN,
        too.
    """

    # Select rangebins inside the defined center-range n_r.
    center = gateset[..., :n_r].reshape(-1, n_r * gateset.shape[-2])
    center_m = np.ma.masked_array(center, np.isnan(center))
    # Calculate rainrate in the center-range based on statistical method stat
    # and with standard ZR-relation.
    rain_over_radome = z2r(idecibel(stat(center_m, axis=-1)))
    # Estimate the empirical two-way transmission loss due to
    # radome-attenuation.
    k = 2 * hydrophobicity * rain_over_radome * np.tanh(frequency / 10.)**2
    # Reshape the result to gateset-shape.
    k = np.repeat(k,
                  gateset.shape[-1] * gateset.shape[-2]).reshape(gateset.shape)

    return k
コード例 #15
0
        blon, blat, gprof_pp_b = cut_the_swath(gprof_lon,
                                               gprof_lat,
                                               gprof_pp,
                                               eu=0)

        proj_stereo = wrl.georef.create_osr("dwd-radolan")
        proj_wgs = osr.SpatialReference()
        proj_wgs.ImportFromEPSG(4326)

        gpm_x, gpm_y = wradlib.georef.reproject(blon,
                                                blat,
                                                projection_target=proj_stereo,
                                                projection_source=proj_wgs)
        grid_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()

        rwdata = idecibel(rwdata)

        ## INTERLOLATION
        ## --------------

        gk3 = wradlib.georef.epsg_to_osr(31467)

        grid_gpm_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()

        xy = np.vstack((x.ravel(), y.ravel())).transpose()

        mask = ~np.isnan(rwdata)

        result = wrl.ipol.interpolate(xy,
                                      grid_gpm_xy,
                                      rwdata.reshape(900 * 900, 1),
コード例 #16
0
ファイル: test_trafo.py プロジェクト: Maxima86/wradlib
 def test_idecibel(self):
     self.assertTrue(np.allclose(trafo.idecibel(self.dec), self.lin))
コード例 #17
0
ファイル: pcc_alldproverpass.py プロジェクト: vecoveco/gpm
        ## Cut the GPM Swath
        ## ------------------


        blon, blat, gprof_pp_b = cut_the_swath(gprof_lon,gprof_lat,gprof_pp,eu=0)

        proj_stereo = wrl.georef.create_osr("dwd-radolan")
        proj_wgs = osr.SpatialReference()
        proj_wgs.ImportFromEPSG(4326)

        gpm_x, gpm_y = wradlib.georef.reproject(blon, blat, projection_target=proj_stereo , projection_source=proj_wgs)
        grid_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()


        rwdata = idecibel(rwdata)


        ## INTERLOLATION
        ## --------------

        gk3 = wradlib.georef.epsg_to_osr(31467)

        grid_gpm_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()

        xy = np.vstack((x.ravel(), y.ravel())).transpose()

        mask = ~np.isnan(rwdata)

        result = wrl.ipol.interpolate(xy, grid_gpm_xy, rwdata.reshape(900*900,1), wrl.ipol.Idw, nnearest=4)
コード例 #18
0
                proj_stereo = wrl.georef.create_osr("dwd-radolan")
                proj_wgs = osr.SpatialReference()
                proj_wgs.ImportFromEPSG(4326)

                gpm_x, gpm_y = wradlib.georef.reproject(
                    blon,
                    blat,
                    projection_target=proj_stereo,
                    projection_source=proj_wgs)
                grid_xy = np.vstack((gpm_x.ravel(), gpm_y.ravel())).transpose()

                ####################################### Neu
                #rwdata2[rwdata2 <= 15] = -9999

                rwdata2 = idecibel(rwdata2)

                ############################################## INTERLOLATION RY

                gk3 = wradlib.georef.epsg_to_osr(31467)

                grid_gpm_xy = np.vstack(
                    (gpm_x.ravel(), gpm_y.ravel())).transpose()

                xy = np.vstack((x.ravel(), y.ravel())).transpose()

                #mask = ~np.isnan(rwdata)

                result = wrl.ipol.interpolate(xy,
                                              grid_gpm_xy,
                                              rwdata.reshape(900 * 900, 1),
コード例 #19
0
ファイル: atten.py プロジェクト: Maxima86/wradlib
def correctRadomeAttenuationEmpirical(gateset, frequency=5.64,
                                      hydrophobicity=0.165, n_r=2,
                                      stat=np.mean):
    """Estimate two-way wet radome losses as an empirical
    function of frequency and rainfall rate for both standard and
    hydrophobic radomes based on the approach of Francis J. Merceret
    and Jennifer G. Ward :cite:`Merceret2000`.



    Parameters
    ----------
    gateset : array
        Multidimensional array, where the range gates (over which
        iteration has to be performed) are supposed to vary along the
        last array-dimension and the azimuths are supposed to vary
        along the next to last array-dimension. Data has to be provided
        in decibel representation of reflectivity [dBZ].
    frequency : float
        Radar-frequency [GHz]:

            Standard frequencies in X-band range between 8.0 and 12.0 GHz,

            Standard frequencies in C-band range between 4.0 and 8.0 GHz,

            Standard frequencies in S-band range between 2.0 and 4.0 GHz.

            Be aware that the empirical fit of the formula was just
            done for C- and S-band. The use for X-band is probably an
            undue extrapolation.

            Per default set to 5.64 as used by the German Weather
            Service radars.
    hydrophobicity : float
        Empirical parameter based on the hydrophobicity of the radome
        material.

            - 0.165 for standard radomes,
            - 0.0575 for hydrophobic radomes.

            Per default set to 0.165.
    n_r : integer
        The radius of rangebins within the rain-intensity is
        statistically evaluated as the representative rain-intensity
        over radome.
    stat : class
        A name of a numpy function for statistical aggregation of the
        central rangebins defined by n_r.

        Potential options: np.mean, np.median, np.max, np.min.

    Returns
    -------
    k : array
        Array with the same shape as ``gateset`` containing the
        calculated two-way transmission loss [dB] for each range gate.
        In case the input array (gateset) contains NaNs the
        corresponding beams of the output array (k) will be set as NaN,
        too.
    """

    # Select rangebins inside the defined center-range n_r.
    center = gateset[...,:n_r].reshape(-1, n_r * gateset.shape[-2])
    center_m = np.ma.masked_array(center, np.isnan(center))
    # Calculate rainrate in the center-range based on statistical method stat
    # and with standard ZR-relation.
    rain_over_radome = z2r(idecibel(stat(center_m, axis = -1)))
    # Estimate the empirical two-way transmission loss due to
    # radome-attenuation.
    k = 2 * hydrophobicity * rain_over_radome * np.tanh(frequency / 10.)**2
    # Reshape the result to gateset-shape.
    k = np.repeat(k, gateset.shape[-1] *
        gateset.shape[-2]).reshape(gateset.shape)

    return k
コード例 #20
0
ファイル: dwd_dpr_boxpol.py プロジェクト: vecoveco/gpm
r = attrs['SCAN0']['r']
az = attrs['SCAN0']['az']
lon_ppi = attrs['VOL']['Longitude']
lat_ppi = attrs['VOL']['Latitude']
alt_ppi = attrs['VOL']['Height']


data,attributes=wrl.io.read_GAMIC_hdf5('/automount/radar-archiv/scans/2014/2014-10/2014-10-07/ppi_1p5deg/2014-10-07--02:37:44,00.mvol')
Ah,ZH,ZH_corr,phidp,phidp_est,deltaphidp,r1,r2 = ZPHI_Method(data,attributes)

R = ZH_corr


from wradlib.trafo import idecibel, decibel
R = idecibel(R)

#R = R + pia
R[151:165]=np.nan

#R[np.where(rho<0.95)]=np.nan
R[rho<=0.8]=np.nan

# DPR Einlesen
# ------------

gpmku = h5py.File(pfad_radar_Ku, 'r')
gpmku_HS=gpmku['NS']['SLV']
ku_lat=np.array(gpmku['NS']['Latitude'])			#(7934, 24)
ku_lon=np.array(gpmku['NS']['Longitude'])			#(7934, 24)
ku_pp=np.array(gpmku_HS['zFactorCorrectedNearSurface'])
コード例 #21
0
# Dpr zuschneiden
#-----------------

lon0, lat0, radius = blon, blat, 100
rr = np.sqrt((dpr_lat - lat0)**2 + (dpr_lon - lon0)**2)
position = rr < radius

pp = dpr_pp.copy()

pp[np.where(rr > radius)] = np.nan

from wradlib.trafo import idecibel
from wradlib.trafo import decibel

R = idecibel(R)

radar_location = (lon_ppi, lat_ppi, alt_ppi)
elevation = 1.5
azimuths = az
ranges = r
polargrid = np.meshgrid(ranges, azimuths)
lon, lat, alt = wradlib.georef.polar2lonlatalt_n(polargrid[0], polargrid[1],
                                                 elevation, radar_location)
lon, lat = wradlib.georef.reproject(lon,
                                    lat,
                                    projection_target=proj_stereo,
                                    projection_source=proj_wgs)

grid_xy = np.vstack((dpr_lon.ravel(), dpr_lat.ravel())).transpose()