Beispiel #1
0
    def test_GenericImageFileHandler_nodata(self):
        """Test nodata handling with direct use of the reader."""
        from satpy.readers.generic_image import GenericImageFileHandler

        fname = os.path.join(self.base_dir, 'test_l_nan_fillvalue.tif')
        fname_info = {'start_time': self.date}
        ftype_info = {}
        reader = GenericImageFileHandler(fname, fname_info, ftype_info)

        foo = make_dataid(name='image-custom')
        self.assertTrue(reader.file_content, 'file_content should be set')
        info = {'nodata_handling': 'nan_mask'}
        dataset = reader.get_dataset(foo, info)
        self.assertTrue(isinstance(dataset, xr.DataArray),
                        'dataset should be a xr.DataArray')
        self.assertTrue(np.all(np.isnan(dataset.data[0][:10, :10].compute())),
                        'values should be np.nan')
        self.assertTrue(np.isnan(dataset.attrs['_FillValue']),
                        '_FillValue should be np.nan')

        info = {'nodata_handling': 'fill_value'}
        dataset = reader.get_dataset(foo, info)
        self.assertTrue(isinstance(dataset, xr.DataArray),
                        'dataset should be a xr.DataArray')
        self.assertEqual(np.sum(dataset.data[0][:10, :10].compute()), 0)
        self.assertEqual(dataset.attrs['_FillValue'], 0)

        # default same as 'nodata_handling': 'fill_value'
        dataset = reader.get_dataset(foo, {})
        self.assertTrue(isinstance(dataset, xr.DataArray),
                        'dataset should be a xr.DataArray')
        self.assertEqual(np.sum(dataset.data[0][:10, :10].compute()), 0)
        self.assertEqual(dataset.attrs['_FillValue'], 0)
Beispiel #2
0
    def test_GenericImageFileHandler(self):
        """Test direct use of the reader."""
        from satpy.readers.generic_image import GenericImageFileHandler
        from satpy.readers.generic_image import mask_image_data

        fname = os.path.join(self.base_dir, 'test_rgba.tif')
        fname_info = {'start_time': self.date}
        ftype_info = {}
        reader = GenericImageFileHandler(fname, fname_info, ftype_info)

        foo = make_dataid(name='image')
        self.assertTrue(reader.file_content)
        self.assertEqual(reader.finfo['filename'], fname)
        self.assertEqual(reader.finfo['start_time'], self.date)
        self.assertEqual(reader.finfo['end_time'], self.date)
        self.assertEqual(reader.area, self.area_def)
        self.assertEqual(reader.get_area_def(None), self.area_def)
        self.assertEqual(reader.start_time, self.date)
        self.assertEqual(reader.end_time, self.date)

        dataset = reader.get_dataset(foo, None)
        self.assertTrue(isinstance(dataset, xr.DataArray))
        self.assertTrue('crs' in dataset.attrs)
        self.assertTrue('transform' in dataset.attrs)
        self.assertTrue(np.all(np.isnan(dataset.data[:, :10, :10].compute())))

        # Test masking of floats
        data = self.scn['rgba']
        self.assertRaises(ValueError, mask_image_data, data / 255.)
        data = data.astype(np.uint32)
        self.assertTrue(data.bands.size == 4)
        data = mask_image_data(data)
        self.assertTrue(data.bands.size == 3)
Beispiel #3
0
    def test_GenericImageFileHandler_datasetid(self):
        """Test direct use of the reader."""
        from satpy.readers.generic_image import GenericImageFileHandler

        fname = os.path.join(self.base_dir, 'test_rgba.tif')
        fname_info = {'start_time': self.date}
        ftype_info = {}
        reader = GenericImageFileHandler(fname, fname_info, ftype_info)

        foo = make_dataid(name='image-custom')
        self.assertTrue(reader.file_content, 'file_content should be set')
        dataset = reader.get_dataset(foo, {})
        self.assertTrue(isinstance(dataset, xr.DataArray),
                        'dataset should be a xr.DataArray')
Beispiel #4
0
    def test_GenericImageFileHandler(self):
        """Test direct use of the reader."""
        from satpy.readers.generic_image import GenericImageFileHandler

        fname = os.path.join(self.base_dir, 'test_rgba.tif')
        fname_info = {'start_time': self.date}
        ftype_info = {}
        reader = GenericImageFileHandler(fname, fname_info, ftype_info)

        foo = make_dataid(name='image')
        self.assertTrue(reader.file_content)
        self.assertEqual(reader.finfo['filename'], fname)
        self.assertEqual(reader.finfo['start_time'], self.date)
        self.assertEqual(reader.finfo['end_time'], self.date)
        self.assertEqual(reader.area, self.area_def)
        self.assertEqual(reader.get_area_def(None), self.area_def)
        self.assertEqual(reader.start_time, self.date)
        self.assertEqual(reader.end_time, self.date)

        dataset = reader.get_dataset(foo, {})
        self.assertTrue(isinstance(dataset, xr.DataArray))
        self.assertIn('crs', dataset.attrs)
        self.assertIn('transform', dataset.attrs)
        self.assertTrue(np.all(np.isnan(dataset.data[:, :10, :10].compute())))