Exemplo n.º 1
0
    def create_reader(self, proj_name, proj_attrs, xr_):
        """Create a fake reader."""
        from satpy.readers.scmi import SCMIFileHandler
        proj = xr.DataArray([], attrs=proj_attrs)
        x__ = xr.DataArray(
            [0, 1],
            attrs={'scale_factor': 2., 'add_offset': -1., 'units': 'meters'},
        )
        y__ = xr.DataArray(
            [0, 1],
            attrs={'scale_factor': -2., 'add_offset': 1., 'units': 'meters'},
        )
        xr_.open_dataset.return_value = FakeDataset({
            'goes_imager_projection': proj,
            'x': x__,
            'y': y__,
            'Sectorized_CMI': np.ones((2, 2))},
            {
                'satellite_id': 'GOES-16',
                'grid_mapping': proj_name,
            },
            {
                'y': y__.size,
                'x': x__.size,
            }
        )

        return SCMIFileHandler('filename',
                               {'platform_shortname': 'G16'},
                               {'filetype': 'info'})
Exemplo n.º 2
0
    def setUp(self, xr_):
        """Setup for test."""
        from satpy.readers.scmi import SCMIFileHandler
        rad_data = (np.arange(10.).reshape((2, 5)) + 1.)
        rad_data = (rad_data + 1.) / 0.5
        rad_data = rad_data.astype(np.int16)
        self.expected_rad = rad_data.astype(np.float64) * 0.5 + -1.
        self.expected_rad[-1, -2] = np.nan
        time = xr.DataArray(0.)
        rad = xr.DataArray(rad_data,
                           dims=('y', 'x'),
                           attrs={
                               'scale_factor': 0.5,
                               'add_offset': -1.,
                               '_FillValue': 20,
                               'standard_name':
                               'toa_bidirectional_reflectance',
                           },
                           coords={
                               'time': time,
                           })
        xr_.open_dataset.return_value = FakeDataset(
            {
                'Sectorized_CMI': rad,
                "nominal_satellite_subpoint_lat": np.array(0.0),
                "nominal_satellite_subpoint_lon": np.array(-89.5),
                "nominal_satellite_height": np.array(35786.02),
            },
            {
                'start_date_time': "2017210120000",
                'satellite_id': 'GOES-16',
                'satellite_longitude': -90.,
                'satellite_latitude': 0.,
                'satellite_altitude': 35785831.,
            },
            {
                'y': 2,
                'x': 5
            },
        )

        self.reader = SCMIFileHandler('filename',
                                      {'platform_shortname': 'G16'},
                                      {'filetype': 'info'})
Exemplo n.º 3
0
class TestSCMIFileHandler(unittest.TestCase):
    """Test the SCMIFileHandler reader."""

    @mock.patch('satpy.readers.scmi.xr')
    def setUp(self, xr_):
        """Set up for test."""
        from satpy.readers.scmi import SCMIFileHandler
        rad_data = (np.arange(10.).reshape((2, 5)) + 1.)
        rad_data = (rad_data + 1.) / 0.5
        rad_data = rad_data.astype(np.int16)
        self.expected_rad = rad_data.astype(np.float64) * 0.5 + -1.
        self.expected_rad[-1, -2] = np.nan
        time = xr.DataArray(0.)
        rad = xr.DataArray(
            rad_data,
            dims=('y', 'x'),
            attrs={
                'scale_factor': 0.5,
                'add_offset': -1.,
                '_FillValue': 20,
                'standard_name': 'toa_bidirectional_reflectance',
            },
            coords={
                'time': time,
            }
        )
        xr_.open_dataset.return_value = FakeDataset(
            {
                'Sectorized_CMI': rad,
                "nominal_satellite_subpoint_lat": np.array(0.0),
                "nominal_satellite_subpoint_lon": np.array(-89.5),
                "nominal_satellite_height": np.array(35786.02),
            },
            {
                'start_date_time': "2017210120000",
                'satellite_id': 'GOES-16',
                'satellite_longitude': -90.,
                'satellite_latitude': 0.,
                'satellite_altitude': 35785831.,
            },
            {'y': 2, 'x': 5},
        )

        self.reader = SCMIFileHandler('filename',
                                      {'platform_shortname': 'G16'},
                                      {'filetype': 'info'})

    def test_basic_attributes(self):
        """Test getting basic file attributes."""
        from datetime import datetime

        from satpy.tests.utils import make_dataid
        self.assertEqual(self.reader.start_time,
                         datetime(2017, 7, 29, 12, 0, 0, 0))
        self.assertEqual(self.reader.end_time,
                         datetime(2017, 7, 29, 12, 0, 0, 0))
        self.assertEqual(self.reader.get_shape(make_dataid(name='C05'), {}),
                         (2, 5))

    def test_data_load(self):
        """Test data loading."""
        from satpy.tests.utils import make_dataid
        res = self.reader.get_dataset(
            make_dataid(name='C05', calibration='reflectance'), {})

        np.testing.assert_allclose(res.data, self.expected_rad, equal_nan=True)
        self.assertNotIn('scale_factor', res.attrs)
        self.assertNotIn('_FillValue', res.attrs)
        self.assertEqual(res.attrs['standard_name'],
                         'toa_bidirectional_reflectance')