Exemplo n.º 1
0
 def test_proj4_to_osr(self):
     srs = georef.proj4_to_osr('+proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=0 '
                               '+k_0=0.99987742 +x_0=600000 +y_0=2200000 '
                               '+a=6378249.2 +b=6356515 '
                               '+towgs84=-168,-60,320,0,0,0,0 '
                               '+pm=paris +units=m +no_defs')
     p4 = srs.ExportToProj4()
     srs2 = osr.SpatialReference()
     srs2.ImportFromProj4(p4)
     self.assertTrue(srs.IsSame(srs2))
     self.assertRaises(ValueError,
                       lambda: georef.proj4_to_osr("+proj=lcc1"))
Exemplo n.º 2
0
 def test_proj4_to_osr(self):
     srs = georef.proj4_to_osr('+proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=0 '
                               '+k_0=0.99987742 +x_0=600000 +y_0=2200000 '
                               '+a=6378249.2 +b=6356515 '
                               '+towgs84=-168,-60,320,0,0,0,0 '
                               '+pm=paris +units=m +no_defs')
     p4 = srs.ExportToProj4()
     srs2 = osr.SpatialReference()
     srs2.ImportFromProj4(p4)
     self.assertTrue(srs.IsSame(srs2))
     self.assertRaises(ValueError,
                       lambda: georef.proj4_to_osr("+proj=lcc1"))
Exemplo n.º 3
0
    def test_proj4_to_osr(self):
        projstr = ('+proj=tmerc +lat_0=0 +lon_0=9 +k=1 '
                   '+x_0=3500000 +y_0=0 +ellps=bessel '
                   '+towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 '
                   '+units=m +no_defs')

        srs = georef.proj4_to_osr(projstr)
        p4 = srs.ExportToProj4()
        srs2 = osr.SpatialReference()
        srs2.ImportFromProj4(p4)
        self.assertTrue(srs.IsSame(srs2))
        with self.assertRaises(ValueError):
            georef.proj4_to_osr("+proj=lcc1")
Exemplo n.º 4
0
    def test_get_radolan_grid_equality(self):
        # create radolan projection osr object
        scale = (1. + np.sin(np.radians(60.))) / (1. + np.sin(np.radians(90.)))
        dwd_string = ('+proj=stere +lat_0=90 +lat_ts=90 +lon_0=10 '
                      '+k={0:10.8f} +x_0=0 +y_0=0 +a=6370040 +b=6370040 '
                      '+to_meter=1000 +no_defs'.format(scale))
        proj_stereo = georef.proj4_to_osr(dwd_string)

        # create wgs84 projection osr object
        proj_wgs = osr.SpatialReference()
        proj_wgs.ImportFromEPSG(4326)

        # transform radolan polar stereographic projection to wgs84 and wgs84
        # to polar stereographic
        # using osr transformation routines
        radolan_grid_ll = georef.reproject(self.radolan_grid_xy,
                                           projection_source=proj_stereo,
                                           projection_target=proj_wgs)
        radolan_grid_xy = georef.reproject(self.radolan_grid_ll,
                                           projection_source=proj_wgs,
                                           projection_target=proj_stereo)

        # check source and target arrays for equality
        self.assertTrue(np.allclose(radolan_grid_ll, self.radolan_grid_ll))
        self.assertTrue(np.allclose(radolan_grid_xy, self.radolan_grid_xy))
Exemplo n.º 5
0
    def test_get_radolan_grid_equality(self):
        # create radolan projection osr object
        scale = (1. + np.sin(np.radians(60.))) / (1. + np.sin(np.radians(90.)))
        dwd_string = ('+proj=stere +lat_0=90 +lat_ts=90 +lon_0=10 '
                      '+k={0:10.8f} +x_0=0 +y_0=0 +a=6370040 +b=6370040 '
                      '+to_meter=1000 +no_defs'.format(scale))
        proj_stereo = georef.proj4_to_osr(dwd_string)

        # create wgs84 projection osr object
        proj_wgs = osr.SpatialReference()
        proj_wgs.ImportFromEPSG(4326)

        # transform radolan polar stereographic projection to wgs84 and wgs84
        # to polar stereographic
        # using osr transformation routines
        radolan_grid_ll = georef.reproject(self.radolan_grid_xy,
                                           projection_source=proj_stereo,
                                           projection_target=proj_wgs)
        radolan_grid_xy = georef.reproject(self.radolan_grid_ll,
                                           projection_source=proj_wgs,
                                           projection_target=proj_stereo)

        # check source and target arrays for equality
        self.assertTrue(np.allclose(radolan_grid_ll, self.radolan_grid_ll))
        self.assertTrue(np.allclose(radolan_grid_xy, self.radolan_grid_xy))

        radolan_grid_xy = georef.get_radolan_grid(900, 900)
        radolan_grid_ll = georef.get_radolan_grid(900, 900, wgs84=True)

        # check source and target arrays for equality
        self.assertTrue(np.allclose(radolan_grid_ll, self.radolan_grid_ll))
        self.assertTrue(np.allclose(radolan_grid_xy, self.radolan_grid_xy))
