Exemplo n.º 1
0
 def test_dtype_for_enhance_false_and_given_dtype(self, tmp_path):
     """Test that dtype of dataset is used if enhance=False and dtype=uint8."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = _get_test_datasets_2d()
     w = GeoTIFFWriter(base_dir=tmp_path, enhance=False, dtype=np.uint8)
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets, compute=False)
         assert save_method.call_args[1]['dtype'] == np.uint8
Exemplo n.º 2
0
 def test_tiled_value_from_config(self):
     """Test tiled value coming from the writer config."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir)
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets, compute=False)
         self.assertEqual(save_method.call_args[1]['tiled'], True)
Exemplo n.º 3
0
 def test_dtype_for_enhance_false(self):
     """Test that dtype of dataset is used if parameters enhance=False and dtype=None."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir, enhance=False)
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets, compute=False)
         self.assertEqual(save_method.call_args[1]['dtype'], np.float64)
Exemplo n.º 4
0
 def test_fill_value_from_config(self, tmp_path):
     """Test fill_value coming from the writer config."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = _get_test_datasets_2d()
     w = GeoTIFFWriter(base_dir=tmp_path)
     w.info['fill_value'] = 128
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets, compute=False)
         assert save_method.call_args[1]['fill_value'] == 128
Exemplo n.º 5
0
    def test_float_write(self, tmp_path):
        """Test that geotiffs can be written as floats.

        NOTE: Does not actually check that the output is floats.

        """
        from satpy.writers.geotiff import GeoTIFFWriter
        datasets = _get_test_datasets_2d()
        w = GeoTIFFWriter(base_dir=tmp_path, enhance=False, dtype=np.float32)
        w.save_datasets(datasets)
Exemplo n.º 6
0
 def test_scale_offset(self):
     """Test tags being added."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(tags={'test1': 1}, base_dir=self.base_dir)
     w.info['fill_value'] = 128
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets, tags={'test2': 2}, compute=False, include_scale_offset=True)
         called_include = save_method.call_args[1]['include_scale_offset_tags']
         self.assertTrue(called_include)
Exemplo n.º 7
0
 def test_tags(self, tmp_path):
     """Test tags being added."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = _get_test_datasets_2d()
     w = GeoTIFFWriter(tags={'test1': 1}, base_dir=tmp_path)
     w.info['fill_value'] = 128
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets, tags={'test2': 2}, compute=False)
         called_tags = save_method.call_args[1]['tags']
         assert called_tags == {'test1': 1, 'test2': 2}
Exemplo n.º 8
0
    def test_float_write(self):
        """Test that geotiffs can be written as floats.

        NOTE: Does not actually check that the output is floats.

        """
        from satpy.writers.geotiff import GeoTIFFWriter
        datasets = self._get_test_datasets()
        w = GeoTIFFWriter(base_dir=self.base_dir,
                          enhancement_config=False,
                          dtype=np.float32)
        w.save_datasets(datasets)
Exemplo n.º 9
0
    def test_float_write(self):
        """Test that geotiffs can be written as floats.

        NOTE: Does not actually check that the output is floats.

        """
        from satpy.writers.geotiff import GeoTIFFWriter
        datasets = self._get_test_datasets()
        w = GeoTIFFWriter(base_dir=self.base_dir,
                          enhancement_config=False,
                          dtype=np.float32)
        w.save_datasets(datasets)
Exemplo n.º 10
0
 def test_colormap_write(self):
     """Test writing an image with a colormap."""
     from satpy.writers.geotiff import GeoTIFFWriter
     from trollimage.xrimage import XRImage
     from trollimage.colormap import spectral
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir)
     # we'd have to customize enhancements to test this through
     # save_datasets. We'll use `save_image` as a workaround.
     img = XRImage(datasets[0])
     img.palettize(spectral)
     w.save_image(img, keep_palette=True)
Exemplo n.º 11
0
 def test_scale_offset(self, input_func, save_kwargs, tmp_path):
     """Test tags being added."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = input_func()
     w = GeoTIFFWriter(tags={'test1': 1}, base_dir=tmp_path)
     w.info['fill_value'] = 128
     with mock.patch('satpy.writers.XRImage.save') as save_method:
         save_method.return_value = None
         w.save_datasets(datasets,
                         tags={'test2': 2},
                         compute=False,
                         **save_kwargs)
     kwarg_name = "include_scale_offset_tags" if "include_scale_offset" in save_kwargs else "scale_offset_tags"
     kwarg_value = save_method.call_args[1].get(kwarg_name)
     assert kwarg_value is not None
Exemplo n.º 12
0
 def test_simple_delayed_write(self, tmp_path):
     """Test writing can be delayed."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = _get_test_datasets_2d()
     w = GeoTIFFWriter(base_dir=tmp_path)
     # when we switch to rio_save on XRImage then this will be sources
     # and targets
     res = w.save_datasets(datasets, compute=False)
     # this will fail if rasterio isn't installed
     assert isinstance(res, tuple)
     # two lists, sources and destinations
     assert len(res) == 2
     assert isinstance(res[0], list)
     assert isinstance(res[1], list)
     assert isinstance(res[0][0], da.Array)
     da.store(res[0], res[1])
     for target in res[1]:
         if hasattr(target, 'close'):
             target.close()
Exemplo n.º 13
0
 def test_simple_delayed_write(self):
     """Test writing can be delayed."""
     import dask.array as da
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir)
     # when we switch to rio_save on XRImage then this will be sources
     # and targets
     res = w.save_datasets(datasets, compute=False)
     # this will fail if rasterio isn't installed
     self.assertIsInstance(res, tuple)
     # two lists, sources and destinations
     self.assertEqual(len(res), 2)
     self.assertIsInstance(res[0], list)
     self.assertIsInstance(res[1], list)
     self.assertIsInstance(res[0][0], da.Array)
     da.store(res[0], res[1])
     for target in res[1]:
         if hasattr(target, 'close'):
             target.close()
Exemplo n.º 14
0
 def test_simple_delayed_write(self):
     """Test writing can be delayed."""
     import dask.array as da
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir)
     # when we switch to rio_save on XRImage then this will be sources
     # and targets
     res = w.save_datasets(datasets, compute=False)
     # this will fail if rasterio isn't installed
     self.assertIsInstance(res, tuple)
     # two lists, sources and destinations
     self.assertEqual(len(res), 2)
     self.assertIsInstance(res[0], list)
     self.assertIsInstance(res[1], list)
     self.assertIsInstance(res[0][0], da.Array)
     da.store(res[0], res[1])
     for target in res[1]:
         if hasattr(target, 'close'):
             target.close()
Exemplo n.º 15
0
 def test_simple_write(self):
     """Test basic writer operation."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir)
     w.save_datasets(datasets)
Exemplo n.º 16
0
 def test_init(self):
     """Test creating the writer with no arguments."""
     from satpy.writers.geotiff import GeoTIFFWriter
     w = GeoTIFFWriter()
Exemplo n.º 17
0
 def test_init(self):
     from satpy.writers.geotiff import GeoTIFFWriter
     w = GeoTIFFWriter()
Exemplo n.º 18
0
 def test_simple_write(self):
     """Test basic writer operation."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = self._get_test_datasets()
     w = GeoTIFFWriter(base_dir=self.base_dir)
     w.save_datasets(datasets)
Exemplo n.º 19
0
 def test_simple_write(self, input_func, tmp_path):
     """Test basic writer operation."""
     from satpy.writers.geotiff import GeoTIFFWriter
     datasets = input_func()
     w = GeoTIFFWriter(base_dir=tmp_path)
     w.save_datasets(datasets)