Beispiel #1
0
    def test_enhance_with_sensor_entry(self):
        """Test enhancing an image with a configuration section."""
        from satpy.writers import Enhancer, get_enhanced_image
        from xarray import DataArray
        import dask.array as da
        ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                       attrs=dict(name='test1', sensor='test_sensor',
                                  mode='L'),
                       dims=['y', 'x'])
        e = Enhancer()
        self.assertIsNotNone(e.enhancement_tree)
        img = get_enhanced_image(ds, enhance=e)
        self.assertSetEqual(
            set(e.sensor_enhancement_configs),
            {os.path.abspath(self.ENH_FN),
             os.path.abspath(self.ENH_ENH_FN)})
        np.testing.assert_almost_equal(img.data.isel(bands=0).max().values, 1.)

        ds = DataArray(da.arange(1, 11., chunks=5).reshape((2, 5)),
                       attrs=dict(name='test1', sensor='test_sensor',
                                  mode='L'),
                       dims=['y', 'x'])
        e = Enhancer()
        self.assertIsNotNone(e.enhancement_tree)
        img = get_enhanced_image(ds, enhance=e)
        self.assertSetEqual(
            set(e.sensor_enhancement_configs),
            {os.path.abspath(self.ENH_FN),
             os.path.abspath(self.ENH_ENH_FN)})
        np.testing.assert_almost_equal(img.data.isel(bands=0).max().values, 1.)
Beispiel #2
0
 def _get_enhanced_image(self, data_arr):
     from satpy.writers import Enhancer, get_enhanced_image
     e = Enhancer()
     assert e.enhancement_tree is not None
     img = get_enhanced_image(data_arr, enhance=e)
     # make sure that both configs were loaded
     assert (set(
         e.sensor_enhancement_configs) == {os.path.abspath(self.ENH_FN)})
     return img
Beispiel #3
0
 def test_enhance_with_sensor_no_entry(self):
     """Test enhancing an image that has no configuration sections"""
     from satpy.writers import Enhancer, get_enhanced_image
     from satpy import Dataset
     ds = Dataset(np.arange(1, 11.).reshape((2, 5)), sensor='test_sensor2', mode='L')
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)
     get_enhanced_image(ds, enhancer=e)
     self.assertSetEqual(set(e.sensor_enhancement_configs),
                         {'test_sensor2.yaml', 'enhancements/test_sensor2.yaml'})
Beispiel #4
0
 def test_enhance_empty_config(self):
     """Test Enhancer doesn't fail with empty enhancement file."""
     from satpy.writers import Enhancer, get_enhanced_image
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs=dict(sensor='test_empty', mode='L'),
                    dims=['y', 'x'])
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)
     get_enhanced_image(ds, enhancer=e)
     self.assertSetEqual(set(e.sensor_enhancement_configs), {self.ENH_FN3})
Beispiel #5
0
 def test_enhance_empty_config(self):
     """Test Enhancer doesn't fail with empty enhancement file."""
     from satpy.writers import Enhancer, get_enhanced_image
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs=dict(sensor='test_empty', mode='L'),
                    dims=['y', 'x'])
     e = Enhancer()
     assert e.enhancement_tree is not None
     get_enhanced_image(ds, enhance=e)
     assert (set(
         e.sensor_enhancement_configs) == {os.path.abspath(self.ENH_FN3)})
Beispiel #6
0
 def test_enhance_with_sensor_no_entry(self):
     """Test enhancing an image that has no configuration sections."""
     from satpy.writers import Enhancer, get_enhanced_image
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs=dict(sensor='test_sensor2', mode='L'),
                    dims=['y', 'x'])
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)
     get_enhanced_image(ds, enhancer=e)
     self.assertSetEqual(set(e.sensor_enhancement_configs),
                         {self.ENH_FN2, self.ENH_ENH_FN2})
Beispiel #7
0
 def test_writer_custom_enhance(self):
     """Test using custom enhancements with writer."""
     from satpy.writers import Enhancer
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs=dict(name='test1', sensor='test_sensor', mode='L'),
                    dims=['y', 'x'])
     enhance = Enhancer()
     writer = self.CustomImageWriter(enhance=enhance)
     writer.save_datasets((ds,), compute=False)
     img = writer.img
     np.testing.assert_almost_equal(img.data.isel(bands=0).max().values, 1.)
