def _check(self, factors=1, values=111): # Prepare the arguments. series = mock.sentinel.satelliteSeries number = mock.sentinel.satelliteNumber instrument = mock.sentinel.instrumentType section = { 'NB': 1, 'satelliteSeries': series, 'satelliteNumber': number, 'instrumentType': instrument, 'scaleFactorOfCentralWaveNumber': factors, 'scaledValueOfCentralWaveNumber': values } # Call the function. metadata = empty_metadata() satellite_common(section, metadata) # Check the result. expected = empty_metadata() coord = AuxCoord(series, long_name='satellite_series') expected['aux_coords_and_dims'].append((coord, None)) coord = AuxCoord(number, long_name='satellite_number') expected['aux_coords_and_dims'].append((coord, None)) coord = AuxCoord(instrument, long_name='instrument_type') expected['aux_coords_and_dims'].append((coord, None)) standard_name = 'sensor_band_central_radiation_wavenumber' coord = AuxCoord(values / (10.0**factors), standard_name=standard_name, units='m-1') expected['aux_coords_and_dims'].append((coord, None)) self.assertEqual(metadata, expected)
def _check(self, factors=1, values=111): # Prepare the arguments. series = mock.sentinel.satelliteSeries number = mock.sentinel.satelliteNumber instrument = mock.sentinel.instrumentType section = {'NB': 1, 'satelliteSeries': series, 'satelliteNumber': number, 'instrumentType': instrument, 'scaleFactorOfCentralWaveNumber': factors, 'scaledValueOfCentralWaveNumber': values} # Call the function. metadata = empty_metadata() satellite_common(section, metadata) # Check the result. expected = empty_metadata() coord = AuxCoord(series, long_name='satellite_series') expected['aux_coords_and_dims'].append((coord, None)) coord = AuxCoord(number, long_name='satellite_number') expected['aux_coords_and_dims'].append((coord, None)) coord = AuxCoord(instrument, long_name='instrument_type') expected['aux_coords_and_dims'].append((coord, None)) standard_name = 'sensor_band_central_radiation_wavenumber' coord = AuxCoord(values / (10.0 ** factors), standard_name=standard_name, units='m-1') expected['aux_coords_and_dims'].append((coord, None)) self.assertEqual(metadata, expected)
def test_constituent_type(self): metadata = empty_metadata() rt_coord = iris.coords.DimCoord(24, 'forecast_reference_time', units='hours since epoch') product_definition_template_40(self.section_4, metadata, rt_coord) expected = empty_metadata() expected['attributes']['WMO_constituent_type'] = 1 self.assertEqual(metadata['attributes'], expected['attributes'])
def test_constituent_type(self): metadata = empty_metadata() rt_coord = iris.coords.DimCoord(24, 'forecast_reference_time', units='hours since epoch') product_definition_template_40(self.section_4, metadata, rt_coord) expected = empty_metadata() expected['attributes']['WMO_constituent_type'] = 1 self.assertEqual(metadata['attributes'], expected['attributes'])
def test_given_frt(self): metadata = empty_metadata() rt_coord = iris.coords.DimCoord(24, 'forecast_reference_time', units='hours since epoch') product_definition_template_0(section_4(), metadata, rt_coord) expected = empty_metadata() aux = expected['aux_coords_and_dims'] aux.append((iris.coords.DimCoord(6, 'forecast_period', units='hours'), None)) aux.append(( iris.coords.DimCoord(30, 'time', units='hours since epoch'), None)) aux.append((rt_coord, None)) aux.append((iris.coords.DimCoord(9999, long_name='height', units='m'), None)) self.assertMetadataEqual(metadata, expected)
def test_given_t(self): metadata = empty_metadata() rt_coord = iris.coords.DimCoord(24, 'time', units='hours since epoch') product_definition_template_0(section_4(), metadata, rt_coord) expected = empty_metadata() aux = expected['aux_coords_and_dims'] aux.append((iris.coords.DimCoord(6, 'forecast_period', units='hours'), None)) aux.append((iris.coords.DimCoord(18, 'forecast_reference_time', units='hours since epoch'), None)) aux.append((rt_coord, None)) aux.append((iris.coords.DimCoord(9999, long_name='height', units='m'), None)) self.assertMetadataEqual(metadata, expected)
def expected_uk(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() major = 6378168.8 ellipsoid = iris.coord_systems.GeogCS(major, 6356584.0) height = (6610674e-6 - 1) * major lat = lon = 0 easting = northing = 0 cs = iris.coord_systems.VerticalPerspective(lat, lon, height, easting, northing, ellipsoid) nx = 390 x_origin = 369081.56145444815 dx = -3000.663101255676 x = iris.coords.DimCoord(np.arange(nx) * dx + x_origin, 'projection_x_coordinate', units='m', coord_system=cs) ny = 227 y_origin = 4392884.59201891 dy = 3000.604229521113 y = iris.coords.DimCoord(np.arange(ny) * dy + y_origin, 'projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def expected(self, y_dim, x_dim, y_neg=True): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) nx = 16 dx = 22.5 x_origin = 0 x = iris.coords.DimCoord(np.arange(nx) * dx + x_origin, standard_name='longitude', units='degrees_east', coord_system=cs, circular=True) y_points = np.array([73.79921363, 52.81294319, 31.70409175, 10.56988231, -10.56988231, -31.70409175, -52.81294319, -73.79921363]) if not y_neg: y_points = y_points[::-1] y = iris.coords.DimCoord(y_points, standard_name='latitude', units='degrees_north', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test_orthographic(self): section = self.uk() section['Nr'] = MDI metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'orthographic'): grid_definition_template_90(section, metadata)
def test_rotated_meridian(self): section = self.uk() section['orientationOfTheGrid'] = 1 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'orientation'): grid_definition_template_90(section, metadata)
def test_non_zero_latitude(self): section = self.uk() section['latitudeOfSubSatellitePoint'] = 1 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'non-zero latitude'): grid_definition_template_90(section, metadata)
def test_uk_transposed(self): section = self.uk() section['scanningMode'] = 0b11100000 metadata = empty_metadata() grid_definition_template_90(section, metadata) expected = self.expected_uk(1, 0) self.compare(metadata, expected)
def test_transposed(self): section = self.section_3() section["scanningMode"] = 0b01100000 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(1, 0) self.assertEqual(metadata, expected)
def test_negative_y(self): section = self.section_3() section['scanningMode'] = 0b00000000 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, '-y scanning'): grid_definition_template_12(section, metadata)
def test_reverse_latitude(self): section = self.section_3() section['scanningMode'] = 0b00000000 metadata = empty_metadata() grid_definition_template_40(section, metadata) expected = self.expected(0, 1, y_neg=True) self.assertEqual(metadata, expected)
def test_orthographic(self): section = self.uk() section['Nr'] = MDI metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'orthographic'): grid_definition_template_90(section, metadata)
def test(self): # Prepare the arguments. series = mock.sentinel.satelliteSeries number = mock.sentinel.satelliteNumber instrument = mock.sentinel.instrumentType rt_coord = mock.sentinel.observation_time section = { 'NB': 1, 'satelliteSeries': series, 'satelliteNumber': number, 'instrumentType': instrument, 'scaleFactorOfCentralWaveNumber': 1, 'scaledValueOfCentralWaveNumber': 12 } # Call the function. metadata = empty_metadata() product_definition_template_31(section, metadata, rt_coord) # Check that 'satellite_common' was called. self.assertEqual(self.satellite_common_patch.call_count, 1) # Check that 'generating_process' was called. self.assertEqual(self.generating_process_patch.call_count, 1) # Check that the scalar time coord was added in. self.assertIn((rt_coord, None), metadata['aux_coords_and_dims'])
def test_percentile_coord(self): metadata = empty_metadata() percentileValue = 75 section = { 'percentileValue': percentileValue, 'hoursAfterDataCutoff': 1, 'minutesAfterDataCutoff': 1, 'numberOfTimeRange': 1, 'typeOfStatisticalProcessing': 1, 'typeOfTimeIncrement': 2, 'timeIncrement': 0, 'yearOfEndOfOverallTimeInterval': 2000, 'monthOfEndOfOverallTimeInterval': 1, 'dayOfEndOfOverallTimeInterval': 1, 'hourOfEndOfOverallTimeInterval': 1, 'minuteOfEndOfOverallTimeInterval': 0, 'secondOfEndOfOverallTimeInterval': 1 } forecast_reference_time = mock.Mock() # The called being tested. product_definition_template_10(section, metadata, forecast_reference_time) expected = {'aux_coords_and_dims': []} percentile = DimCoord(percentileValue, long_name='percentile_over_time', units='no_unit') expected['aux_coords_and_dims'].append((percentile, None)) self.assertEqual(metadata['aux_coords_and_dims'][-1], expected['aux_coords_and_dims'][0])
def test_zero_height(self): section = self.uk() section['Nr'] = 0 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'zero'): grid_definition_template_90(section, metadata)
def test_negative_y(self): section = self.section_3() section['scanningMode'] = 0b00000000 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, '-y scanning'): grid_definition_template_12(section, metadata)
def expected(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) cs = iris.coord_systems.LambertConformal( central_lat=60., central_lon=262., false_easting=0, false_northing=0, secant_latitudes=(60., 30.), ellipsoid=iris.coord_systems.GeogCS(6367470)) lon0 = 239.55 lat0 = 21.641 x0m, y0m = cs.as_cartopy_crs().transform_point( lon0, lat0, ccrs.Geodetic()) dxm = dym = 320000. x_points = x0m + dxm * np.arange(15) y_points = y0m + dym * np.arange(10) x = iris.coords.DimCoord(x_points, standard_name='projection_x_coordinate', units='m', coord_system=cs, circular=False) y = iris.coords.DimCoord(y_points, standard_name='projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test_percentile_coord(self): metadata = empty_metadata() percentileValue = 75 section = {'productDefinitionTemplateNumber': 10, 'percentileValue': percentileValue, 'hoursAfterDataCutoff': 1, 'minutesAfterDataCutoff': 1, 'numberOfTimeRange': 1, 'typeOfStatisticalProcessing': 1, 'typeOfTimeIncrement': 2, 'timeIncrement': 0, 'yearOfEndOfOverallTimeInterval': 2000, 'monthOfEndOfOverallTimeInterval': 1, 'dayOfEndOfOverallTimeInterval': 1, 'hourOfEndOfOverallTimeInterval': 1, 'minuteOfEndOfOverallTimeInterval': 0, 'secondOfEndOfOverallTimeInterval': 1} forecast_reference_time = mock.Mock() # The called being tested. product_definition_template_10(section, metadata, forecast_reference_time) expected = {'aux_coords_and_dims': []} percentile = DimCoord(percentileValue, long_name='percentile_over_time', units='no_unit') expected['aux_coords_and_dims'].append((percentile, None)) self.assertEqual(metadata['aux_coords_and_dims'][-1], expected['aux_coords_and_dims'][0])
def test_transposed(self): section = self.section_3() section['scanningMode'] = 0b01100000 metadata = empty_metadata() grid_definition_template_40(section, metadata) expected = self.expected(1, 0, y_neg=False) self.assertEqual(metadata, expected)
def test(self, value=10, factor=1): # Prepare the arguments. series = mock.sentinel.satelliteSeries number = mock.sentinel.satelliteNumber instrument = mock.sentinel.instrumentType rt_coord = mock.sentinel.observation_time section = { 'NB': 1, 'hoursAfterDataCutoff': None, 'minutesAfterDataCutoff': None, 'satelliteSeries': series, 'satelliteNumber': number, 'instrumentType': instrument, 'scaleFactorOfCentralWaveNumber': 1, 'scaledValueOfCentralWaveNumber': 12, } # Call the function. metadata = empty_metadata() product_definition_template_32(section, metadata, rt_coord) # Check that 'satellite_common' was called. self.assertEqual(self.satellite_common_patch.call_count, 1) # Check that 'generating_process' was called. self.assertEqual(self.generating_process_patch.call_count, 1) # Check that 'data_cutoff' was called. self.assertEqual(self.data_cutoff_patch.call_count, 1) # Check that 'time_coords' was called. self.assertEqual(self.time_coords_patch.call_count, 1)
def expected(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) cs = iris.coord_systems.Stereographic( central_lat=90., central_lon=262., false_easting=0, false_northing=0, true_scale_lat=60., ellipsoid=iris.coord_systems.GeogCS(6367470)) lon0 = 225385728 * 1e-6 lat0 = 32549114 * 1e-6 x0m, y0m = cs.as_cartopy_crs().transform_point(lon0, lat0, ccrs.Geodetic()) dxm = dym = 320000. x_points = x0m + dxm * np.arange(15) y_points = y0m + dym * np.arange(10) x = iris.coords.DimCoord(x_points, standard_name='projection_x_coordinate', units='m', coord_system=cs, circular=False) y = iris.coords.DimCoord(y_points, standard_name='projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test_transposed(self): section = self.section_3() section['scanningMode'] = 0b01100000 metadata = empty_metadata() grid_definition_template_40(section, metadata) expected = self.expected(1, 0, y_neg=False) self.assertEqual(metadata, expected)
def expected(self, y_dim, x_dim, y_neg=True): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) nx = 16 dx = 22.5 x_origin = 0 x = iris.coords.DimCoord(np.arange(nx) * dx + x_origin, standard_name='longitude', units='degrees_east', coord_system=cs, circular=True) y_points = np.array([ 73.79921363, 52.81294319, 31.70409175, 10.56988231, -10.56988231, -31.70409175, -52.81294319, -73.79921363 ]) if not y_neg: y_points = y_points[::-1] y = iris.coords.DimCoord(y_points, standard_name='latitude', units='degrees_north', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test_incompatible_grid_extent(self): section = self.section_3() section['X2'] += 100 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'grid'): grid_definition_template_12(section, metadata)
def test_reverse_latitude(self): section = self.section_3() section['scanningMode'] = 0b00000000 metadata = empty_metadata() grid_definition_template_40(section, metadata) expected = self.expected(0, 1, y_neg=True) self.assertEqual(metadata, expected)
def test_non_zero_latitude(self): section = self.uk() section['latitudeOfSubSatellitePoint'] = 1 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'non-zero latitude'): grid_definition_template_90(section, metadata)
def expected_uk(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() major = 6378168.8 ellipsoid = iris.coord_systems.GeogCS(major, 6356584.0) height = (6610674e-6 - 1) * major lat = lon = 0 easting = northing = 0 cs = iris.coord_systems.VerticalPerspective(lat, lon, height, easting, northing, ellipsoid) nx = 390 x_origin = 369081.56145444815 dx = -3000.663101255676 x = iris.coords.DimCoord(np.arange(nx) * dx + x_origin, 'projection_x_coordinate', units='m', coord_system=cs) ny = 227 y_origin = 4392884.59201891 dy = 3000.604229521113 y = iris.coords.DimCoord(np.arange(ny) * dy + y_origin, 'projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def expected(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) cs = iris.coord_systems.LambertConformal( central_lat=60., central_lon=262., false_easting=0, false_northing=0, secant_latitudes=(60., 30.), ellipsoid=iris.coord_systems.GeogCS(6367470)) lon0 = 239.55 lat0 = 21.641 x0m, y0m = cs.as_cartopy_crs().transform_point(lon0, lat0, ccrs.Geodetic()) dxm = dym = 320000. x_points = x0m + dxm * np.arange(15) y_points = y0m + dym * np.arange(10) x = iris.coords.DimCoord(x_points, standard_name='projection_x_coordinate', units='m', coord_system=cs, circular=False) y = iris.coords.DimCoord(y_points, standard_name='projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test_rotated_meridian(self): section = self.uk() section['orientationOfTheGrid'] = 1 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'orientation'): grid_definition_template_90(section, metadata)
def expected(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) cs = iris.coord_systems.Stereographic( central_lat=90., central_lon=262., false_easting=0, false_northing=0, true_scale_lat=60., ellipsoid=iris.coord_systems.GeogCS(6367470)) lon0 = 225385728 * 1e-6 lat0 = 32549114 * 1e-6 x0m, y0m = cs.as_cartopy_crs().transform_point( lon0, lat0, ccrs.Geodetic()) dxm = dym = 320000. x_points = x0m + dxm * np.arange(15) y_points = y0m + dym * np.arange(10) x = iris.coords.DimCoord(x_points, standard_name='projection_x_coordinate', units='m', coord_system=cs, circular=False) y = iris.coords.DimCoord(y_points, standard_name='projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test_uk_transposed(self): section = self.uk() section['scanningMode'] = 0b11100000 metadata = empty_metadata() grid_definition_template_90(section, metadata) expected = self.expected_uk(1, 0) self.compare(metadata, expected)
def test_spherical(self): section = self.section_3() section['shapeOfTheEarth'] = 0 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(0, 1) cs = expected['dim_coords_and_dims'][0][0].coord_system cs.ellipsoid = iris.coord_systems.GeogCS(6367470) self.assertEqual(metadata, expected)
def test_spherical(self): section = self.section_3() section['shapeOfTheEarth'] = 0 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(0, 1) cs = expected['dim_coords_and_dims'][0][0].coord_system cs.ellipsoid = iris.coord_systems.GeogCS(6367470) self.assertEqual(metadata, expected)
def test_scale_workaround(self): section = self.section_3() section['scaleFactorAtReferencePoint'] = 1065346526 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(0, 1) # A float32 can't hold exactly the same value. cs = expected['dim_coords_and_dims'][0][0].coord_system cs.scale_factor_at_central_meridian = 0.9996012449264526 self.assertEqual(metadata, expected)
def test_scale_workaround(self): section = self.section_3() section['scaleFactorAtReferencePoint'] = 1065346526 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(0, 1) # A float32 can't hold exactly the same value. cs = expected['dim_coords_and_dims'][0][0].coord_system cs.scale_factor_at_central_meridian = 0.9996012449264526 self.assertEqual(metadata, expected)
def test_di_tolerance(self): # Even though Ni * Di doesn't exactly match X1 to X2 it should # be close enough to allow the translation. section = self.section_3() section['X2'] += 1 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(0, 1) x = expected['dim_coords_and_dims'][1][0] x.points = np.linspace(293000, 299000.01, 4) self.assertEqual(metadata, expected)
def test_di_tolerance(self): # Even though Ni * Di doesn't exactly match X1 to X2 it should # be close enough to allow the translation. section = self.section_3() section['X2'] += 1 metadata = empty_metadata() grid_definition_template_12(section, metadata) expected = self.expected(0, 1) x = expected['dim_coords_and_dims'][1][0] x.points = np.linspace(293000, 299000.01, 4) self.assertEqual(metadata, expected)
def test_t(self): metadata = self._check_translate(section_4()) expected = empty_metadata() aux = expected['aux_coords_and_dims'] aux.append((DimCoord(6, 'forecast_period', units='hours'), None)) aux.append((DimCoord(18, 'forecast_reference_time', units='hours since epoch'), None)) aux.append((self.ref_time_coord, None)) aux.append((DimCoord(9999, long_name='height', units='m'), None)) expected['cell_methods'] = [CellMethod(coords=('area',), method='maximum')] self.assertMetadataEqual(metadata, expected)
def expected(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() ellipsoid = iris.coord_systems.GeogCS(6377563.396, 6356256.909) cs = iris.coord_systems.TransverseMercator(49, -2, 400000, -100000, 0.9996012717, ellipsoid) nx = 4 x_origin = 293000 dx = 2000 x = iris.coords.DimCoord(np.arange(nx) * dx + x_origin, "projection_x_coordinate", units="m", coord_system=cs) ny = 3 y_origin = 92000 dy = 1000 y = iris.coords.DimCoord(np.arange(ny) * dy + y_origin, "projection_y_coordinate", units="m", coord_system=cs) expected["dim_coords_and_dims"].append((y, y_dim)) expected["dim_coords_and_dims"].append((x, x_dim)) return expected
def test_t(self): metadata = self._check_translate(section_4()) expected = empty_metadata() aux = expected['aux_coords_and_dims'] aux.append((DimCoord(6, 'forecast_period', units='hours'), None)) aux.append((DimCoord(18, 'forecast_reference_time', units='hours since epoch'), None)) aux.append((self.ref_time_coord, None)) aux.append((DimCoord(9999, long_name='height', units='m'), None)) expected['cell_methods'] = [ CellMethod(coords=('area', ), method='maximum') ] self.assertMetadataEqual(metadata, expected)
def test_generating_process_warnings(self): metadata = empty_metadata() rt_coord = iris.coords.DimCoord(24, 'forecast_reference_time', units='hours since epoch') convert_options = iris.fileformats.grib._load_convert.options emit_warnings = convert_options.warn_on_unsupported try: convert_options.warn_on_unsupported = True with mock.patch('warnings.warn') as warn: product_definition_template_0(section_4(), metadata, rt_coord) warn_msgs = [call[1][0] for call in warn.mock_calls] expected = ['Unable to translate type of generating process.', 'Unable to translate background generating process ' 'identifier.', 'Unable to translate forecast generating process ' 'identifier.'] self.assertEqual(warn_msgs, expected) finally: convert_options.warn_on_unsupported = emit_warnings
def test_generating_process_warnings(self): metadata = empty_metadata() rt_coord = iris.coords.DimCoord(24, 'forecast_reference_time', units='hours since epoch') convert_options = iris.fileformats.grib._load_convert.options emit_warnings = convert_options.warn_on_unsupported try: convert_options.warn_on_unsupported = True with mock.patch('warnings.warn') as warn: product_definition_template_0(section_4(), metadata, rt_coord) warn_msgs = [call[1][0] for call in warn.mock_calls] expected = [ 'Unable to translate type of generating process.', 'Unable to translate background generating process ' 'identifier.', 'Unable to translate forecast generating process ' 'identifier.' ] self.assertEqual(warn_msgs, expected) finally: convert_options.warn_on_unsupported = emit_warnings
def expected(self): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) x_points = np.array( [0., 180., 0., 120., 240., 0., 120., 240., 0., 180.]) y_points = np.array([ -59.44440829, -59.44440829, -19.87571915, -19.87571915, -19.87571915, 19.87571915, 19.87571915, 19.87571915, 59.44440829, 59.44440829 ]) x = iris.coords.AuxCoord(x_points, standard_name='longitude', units='degrees_east', coord_system=cs) y = iris.coords.AuxCoord(y_points, standard_name='latitude', units='degrees_north', coord_system=cs) expected['aux_coords_and_dims'].append((y, 0)) expected['aux_coords_and_dims'].append((x, 0)) return expected
def expected(self, y_dim, x_dim): # Prepare the expectation. expected = empty_metadata() ellipsoid = iris.coord_systems.GeogCS(6377563.396, 6356256.909) cs = iris.coord_systems.TransverseMercator(49, -2, 400000, -100000, 0.9996012717, ellipsoid) nx = 4 x_origin = 293000 dx = 2000 x = iris.coords.DimCoord(np.arange(nx) * dx + x_origin, 'projection_x_coordinate', units='m', coord_system=cs) ny = 3 y_origin = 92000 dy = 1000 y = iris.coords.DimCoord(np.arange(ny) * dy + y_origin, 'projection_y_coordinate', units='m', coord_system=cs) expected['dim_coords_and_dims'].append((y, y_dim)) expected['dim_coords_and_dims'].append((x, x_dim)) return expected
def test(self): # Prepare the arguments. series = mock.sentinel.satelliteSeries number = mock.sentinel.satelliteNumber instrument = mock.sentinel.instrumentType rt_coord = mock.sentinel.observation_time section = {'NB': 1, 'satelliteSeries': series, 'satelliteNumber': number, 'instrumentType': instrument, 'scaleFactorOfCentralWaveNumber': 1, 'scaledValueOfCentralWaveNumber': 12} # Call the function. metadata = empty_metadata() product_definition_template_31(section, metadata, rt_coord) # Check that 'satellite_common' was called. self.assertEqual(self.satellite_common_patch.call_count, 1) # Check that 'generating_process' was called. self.assertEqual(self.generating_process_patch.call_count, 1) # Check that the scalar time coord was added in. self.assertIn((rt_coord, None), metadata['aux_coords_and_dims'])
def expected(self): # Prepare the expectation. expected = empty_metadata() cs = iris.coord_systems.GeogCS(6367470) x_points = np.array([0., 180., 0., 120., 240., 0., 120., 240., 0., 180.]) y_points = np.array([-59.44440829, -59.44440829, -19.87571915, -19.87571915, -19.87571915, 19.87571915, 19.87571915, 19.87571915, 59.44440829, 59.44440829]) x = iris.coords.AuxCoord(x_points, standard_name='longitude', units='degrees_east', coord_system=cs) y = iris.coords.AuxCoord(y_points, standard_name='latitude', units='degrees_north', coord_system=cs) expected['aux_coords_and_dims'].append((y, 0)) expected['aux_coords_and_dims'].append((x, 0)) return expected
def _check_translate(self, section): metadata = empty_metadata() product_definition_template_15(section, metadata, self.ref_time_coord) return metadata
def _check_translate(self, section): metadata = empty_metadata() product_definition_template_15(section, metadata, self.ref_time_coord) return metadata
def test_uk(self): section = self.uk() metadata = empty_metadata() grid_definition_template_90(section, metadata) expected = self.expected_uk(0, 1) self.compare(metadata, expected)
def test_zero_height(self): section = self.uk() section['Nr'] = 0 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'zero'): grid_definition_template_90(section, metadata)
def test(self): section = self.section_3() metadata = empty_metadata() grid_definition_template_40(section, metadata) expected = self.expected(0, 1, y_neg=False) self.assertEqual(metadata, expected)
def test_scanning_mode_positive_x(self): section = self.uk() section['scanningMode'] = 0b01000000 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, r'\+x'): grid_definition_template_90(section, metadata)
def test_incompatible_grid_extent(self): section = self.section_3() section['X2'] += 100 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, 'grid'): grid_definition_template_12(section, metadata)
def test(self): section = self.section_3() metadata = empty_metadata() grid_definition_template_30(section, metadata) expected = self.expected(0, 1) self.assertEqual(metadata, expected)
def test_uk(self): section = self.uk() metadata = empty_metadata() grid_definition_template_90(section, metadata) expected = self.expected_uk(0, 1) self.compare(metadata, expected)
def test_scanning_mode_positive_x(self): section = self.uk() section['scanningMode'] = 0b01000000 metadata = empty_metadata() with self.assertRaisesRegexp(iris.exceptions.TranslationError, r'\+x'): grid_definition_template_90(section, metadata)