def test_reduced_raw(self): # Loading a GRIB message defined on a reduced grid without # interpolating to a regular grid. gribfile = tests.get_data_path( ("GRIB", "reduced", "reduced_gg.grib2")) grib_generator = load_cubes(gribfile) self.assertCML(next(grib_generator))
def _load_grib(*args, **kwargs): try: from iris_grib import load_cubes except ImportError: raise RuntimeError("Unable to load GRIB file - " '"iris_grib" package is not installed.') return load_cubes(*args, **kwargs)
def _load_grib(*args, **kwargs): try: from iris_grib import load_cubes except ImportError: raise RuntimeError('Unable to load GRIB file - ' '"iris_grib" package is not installed.') return load_cubes(*args, **kwargs)
def test(self): generator = iris_grib._load_generate converter = iris_grib._load_convert.convert files = mock.sentinel.FILES callback = mock.sentinel.CALLBACK expected_result = mock.sentinel.RESULT with mock.patch('iris.fileformats.rules.load_cubes') as rules_load: rules_load.return_value = expected_result result = load_cubes(files, callback) kwargs = {} loader = Loader(generator, kwargs, converter, None) rules_load.assert_called_once_with(files, callback, loader) self.assertIs(result, expected_result)
def test(self): generator = iris_grib._load_generate converter = iris_grib._load_convert.convert files = mock.sentinel.FILES callback = mock.sentinel.CALLBACK expected_result = mock.sentinel.RESULT with mock.patch('iris.fileformats.rules.load_cubes') as rules_load: rules_load.return_value = expected_result result = load_cubes(files, callback) kwargs = {} loader = Loader(generator, kwargs, converter) rules_load.assert_called_once_with(files, callback, loader) self.assertIs(result, expected_result)
def test_warn_unknown_pdts(self): # Test loading of an unrecognised GRIB Product Definition Template. # Get a temporary file by name (deleted afterward by context). with self.temp_filename() as temp_gribfile_path: # Write a test grib message to the temporary file. with open(temp_gribfile_path, 'wb') as temp_gribfile: grib_message = gribapi.grib_new_from_samples('GRIB2') # Set the PDT to something unexpected. gribapi.grib_set_long(grib_message, 'productDefinitionTemplateNumber', 5) gribapi.grib_write(grib_message, temp_gribfile) # Load the message from the file as a cube. cube_generator = iris_grib.load_cubes(temp_gribfile_path) with self.assertRaises(iris.exceptions.TranslationError) as te: cube = next(cube_generator) self.assertEqual( 'Product definition template [5]' ' is not supported', str(te.exception))
def test_warn_unknown_pdts(self): # Test loading of an unrecognised GRIB Product Definition Template. # Get a temporary file by name (deleted afterward by context). with self.temp_filename() as temp_gribfile_path: # Write a test grib message to the temporary file. with open(temp_gribfile_path, 'wb') as temp_gribfile: grib_message = gribapi.grib_new_from_samples('GRIB2') # Set the PDT to something unexpected. gribapi.grib_set_long( grib_message, 'productDefinitionTemplateNumber', 5) gribapi.grib_write(grib_message, temp_gribfile) # Load the message from the file as a cube. cube_generator = iris_grib.load_cubes( temp_gribfile_path) with self.assertRaises(iris.exceptions.TranslationError) as te: cube = next(cube_generator) self.assertEqual('Product definition template [5]' ' is not supported', str(te.exception))
def test_no_forecast_period(self): # The stock cube has a non-compliant forecast_period. fname = tests.get_data_path(('GRIB', 'global_t', 'global.grib2')) [cube] = load_cubes(fname) cube.remove_coord("forecast_period") self._test(cube)
def _load_grib(*args, **kwargs): if igrib is None: raise RuntimeError('Unable to load GRIB file - the ECMWF ' '`gribapi` package is not installed.') return igrib.load_cubes(*args, **kwargs)
def test_reduced_raw(self): # Loading a GRIB message defined on a reduced grid without # interpolating to a regular grid. gribfile = tests.get_data_path(("GRIB", "reduced", "reduced_gg.grib2")) grib_generator = load_cubes(gribfile) self.assertCML(next(grib_generator))