Beispiel #8
0
    def test_basic_init_provided_enh(self):
        """Test Enhancer init with string enhancement configs."""
        from satpy.writers import Enhancer
        e = Enhancer(enhancement_config_file=["""enhancements:
  enh1:
    standard_name: toa_bidirectional_reflectance
    operations:
    - name: stretch
      method: !!python/name:satpy.enhancements.stretch
      kwargs: {stretch: linear}
"""])
        self.assertIsNotNone(e.enhancement_tree)
Beispiel #9
0
 def test_enhance_with_sensor_entry2(self):
     """Test enhancing an image with a more detailed configuration section"""
     from satpy.writers import Enhancer, get_enhanced_image
     from satpy import Dataset
     ds = Dataset(np.arange(1, 11.).reshape((2, 5)),
                  name='test1', units='kelvin', sensor='test_sensor', mode='L')
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)
     img = get_enhanced_image(ds, enhancer=e)
     self.assertSetEqual(set(e.sensor_enhancement_configs),
                         {'test_sensor.yaml', 'enhancements/test_sensor.yaml'})
     np.testing.assert_almost_equal(img.channels[0].max(), 0.5)
Beispiel #10
0
 def test_enhance_with_sensor_no_entry(self):
     """Test enhancing an image that has no configuration sections."""
     from satpy.writers import Enhancer, get_enhanced_image
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs=dict(sensor='test_sensor2', mode='L'),
                    dims=['y', 'x'])
     e = Enhancer()
     assert e.enhancement_tree is not None
     get_enhanced_image(ds, enhance=e)
     assert (set(e.sensor_enhancement_configs) == {
         os.path.abspath(self.ENH_FN2),
         os.path.abspath(self.ENH_ENH_FN2)
     })
Beispiel #11
0
 def test_enhance_with_sensor_entry2(self):
     """Test enhancing an image with a more detailed configuration section."""
     from satpy.writers import Enhancer, get_enhanced_image
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs=dict(name='test1', units='kelvin',
                               sensor='test_sensor', mode='L'),
                    dims=['y', 'x'])
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)
     img = get_enhanced_image(ds, enhancer=e)
     self.assertSetEqual(set(e.sensor_enhancement_configs),
                         {self.ENH_FN, self.ENH_ENH_FN})
     np.testing.assert_almost_equal(img.data.isel(bands=0).max().values, 0.5)
Beispiel #12
0
 def test_multisensor_exact(self):
     """Test that a DataArray with two sensors can match exactly."""
     from satpy.writers import Enhancer, get_enhanced_image
     from xarray import DataArray
     ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
                    attrs={
                        'name': 'my_comp',
                        'sensor': {'test_sensor2', 'test_sensor1'},
                        'mode': 'L'
                    },
                    dims=['y', 'x'])
     e = Enhancer()
     assert e.enhancement_tree is not None
     img = get_enhanced_image(ds, enhance=e)
     # make sure that both sensor configs were loaded
     assert (set(e.sensor_enhancement_configs) == {
         os.path.abspath(self.ENH_FN),
         os.path.abspath(self.ENH_FN2)
     })
     # test_sensor1 config should have been used because it is
     # alphabetically first
     np.testing.assert_allclose(img.data.values[0], ds.data / 20.0)
Beispiel #13
0
 def test_basic_init_no_enh(self):
     """Test Enhancer init requesting no enhancements."""
     from satpy.writers import Enhancer
     e = Enhancer(enhancement_config_file=False)
     self.assertIsNone(e.enhancement_tree)
Beispiel #14
0
 def test_basic_init_no_args(self):
     """Test Enhancer init with no arguments passed."""
     from satpy.writers import Enhancer
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)
Beispiel #15
0
 def test_basic_init_no_enh(self):
     from satpy.writers import Enhancer
     e = Enhancer(enhancement_config_file=False)
     self.assertIsNone(e.enhancement_tree)
Beispiel #16
0
 def test_basic_init_no_args(self):
     from satpy.writers import Enhancer
     e = Enhancer()
     self.assertIsNotNone(e.enhancement_tree)