Exemplo n.º 6
0
    def setUp(self):
        f = 'gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5'  # noqa
        gpm_file = util.get_wradlib_data_file(f)
        pr_data = read_generic_hdf5(gpm_file)
        pr_lon = pr_data['NS/Longitude']['data']
        pr_lat = pr_data['NS/Latitude']['data']
        zenith = pr_data['NS/PRE/localZenithAngle']['data']
        wgs84 = georef.get_default_projection()
        a = wgs84.GetSemiMajor()
        b = wgs84.GetSemiMinor()
        rad = georef.proj4_to_osr(
            ('+proj=aeqd +lon_0={lon:f} ' +
             '+lat_0={lat:f} +a={a:f} +b={b:f}' + '').format(lon=pr_lon[68, 0],
                                                             lat=pr_lat[68, 0],
                                                             a=a,
                                                             b=b))
        pr_x, pr_y = georef.reproject(pr_lon,
                                      pr_lat,
                                      projection_source=wgs84,
                                      projection_target=rad)
        self.re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4. / 3.
        self.pr_xy = np.dstack((pr_x, pr_y))
        self.alpha = zenith
        self.zt = 407000.
        self.dr = 125.
        self.bw_pr = 0.71
        self.nbin = 176
        self.nray = pr_lon.shape[1]

        self.pr_out = np.array([[[[-58533.78453556, 124660.60390174],
                                  [-58501.33048429, 124677.58873852]],
                                 [[-53702.13393133, 127251.83656509],
                                  [-53670.98686161, 127268.11882882]]],
                                [[[-56444.00788528, 120205.5374491],
                                  [-56411.55421163, 120222.52300741]],
                                 [[-51612.2360682, 122796.78620764],
                                  [-51581.08938314, 122813.06920719]]]])
        self.r_out = np.array(
            [0., 125., 250., 375., 500., 625., 750., 875., 1000., 1125.])
        self.z_out = np.array([
            0., 119.51255112, 239.02510224, 358.53765337, 478.05020449,
            597.56275561, 717.07530673, 836.58785786, 956.10040898,
            1075.6129601
        ])
Exemplo n.º 7
0
    def setUp(self):
        f = 'gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5'  # noqa
        gpm_file = util.get_wradlib_data_file(f)
        pr_data = read_generic_hdf5(gpm_file)
        pr_lon = pr_data['NS/Longitude']['data']
        pr_lat = pr_data['NS/Latitude']['data']
        zenith = pr_data['NS/PRE/localZenithAngle']['data']
        wgs84 = georef.get_default_projection()
        a = wgs84.GetSemiMajor()
        b = wgs84.GetSemiMinor()
        rad = georef.proj4_to_osr(('+proj=aeqd +lon_0={lon:f} ' +
                                   '+lat_0={lat:f} +a={a:f} +b={b:f}' +
                                   '').format(lon=pr_lon[68, 0],
                                              lat=pr_lat[68, 0],
                                              a=a, b=b))
        pr_x, pr_y = georef.reproject(pr_lon, pr_lat,
                                      projection_source=wgs84,
                                      projection_target=rad)
        self.re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4. / 3.
        self.pr_xy = np.dstack((pr_x, pr_y))
        self.alpha = zenith
        self.zt = 407000.
        self.dr = 125.
        self.bw_pr = 0.71
        self.nbin = 176
        self.nray = pr_lon.shape[1]

        self.pr_out = np.array([[[[-58533.78453556, 124660.60390174],
                                  [-58501.33048429, 124677.58873852]],
                                 [[-53702.13393133, 127251.83656509],
                                  [-53670.98686161, 127268.11882882]]],
                                [[[-56444.00788528, 120205.5374491],
                                  [-56411.55421163, 120222.52300741]],
                                 [[-51612.2360682, 122796.78620764],
                                  [-51581.08938314, 122813.06920719]]]])
        self.r_out = np.array([0., 125., 250., 375., 500., 625., 750., 875.,
                               1000., 1125.])
        self.z_out = np.array([0., 119.51255112, 239.02510224, 358.53765337,
                               478.05020449, 597.56275561, 717.07530673,
                               836.58785786, 956.10040898, 1075.6129601])
