Пример #1
0
    def test_resample_blocks_supports_warns_when_chunk_size_is_too_big(
            self, caplog):
        from pyresample.resampler import resample_blocks

        def fun(src_array, block_info=None, **kwargs):
            dst_area = block_info[None]["area"]
            return np.full(src_array.shape[:-2] + dst_area.shape, 18)

        src_area = create_area_def("epsg4326", "EPSG:4326", 20000, 20000,
                                   (20., 60., 30., 70.))

        area_id = 'Suomi_3067'
        description = 'Suomi_kansallinen, EPSG 3067'
        proj_id = 'Suomi_3067'
        projection = 'EPSG:3067'
        width = 1160
        height = 1820
        from pyproj import Proj
        pp = Proj(proj='utm', zone=35, ellps='GRS80')
        xx1, yy1 = pp(15.82308183, 55.93417040)  # LL_lon, LL_lat
        xx2, yy2 = pp(43.12029189, 72.19756918)  # UR_lon, UR_lat
        area_extent = (xx1, yy1, xx2, yy2)
        dst_area = AreaDefinition(area_id, description, proj_id, projection,
                                  width, height, area_extent)

        _ = resample_blocks(fun,
                            src_area, [],
                            dst_area,
                            chunk_size=(3, 2048, 2048),
                            dtype=float)
        assert "The input area chunks are large." in caplog.text
Пример #2
0
def create_area_def(*args, **kwargs):
    """Create an area definition."""
    from pyresample.area_config import create_area_def
    warnings.warn(
        "'create_area_def' has moved, import it with 'from pyresample import create_area_def'",
        stacklevel=2)
    return create_area_def(*args, **kwargs)
Пример #3
0
    def test_resample_area_to_area_bilinear(self):
        """Resample area to area and check result values for bilinear."""
        data = xr.DataArray(da.arange(np.prod(self.src_area.shape),
                                      dtype=np.float64).reshape(
                                          self.src_area.shape),
                            dims=['y', 'x'])
        dst_area = create_area_def(
            "epsg3035", "EPSG:3035", 5, 5,
            (2426378.0132, 1528101.2618, 6293974.6215, 5446513.5222))

        expected_resampled_data = [[
            9657.73659888, 9736.06994061, 9744.63765978, 9684.31222874,
            9556.53097857
        ],
                                   [
                                       9473.47091892, 9551.45304151,
                                       9559.75772548, 9499.27398623,
                                       9371.5132557
                                   ],
                                   [
                                       9207.81468378, 9285.56859415,
                                       9293.95955182, 9233.88183094,
                                       9106.9076482
                                   ],
                                   [
                                       8861.02653887, 8938.6220088,
                                       8947.46145892, 8888.42994376,
                                       8763.14315424
                                   ],
                                   [
                                       8434.30749791, 8511.74525856,
                                       8521.39324998, 8464.10968423,
                                       8341.53220395
                                   ]]

        self.resampler.target_geo_def = dst_area
        self.resampler.precompute()
        res = self.resampler.compute(
            data, method='bilinear',
            fill_value=2.0).compute(scheduler='single-threaded').values
        np.testing.assert_allclose(res, expected_resampled_data)
        assert res.shape == dst_area.shape
Пример #4
0
    def test_resample_area_to_area_does_not_flip_the_result(self):
        """Resample area to area, check that x and y aren't flipped."""
        data = xr.DataArray(da.arange(np.prod(self.src_area.shape),
                                      dtype=np.float64).reshape(
                                          self.src_area.shape),
                            dims=['y', 'x'])
        dst_area = create_area_def(
            "epsg3035", "EPSG:3035", 10, 10,
            (2426378.0132, 1528101.2618, 6293974.6215, 5446513.5222))

        self.resampler.target_geo_def = dst_area
        self.resampler.precompute()
        res = self.resampler.compute(
            data, method='bilinear',
            fill_value=2.0).compute(scheduler='single-threaded').values
        corners = (res[0, 0], res[0, -1], res[-1, -1], res[-1, 0])
        expected_corners = (9660.560479802409, 9548.105823664819, 8183.903753,
                            8285.489720486787)
        np.testing.assert_allclose(corners, expected_corners)
        assert res.shape == dst_area.shape
Пример #5
0
    def test_slicing_works_with_extents_of_different_units(self):
        """Test a problematic case."""
        src_area = create_area_def("epsg4326", "EPSG:4326", 200, 200,
                                   (20., 60., 30., 70.))

        area_id = 'Suomi_3067'
        description = 'Suomi_kansallinen, EPSG 3067'
        proj_id = 'Suomi_3067'
        projection = 'EPSG:3067'
        width = 116
        height = 182
        from pyproj import Proj
        pp = Proj(proj='utm', zone=35, ellps='GRS80')
        xx1, yy1 = pp(15.82308183, 55.93417040)  # LL_lon, LL_lat
        xx2, yy2 = pp(43.12029189, 72.19756918)  # UR_lon, UR_lat
        area_extent = (xx1, yy1, xx2, yy2)
        dst_area = AreaDefinition(area_id, description, proj_id, projection,
                                  width, height, area_extent)

        slicer = create_slicer(src_area, dst_area[:50, :50])
        slice_x, slice_y = slicer.get_slices()
        assert 60 <= slice_x.stop < 65
        assert 50 <= slice_y.stop < 55
Пример #6
0
    def test_resample_area_to_area_nn(self):
        """Resample area to area and check result values for nn."""
        data = xr.DataArray(da.arange(np.prod(self.src_area.shape),
                                      dtype=np.float64).reshape(
                                          self.src_area.shape),
                            dims=['y', 'x'])
        dst_area = create_area_def(
            "epsg3035", "EPSG:3035", 5, 5,
            (2426378.0132, 1528101.2618, 6293974.6215, 5446513.5222))

        expected_resampled_data = [[9658., 9752., 9746., 9640., 9534.],
                                   [9457., 9551., 9545., 9539., 9333.],
                                   [9257., 9250., 9344., 9238., 9132.],
                                   [8856., 8949., 8943., 8936., 8730.],
                                   [8455., 8548., 8542., 8435., 8329.]]

        self.resampler.target_geo_def = dst_area
        self.resampler.precompute()
        res = self.resampler.compute(
            data, method='nn',
            fill_value=2.0).compute(scheduler='single-threaded').values
        print(res)
        np.testing.assert_allclose(res, expected_resampled_data)
        assert res.shape == dst_area.shape
Пример #7
0
def create_area_def(*args, **kwargs):
    from pyresample.area_config import create_area_def
    warnings.warn(
        "'create_area_def' has moved, import it with 'from pyresample import create_area_def'"
    )
    return create_area_def(*args, **kwargs)
Пример #8
0
def create_area_def(*args, **kwargs):
    from pyresample.area_config import create_area_def
    warnings.warn("'create_area_def' has moved, import it with 'from pyresample import create_area_def'")
    return create_area_def(*args, **kwargs)