Example #1
0
    def test_read_band(self, calibrate, *mocks):
        # Test masking of space pixels
        nrows = 25
        ncols = 100
        self.fh.area = AreaDefinition(
            'test', 'test', 'test', {
                'a': '6378137.0',
                'b': '6356752.3',
                'h': '35785863.0',
                'lon_0': '140.7',
                'proj': 'geos',
                'units': 'm'
            }, ncols, nrows, [
                -5499999.901174725, -4399999.92093978, 5499999.901174725,
                -3299999.9407048346
            ])
        calibrate.return_value = np.ones((nrows, ncols))
        m = mock.mock_open()
        with mock.patch('satpy.readers.ahi_hsd.open', m, create=True):
            im = self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
            # Note: Within the earth's shape get_geostationary_mask() is True but the numpy.ma mask
            # is False
            mask = im.to_masked_array().mask
            ref_mask = np.logical_not(
                get_geostationary_mask(self.fh.area).compute())
            self.assertTrue(np.all(mask == ref_mask))

            # Test if masking space pixels disables with appropriate flag
            self.fh.mask_space = False
            with mock.patch(
                    'satpy.readers.ahi_hsd.AHIHSDFileHandler._mask_space'
            ) as mask_space:
                self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
                mask_space.assert_not_called()
Example #2
0
    def test_read_band(self, calibrate, *mocks):
        """Test masking of space pixels."""
        nrows = 25
        ncols = 100
        self.fh.area = AreaDefinition('test', 'test', 'test',
                                      {'a': '6378137.0', 'b': '6356752.3', 'h': '35785863.0', 'lon_0': '140.7',
                                       'proj': 'geos', 'units': 'm'},
                                      ncols, nrows,
                                      [-5499999.901174725, -4399999.92093978, 5499999.901174725, -3299999.9407048346])
        calibrate.return_value = np.ones((nrows, ncols))
        m = mock.mock_open()
        with mock.patch('satpy.readers.ahi_hsd.open', m, create=True):
            im = self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
            # Note: Within the earth's shape get_geostationary_mask() is True but the numpy.ma mask
            # is False
            mask = im.to_masked_array().mask
            ref_mask = np.logical_not(get_geostationary_mask(self.fh.area).compute())
            self.assertTrue(np.all(mask == ref_mask))

            # Test attributes
            orb_params_exp = {'projection_longitude': 140.7,
                              'projection_latitude': 0.,
                              'projection_altitude': 35785863.0,
                              'satellite_actual_longitude': 140.66,
                              'satellite_actual_latitude': 0.03,
                              'nadir_longitude': 140.67,
                              'nadir_latitude': 0.04}
            self.assertTrue(set(orb_params_exp.items()).issubset(set(im.attrs['orbital_parameters'].items())))
            self.assertTrue(np.isclose(im.attrs['orbital_parameters']['satellite_actual_altitude'], 35786903.00581372))

            # Test if masking space pixels disables with appropriate flag
            self.fh.mask_space = False
            with mock.patch('satpy.readers.ahi_hsd.AHIHSDFileHandler._mask_space') as mask_space:
                self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
                mask_space.assert_not_called()
Example #3
0
    def test_scene_loading(self, calibrate, *mocks):
        """Test masking of space pixels."""
        from satpy import Scene
        nrows = 25
        ncols = 100
        calibrate.return_value = np.ones((nrows, ncols))
        m = mock.mock_open()
        with mock.patch('satpy.readers.ahi_hsd.open', m, create=True), \
             mock.patch('satpy.readers.ahi_hsd.AHIHSDFileHandler') as fh_cls:
            fh_cls.return_value = self.fh
            self.fh.filename_info['total_segments'] = 1
            self.fh.filename_info['segment'] = 1
            self.fh.data_info['number_of_columns'] = ncols
            self.fh.data_info['number_of_lines'] = nrows
            scn = Scene(
                reader='ahi_hsd',
                filenames=['HS_H08_20210225_0700_B07_FLDK_R20_S0110.DAT'])
            scn.load(['B07'])
            im = scn['B07']

            # Make sure space masking worked
            mask = im.to_masked_array().mask
            ref_mask = np.logical_not(
                get_geostationary_mask(self.fh.area).compute())
            self.assertTrue(np.all(mask == ref_mask))
Example #4
0
    def test_read_band(self, calibrate, *mocks):
        """Test masking of space pixels."""
        nrows = 25
        ncols = 100
        self.fh.data_info['number_of_columns'] = ncols
        self.fh.data_info['number_of_lines'] = nrows
        calibrate.return_value = np.ones((nrows, ncols))
        m = mock.mock_open()
        with mock.patch('satpy.readers.ahi_hsd.open', m, create=True):
            im = self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
            # Note: Within the earth's shape get_geostationary_mask() is True but the numpy.ma mask
            # is False
            mask = im.to_masked_array().mask
            ref_mask = np.logical_not(get_geostationary_mask(self.fh.area).compute())
            self.assertTrue(np.all(mask == ref_mask))

            # Test attributes
            orb_params_exp = {'projection_longitude': 140.7,
                              'projection_latitude': 0.,
                              'projection_altitude': 35785863.0,
                              'satellite_actual_longitude': 140.66,
                              'satellite_actual_latitude': 0.03,
                              'nadir_longitude': 140.67,
                              'nadir_latitude': 0.04}
            self.assertTrue(set(orb_params_exp.items()).issubset(set(im.attrs['orbital_parameters'].items())))
            self.assertTrue(np.isclose(im.attrs['orbital_parameters']['satellite_actual_altitude'], 35786903.00581372))

            # Test if masking space pixels disables with appropriate flag
            self.fh.mask_space = False
            with mock.patch('satpy.readers.ahi_hsd.AHIHSDFileHandler._mask_space') as mask_space:
                self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
                mask_space.assert_not_called()
