コード例 #1
0
ファイル: test_resample.py プロジェクト: ziaridoy20/satpy
 def test_expand_without_dims(self):
     """Test expanding native resampling with no dimensions specified."""
     from satpy.resample import NativeResampler
     import numpy as np
     import dask.array as da
     from xarray import DataArray
     from pyresample.geometry import AreaDefinition
     from pyresample.utils import proj4_str_to_dict
     ds1 = DataArray(da.zeros((100, 50), chunks=85))
     proj_dict = proj4_str_to_dict('+proj=lcc +datum=WGS84 +ellps=WGS84 '
                                   '+lon_0=-95. +lat_0=25 +lat_1=25 '
                                   '+units=m +no_defs')
     target = AreaDefinition(
         'test',
         'test',
         'test',
         proj_dict,
         x_size=100,
         y_size=200,
         area_extent=(-1000., -1500., 1000., 1500.),
     )
     # source geo def doesn't actually matter
     resampler = NativeResampler(None, target)
     new_arr = resampler.resample(ds1)
     self.assertEqual(new_arr.shape, (200, 100))
     new_arr2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_arr == new_arr2))
コード例 #2
0
    def test_expand_reduce(self):
        """Test class method 'expand_reduce' basics."""
        from satpy.resample import NativeResampler
        import numpy as np
        import dask.array as da
        d_arr = da.zeros((6, 20), chunks=4)
        new_arr = NativeResampler.expand_reduce(d_arr, {0: 2., 1: 2.})
        self.assertEqual(new_arr.shape, (12, 40))
        new_arr = NativeResampler.expand_reduce(d_arr, {0: .5, 1: .5})
        self.assertEqual(new_arr.shape, (3, 10))
        self.assertRaises(ValueError, NativeResampler.expand_reduce, d_arr, {
            0: 1. / 3,
            1: 1.
        })
        new_arr = NativeResampler.expand_reduce(d_arr, {0: 1., 1: 1.})
        self.assertEqual(new_arr.shape, (6, 20))
        self.assertIs(new_arr, d_arr)
        self.assertRaises(ValueError, NativeResampler.expand_reduce, d_arr, {
            0: 0.333323423,
            1: 1.
        })
        self.assertRaises(ValueError, NativeResampler.expand_reduce, d_arr, {
            0: 1.333323423,
            1: 1.
        })

        n_arr = np.zeros((6, 20))
        new_arr = NativeResampler.expand_reduce(n_arr, {0: 2., 1: 1.0})
        self.assertTrue(np.all(new_arr.compute()[::2, :] == n_arr))
コード例 #3
0
 def test_expand_dims_3d(self):
     """Test expanding native resampling with 3D data."""
     from satpy.resample import NativeResampler
     import numpy as np
     import dask.array as da
     from xarray import DataArray
     from pyresample.geometry import AreaDefinition
     from pyresample.utils import proj4_str_to_dict
     ds1 = DataArray(da.zeros((3, 100, 50), chunks=85),
                     dims=('bands', 'y', 'x'),
                     coords={
                         'bands': ['R', 'G', 'B'],
                         'y': da.arange(100, chunks=85),
                         'x': da.arange(50, chunks=85)
                     })
     proj_dict = proj4_str_to_dict('+proj=lcc +datum=WGS84 +ellps=WGS84 '
                                   '+lon_0=-95. +lat_0=25 +lat_1=25 '
                                   '+units=m +no_defs')
     target = AreaDefinition(
         'test',
         'test',
         'test',
         proj_dict,
         100,
         200,
         (-1000., -1500., 1000., 1500.),
     )
     # source geo def doesn't actually matter
     resampler = NativeResampler(None, target)
     new_arr = resampler.resample(ds1)
     self.assertEqual(new_arr.shape, (3, 200, 100))
     new_arr2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_arr == new_arr2))
