def _check(self, append=False): iris_grib.save_grib2(self.cube, self.target, append=append) self.save_pairs_from_cube.called_once_with(self.cube) args, kwargs = self.save_messages.call_args self.assertEqual(len(args), 2) messages, target = args self.assertEqual(list(messages), self.messages) self.assertEqual(target, self.target) self.assertEqual(kwargs, dict(append=append))
def _grib_save(cube, target, append=False, **kwargs): # A simple wrapper for the grib save routine, which allows the saver to be # registered without having the grib implementation installed. try: from iris_grib import save_grib2 except ImportError: raise RuntimeError('Unable to save GRIB file - ' '"iris_grib" package is not installed.') save_grib2(cube, target, append, **kwargs)
def _grib_save(cube, target, append=False, **kwargs): # A simple wrapper for the grib save routine, which allows the saver to be # registered without having the grib implementation installed. try: import iris_grib as igrib except ImportError: try: import gribapi except ImportError: raise RuntimeError("Unable to save GRIB file - the ECMWF " "`gribapi` package is not installed.") from iris.fileformats import grib as igrib return igrib.save_grib2(cube, target, append, **kwargs)
def _grib_save(cube, target, append=False, **kwargs): # A simple wrapper for the grib save routine, which allows the saver to be # registered without having the grib implementation installed. try: import iris_grib as igrib except ImportError: try: import gribapi except ImportError: raise RuntimeError('Unable to save GRIB file - the ECMWF ' '`gribapi` package is not installed.') from iris.fileformats import grib as igrib return igrib.save_grib2(cube, target, append, **kwargs)
latitude = DimCoord(np.linspace(29.45, 20.70, 35), standard_name='latitude', units='degrees') longitude = DimCoord(np.linspace(97.33, 106.58, 37), standard_name='longitude', units='degrees') time = DimCoord(0, standard_name='time', units='hours since {}'.format( str(datetime.datetime(2017, 3, 2, 17)))) forecast_period = DimCoord(int(000), standard_name='forecast_period', units='hours') cube = Cube(data, dim_coords_and_dims=[(latitude, 0), (longitude, 1)], units='m s-1', standard_name='wind_speed') cube.add_aux_coord(time) cube.add_aux_coord(forecast_period) cube.coord(axis='X').coord_system = iris.coord_systems.GeogCS(654321) cube.coord(axis='Y').coord_system = iris.coord_systems.GeogCS(654321) # iris_grib.save_grib2(cube, "%s%s_EC-1000hpa-24h_temperature-CHINA_0.25deg.grib2" %(name, fh), append=False) iris_grib.save_grib2(cube, "2017030217%s%s_MICAPS_wind-speed_YUNNAN_27km.grib2" % (name, fh), append=False) # print cube.data
pd.to_datetime('1981-01-01')).days * 24 new_t_coord = iris.coords.DimCoord(date, standard_name='time', units='hours since 1981-01-01') data1.add_dim_coord(new_t_coord, time1_dims) lon_coord1 = data1.coords("longitude")[0] lat_coord1 = data1.coords("latitude")[0] lon_coord1.coord_system = iris.coord_systems.GeogCS( iris.fileformats.pp.EARTH_RADIUS) lat_coord1.coord_system = iris.coord_systems.GeogCS( iris.fileformats.pp.EARTH_RADIUS) data1.add_aux_coord( iris.coords.DimCoord(0, standard_name='forecast_period', units='hours')) data1.add_aux_coord(iris.coords.DimCoord(0, "height", units="m")) data1.var_name = "SST" data1.long_name = "Sea Surface Temperature" data1.standard_name = 'sea_surface_temperature' data1.units = 'K' data1.discipline = 0 data1.category = 0 data1.typeOfFirstFixedSurface = 1 time = file[0:4] + '-' + file[4:6] + '-' + file[6:8] time1 = file[0:4] + '-' + file[4:6] + '-' + file[6:8] print(data1) iris_grib.save_grib2(data1, filename)