コード例 #1
0
ファイル: test_georef.py プロジェクト: zhatin/wradlib
 def test_spherical_to_polyvert(self):
     sph = georef.get_default_projection()
     polyvert = georef.spherical_to_polyvert(np.array([10000., 10100.]),
                                             np.array([45., 90.]),
                                             0, (9., 48.),
                                             proj=sph)
     arr = np.asarray([[[9.05084865, 48.08224715, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.12264494, 48.03400725, 6.],
                        [9.05084865, 48.08224715, 6.]],
                       [[9.05136309, 48.0830778, 6.],
                        [9.05187756, 48.08390846, 6.],
                        [9.12512428, 48.03469291, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.05136309, 48.0830778, 6.]],
                       [[9.12264494, 48.03400725, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.05084865, 48.08224715, 6.],
                        [9.12264494, 48.03400725, 6.]],
                       [[9.1238846, 48.03435008, 6.],
                        [9.12512428, 48.03469291, 6.],
                        [9.05187756, 48.08390846, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.1238846, 48.03435008, 6.]]])
     np.testing.assert_array_almost_equal(polyvert, arr, decimal=3)
     polyvert, pr = georef.spherical_to_polyvert(np.array([10000., 10100.]),
                                                 np.array([45., 90.]), 0,
                                                 (9., 48.))
     arr = np.asarray([[[3.7885640e+03, 9.1464023e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.],
                        [9.1464023e+03, 3.7885645e+03, 6.],
                        [3.7885640e+03, 9.1464023e+03, 6.]],
                       [[3.8268320e+03, 9.2387900e+03, 6.],
                        [3.8651003e+03, 9.3311777e+03, 6.],
                        [9.3311777e+03, 3.8651006e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.]],
                       [[9.1464023e+03, 3.7885645e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.],
                        [3.7885640e+03, 9.1464023e+03, 6.],
                        [9.1464023e+03, 3.7885645e+03, 6.]],
                       [[9.2387900e+03, 3.8268323e+03, 6.],
                        [9.3311777e+03, 3.8651006e+03, 6.],
                        [3.8651003e+03, 9.3311777e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.]]])
     np.testing.assert_array_almost_equal(polyvert, arr, decimal=3)
コード例 #2
0
ファイル: test_georef.py プロジェクト: wradlib/wradlib
 def test_spherical_to_polyvert(self):
     sph = georef.get_default_projection()
     polyvert = georef.spherical_to_polyvert(np.array([10000., 10100.]),
                                             np.array([45., 90.]), 0,
                                             (9., 48.), proj=sph)
     arr = np.asarray([[[9.05084865, 48.08224715, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.12264494, 48.03400725, 6.],
                        [9.05084865, 48.08224715, 6.]],
                       [[9.05136309, 48.0830778, 6.],
                        [9.05187756, 48.08390846, 6.],
                        [9.12512428, 48.03469291, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.05136309, 48.0830778, 6.]],
                       [[9.12264494, 48.03400725, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.05084865, 48.08224715, 6.],
                        [9.12264494, 48.03400725, 6.]],
                       [[9.1238846, 48.03435008, 6.],
                        [9.12512428, 48.03469291, 6.],
                        [9.05187756, 48.08390846, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.1238846, 48.03435008, 6.]]])
     np.testing.assert_array_almost_equal(polyvert, arr, decimal=3)
     polyvert, pr = georef.spherical_to_polyvert(np.array([10000., 10100.]),
                                                 np.array([45., 90.]), 0,
                                                 (9., 48.))
     arr = np.asarray([[[3.7885640e+03, 9.1464023e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.],
                        [9.1464023e+03, 3.7885645e+03, 6.],
                        [3.7885640e+03, 9.1464023e+03, 6.]],
                       [[3.8268320e+03, 9.2387900e+03, 6.],
                        [3.8651003e+03, 9.3311777e+03, 6.],
                        [9.3311777e+03, 3.8651006e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.]],
                       [[9.1464023e+03, 3.7885645e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.],
                        [3.7885640e+03, 9.1464023e+03, 6.],
                        [9.1464023e+03, 3.7885645e+03, 6.]],
                       [[9.2387900e+03, 3.8268323e+03, 6.],
                        [9.3311777e+03, 3.8651006e+03, 6.],
                        [3.8651003e+03, 9.3311777e+03, 6.],
                        [3.8268320e+03, 9.2387900e+03, 6.],
                        [9.2387900e+03, 3.8268323e+03, 6.]]])
     np.testing.assert_array_almost_equal(polyvert, arr, decimal=3)