コード例 #4
0
 def test_expand_dims_3d(self):
     """Test expanding native resampling with 3D data."""
     from satpy.resample import NativeResampler
     import numpy as np
     ds1, source_area, _, _, target_area = get_test_data(
         input_shape=(3, 100, 50), input_dims=('bands', 'y', 'x'))
     # source geo def doesn't actually matter
     resampler = NativeResampler(source_area, target_area)
     new_data = resampler.resample(ds1)
     self.assertEqual(new_data.shape, (3, 200, 100))
     new_data2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_data == new_data2))
     self.assertIn('y', new_data.coords)
     self.assertIn('x', new_data.coords)
     self.assertIn('bands', new_data.coords)
     np.testing.assert_equal(new_data.coords['bands'].values,
                             ['R', 'G', 'B'])
     if CRS is not None:
         self.assertIn('crs', new_data.coords)
         self.assertIsInstance(new_data.coords['crs'].item(), CRS)
         self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
         self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
         self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
         if hasattr(target_area, 'crs'):
             self.assertIs(target_area.crs, new_data.coords['crs'].item())
コード例 #5
0
ファイル: test_resample.py プロジェクト: davidh-ssec/satpy
 def test_expand_without_dims(self):
     from satpy.resample import NativeResampler
     import numpy as np
     import dask.array as da
     from xarray import DataArray
     from pyresample.geometry import AreaDefinition
     from pyresample.utils import proj4_str_to_dict
     ds1 = DataArray(da.zeros((100, 50), chunks=85))
     proj_dict = proj4_str_to_dict('+proj=lcc +datum=WGS84 +ellps=WGS84 '
                                   '+lon_0=-95. +lat_0=25 +lat_1=25 '
                                   '+units=m +no_defs')
     target = AreaDefinition(
         'test',
         'test',
         'test',
         proj_dict,
         x_size=100,
         y_size=200,
         area_extent=(-1000., -1500., 1000., 1500.),
     )
     # source geo def doesn't actually matter
     resampler = NativeResampler(None, target)
     new_arr = resampler.resample(ds1)
     self.assertEqual(new_arr.shape, (200, 100))
     new_arr2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_arr == new_arr2))
コード例 #6
0
 def test_expand_without_dims(self):
     """Test expanding native resampling with no dimensions specified."""
     from satpy.resample import NativeResampler
     import numpy as np
     ds1, source_area, _, _, target_area = get_test_data(input_dims=None)
     # source geo def doesn't actually matter
     resampler = NativeResampler(source_area, target_area)
     new_data = resampler.resample(ds1)
     self.assertEqual(new_data.shape, (200, 100))
     new_data2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_data == new_data2))
     if CRS is not None:
         self.assertIn('crs', new_data.coords)
         self.assertIsInstance(new_data.coords['crs'].item(), CRS)
         self.assertIn('lcc', new_data.coords['crs'].item().to_proj4())
コード例 #7
0
 def test_expand_without_dims_4D(self):
     """Test expanding native resampling with 4D data with no dimensions specified."""
     from satpy.resample import NativeResampler
     ds1, source_area, _, _, target_area = get_test_data(
         input_shape=(2, 3, 100, 50), input_dims=None)
     # source geo def doesn't actually matter
     resampler = NativeResampler(source_area, target_area)
     self.assertRaises(ValueError, resampler.resample, ds1)
コード例 #8
0
    def test_expand_without_dims(self):
        """Test expanding native resampling with no dimensions specified."""
        import numpy as np

        from satpy.resample import NativeResampler
        ds1, source_area, _, _, target_area = get_test_data(input_dims=None)
        # source geo def doesn't actually matter
        resampler = NativeResampler(source_area, target_area)
        new_data = resampler.resample(ds1)
        self.assertEqual(new_data.shape, (200, 100))
        new_data2 = resampler.resample(ds1.compute())
        self.assertTrue(np.all(new_data == new_data2))
        self.assertIn('crs', new_data.coords)
        self.assertIsInstance(new_data.coords['crs'].item(), CRS)
        self.assertIn(
            'lambert', new_data.coords['crs'].item().coordinate_operation.
            method_name.lower())
        self.assertEqual(target_area.crs, new_data.coords['crs'].item())
