本文整理汇总了Python中ocgis.RequestDataset.create_field方法的典型用法代码示例。如果您正苦于以下问题:Python RequestDataset.create_field方法的具体用法?Python RequestDataset.create_field怎么用?Python RequestDataset.create_field使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ocgis.RequestDataset
的用法示例。
在下文中一共展示了RequestDataset.create_field方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_system_rotated_pole_spherical_subsetting
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import create_field [as 别名]
def test_system_rotated_pole_spherical_subsetting(self):
"""Test rotated pole coordinates are left alone during a subset (no mask applied)."""
def _run_mask_test_(target):
for vn in ['rlat', 'rlon']:
self.assertIsNone(target[vn].get_mask())
rd = RequestDataset(metadata=self.fixture_rotated_spherical_metadata)
field = rd.create_field()
_run_mask_test_(field)
for ctr, vn in enumerate(['lat', 'lon', 'rlat', 'rlon']):
var = field[vn]
var.get_value()[:] = np.arange(var.size).reshape(var.shape) + (ctr * 10)
path = self.get_temporary_file_path('foo.nc')
field.write(path)
new_field = RequestDataset(path).create_field()
_run_mask_test_(new_field)
subset_geom = box(*new_field.grid.extent)
subset_field = new_field.grid.get_intersects(subset_geom, optimized_bbox_subset=True).parent
_run_mask_test_(subset_field)
path2 = self.get_temporary_file_path('foo2.nc')
subset_field.write(path2)
in_subset_field = RequestDataset(path2).create_field()
_run_mask_test_(in_subset_field)
示例2: test_init_metadata_only
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import create_field [as 别名]
def test_init_metadata_only(self):
metadata = {'variables': {'foo': {}}}
rd = RequestDataset(metadata=metadata)
self.assertEqual(rd.driver.key, DriverKey.NETCDF_CF)
self.assertIsNone(rd.uri)
self.assertEqual(rd.metadata, metadata)
field = rd.create_field()
self.assertIn('foo', field.keys())
示例3: test_redistribute_by_src_idx
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import create_field [as 别名]
def test_redistribute_by_src_idx(self):
if vm.size != 4:
raise SkipTest('vm.size != 4')
dist = OcgDist()
dim1 = dist.create_dimension('dim1', 5 * vm.size, dist=True)
dim2 = dist.create_dimension('dim2', 2, dist=False)
dist.update_dimension_bounds()
rank_value = np.arange(5) + (10 * (vm.rank + 1))
var1 = Variable(name='dvar1', value=rank_value, dimensions=dim1)
var2 = Variable(name='dvar2', dimensions=[dim1, dim2])
var1.parent.add_variable(var2)
path = self.get_temporary_file_path('out.nc')
var1.parent.write(path)
desired_idx = np.array([1, 7, 9, 10, 14])
vdesired_value = variable_gather(var1)
if vm.rank == 0:
desired_value = vdesired_value.get_value()[desired_idx]
desired_idx_ranks = {0: slice(1, 2),
1: [2, 4],
2: [0, 4]}
rd = RequestDataset(path)
rd.metadata['dimensions'][dim1.name]['dist'] = True
field = rd.create_field()
indvar = field[var1.name]
field[var2.name].load()
try:
rank_slice = desired_idx_ranks[vm.rank]
except KeyError:
sub = Variable(is_empty=True)
else:
sub = indvar[rank_slice]
self.barrier_print(sub.is_empty)
redistribute_by_src_idx(indvar, dim1.name, sub.dimensions_dict.get(dim1.name))
with vm.scoped_by_emptyable('gather for test', indvar):
if vm.is_null:
self.assertIn(vm.rank_global, [2, 3])
else:
self.assertIn(vm.rank_global, [0, 1])
for v in [indvar, indvar.parent[var2.name]]:
self.assertIsNone(v._value)
self.assertIsNone(v._mask)
self.assertIsNone(v._is_empty)
self.assertFalse(v._has_initialized_value)
self.rank_print(indvar)
actual_value = variable_gather(indvar)
if vm.rank == 0:
actual_value = actual_value.get_value()
self.assertNumpyAll(actual_value, desired_value)
示例4: range
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import create_field [as 别名]
from ocgis import RequestDataset, OcgOperations
from ocgis.contrib.library_icclim import IcclimTG90p
########################################################################################################################
# Compute a custom percentile basis using ICCLIM.
# Path to CF climate dataset. This examples uses the same file for indice and percentile basis calculation.
in_file = '/path/to/cf_data.nc'
# Subset the input dataset to return the desired base period for the percentile basis.
variable = 'tas'
years = range(2001, 2003) # A custom date range may be required for your data
time_region = {'year': years}
rd = RequestDataset(uri=in_file, variable=variable)
field = rd.create_field()
field = field.time.get_time_region(time_region).parent
# Calculate the percentile basis. The data values must be a three-dimensional array.
arr = field[variable].get_masked_value().squeeze() # This is the field data to use for the calculation
dt_arr = field.temporal.value_datetime # This is an array of datetime objects.
percentile = 90
window_width = 5
t_calendar, t_units = field.time.calendar, field.time.units # ICCLIM requires calendar and units for the calculation
percentile_dict = IcclimTG90p.get_percentile_dict(arr, dt_arr, percentile, window_width, t_calendar, t_units)
########################################################################################################################
# Calculate indice using custom percentile basis.
# Depending on the size of the data, this computation may take some time...
calc = [{'func': 'icclim_TG90p', 'name': 'TG90p', 'kwds': {'percentile_dict': percentile_dict}}]
calc_grouping = 'month'