Exemplo n.º 8
0
class TestSatellite:
    f = "gpm/2A-CS-151E24S154E30S.GPM.Ku.V7-20170308.20141206-S095002-E095137.004383.V05A.HDF5"  # noqa
    gpm_file = util.get_wradlib_data_file(f)
    pr_data = wradlib.io.read_generic_hdf5(gpm_file)
    pr_lon = pr_data["NS/Longitude"]["data"]
    pr_lat = pr_data["NS/Latitude"]["data"]
    zenith = pr_data["NS/PRE/localZenithAngle"]["data"]
    wgs84 = georef.get_default_projection()
    a = wgs84.GetSemiMajor()
    b = wgs84.GetSemiMinor()
    rad = georef.proj4_to_osr(
        ("+proj=aeqd +lon_0={lon:f} " + "+lat_0={lat:f} +a={a:f} +b={b:f}" + "").format(
            lon=pr_lon[68, 0], lat=pr_lat[68, 0], a=a, b=b
        )
    )
    pr_x, pr_y = georef.reproject(
        pr_lon, pr_lat, projection_source=wgs84, projection_target=rad
    )
    re = georef.get_earth_radius(pr_lat[68, 0], wgs84) * 4.0 / 3.0
    pr_xy = np.dstack((pr_x, pr_y))
    alpha = zenith
    zt = 407000.0
    dr = 125.0
    bw_pr = 0.71
    nbin = 176
    nray = pr_lon.shape[1]

    pr_out = np.array(
        [
            [
                [
                    [-58533.78453556, 124660.60390174],
                    [-58501.33048429, 124677.58873852],
                ],
                [
                    [-53702.13393133, 127251.83656509],
                    [-53670.98686161, 127268.11882882],
                ],
            ],
            [
                [
                    [-56444.00788528, 120205.5374491],
                    [-56411.55421163, 120222.52300741],
                ],
                [
                    [-51612.2360682, 122796.78620764],
                    [-51581.08938314, 122813.06920719],
                ],
            ],
        ]
    )
    r_out = np.array(
        [0.0, 125.0, 250.0, 375.0, 500.0, 625.0, 750.0, 875.0, 1000.0, 1125.0]
    )
    z_out = np.array(
        [
            0.0,
            119.51255112,
            239.02510224,
            358.53765337,
            478.05020449,
            597.56275561,
            717.07530673,
            836.58785786,
            956.10040898,
            1075.6129601,
        ]
    )

    def test_correct_parallax(self):
        xy, r, z = georef.correct_parallax(self.pr_xy, self.nbin, self.dr, self.alpha)
        pr_out = np.array(
            [
                [
                    [
                        [-16582.50734831, 35678.47219358],
                        [-16547.94607589, 35696.40777009],
                    ],
                    [
                        [-11742.02016667, 38252.32622057],
                        [-11708.84553319, 38269.52268457],
                    ],
                ],
                [
                    [
                        [-14508.62005182, 31215.98689653],
                        [-14474.05905935, 31233.92329553],
                    ],
                    [
                        [-9667.99183645, 33789.86576047],
                        [-9634.81750708, 33807.06305397],
                    ],
                ],
            ]
        )
        r_out = np.array(
            [0.0, 125.0, 250.0, 375.0, 500.0, 625.0, 750.0, 875.0, 1000.0, 1125.0]
        )
        z_out = np.array(
            [
                0.0,
                118.78164113,
                237.56328225,
                356.34492338,
                475.1265645,
                593.90820563,
                712.68984675,
                831.47148788,
                950.25312901,
                1069.03477013,
            ]
        )

        np.testing.assert_allclose(xy[60:62, 0:2, 0:2, :], pr_out, rtol=1e-12)
        np.testing.assert_allclose(r[0:10], r_out, rtol=1e-12)
        np.testing.assert_allclose(z[0, 0, 0:10], z_out, rtol=1e-10)

    def test_dist_from_orbit(self):
        beta = abs(-17.04 + np.arange(self.nray) * self.bw_pr)
        xy, r, z = georef.correct_parallax(self.pr_xy, self.nbin, self.dr, self.alpha)
        dists = georef.dist_from_orbit(self.zt, self.alpha, beta, r, re=self.re)
        bd = np.array(
            [
                426553.58667772,
                426553.50342119,
                426553.49658156,
                426553.51025979,
                426553.43461609,
                426553.42515894,
                426553.46559985,
                426553.37020786,
                426553.44407286,
                426553.42173696,
            ]
        )
        sd = np.array(
            [
                426553.58667772,
                424895.63462839,
                423322.25176564,
                421825.47714885,
                420405.9414294,
                419062.44208923,
                417796.86827302,
                416606.91482435,
                415490.82582636,
                414444.11587979,
            ]
        )
        np.testing.assert_allclose(dists[0:10, 0, 0], bd, rtol=1e-12)
        np.testing.assert_allclose(dists[0, 0:10, 0], sd, rtol=1e-12)