コード例 #9
0
ファイル: test_resample.py プロジェクト: youssef-osrhir/satpy
 def test_expand_dims(self):
     """Test expanding native resampling with 2D data."""
     from satpy.resample import NativeResampler
     import numpy as np
     ds1, source_area, _, _, target_area = get_test_data()
     # source geo def doesn't actually matter
     resampler = NativeResampler(source_area, target_area)
     new_data = resampler.resample(ds1)
     self.assertEqual(new_data.shape, (200, 100))
     new_data2 = resampler.resample(ds1.compute())
     self.assertTrue(np.all(new_data == new_data2))
     self.assertIn('y', new_data.coords)
     self.assertIn('x', new_data.coords)
     self.assertIn('crs', new_data.coords)
     self.assertIsInstance(new_data.coords['crs'].item(), CRS)
     self.assertIn('lambert', new_data.coords['crs'].item().coordinate_operation.method_name.lower())
     self.assertEqual(new_data.coords['y'].attrs['units'], 'meter')
     self.assertEqual(new_data.coords['x'].attrs['units'], 'meter')
     self.assertEqual(target_area.crs, new_data.coords['crs'].item())
コード例 #10
0
ファイル: test_resample.py プロジェクト: davidh-ssec/satpy
    def test_expand_reduce(self):
        from satpy.resample import NativeResampler
        import numpy as np
        import dask.array as da
        d_arr = da.zeros((6, 20), chunks=4)
        new_arr = NativeResampler.expand_reduce(d_arr, {0: 2., 1: 2.})
        self.assertEqual(new_arr.shape, (12, 40))
        new_arr = NativeResampler.expand_reduce(d_arr, {0: .5, 1: .5})
        self.assertEqual(new_arr.shape, (3, 10))
        self.assertRaises(ValueError, NativeResampler.expand_reduce,
                          d_arr, {0: 1. / 3, 1: 1.})
        new_arr = NativeResampler.expand_reduce(d_arr, {0: 1., 1: 1.})
        self.assertEqual(new_arr.shape, (6, 20))
        self.assertIs(new_arr, d_arr)
        self.assertRaises(ValueError, NativeResampler.expand_reduce,
                          d_arr, {0: 0.333323423, 1: 1.})
        self.assertRaises(ValueError, NativeResampler.expand_reduce,
                          d_arr, {0: 1.333323423, 1: 1.})

        n_arr = np.zeros((6, 20))
        new_arr = NativeResampler.expand_reduce(n_arr, {0: 2., 1: 1.0})
        self.assertTrue(np.all(new_arr.compute()[::2, :] == n_arr))
コード例 #11
0
ファイル: test_resample.py プロジェクト: ziaridoy20/satpy
 def test_expand_without_dims_4D(self):
     """Test expanding native resampling with 4D data with no dimensions specified."""
     from satpy.resample import NativeResampler
     import dask.array as da
     from xarray import DataArray
     from pyresample.geometry import AreaDefinition
     from pyresample.utils import proj4_str_to_dict
     ds1 = DataArray(da.zeros((2, 3, 100, 50), chunks=85))
     proj_dict = proj4_str_to_dict('+proj=lcc +datum=WGS84 +ellps=WGS84 '
                                   '+lon_0=-95. +lat_0=25 +lat_1=25 '
                                   '+units=m +no_defs')
     target = AreaDefinition(
         'test',
         'test',
         'test',
         proj_dict,
         x_size=100,
         y_size=200,
         area_extent=(-1000., -1500., 1000., 1500.),
     )
     # source geo def doesn't actually matter
     resampler = NativeResampler(None, target)
     self.assertRaises(ValueError, resampler.resample, ds1)