本文整理汇总了Python中iris.FUTURE类的典型用法代码示例。如果您正苦于以下问题:Python FUTURE类的具体用法?Python FUTURE怎么用?Python FUTURE使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FUTURE类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cell_datetime_objects
def test_cell_datetime_objects(self):
# Check the scalar coordinate summary still works even when
# iris.FUTURE.cell_datetime_objects is True.
cube = Cube(0)
cube.add_aux_coord(AuxCoord(42, units='hours since epoch'))
with FUTURE.context(cell_datetime_objects=True):
summary = cube.summary()
self.assertIn('1970-01-02 18:00:00', summary)
示例2: pick_times
def pick_times(some_cube,years,months,days,hours):
tconstraint = Constraint(time = lambda a: _get_truth_value(a, years, months, days,hours))
with FUTURE.context(cell_datetime_objects=True):
extracted = some_cube.extract(tconstraint)
if extracted is None:
t_coord = some_cube.coord('time')
print("No cube extracted, returning 'None'.")
print("Is your selection within the time bounds of the original cube?")
print(t_coord.units.num2date(t_coord.points[0]))
print(t_coord.units.num2date(t_coord.points[-1]))
print(t_coord.units.calendar)
return some_cube.extract(tconstraint)
示例3: test_gdt90_with_bitmap
def test_gdt90_with_bitmap(self):
with FUTURE.context(strict_grib_load=True):
path = tests.get_data_path(('GRIB', 'umukv', 'ukv_chan9.grib2'))
cube = load_cube(path)
# Pay particular attention to the orientation.
self.assertIsNot(cube.data[0, 0], ma.masked)
self.assertIs(cube.data[-1, 0], ma.masked)
self.assertIs(cube.data[0, -1], ma.masked)
self.assertIs(cube.data[-1, -1], ma.masked)
x = cube.coord('projection_x_coordinate').points
y = cube.coord('projection_y_coordinate').points
self.assertGreater(x[0], x[-1]) # Decreasing X coordinate
self.assertLess(y[0], y[-1]) # Increasing Y coordinate
# Check everything else.
self.assertCMLApproxData(cube)
示例4: test_save_load
def test_save_load(self):
cube = stock.lat_lon_cube()
cube.rename('atmosphere_mole_content_of_ozone')
cube.units = Unit('Dobson')
tcoord = DimCoord(23, 'time',
units=Unit('days since epoch', calendar='standard'))
fpcoord = DimCoord(24, 'forecast_period', units=Unit('hours'))
cube.add_aux_coord(tcoord)
cube.add_aux_coord(fpcoord)
cube.attributes['WMO_constituent_type'] = 0
with self.temp_filename('test_grib_pdt40.grib2') as temp_file_path:
save(cube, temp_file_path)
with FUTURE.context(strict_grib_load=True):
loaded = load_cube(temp_file_path)
self.assertEqual(loaded.attributes, cube.attributes)
示例5: setUp
def setUp(self):
# Load from the test file.
file_path = tests.get_data_path(('GRIB', 'time_processed',
'time_bound.grib2'))
with FUTURE.context(strict_grib_load=True):
self.cube = load_cube(file_path)
示例6: test_gdt1
def test_gdt1(self):
with FUTURE.context(strict_grib_load=True):
path = tests.get_data_path(('GRIB', 'rotated_nae_t',
'sensible_pole.grib2'))
cube = load_cube(path)
self.assertCMLApproxData(cube)
示例7: test_grid_complex_spatial_differencing
def test_grid_complex_spatial_differencing(self):
path = tests.get_data_path(('GRIB', 'missing_values',
'missing_values.grib2'))
with FUTURE.context(strict_grib_load=True):
cube = load_cube(path)
self.assertCMLApproxData(cube)
示例8: test_reduced
def test_reduced(self):
path = tests.get_data_path(('GRIB', 'reduced', 'reduced_gg.grib2'))
with FUTURE.context(strict_grib_load=True):
cube = load_cube(path)
self.assertCMLApproxData(cube)
示例9: test_save_load
def test_save_load(self):
# Load sample UKV data (variable-resolution rotated grid).
path = tests.get_data_path(('PP', 'ukV1', 'ukVpmslont.pp'))
cube = load_cube(path)
# Extract a single 2D field, for simplicity.
self.assertEqual(cube.ndim, 3)
self.assertEqual(cube.coord_dims('time'), (0,))
cube = cube[0]
# FOR NOW: **also** fix the data so that it is square, i.e. nx=ny.
# This is needed because of a bug in the gribapi.
# See : https://software.ecmwf.int/issues/browse/SUP-1096
ny, nx = cube.shape
nn = min(nx, ny)
cube = cube[:nn, :nn]
# Check that it has a rotated-pole variable-spaced grid, as expected.
x_coord = cube.coord(axis='x')
self.assertIsInstance(x_coord.coord_system, RotatedGeogCS)
self.assertFalse(is_regular(x_coord))
# Write to temporary file, check grib_dump output, and load back in.
with self.temp_filename('ukv_sample.grib2') as temp_file_path:
save(cube, temp_file_path)
# Get a grib_dump of the output file.
dump_text = check_output(('grib_dump -O -wcount=1 ' +
temp_file_path),
shell=True).decode()
# Check that various aspects of the saved file are as expected.
expect_strings = (
'editionNumber = 2',
'gridDefinitionTemplateNumber = 5',
'Ni = {:d}'.format(cube.shape[-1]),
'Nj = {:d}'.format(cube.shape[-2]),
'shapeOfTheEarth = 1',
'scaledValueOfRadiusOfSphericalEarth = {:d}'.format(
int(UM_DEFAULT_EARTH_RADIUS)),
'resolutionAndComponentFlags = 0',
'latitudeOfSouthernPole = -37500000',
'longitudeOfSouthernPole = 357500000',
'angleOfRotation = 0')
for expect in expect_strings:
self.assertIn(expect, dump_text)
# Load the Grib file back into a new cube.
with FUTURE.context(strict_grib_load=True):
cube_loaded_from_saved = load_cube(temp_file_path)
# Also load data, before the temporary file gets deleted.
cube_loaded_from_saved.data
# The re-loaded result will not match the original in every respect:
# * cube attributes are discarded
# * horizontal coordinates are rounded to an integer representation
# * bounds on horizontal coords are lost
# Thus the following "equivalence tests" are rather piecemeal..
# Check those re-loaded properties which should match the original.
for test_cube in (cube, cube_loaded_from_saved):
self.assertEqual(test_cube.standard_name,
'air_pressure_at_sea_level')
self.assertEqual(test_cube.units, 'Pa')
self.assertEqual(test_cube.shape, (744, 744))
self.assertEqual(test_cube.cell_methods, ())
# Check no cube attributes on the re-loaded cube.
# Note: this does *not* match the original, but is as expected.
self.assertEqual(cube_loaded_from_saved.attributes, {})
# Now remaining to check: coordinates + data...
# Check they have all the same coordinates.
co_names = [coord.name() for coord in cube.coords()]
co_names_reload = [coord.name()
for coord in cube_loaded_from_saved.coords()]
self.assertEqual(sorted(co_names_reload), sorted(co_names))
# Check all the coordinates.
for coord_name in co_names:
try:
co_orig = cube.coord(coord_name)
co_load = cube_loaded_from_saved.coord(coord_name)
# Check shape.
self.assertEqual(co_load.shape, co_orig.shape,
'Shape of re-loaded "{}" coord is {} '
'instead of {}'.format(coord_name,
co_load.shape,
co_orig.shape))
# Check coordinate points equal, within a tolerance.
self.assertArrayAllClose(co_load.points, co_orig.points,
rtol=1.0e-6)
# Check all coords are unbounded.
# (NOTE: this is not so for the original X and Y coordinates,
# but Grib does not store those bounds).
self.assertIsNone(co_load.bounds)
#.........这里部分代码省略.........