def setUp(self, fromfile, np2str): """Create a test file handler.""" np2str.side_effect = lambda x: x m = mock.mock_open() with mock.patch('satpy.readers.ahi_hsd.open', m, create=True): # Check if file handler raises exception for invalid calibration mode with self.assertRaises(ValueError): fh = AHIHSDFileHandler(None, { 'segment_number': 8, 'total_segments': 10 }, None, calib_mode='BAD_MODE') fh = AHIHSDFileHandler(None, { 'segment_number': 8, 'total_segments': 10 }, None) fh.proj_info = { 'CFAC': 40932549, 'COFF': 5500.5, 'LFAC': 40932549, 'LOFF': 5500.5, 'blocklength': 127, 'coeff_for_sd': 1737122264.0, 'distance_from_earth_center': 42164.0, 'earth_equatorial_radius': 6378.137, 'earth_polar_radius': 6356.7523, 'hblock_number': 3, 'req2_rpol2': 1.006739501, 'req2_rpol2_req2': 0.0066943844, 'resampling_size': 4, 'resampling_types': 0, 'rpol2_req2': 0.993305616, 'spare': '', 'sub_lon': 140.7 } fh.nav_info = { 'SSP_longitude': 140.66, 'SSP_latitude': 0.03, 'distance_earth_center_to_satellite': 42165.04, 'nadir_longitude': 140.67, 'nadir_latitude': 0.04 } fh.data_info = { 'blocklength': 50, 'compression_flag_for_data': 0, 'hblock_number': 2, 'number_of_bits_per_pixel': 16, 'number_of_columns': 11000, 'number_of_lines': 1100, 'spare': '' } fh.basic_info = { 'observation_start_time': np.array([58413.12523839]), 'observation_end_time': np.array([58413.12562439]), 'observation_timeline': np.array([300]), } self.fh = fh
def _create_fake_file_handler(in_fname, filename_info=None, filetype_info=None): if filename_info is None: filename_info = {'segment': 8, 'total_segments': 10} if filetype_info is None: filetype_info = {'file_type': 'hsd_b01'} fh = AHIHSDFileHandler(in_fname, filename_info, filetype_info) # Check that the filename is altered for bz2 format files assert in_fname != fh.filename fh.proj_info = { 'CFAC': 40932549, 'COFF': 5500.5, 'LFAC': 40932549, 'LOFF': 5500.5, 'blocklength': 127, 'coeff_for_sd': 1737122264.0, 'distance_from_earth_center': 42164.0, 'earth_equatorial_radius': 6378.137, 'earth_polar_radius': 6356.7523, 'hblock_number': 3, 'req2_rpol2': 1.006739501, 'req2_rpol2_req2': 0.0066943844, 'resampling_size': 4, 'resampling_types': 0, 'rpol2_req2': 0.993305616, 'spare': '', 'sub_lon': 140.7 } fh.nav_info = { 'SSP_longitude': 140.66, 'SSP_latitude': 0.03, 'distance_earth_center_to_satellite': 42165.04, 'nadir_longitude': 140.67, 'nadir_latitude': 0.04 } fh.data_info = { 'blocklength': 50, 'compression_flag_for_data': 0, 'hblock_number': 2, 'number_of_bits_per_pixel': 16, 'number_of_columns': 11000, 'number_of_lines': 1100, 'spare': '' } fh.basic_info = { 'observation_area': np.array(['FLDK']), 'observation_start_time': np.array([58413.12523839]), 'observation_end_time': np.array([58413.12562439]), 'observation_timeline': np.array([300]), } fh.observation_area = fh.basic_info['observation_area'] return fh
def test_region(self, fromfile, np2str): """Test region navigation.""" from pyresample.utils import proj4_radius_parameters np2str.side_effect = lambda x: x m = mock.mock_open() with mock.patch('satpy.readers.ahi_hsd.open', m, create=True): fh = AHIHSDFileHandler('somefile', { 'segment': 1, 'total_segments': 1 }, filetype_info={'file_type': 'hsd_b01'}, user_calibration=None) fh.proj_info = { 'CFAC': 40932549, 'COFF': -591.5, 'LFAC': 40932549, 'LOFF': 5132.5, 'blocklength': 127, 'coeff_for_sd': 1737122264.0, 'distance_from_earth_center': 42164.0, 'earth_equatorial_radius': 6378.137, 'earth_polar_radius': 6356.7523, 'hblock_number': 3, 'req2_rpol2': 1.006739501, 'req2_rpol2_req2': 0.0066943844, 'resampling_size': 4, 'resampling_types': 0, 'rpol2_req2': 0.993305616, 'spare': '', 'sub_lon': 140.7 } fh.data_info = { 'blocklength': 50, 'compression_flag_for_data': 0, 'hblock_number': 2, 'number_of_bits_per_pixel': 16, 'number_of_columns': 1000, 'number_of_lines': 1000, 'spare': '' } area_def = fh.get_area_def(None) proj_dict = area_def.proj_dict a, b = proj4_radius_parameters(proj_dict) self.assertEqual(a, 6378137.0) self.assertEqual(b, 6356752.3) self.assertEqual(proj_dict['h'], 35785863.0) self.assertEqual(proj_dict['lon_0'], 140.7) self.assertEqual(proj_dict['proj'], 'geos') self.assertEqual(proj_dict['units'], 'm') np.testing.assert_allclose(area_def.area_extent, (592000.0038256242, 4132000.0267018233, 1592000.0102878273, 5132000.033164027))
def test_segment(self, fromfile, np2str): """Test segment navigation.""" np2str.side_effect = lambda x: x m = mock.mock_open() with mock.patch('satpy.readers.ahi_hsd.open', m, create=True): fh = AHIHSDFileHandler(None, { 'segment_number': 8, 'total_segments': 10 }, None) fh.proj_info = { 'CFAC': 40932549, 'COFF': 5500.5, 'LFAC': 40932549, 'LOFF': 5500.5, 'blocklength': 127, 'coeff_for_sd': 1737122264.0, 'distance_from_earth_center': 42164.0, 'earth_equatorial_radius': 6378.137, 'earth_polar_radius': 6356.7523, 'hblock_number': 3, 'req2_rpol2': 1.006739501, 'req2_rpol2_req2': 0.0066943844, 'resampling_size': 4, 'resampling_types': 0, 'rpol2_req2': 0.993305616, 'spare': '', 'sub_lon': 140.7 } fh.data_info = { 'blocklength': 50, 'compression_flag_for_data': 0, 'hblock_number': 2, 'number_of_bits_per_pixel': 16, 'number_of_columns': 11000, 'number_of_lines': 1100, 'spare': '' } area_def = fh.get_area_def(None) self.assertEqual( area_def.proj_dict, { 'a': 6378137.0, 'b': 6356752.3, 'h': 35785863.0, 'lon_0': 140.7, 'proj': 'geos', 'units': 'm' }) self.assertEqual(area_def.area_extent, (-5500000.035542117, -3300000.021325271, 5500000.035542117, -2200000.0142168473))
def test_segment(self, fromfile, np2str): """Test segment navigation.""" np2str.side_effect = lambda x: x m = mock.mock_open() with mock.patch('satpy.readers.ahi_hsd.open', m, create=True): fh = AHIHSDFileHandler(None, {'segment_number': 8, 'total_segments': 10}, None) fh.proj_info = {'CFAC': 40932549, 'COFF': 5500.5, 'LFAC': 40932549, 'LOFF': 5500.5, 'blocklength': 127, 'coeff_for_sd': 1737122264.0, 'distance_from_earth_center': 42164.0, 'earth_equatorial_radius': 6378.137, 'earth_polar_radius': 6356.7523, 'hblock_number': 3, 'req2_rpol2': 1.006739501, 'req2_rpol2_req2': 0.0066943844, 'resampling_size': 4, 'resampling_types': 0, 'rpol2_req2': 0.993305616, 'spare': '', 'sub_lon': 140.7} fh.data_info = {'blocklength': 50, 'compression_flag_for_data': 0, 'hblock_number': 2, 'number_of_bits_per_pixel': 16, 'number_of_columns': 11000, 'number_of_lines': 1100, 'spare': ''} area_def = fh.get_area_def(None) self.assertEqual(area_def.proj_dict, {'a': 6378137.0, 'b': 6356752.3, 'h': 35785863.0, 'lon_0': 140.7, 'proj': 'geos', 'units': 'm'}) self.assertEqual(area_def.area_extent, (-5500000.035542117, -3300000.021325271, 5500000.035542117, -2200000.0142168473))