コード例 #3
0
ファイル: test_georef.py プロジェクト: wradlib/wradlib-old
 def test_spherical_to_polyvert(self):
     sph = georef.get_default_projection()
     polyvert = georef.spherical_to_polyvert(np.array([10000., 10100.]),
                                             np.array([45., 90.]), 0,
                                             (9., 48.), proj=sph)
     arr = np.asarray([[[9.05084865, 48.08224715, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.12264494, 48.03400725, 6.],
                        [9.05084865, 48.08224715, 6.]],
                       [[9.05136309, 48.0830778, 6.],
                        [9.05187756, 48.08390846, 6.],
                        [9.12512428, 48.03469291, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.05136309, 48.0830778, 6.]],
                       [[9.12264494, 48.03400725, 6.],
                        [9.1238846, 48.03435008, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.05084865, 48.08224715, 6.],
                        [9.12264494, 48.03400725, 6.]],
                       [[9.1238846, 48.03435008, 6.],
                        [9.12512428, 48.03469291, 6.],
                        [9.05187756, 48.08390846, 6.],
                        [9.05136309, 48.0830778, 6.],
                        [9.1238846, 48.03435008, 6.]]])
     self.assertTrue(np.allclose(polyvert, arr, rtol=1e-12))
コード例 #4
0
    def setUp(self):
        global skip
        # setup test grid and catchment
        lon = 7.071664
        lat = 50.730521
        r = np.array(range(50, 100 * 1000 + 50, 100))
        a = np.array(range(0, 360, 1))
        rays = a.shape[0]
        bins = r.shape[0]

        # setup OSR objects
        self.proj_gk = osr.SpatialReference()
        self.proj_gk.ImportFromEPSG(31466)
        self.proj_ll = osr.SpatialReference()
        self.proj_ll.ImportFromEPSG(4326)

        # create polar grid polygon vertices in lat,lon
        radar_ll = georef.spherical_to_polyvert(r,
                                                a,
                                                0, (lon, lat),
                                                proj=self.proj_ll)[..., 0:2]

        # create polar grid centroids in lat,lon
        coords = georef.spherical_to_centroids(r,
                                               a,
                                               0, (lon, lat),
                                               proj=self.proj_ll)

        radar_llc = coords[..., 0:2]

        # project ll grids to GK2
        self.radar_gk = georef.reproject(radar_ll,
                                         projection_source=self.proj_ll,
                                         projection_target=self.proj_gk)
        self.radar_gkc = georef.reproject(radar_llc,
                                          projection_source=self.proj_ll,
                                          projection_target=self.proj_gk)

        # reshape
        self.radar_gk.shape = (rays, bins, 5, 2)
        self.radar_gkc.shape = (rays, bins, 2)

        self.box0 = np.array([[2600000., 5630000.], [2600000., 5630100.],
                              [2600100., 5630100.], [2600100., 5630000.],
                              [2600000., 5630000.]])

        self.box1 = np.array([[2600100., 5630000.], [2600100., 5630100.],
                              [2600200., 5630100.], [2600200., 5630000.],
                              [2600100., 5630000.]])

        self.data = np.array([self.box0, self.box1])

        # create catchment bounding box
        buffer = 5000.
        bbox = zonalstats.get_bbox(self.data[..., 0], self.data[..., 1])
        bbox = dict(left=bbox['left'] - buffer,
                    right=bbox['right'] + buffer,
                    bottom=bbox['bottom'] - buffer,
                    top=bbox['top'] + buffer)

        mask, shape = zonalstats.mask_from_bbox(self.radar_gkc[..., 0],
                                                self.radar_gkc[..., 1],
                                                bbox,
                                                polar=True)

        self.radar_gkc = self.radar_gkc[mask, :]
        self.radar_gk = self.radar_gk[mask]

        self.zdpoly = zonalstats.ZonalDataPoly(self.radar_gk,
                                               self.data,
                                               srs=self.proj_gk)
        # self.zdpoly.dump_vector('test_zdpoly')
        self.zdpoint = zonalstats.ZonalDataPoint(self.radar_gkc,
                                                 self.data,
                                                 srs=self.proj_gk)
        # self.zdpoint.dump_vector('test_zdpoint')

        isec_poly0 = np.array([
            np.array([[2600000., 5630000.], [2600000., 5630100.],
                      [2600009.61157242, 5630100.],
                      [2600041.77844048, 5630000.], [2600000., 5630000.]]),
            np.array([[2600009.61157242, 5630100.], [2600100., 5630100.],
                      [2600100., 5630000.], [2600041.77844048, 5630000.],
                      [2600009.61157242, 5630100.]]),
            np.array([[2600091.80406488, 5630100.], [2600100., 5630100.],
                      [2600100., 5630074.58501104],
                      [2600091.80406488, 5630100.]])
        ])
        isec_poly1 = np.array([
            np.array([[2600100., 5630000.], [2600100., 5630100.],
                      [2600114.66582085, 5630100.],
                      [2600146.83254704, 5630000.], [2600100., 5630000.]]),
            np.array([[2600114.66582085, 5630100.], [2600200., 5630100.],
                      [2600200., 5630000.], [2600146.83254704, 5630000.],
                      [2600114.66582085, 5630100.]]),
            np.array([[2600197.20644071, 5630100.], [2600200., 5630100.],
                      [2600200., 5630091.33737992],
                      [2600197.20644071, 5630100.]])
        ])

        isec_point0 = np.array([[2600077.2899581, 5630056.0874306]])
        isec_point1 = np.array([[2600172.498418, 5630086.7127034]])

        self.isec_poly = np.array([isec_poly0, isec_poly1])
        self.isec_point = np.array([isec_point0, isec_point1])
