def prepare_area_defs(self, test_dict): """Prepare calculated and expected area definitions for equal checking.""" earth_model = test_dict['earth_model'] dataset_id = test_dict['dataset_id'] is_full_disk = test_dict['is_full_disk'] header = self.create_test_header(earth_model, dataset_id, is_full_disk) trailer = self.create_test_trailer() expected_area_def = test_dict['expected_area_def'] with mock.patch( 'satpy.readers.seviri_l1b_native.np.fromfile') as fromfile: fromfile.return_value = header with mock.patch('satpy.readers.seviri_l1b_native.recarray2dict' ) as recarray2dict: recarray2dict.side_effect = (lambda x: x) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap' ) as _get_memmap: _get_memmap.return_value = np.arange(3) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer' ): fh = NativeMSGFileHandler(None, {}, None) fh.header = header fh.trailer = trailer calc_area_def = fh.get_area_def(dataset_id) return (calc_area_def, expected_area_def)
def prepare_area_extents(self, test_dict): earth_model = test_dict['earth_model'] dsid = test_dict['dsid'] is_full_disk = test_dict['is_full_disk'] header = self.create_test_header(earth_model, dsid, is_full_disk) expected_area_extent = (np.array(test_dict['expected_area_extent'])) with mock.patch( 'satpy.readers.seviri_l1b_native.np.fromfile') as fromfile: fromfile.return_value = header with mock.patch('satpy.readers.seviri_l1b_native.recarray2dict' ) as recarray2dict: recarray2dict.side_effect = (lambda x: x) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap' ) as _get_memmap: _get_memmap.return_value = np.arange(3) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer' ): fh = NativeMSGFileHandler(None, {}, None) fh.header = header calc_area_extent = np.array(fh.get_area_extent(dsid)) return (calc_area_extent, expected_area_extent)
def file_handler(self): """Create a mocked file handler.""" header = { '15_DATA_HEADER': { 'RadiometricProcessing': { 'Level15ImageCalibration': { 'CalSlope': self.gains_nominal, 'CalOffset': self.offsets_nominal, }, 'MPEFCalFeedback': { 'GSICSCalCoeff': self.gains_gsics, 'GSICSOffsetCount': self.offsets_gsics } }, 'ImageDescription': { 'Level15ImageProduction': { 'PlannedChanProcessing': self.radiance_types } }, 'ImageAcquisition': { 'PlannedAcquisitionTime': { 'TrueRepeatCycleStart': self.scan_time } } } } with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler.__init__', return_value=None): fh = NativeMSGFileHandler() fh.header = header fh.platform_id = self.platform_id return fh
def prepare_is_roi(self, test_dict): """Prepare calculated and expected check for region of interest data for equal checking.""" earth_model = 2 dataset_id = make_dataid(name='VIS006') is_full_disk = test_dict['is_full_disk'] is_rapid_scan = test_dict['is_rapid_scan'] header = self.create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan) trailer = self.create_test_trailer(is_rapid_scan) expected_is_roi = test_dict['is_roi'] with mock.patch( 'satpy.readers.seviri_l1b_native.np.fromfile') as fromfile: fromfile.return_value = header with mock.patch('satpy.readers.seviri_l1b_native.recarray2dict' ) as recarray2dict: recarray2dict.side_effect = (lambda x: x) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap' ) as _get_memmap: _get_memmap.return_value = np.arange(3) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer' ): fh = NativeMSGFileHandler(None, {}, None) fh.header = header fh.trailer = trailer calc_is_roi = fh.is_roi() return (calc_is_roi, expected_is_roi)
def calibration_mode_test(self, test_dict, cal_mode): """Test the Calibration Mode.""" # dummy data array data = xr.DataArray([255., 200., 300.]) earth_model = test_dict['earth_model'] dataset_id = test_dict['dataset_id'] index = CHANNEL_INDEX_LIST.index(dataset_id['name']) # determine the cal coeffs needed for the expected data calculation if cal_mode == 'nominal': cal_slope = test_dict['CalSlope'][index] cal_offset = test_dict['CalOffset'][index] else: cal_slope_arr = test_dict['GSICSCalCoeff'] cal_offset_arr = test_dict['GSICSOffsetCount'] cal_offset = cal_offset_arr[index] * cal_slope_arr[index] cal_slope = cal_slope_arr[index] is_full_disk = test_dict['is_full_disk'] is_rapid_scan = test_dict['is_rapid_scan'] header = self.create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan) with mock.patch( 'satpy.readers.seviri_l1b_native.np.fromfile') as fromfile: fromfile.return_value = header with mock.patch('satpy.readers.seviri_l1b_native.recarray2dict' ) as recarray2dict: recarray2dict.side_effect = (lambda x: x) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap' ) as _get_memmap: _get_memmap.return_value = np.arange(3) with mock.patch( 'satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer' ): # Create an instance of the native msg reader # with the calibration mode to test fh = NativeMSGFileHandler(None, {}, None, calib_mode=cal_mode) # Calculate the expected calibration values using the coeffs # from the test data set expected = fh._convert_to_radiance( data, cal_slope, cal_offset) # Calculate the calibrated values using the cal coeffs from the # test header and using the correct calibration mode values fh.header = header calculated = fh.calibrate(data, dataset_id) return (expected.data, calculated.data)