Example #5
0
    def test_read_band(self, calibrate, *mocks):
        """Test masking of space pixels."""
        nrows = 25
        ncols = 100
        calibrate.return_value = np.ones((nrows, ncols))
        with _fake_hsd_handler() as fh:
            fh.data_info['number_of_columns'] = ncols
            fh.data_info['number_of_lines'] = nrows
            im = fh.read_band(mock.MagicMock(), mock.MagicMock())
            # Note: Within the earth's shape get_geostationary_mask() is True but the numpy.ma mask
            # is False
            mask = im.to_masked_array().mask
            ref_mask = np.logical_not(
                get_geostationary_mask(fh.area).compute())
            np.testing.assert_equal(mask, ref_mask)

            # Test attributes
            orb_params_exp = {
                'projection_longitude': 140.7,
                'projection_latitude': 0.,
                'projection_altitude': 35785863.0,
                'satellite_actual_longitude': 140.657,
                'satellite_actual_latitude': 0.0,
                'satellite_actual_altitude': 35786850,
                'nadir_longitude': 140.252539,
                'nadir_latitude': 0.01674775
            }
            actual_obs_params = im.attrs['orbital_parameters']
            for key, value in orb_params_exp.items():
                assert key in actual_obs_params
                np.testing.assert_allclose(value, actual_obs_params[key])

            time_params_exp = {
                'nominal_start_time': datetime(2018, 10, 22, 3, 0, 0, 0),
                'nominal_end_time': datetime(2018, 10, 22, 3, 0, 0, 0),
                'observation_start_time': datetime(2018, 10, 22, 3, 0, 20,
                                                   596896),
                'observation_end_time': datetime(2018, 10, 22, 3, 0, 53,
                                                 947296),
            }
            actual_time_params = im.attrs['time_parameters']
            for key, value in time_params_exp.items():
                assert key in actual_time_params
                assert value == actual_time_params[key]

            # Test if masking space pixels disables with appropriate flag
            fh.mask_space = False
            with mock.patch(
                    'satpy.readers.ahi_hsd.AHIHSDFileHandler._mask_space'
            ) as mask_space:
                fh.read_band(mock.MagicMock(), mock.MagicMock())
                mask_space.assert_not_called()
Example #6
0
    def test_geostationary_mask(self):
        """Test geostationary mask"""
        # Compute mask of a very elliptical earth
        area = pyresample.geometry.AreaDefinition(
            area_id='FLDK',
            name='Full Disk',
            proj_id='geos',
            proj_dict={
                'a': '6378169.0',
                'b': '3000000.0',
                'h': '35785831.0',
                'lon_0': '145.0',
                'proj': 'geos',
                'units': 'm'
            },
            x_size=101,
            y_size=101,
            area_extent=(-6498000.088960204, -6498000.088960204,
                         6502000.089024927, 6502000.089024927))

        mask = hf.get_geostationary_mask(area).astype(np.int).compute()

        # Check results along a couple of lines
        # a) Horizontal
        self.assertTrue(np.all(mask[50, :8] == 0))
        self.assertTrue(np.all(mask[50, 8:93] == 1))
        self.assertTrue(np.all(mask[50, 93:] == 0))

        # b) Vertical
        self.assertTrue(np.all(mask[:31, 50] == 0))
        self.assertTrue(np.all(mask[31:70, 50] == 1))
        self.assertTrue(np.all(mask[70:, 50] == 0))

        # c) Top left to bottom right
        self.assertTrue(np.all(mask[range(33), range(33)] == 0))
        self.assertTrue(np.all(mask[range(33, 68), range(33, 68)] == 1))
        self.assertTrue(np.all(mask[range(68, 101), range(68, 101)] == 0))

        # d) Bottom left to top right
        self.assertTrue(
            np.all(mask[range(101 - 1, 68 - 1, -1),
                        range(33)] == 0))
        self.assertTrue(
            np.all(mask[range(68 - 1, 33 - 1, -1),
                        range(33, 68)] == 1))
        self.assertTrue(
            np.all(mask[range(33 - 1, -1, -1),
                        range(68, 101)] == 0))
Example #7
0
 def test_read_band(self, calibrate, *mocks):
     # Test masking of space pixels
     nrows = 25
     ncols = 100
     self.fh.area = AreaDefinition(name='test', area_id='test', proj_id='test',
                                   proj_dict={'a': '6378137.0', 'b': '6356752.3',
                                              'h': '35785863.0', 'lon_0': '140.7',
                                              'proj': 'geos', 'units': 'm'},
                                   x_size=ncols, y_size=nrows,
                                   area_extent=[-5499999.901174725, -4399999.92093978,
                                                5499999.901174725, -3299999.9407048346])
     calibrate.return_value = np.ones((nrows, ncols))
     m = mock.mock_open()
     with mock.patch('satpy.readers.ahi_hsd.open', m, create=True):
         im = self.fh.read_band(info=mock.MagicMock(), key=mock.MagicMock())
         # Note: Within the earth's shape get_geostationary_mask() is True but the numpy.ma mask
         # is False
         mask = im.to_masked_array().mask
         ref_mask = np.logical_not(get_geostationary_mask(self.fh.area).compute())
         self.assertTrue(np.all(mask == ref_mask))
Example #8
0
 def _mask_space(self, data):
     """Mask space pixels"""
     return data.where(get_geostationary_mask(self.area))
Example #9
0
 def _mask_space(self, data):
     """Mask space pixels."""
     return data.where(get_geostationary_mask(self.area,
                                              chunks=data.chunks))
Example #10
0
 def _mask_space(self, data):
     """Mask space pixels."""
     geomask = get_geostationary_mask(area=self.area)
     return data.where(geomask)