コード例 #5
0
class TestZonalData:
    global skip
    # setup test grid and catchment
    lon = 7.071664
    lat = 50.730521
    r = np.array(range(50, 100 * 1000 + 50, 100))
    a = np.array(range(0, 360, 1))
    rays = a.shape[0]
    bins = r.shape[0]

    # setup OSR objects
    proj_gk = osr.SpatialReference()
    proj_gk.ImportFromEPSG(31466)
    proj_ll = osr.SpatialReference()
    proj_ll.ImportFromEPSG(4326)

    # create polar grid polygon vertices in lat,lon
    radar_ll = georef.spherical_to_polyvert(r, a, 0, (lon, lat),
                                            proj=proj_ll)[..., 0:2]

    # create polar grid centroids in lat,lon
    coords = georef.spherical_to_centroids(r, a, 0, (lon, lat), proj=proj_ll)

    radar_llc = coords[..., 0:2]

    # project ll grids to GK2
    radar_gk = georef.reproject(radar_ll,
                                projection_source=proj_ll,
                                projection_target=proj_gk)
    radar_gkc = georef.reproject(radar_llc,
                                 projection_source=proj_ll,
                                 projection_target=proj_gk)

    # reshape
    radar_gk.shape = (rays, bins, 5, 2)
    radar_gkc.shape = (rays, bins, 2)

    box0 = np.array([
        [2600000.0, 5630000.0],
        [2600000.0, 5630100.0],
        [2600100.0, 5630100.0],
        [2600100.0, 5630000.0],
        [2600000.0, 5630000.0],
    ])

    box1 = np.array([
        [2600100.0, 5630000.0],
        [2600100.0, 5630100.0],
        [2600200.0, 5630100.0],
        [2600200.0, 5630000.0],
        [2600100.0, 5630000.0],
    ])

    data = np.array([box0, box1])

    # create catchment bounding box
    buffer = 5000.0
    bbox = zonalstats.get_bbox(data[..., 0], data[..., 1])
    bbox = dict(
        left=bbox["left"] - buffer,
        right=bbox["right"] + buffer,
        bottom=bbox["bottom"] - buffer,
        top=bbox["top"] + buffer,
    )

    mask, shape = zonalstats.mask_from_bbox(radar_gkc[..., 0],
                                            radar_gkc[..., 1],
                                            bbox,
                                            polar=True)

    radar_gkc = radar_gkc[mask, :]
    radar_gk = radar_gk[mask]

    zdpoly = zonalstats.ZonalDataPoly(radar_gk, data, srs=proj_gk)
    # zdpoly.dump_vector('test_zdpoly')
    zdpoint = zonalstats.ZonalDataPoint(radar_gkc, data, srs=proj_gk)
    # zdpoint.dump_vector('test_zdpoint')

    isec_poly0 = np.array(
        [
            np.array([
                [2600000.0, 5630000.0],
                [2600000.0, 5630100.0],
                [2600009.61157242, 5630100.0],
                [2600041.77844048, 5630000.0],
                [2600000.0, 5630000.0],
            ]),
            np.array([
                [2600009.61157242, 5630100.0],
                [2600100.0, 5630100.0],
                [2600100.0, 5630000.0],
                [2600041.77844048, 5630000.0],
                [2600009.61157242, 5630100.0],
            ]),
            np.array([
                [2600091.80406488, 5630100.0],
                [2600100.0, 5630100.0],
                [2600100.0, 5630074.58501104],
                [2600091.80406488, 5630100.0],
            ]),
        ],
        dtype=object,
    )
    isec_poly1 = np.array(
        [
            np.array([
                [2600100.0, 5630000.0],
                [2600100.0, 5630100.0],
                [2600114.66582085, 5630100.0],
                [2600146.83254704, 5630000.0],
                [2600100.0, 5630000.0],
            ]),
            np.array([
                [2600114.66582085, 5630100.0],
                [2600200.0, 5630100.0],
                [2600200.0, 5630000.0],
                [2600146.83254704, 5630000.0],
                [2600114.66582085, 5630100.0],
            ]),
            np.array([
                [2600197.20644071, 5630100.0],
                [2600200.0, 5630100.0],
                [2600200.0, 5630091.33737992],
                [2600197.20644071, 5630100.0],
            ]),
        ],
        dtype=object,
    )

    isec_point0 = np.array([[2600077.2899581, 5630056.0874306]])
    isec_point1 = np.array([[2600172.498418, 5630086.7127034]])

    isec_poly = np.array([isec_poly0, isec_poly1])
    isec_point = np.array([isec_point0, isec_point1])

    def test_srs(self):
        assert self.zdpoly.srs == self.proj_gk
        assert self.zdpoint.srs == self.proj_gk

    def test_isecs(self):
        # need to iterate over nested array for correct testing
        for i, ival in enumerate(self.zdpoly.isecs):
            for k, kval in enumerate(ival):
                np.testing.assert_allclose(kval.astype(float),
                                           self.isec_poly[i, k],
                                           rtol=1e-6)

        np.testing.assert_allclose(self.zdpoint.isecs.astype(float),
                                   self.isec_point,
                                   rtol=1e-6)

    def test_get_isec(self):
        for i in [0, 1]:
            for k, arr in enumerate(self.zdpoly.get_isec(i)):
                np.testing.assert_allclose(arr.astype(float),
                                           self.isec_poly[i, k],
                                           rtol=1e-6)
            np.testing.assert_allclose(self.zdpoint.get_isec(i).astype(float),
                                       self.isec_point[i],
                                       rtol=1e-6)

    def test_get_source_index(self):
        np.testing.assert_array_equal(self.zdpoly.get_source_index(0),
                                      np.array([2254, 2255]))
        np.testing.assert_array_equal(self.zdpoly.get_source_index(1),
                                      np.array([2255, 2256]))
        np.testing.assert_array_equal(self.zdpoint.get_source_index(0),
                                      np.array([2255]))
        np.testing.assert_array_equal(self.zdpoint.get_source_index(1),
                                      np.array([2256]))
