本文整理汇总了Python中ocgis.RequestDataset.get方法的典型用法代码示例。如果您正苦于以下问题:Python RequestDataset.get方法的具体用法?Python RequestDataset.get怎么用?Python RequestDataset.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ocgis.RequestDataset
的用法示例。
在下文中一共展示了RequestDataset.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_system_create_field_dimensioned_variables
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_system_create_field_dimensioned_variables(self):
"""Test data is appropriately tagged to identify dimensioned variables."""
path = self.get_temporary_file_path('foo.nc')
time = TemporalVariable(value=[1, 2, 3], dimensions='time')
x = Variable(name='x', value=[10, 20], dimensions='x')
y = Variable(name='y', value=[30, 40, 50, 60], dimensions='y')
data1 = Variable(name='data1', value=np.random.rand(3, 4, 2), dimensions=['time', 'y', 'x'])
data2 = Variable(name='data2', value=np.random.rand(3, 4, 2), dimensions=['time', 'y', 'x'])
data3 = Variable(name='data3', value=[11, 12, 13], dimensions=['time'])
field = Field(time=time, grid=Grid(x, y), variables=[data1, data2, data3])
field.write(path)
# Test dimensioned variables are read from a file with appropriate metadata.
rd = RequestDataset(path)
self.assertEqual(rd.variable, ('data1', 'data2'))
read_field = rd.get()
actual = get_variable_names(read_field.data_variables)
self.assertEqual(actual, ('data1', 'data2'))
# Test dimensioned variables are overloaded.
rd = RequestDataset(path, variable='data2')
read_field = rd.get()
actual = get_variable_names(read_field.data_variables)
self.assertEqual(actual, ('data2',))
示例2: test_load_geometry_subset
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_geometry_subset(self):
ref_test = self.test_data['cancm4_tas']
uri = self.test_data.get_uri('cancm4_tas')
states = self.get_2d_state_boundaries_sdim()
ca = states[:,states.properties['STATE_NAME'] == 'California']
self.assertTrue(ca.properties['STATE_NAME'] == 'California')
ca.crs.unwrap(ca)
ca = ca.geom.polygon.value[0,0]
for u in [True,False]:
try:
rd = RequestDataset(variable=ref_test['variable'],uri=uri,alias='foo')
field = rd.get()
ca_sub = field.get_intersects(ca,use_spatial_index=u)
self.assertEqual(ca_sub.shape,(1, 3650, 1, 5, 4))
self.assertTrue(ca_sub.variables['foo'].value.mask.any())
self.assertFalse(field.spatial.uid.mask.any())
self.assertFalse(field.spatial.get_mask().any())
ca_sub = field.get_intersects(ca.envelope,use_spatial_index=u)
self.assertEqual(ca_sub.shape,(1, 3650, 1, 5, 4))
self.assertFalse(ca_sub.variables['foo'].value.mask.any())
rd = RequestDataset(variable=ref_test['variable'],uri=uri,alias='foo',time_region={'year':[2007]})
field = rd.get()
ca_sub = field.get_intersects(ca,use_spatial_index=u)
self.assertEqual(ca_sub.shape,(1, 365, 1, 5, 4))
self.assertEqual(set([2007]),set([d.year for d in ca_sub.temporal.value_datetime]))
except ImportError:
with self.assertRaises(ImportError):
import_module('rtree')
示例3: test_shapefile_through_operations
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_shapefile_through_operations(self):
path = os.path.join(self.path_bin, 'shp', 'state_boundaries', 'state_boundaries.shp')
rd = RequestDataset(path)
field = rd.get()
ops = OcgOperations(dataset=rd, output_format='shp')
ret = ops.execute()
rd2 = RequestDataset(ret)
field2 = rd2.get()
self.assertAsSetEqual(list(field.keys()) + [HeaderName.ID_GEOMETRY], list(field2.keys()))
self.assertEqual((51,), field2.data_variables[0].shape)
示例4: test_shapefile_through_operations
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_shapefile_through_operations(self):
path = ShpCabinet().get_shp_path('state_boundaries')
rd = RequestDataset(path)
field = rd.get()
self.assertIsNone(field.spatial.properties)
ops = OcgOperations(dataset=rd, output_format='shp')
ret = ops.execute()
rd2 = RequestDataset(ret)
field2 = rd2.get()
self.assertAsSetEqual(field.variables.keys(), field2.variables.keys())
self.assertEqual(field.shape, field2.shape)
示例5: test_load
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load(self):
ref_test = self.test_data['cancm4_tas']
uri = self.test_data.get_uri('cancm4_tas')
rd = RequestDataset(variable=ref_test['variable'],uri=uri)
field = rd.get()
ds = nc.Dataset(uri,'r')
self.assertEqual(field.level,None)
self.assertEqual(field.spatial.crs,WGS84())
tv = field.temporal.value
test_tv = ds.variables['time'][:]
self.assertNumpyAll(tv,test_tv)
self.assertNumpyAll(field.temporal.bounds,ds.variables['time_bnds'][:])
tdt = field.temporal.value_datetime
self.assertEqual(tdt[4],dt(2001,1,5,12))
self.assertNumpyAll(field.temporal.bounds_datetime[1001],np.array([dt(2003,9,29),dt(2003,9,30)]))
rv = field.temporal.value_datetime[100]
rb = field.temporal.bounds_datetime[100]
self.assertTrue(all([rv > rb[0],rv < rb[1]]))
self.assertEqual(field.temporal.extent_datetime,(datetime.datetime(2001,1,1),datetime.datetime(2011,1,1)))
ds.close()
示例6: test_load_bounds_datetime_after_slicing
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_bounds_datetime_after_slicing(self):
ref_test = self.test_data['cancm4_tas']
uri = self.test_data.get_uri('cancm4_tas')
rd = RequestDataset(variable=ref_test['variable'],uri=uri)
field = rd.get()
slced = field[:,10:130,:,4:7,100:37]
self.assertEqual(slced.temporal.bounds_datetime.shape,(120,2))
示例7: test_write_variable_collection_netcdf4_mpi
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_write_variable_collection_netcdf4_mpi(self):
# TODO: TEST: Test writing a grouped netCDF file in parallel.
self.add_barrier = False
if not env.USE_NETCDF4_MPI:
raise SkipTest('not env.USE_NETCDF4_MPI')
path = self.create_rank_valued_netcdf()
# if vm.rank == 0:
# self.ncdump(path, header_only=False)
rd = RequestDataset(path, driver='netcdf')
rd.metadata['dimensions']['dist_dim']['dist'] = True
field = rd.get()
# self.barrier_print(field['data'].get_value())
if vm.rank == 0:
actual_path = self.get_temporary_file_path('actual_mpi.nc')
else:
actual_path = None
actual_path = vm.bcast(actual_path)
# self.barrier_print('before field.write')
field.write(actual_path)
# self.barrier_print('after field.write')
if vm.rank == 0:
# self.ncdump(actual_path, header_only=False)
self.assertNcEqual(actual_path, path)
示例8: test_load_time_range
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_time_range(self):
ref_test = self.test_data['cancm4_tas']
uri = self.test_data.get_uri('cancm4_tas')
rd = RequestDataset(variable=ref_test['variable'],uri=uri,time_range=[dt(2005,2,15),dt(2007,4,18)])
field = rd.get()
self.assertEqual(field.temporal.value_datetime[0],dt(2005, 2, 15, 12, 0))
self.assertEqual(field.temporal.value_datetime[-1],dt(2007, 4, 18, 12, 0))
self.assertEqual(field.shape,(1,793,1,64,128))
示例9: test_esmf
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_esmf(self):
rd1 = RequestDataset(**self.get_dataset())
rd2 = deepcopy(rd1)
ops = OcgOperations(dataset=rd1, regrid_destination=rd2, output_format='nc')
ret = ops.execute()
actual_value = RequestDataset(ret).get().data_variables[0].get_value()
desired_value = rd1.get().data_variables[0].get_value()
self.assertNumpyAllClose(actual_value, desired_value)
示例10: test_load_projection_axes
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_projection_axes(self):
uri = self.test_data.get_uri('cmip3_extraction')
variable = 'Tavg'
rd = RequestDataset(uri,variable)
with self.assertRaises(DimensionNotFound):
rd.get()
rd = RequestDataset(uri,variable,dimension_map={'R':'projection','T':'time','X':'longitude','Y':'latitude'})
field = rd.get()
self.assertEqual(field.shape,(36, 1800, 1, 7, 12))
self.assertEqual(field.temporal.value_datetime[0],datetime.datetime(1950, 1, 16, 0, 0))
self.assertEqual(field.temporal.value_datetime[-1],datetime.datetime(2099, 12, 15, 0, 0))
self.assertEqual(field.level,None)
self.assertNumpyAll(field.realization.value,np.arange(1,37))
ds = nc.Dataset(uri,'r')
to_test = ds.variables['Tavg']
self.assertNumpyAll(to_test[:],field.variables['Tavg'].value.squeeze())
ds.close()
示例11: test_load_climatology_bounds
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_climatology_bounds(self):
rd = self.test_data.get_rd('cancm4_tas')
ops = ocgis.OcgOperations(dataset=rd,output_format='nc',geom='state_boundaries',
select_ugid=[27],calc=[{'func':'mean','name':'mean'}],
calc_grouping=['month'])
ret = ops.execute()
rd = RequestDataset(uri=ret,variable='mean')
field = rd.get()
self.assertNotEqual(field.temporal.bounds,None)
示例12: test_load_time_region_slicing
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_time_region_slicing(self):
ref_test = self.test_data['cancm4_tas']
uri = self.test_data.get_uri('cancm4_tas')
rd = RequestDataset(variable=ref_test['variable'],uri=uri,alias='foo',
time_region={'month':[1,10],'year':[2011,2013]})
with self.assertRaises(EmptySubsetError):
rd.get()
rd = RequestDataset(variable=ref_test['variable'],uri=uri,alias='foo',
time_region={'month':[1,10],'year':[2005,2007]})
field = rd.get()
sub = field[:,:,:,50,75]
self.assertEqual(sub.shape,(1,124,1,1,1))
self.assertEqual(sub.variables['foo'].value.shape,(1,124,1,1,1))
field = rd.get()
sub = field[:,:,:,50,75:77]
sub2 = field[:,:,:,0,1]
self.assertEqual(sub2.shape,(1, 124, 1, 1, 1))
示例13: test_load_datetime_slicing
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_datetime_slicing(self):
ref_test = self.test_data['cancm4_tas']
uri = self.test_data.get_uri('cancm4_tas')
rd = RequestDataset(variable=ref_test['variable'],uri=uri)
field = rd.get()
field.temporal.value_datetime
field.temporal.bounds_datetime
slced = field[:,239,:,:,:]
self.assertEqual(slced.temporal.value_datetime,np.array([dt(2001,8,28,12)]))
self.assertNumpyAll(slced.temporal.bounds_datetime,np.array([dt(2001,8,28),dt(2001,8,29)]))
示例14: test_create_dimension_map_with_spatial_mask
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_create_dimension_map_with_spatial_mask(self):
path = self.get_temporary_file_path('foo.nc')
grid = create_gridxy_global()
gmask = grid.get_mask(create=True)
gmask[1, 1] = True
grid.set_mask(gmask)
grid.parent.write(path)
rd = RequestDataset(path)
driver = DriverNetcdfCF(rd)
dmap = driver.create_dimension_map(driver.metadata_source)
self.assertIsNotNone(dmap.get_spatial_mask())
field = rd.get()
self.assertEqual(field.grid.get_mask().sum(), 1)
# Test mask variable is blown away if set to None during a read.
rd = RequestDataset(path)
rd.dimension_map.set_spatial_mask(None)
self.assertIsNone(rd.dimension_map.get_spatial_mask())
# rd.dimension_map.pprint()
field = rd.get()
self.assertIsNone(field.grid.get_mask())
示例15: test_load_projection_axes_slicing
# 需要导入模块: from ocgis import RequestDataset [as 别名]
# 或者: from ocgis.RequestDataset import get [as 别名]
def test_load_projection_axes_slicing(self):
uri = self.test_data.get_uri('cmip3_extraction')
variable = 'Tavg'
rd = RequestDataset(uri,variable,dimension_map={'R':'projection','T':'time','X':'longitude','Y':'latitude'})
field = rd.get()
sub = field[15,:,:,:,:]
self.assertEqual(sub.shape,(1,1800,1,7,12))
ds = nc.Dataset(uri,'r')
to_test = ds.variables['Tavg']
self.assertNumpyAll(to_test[15,:,:,:],sub.variables[variable].value.squeeze())
ds.close()