Exemple #1
0
    def test_get_user_calibration_factors(self):
        """Test the retrieval of user-supplied calibration factors."""
        radcor_dict = {
            'WV063': {
                'slope': 1.015,
                'offset': -0.0556
            },
            'IR108': {
                'slo': 1.015,
                'off': -0.0556
            }
        }
        # Test that correct values are returned from the dict
        slope, offset = hf.get_user_calibration_factors('WV063', radcor_dict)
        self.assertEqual(slope, 1.015)
        self.assertEqual(offset, -0.0556)

        # Test that channels not present in dict return 1.0, 0.0
        with self.assertWarns(UserWarning):
            slope, offset = hf.get_user_calibration_factors(
                'IR097', radcor_dict)
        self.assertEqual(slope, 1.)
        self.assertEqual(offset, 0.)

        # Check that incorrect dict keys throw an error
        with self.assertRaises(KeyError):
            hf.get_user_calibration_factors('IR108', radcor_dict)
Exemple #2
0
    def convert_to_radiance(self, data):
        """Calibrate to radiance."""
        bnum = self._header["block5"]['band_number'][0]
        # Check calibration mode and select corresponding coefficients
        if self.calib_mode == "UPDATE" and bnum < 7:
            dn_gain = self._header['calibration'][
                "cali_gain_count2rad_conversion"][0]
            dn_offset = self._header['calibration'][
                "cali_offset_count2rad_conversion"][0]
            if dn_gain == 0 and dn_offset == 0:
                logger.info(
                    "No valid updated coefficients, fall back to default values."
                )
                dn_gain = self._header["block5"]["gain_count2rad_conversion"][
                    0]
                dn_offset = self._header["block5"][
                    "offset_count2rad_conversion"][0]
        else:
            dn_gain = self._header["block5"]["gain_count2rad_conversion"][0]
            dn_offset = self._header["block5"]["offset_count2rad_conversion"][
                0]

        # Assume no user correction
        correction_type = None
        if isinstance(self.user_calibration, dict):
            # Check if we have DN correction coeffs
            if 'type' in self.user_calibration:
                correction_type = self.user_calibration['type']
            else:
                # If not, assume radiance correction
                correction_type = 'RAD'
            if correction_type == 'DN':
                # Replace file calibration with user calibration
                dn_gain, dn_offset = get_user_calibration_factors(
                    self.band_name, self.user_calibration)
            elif correction_type == 'RAD':
                user_slope, user_offset = get_user_calibration_factors(
                    self.band_name, self.user_calibration)

        data = (data * dn_gain + dn_offset).clip(0)
        # If using radiance correction factors from GSICS or similar, apply here
        if correction_type == 'RAD':
            data = apply_rad_correction(data, user_slope, user_offset)
        return data
Exemple #3
0
 def _apply_user_rad_correction(self, data):
     """Retrieve user-supplied radiance correction and apply."""
     rad_slope, rad_offset = get_user_calibration_factors(
         self.band_name, self.user_calibration)
     data = apply_rad_correction(data, rad_slope, rad_offset)
     return data