Beispiel #1
0
    def test_nearest_area_2d_to_area_1n(self):
        """Test 2D area definition to 2D area definition; 1 neighbor."""
        import dask.array as da
        import xarray as xr

        from pyresample.kd_tree import XArrayResamplerNN
        from pyresample.test.utils import assert_maximum_dask_computes
        data = self.data_2d
        resampler = XArrayResamplerNN(self.src_area_2d, self.area_def,
                                      radius_of_influence=50000,
                                      neighbours=1)
        with assert_maximum_dask_computes(0):
            ninfo = resampler.get_neighbour_info()
        for val in ninfo[:3]:
            # vii, ia, voi
            self.assertIsInstance(val, da.Array)
        self.assertRaises(AssertionError,
                          resampler.get_sample_from_neighbour_info, data)

        # rename data dimensions to match the expected area dimensions
        data = data.rename({'my_dim_y': 'y', 'my_dim_x': 'x'})
        with assert_maximum_dask_computes(0):
            res = resampler.get_sample_from_neighbour_info(data)
        self.assertIsInstance(res, xr.DataArray)
        self.assertIsInstance(res.data, da.Array)
        res = res.values
        cross_sum = np.nansum(res)
        expected = 27706753.0
        self.assertEqual(cross_sum, expected)
Beispiel #2
0
    def test_nearest_area_2d_to_area_1n(self, area_def_stere_source,
                                        data_2d_float32_xarray_dask,
                                        area_def_stere_target):
        """Test 2D area definition to 2D area definition; 1 neighbor."""
        resampler = KDTreeNearestXarrayResampler(area_def_stere_source,
                                                 area_def_stere_target)
        with assert_maximum_dask_computes(0):
            resampler.precompute(radius_of_influence=50000)

        with assert_maximum_dask_computes(0):
            res = resampler.resample(data_2d_float32_xarray_dask,
                                     radius_of_influence=50000)
        assert isinstance(res, xr.DataArray)
        assert isinstance(res.data, da.Array)
        _check_common_metadata(
            res, isinstance(area_def_stere_target, AreaDefinition))
        res = res.values
        cross_sum = float(np.nansum(res))
        expected = 303048.0
        assert cross_sum == expected
        assert res.shape == resampler.target_geo_def.shape
Beispiel #3
0
 def test_object_type_with_warnings(self, area_def_stere_source,
                                    area_def_stere_target, input_data):
     """Test that providing certain input data causes a warning."""
     resampler = KDTreeNearestXarrayResampler(area_def_stere_source,
                                              area_def_stere_target)
     with catch_warnings(
             PerformanceWarning) as w, assert_maximum_dask_computes(1):
         res = resampler.resample(input_data)
         assert type(res) is type(input_data)
     _check_common_metadata(
         res, isinstance(area_def_stere_target, AreaDefinition))
     is_data_arr_dask = isinstance(input_data, xr.DataArray) and isinstance(
         input_data.data, da.Array)
     is_dask_based = isinstance(input_data, da.Array) or is_data_arr_dask
     if is_dask_based:
         assert not w
     else:
         assert_warnings_contain(w, "will be converted")
     res = np.array(res)
     cross_sum = np.nansum(res)
     expected = 952386.0  # same as 'test_nearest_area_2d_to_area_1n_no_roi'
     assert cross_sum == expected
     assert res.shape == resampler.target_geo_def.shape