コード例 #6
0
    def setUp(self):
        global skip
        # setup test grid and catchment
        lon = 7.071664
        lat = 50.730521
        r = np.array(range(50, 100 * 1000 + 50, 100))
        a = np.array(range(0, 360, 1))
        rays = a.shape[0]
        bins = r.shape[0]

        # setup OSR objects
        self.proj_gk = osr.SpatialReference()
        self.proj_gk.ImportFromEPSG(31466)
        self.proj_ll = osr.SpatialReference()
        self.proj_ll.ImportFromEPSG(4326)

        # create polar grid polygon vertices in lat,lon
        radar_ll = georef.spherical_to_polyvert(r, a, 0, (lon, lat),
                                                proj=self.proj_ll)[..., 0:2]

        # create polar grid centroids in lat,lon
        coords = georef.spherical_to_centroids(r, a, 0, (lon, lat),
                                               proj=self.proj_ll)

        radar_llc = coords[..., 0:2]

        # project ll grids to GK2
        self.radar_gk = georef.reproject(radar_ll,
                                         projection_source=self.proj_ll,
                                         projection_target=self.proj_gk)
        self.radar_gkc = georef.reproject(radar_llc,
                                          projection_source=self.proj_ll,
                                          projection_target=self.proj_gk)

        # reshape
        self.radar_gk.shape = (rays, bins, 5, 2)
        self.radar_gkc.shape = (rays, bins, 2)

        self.box0 = np.array([[2600000., 5630000.], [2600000., 5630100.],
                              [2600100., 5630100.], [2600100., 5630000.],
                              [2600000., 5630000.]])

        self.box1 = np.array([[2600100., 5630000.], [2600100., 5630100.],
                              [2600200., 5630100.], [2600200., 5630000.],
                              [2600100., 5630000.]])

        self.data = np.array([self.box0, self.box1])

        # create catchment bounding box
        buffer = 5000.
        bbox = zonalstats.get_bbox(self.data[..., 0], self.data[..., 1])
        bbox = dict(left=bbox['left'] - buffer, right=bbox['right'] + buffer,
                    bottom=bbox['bottom'] - buffer, top=bbox['top'] + buffer)

        mask, shape = zonalstats.mask_from_bbox(self.radar_gkc[..., 0],
                                                self.radar_gkc[..., 1],
                                                bbox,
                                                polar=True)

        self.radar_gkc = self.radar_gkc[mask, :]
        self.radar_gk = self.radar_gk[mask]

        self.zdpoly = zonalstats.ZonalDataPoly(self.radar_gk, self.data,
                                               srs=self.proj_gk)
        # self.zdpoly.dump_vector('test_zdpoly')
        self.zdpoint = zonalstats.ZonalDataPoint(self.radar_gkc, self.data,
                                                 srs=self.proj_gk)
        # self.zdpoint.dump_vector('test_zdpoint')

        isec_poly0 = np.array([np.array([[2600000., 5630000.],
                                         [2600000., 5630100.],
                                         [2600009.61157242, 5630100.],
                                         [2600041.77844048, 5630000.],
                                         [2600000., 5630000.]]),
                               np.array([[2600009.61157242, 5630100.],
                                         [2600100., 5630100.],
                                         [2600100., 5630000.],
                                         [2600041.77844048, 5630000.],
                                         [2600009.61157242, 5630100.]]),
                               np.array([[2600091.80406488, 5630100.],
                                         [2600100., 5630100.],
                                         [2600100., 5630074.58501104],
                                         [2600091.80406488, 5630100.]])])
        isec_poly1 = np.array([np.array([[2600100., 5630000.],
                                         [2600100., 5630100.],
                                         [2600114.66582085, 5630100.],
                                         [2600146.83254704, 5630000.],
                                         [2600100., 5630000.]]),
                               np.array([[2600114.66582085, 5630100.],
                                         [2600200., 5630100.],
                                         [2600200., 5630000.],
                                         [2600146.83254704, 5630000.],
                                         [2600114.66582085, 5630100.]]),
                               np.array([[2600197.20644071, 5630100.],
                                         [2600200., 5630100.],
                                         [2600200., 5630091.33737992],
                                         [2600197.20644071, 5630100.]])])

        isec_point0 = np.array([[2600077.2899581, 5630056.0874306]])
        isec_point1 = np.array([[2600172.498418, 5630086.7127034]])

        self.isec_poly = np.array([isec_poly0, isec_poly1])
        self.isec_point = np.array([isec_point0, isec_point1])