Exemplo n.º 1
0
 def setUp(self):
     # calculate xy and lonlat grids with georef function
     self.radolan_grid_xy = georef.get_radolan_grid(900, 900, trig=True)
     self.radolan_grid_ll = georef.get_radolan_grid(900,
                                                    900,
                                                    trig=True,
                                                    wgs84=True)
Exemplo n.º 2
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.º 3
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.º 4
0
 def test_get_radolan_grid_shape(self):
     radolan_grid_xy = georef.get_radolan_grid()
     self.assertEqual((900, 900, 2), radolan_grid_xy.shape)
Exemplo n.º 5
0
 def test_get_radolan_grid_raises(self):
     self.assertRaises(TypeError, lambda: georef.get_radolan_grid('900', '900'))
     self.assertRaises(ValueError, lambda: georef.get_radolan_grid(2000, 2000))
Exemplo n.º 6
0
 def setUp(self):
     # calculate xy and lonlat grids with georef function
     self.radolan_grid_xy = georef.get_radolan_grid(900, 900, trig=True)
     self.radolan_grid_ll = georef.get_radolan_grid(900, 900, trig=True, wgs84=True)
Exemplo n.º 7
0
 def test_get_radolan_grid_shape(self):
     radolan_grid_xy = georef.get_radolan_grid()
     self.assertEqual((900, 900, 2), radolan_grid_xy.shape)
Exemplo n.º 8
0
 def test_get_radolan_grid_raises(self):
     self.assertRaises(TypeError,
                       lambda: georef.get_radolan_grid('900', '900'))
     self.assertRaises(ValueError,
                       lambda: georef.get_radolan_grid(2000, 2000))
Exemplo n.º 9
0
 def test_get_radolan_grid_shape(self):
     radolan_grid_xy = georef.get_radolan_grid()
     assert radolan_grid_xy.shape == (900, 900, 2)
Exemplo n.º 10
0
 def test_get_radolan_grid_raises(self):
     with pytest.raises(TypeError):
         georef.get_radolan_grid("900", "900")
     with pytest.raises(ValueError):
         georef.get_radolan_grid(2000, 2000)
Exemplo n.º 11
0
class TestGetGrids:
    # calculate xy and lonlat grids with georef function
    radolan_grid_xy = georef.get_radolan_grid(900, 900, trig=True)
    radolan_grid_ll = georef.get_radolan_grid(900, 900, trig=True, wgs84=True)

    def test_get_radolan_grid_equality(self):
        # create radolan projection osr object
        scale = (1.0 + np.sin(np.radians(60.0))) / (1.0 + np.sin(np.radians(90.0)))
        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
        np.testing.assert_allclose(radolan_grid_ll, self.radolan_grid_ll)
        np.testing.assert_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
        np.testing.assert_allclose(radolan_grid_ll, self.radolan_grid_ll)
        np.testing.assert_allclose(radolan_grid_xy, self.radolan_grid_xy)

    def test_get_radolan_grid_raises(self):
        with pytest.raises(TypeError):
            georef.get_radolan_grid("900", "900")
        with pytest.raises(ValueError):
            georef.get_radolan_grid(2000, 2000)

    def test_get_radolan_grid_shape(self):
        radolan_grid_xy = georef.get_radolan_grid()
        assert radolan_grid_xy.shape == (900, 900, 2)

    def test_radolan_coords(self):
        x, y = georef.get_radolan_coords(7.0, 53.0)
        assert pytest.approx(x) == -208.15159184860158
        assert pytest.approx(y) == -3971.7689758313813
        # Also test with trigonometric approach
        x, y = georef.get_radolan_coords(7.0, 53.0, trig=True)
        assert x == -208.15159184860175
        assert y == -3971.7689758313832

    def test_xyz_to_spherical(self):
        xyz = np.array([[1000, 1000, 1000]])
        r, phi, theta = georef.xyz_to_spherical(xyz)
        assert pytest.approx(r[0]) == 1732.11878135
        assert pytest.approx(phi[0]) == 45.0
        assert pytest.approx(theta[0]) == 35.25802956
Exemplo n.º 12
0
 def test_grid_reference_points(self, grid, origin, wgs):
     arr = list(georef.get_radolan_grid(grid[0], grid[1], wgs84=wgs)[0, 0])
     assert pytest.approx(arr, origin[0])
Exemplo n.º 13
0
class TestGetGrids:
    # calculate xy and lonlat grids with georef function
    radolan_grid_xy = georef.get_radolan_grid(900, 900, trig=True)
    radolan_grid_ll = georef.get_radolan_grid(900, 900, trig=True, wgs84=True)

    def test_get_radolan_grid_equality(self):
        # create radolan projection osr object
        scale = (1.0 + np.sin(np.radians(60.0))) / (1.0 + np.sin(np.radians(90.0)))
        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
        np.testing.assert_allclose(radolan_grid_ll, self.radolan_grid_ll)
        np.testing.assert_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
        np.testing.assert_allclose(radolan_grid_ll, self.radolan_grid_ll)
        np.testing.assert_allclose(radolan_grid_xy, self.radolan_grid_xy)

    def test_get_radolan_grid_raises(self):
        with pytest.raises(TypeError):
            georef.get_radolan_grid("900", "900")
        with pytest.raises(ValueError):
            georef.get_radolan_grid(2000, 2000)

    def test_get_radolan_grid_shape(self):
        radolan_grid_xy = georef.get_radolan_grid()
        assert radolan_grid_xy.shape == (900, 900, 2)

    def test_radolan_coords(self):
        x, y = georef.get_radolan_coords(7.0, 53.0)
        assert pytest.approx(x) == -208.15159184860158
        assert pytest.approx(y) == -3971.7689758313813
        # Also test with trigonometric approach
        x, y = georef.get_radolan_coords(7.0, 53.0, trig=True)
        assert x == -208.15159184860175
        assert y == -3971.7689758313832

    def test_xyz_to_spherical(self):
        xyz = np.array([[1000, 1000, 1000]])
        r, phi, theta = georef.xyz_to_spherical(xyz)
        assert pytest.approx(r[0]) == 1732.11878135
        assert pytest.approx(phi[0]) == 45.0
        assert pytest.approx(theta[0]) == 35.25802956

    @pytest.mark.parametrize(
        "grid, origin, wgs",
        [
            ((450, 450), [3.58892995, 46.95258041], True),
            ((450, 450), [-523.46216692, -4658.64472426], False),
            ((460, 460), [3.48137612, 46.86031976], True),
            ((460, 460), [-533.46216692, -4668.64472426], False),
            ((900, 900), [3.58892995, 46.95258041], True),
            ((900, 900), [-523.46216692, -4658.64472426], False),
            ((1100, 900), [4.67593418, 46.19287861], True),
            ((1100, 900), [-443.46216692, -4758.64472426], False),
            ((1200, 1100), [3.5519213, 45.69587048], True),
            ((1200, 1100), [-543.46216692, -4808.64472426], False),
            ((1500, 1400), [2.34194262, 43.9335861], True),
            ((1500, 1400), [-673.46216692, -5008.64472426], False),
        ],
    )
    def test_grid_reference_points(self, grid, origin, wgs):
        arr = list(georef.get_radolan_grid(grid[0], grid[1], wgs84=wgs)[0, 0])
        assert pytest.approx(arr, origin[0])
Exemplo n.º 14
0
 def test_get_radolan_grid_raises(self):
     with self.assertRaises(TypeError):
         georef.get_radolan_grid('900', '900')
     with self.assertRaises(ValueError):
         georef.get_radolan_grid(2000, 2000)