本文整理汇总了Python中ocgis.api.operations.OcgOperations.execute方法的典型用法代码示例。如果您正苦于以下问题:Python OcgOperations.execute方法的具体用法?Python OcgOperations.execute怎么用?Python OcgOperations.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ocgis.api.operations.OcgOperations
的用法示例。
在下文中一共展示了OcgOperations.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_HeatIndex
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_HeatIndex(self):
ds = [self.tasmax,self.rhsmax]
calc = [{'func':'heat_index','name':'heat_index','kwds':{'tas':'tasmax','rhs':'rhsmax','units':'k'}}]
time_range = [dt(2011,1,1),dt(2011,12,31,23,59,59)]
for d in ds: d['time_range'] = time_range
ops = OcgOperations(dataset=ds,calc=calc)
self.assertEqual(ops.calc_grouping,None)
ret = ops.execute()
ref = ret[1]
self.assertEqual(ref.variables.keys(),['tasmax','rhsmax','heat_index'])
hi = ref.variables['heat_index']
self.assertEqual(hi.value.shape,(365,1,64,128))
it = MeltedIterator(ret[1],mode='calc')
for ii,row in enumerate(it.iter_rows()):
if ii == 0:
self.assertEqual(row['value'],None)
if ii < 1000:
for key in ['vid','var_name','did','uri']:
self.assertEqual(row[key],None)
else:
break
ops = OcgOperations(dataset=ds,calc=calc,output_format='numpy',snippet=True)
ret = ops.execute()
示例2: test_HeatIndex
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_HeatIndex(self):
kwds = {'time_range':[dt(2011,1,1),dt(2011,12,31,23,59,59)]}
ds = [self.test_data.get_rd('cancm4_tasmax_2011',kwds=kwds),self.test_data.get_rd('cancm4_rhsmax',kwds=kwds)]
calc = [{'func':'heat_index','name':'heat_index','kwds':{'tas':'tasmax','rhs':'rhsmax','units':'k'}}]
## operations on entire data arrays
ops = OcgOperations(dataset=ds,calc=calc)
self.assertEqual(ops.calc_grouping,None)
ret = ops.execute()
ref = ret[1]
self.assertEqual(ref.variables.keys(),['tasmax','rhsmax'])
self.assertEqual(ref.calc.keys(),['heat_index'])
hi = ref.calc['heat_index']
self.assertEqual(hi.shape,(365,1,64,128))
## confirm no masked geometries
self.assertFalse(ref._archetype.spatial.vector.geom.mask.any())
## confirm some masked data in calculation output
self.assertTrue(hi.mask.any())
## snippet-based testing
ops = OcgOperations(dataset=ds,calc=calc,snippet=True)
ret = ops.execute()
self.assertEqual(ret[1].calc['heat_index'].shape,(1,1,64,128))
ops = OcgOperations(dataset=ds,calc=calc,snippet=True,output_format='csv')
ret = ops.execute()
# subprocess.check_call(['loffice',ret])
# try temporal grouping
ops = OcgOperations(dataset=ds,calc=calc,calc_grouping=['month'])
ret = ops.execute()
self.assertEqual(ret[1].calc['heat_index'].shape,(12,1,64,128))
ret = OcgOperations(dataset=ds,calc=calc,calc_grouping=['month'],
output_format='csv',snippet=True).execute()
示例3: test_operations_two_steps
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_operations_two_steps(self):
## get the request dataset to use as the basis for the percentiles
uri = self.test_data.get_uri('cancm4_tas')
variable = 'tas'
rd = RequestDataset(uri=uri,variable=variable)
## this is the underly OCGIS dataset object
nc_basis = rd.get()
## NOTE: if you want to subset the basis by time, this step is necessary
# nc_basis = nc_basis.get_between('temporal',datetime.datetime(2001,1,1),datetime.datetime(2003,12,31,23,59))
## these are the values to use when calculating the percentile basis. it
## may be good to wrap this in a function to have memory freed after the
## percentile structure array is computed.
all_values = nc_basis.variables[variable].value
## these are the datetime objects used for window creation
temporal = nc_basis.temporal.value_datetime
## additional parameters for calculating the basis
percentile = 10
width = 5
## get the structure array
from ocgis.calc.library.index.dynamic_kernel_percentile import DynamicDailyKernelPercentileThreshold
daily_percentile = DynamicDailyKernelPercentileThreshold.get_daily_percentile(all_values,temporal,percentile,width)
## perform the calculation using the precomputed basis. in this case,
## the basis and target datasets are the same, so the RequestDataset is
## reused.
calc_grouping = ['month','year']
kwds = {'percentile':percentile,'width':width,'operation':'lt','daily_percentile':daily_percentile}
calc = [{'func':'dynamic_kernel_percentile_threshold','name':'tg10p','kwds':kwds}]
ops = OcgOperations(dataset=rd,calc_grouping=calc_grouping,calc=calc,
output_format='nc')
ret = ops.execute()
## if we want to return the values as a three-dimenional numpy array the
## method below will do this. note the interface arrangement for the next
## release will alter this slightly.
ops = OcgOperations(dataset=rd,calc_grouping=calc_grouping,calc=calc,
output_format='numpy')
arrs = ops.execute()
## reference the returned numpy data. the first key is the geometry identifier.
## 1 in this case as this is the default for no selection geometry. the second
## key is the request dataset alias and the third is the calculation name.
## the variable name is appended to the end of the calculation to maintain
## a unique identifier.
tg10p = arrs[1]['tas'].variables['tg10p'].value
## if we want the date information for the temporal groups date attributes
date_parts = arrs[1]['tas'].temporal.date_parts
assert(date_parts.shape[0] == tg10p.shape[1])
## these are the representative datetime objects
rep_dt = arrs[1]['tas'].temporal.value_datetime
## and these are the lower and upper time bounds on the date groups
bin_bounds = arrs[1]['tas'].temporal.bounds_datetime
## confirm we have values for each month and year (12*10)
ret_ds = nc.Dataset(ret)
try:
self.assertEqual(ret_ds.variables['tg10p'].shape,(120,64,128))
finally:
ret_ds.close()
示例4: test_differing_projections
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_differing_projections(self):
rd1 = self.test_data.get_rd('daymet_tmax')
# rd2 = RequestDataset(uri=self.hostetler,variable='TG',t_calendar='noleap')
rd2 = self.test_data.get_rd('cancm4_tas')
ops = OcgOperations(dataset=[rd1,rd2],snippet=True)
with self.assertRaises(ValueError):
ops.execute()
示例5: test_heat_index
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_heat_index(self):
ocgis.env.OVERWRITE = True
kwds = {'time_range':[dt(2011,1,1),dt(2011,12,31,23,59,59)]}
ds = [self.test_data.get_rd('cancm4_tasmax_2011',kwds=kwds),self.test_data.get_rd('cancm4_rhsmax',kwds=kwds)]
calc = [{'func':'heat_index','name':'heat_index','kwds':{'tas':'tasmax','rhs':'rhsmax','units':'k'}}]
select_ugid = [25]
## operations on entire data arrays
ops = OcgOperations(dataset=ds,calc=calc)
self.assertEqual(ops.calc_grouping,None)
ret = ops.execute()
ref = ret[1]
self.assertEqual(ref.keys(),['tasmax_rhsmax'])
self.assertEqual(ref['tasmax_rhsmax'].variables.keys(),['heat_index'])
hi = ref['tasmax_rhsmax'].variables['heat_index'].value
self.assertEqual(hi.shape,(1,365,1,64,128))
## confirm no masked geometries
self.assertFalse(ref['tasmax_rhsmax'].spatial.geom.point.value.mask.any())
## confirm some masked data in calculation output
self.assertTrue(hi.mask.any())
# try temporal grouping
ops = OcgOperations(dataset=ds,calc=calc,calc_grouping=['month'],geom='state_boundaries',select_ugid=select_ugid)
ret = ops.execute()
self.assertEqual(ret[25]['tasmax_rhsmax'].variables['heat_index'].value.shape,(1,12,1,5,4))
示例6: test_daymet
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_daymet(self):
# uri = 'http://daymet.ornl.gov/thredds//dodsC/allcf/2011/9947_2011/tmax.nc'
rd = self.test_data.get_rd('daymet_tmax')
geom = 'state_boundaries'
select_ugid = [32]
snippet = True
ops = OcgOperations(dataset=rd,geom=geom,snippet=snippet,
select_ugid=select_ugid,output_format='numpy')
ops.execute()
示例7: test_keyword_dataset_esmf
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_keyword_dataset_esmf(self):
"""Test with operations on an ESMF Field."""
efield = self.get_esmf_field()
output_format = OutputFormat.iter_possible()
for kk in output_format:
ops = OcgOperations(dataset=efield, output_format=kk, prefix=kk)
ops.execute()
# self.inspect(ret)
raise
示例8: test_geometries_not_duplicated_with_equivalent_ugid
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_geometries_not_duplicated_with_equivalent_ugid(self):
# if geometries are equivalent, they should not have duplicates in the output shapefile.
rd = self.test_data.get_rd('cancm4_tas')
rd2 = self.test_data.get_rd('cancm4_tasmax_2011')
ops = OcgOperations(dataset=[rd, rd2], geom='state_boundaries', select_ugid=[16],
output_format=constants.OUTPUT_FORMAT_CSV_SHAPEFILE, snippet=True)
ops.execute()
path_shp = os.path.join(self.current_dir_output, ops.prefix, 'shp', ops.prefix + '_ugid.shp')
with fiona.open(path_shp) as source:
self.assertEqual(len(list(source)), 1)
示例9: get_does_intersect
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def get_does_intersect(request_dataset,geom):
'''
:param :class:`ocgis.RequestDataset` request_dataset:
:param shapely.geometry geom:
'''
ops = OcgOperations(dataset=request_dataset,geom=geom,snippet=True)
try:
ops.execute()
ret = True
except ExtentError:
ret = False
return(ret)
示例10: test_differing_projections
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_differing_projections(self):
rd1 = self.test_data.get_rd('daymet_tmax')
# rd2 = RequestDataset(uri=self.hostetler,variable='TG',t_calendar='noleap')
rd2 = self.test_data.get_rd('cancm4_tas')
## for numpy formats, different projections are allowed.
ops = OcgOperations(dataset=[rd1,rd2],snippet=True)
ret = ops.execute()
## it is not okay for other formats
with self.assertRaises(ValueError):
ops = OcgOperations(dataset=[rd1,rd2],snippet=True,output_format='csv+')
ops.execute()
示例11: test_geometries_different_ugid
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_geometries_different_ugid(self):
# equivalent geometries with different ugid values should be included
row = list(ShpCabinetIterator(key='state_boundaries', select_uid=[16]))
row.append(deepcopy(row[0]))
row[1]['properties']['UGID'] = 17
rd = self.test_data.get_rd('cancm4_tas')
rd2 = self.test_data.get_rd('cancm4_tasmax_2011')
ops = OcgOperations(dataset=[rd, rd2], geom=row, output_format=constants.OUTPUT_FORMAT_CSV_SHAPEFILE,
snippet=True)
ops.execute()
path_shp = os.path.join(self.current_dir_output, ops.prefix, 'shp', ops.prefix + '_ugid.shp')
with fiona.open(path_shp) as source:
self.assertEqual(len(list(source)), 2)
示例12: test_dataset_as_field_from_file
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_dataset_as_field_from_file(self):
"""Test with dataset argument coming in as a field as opposed to a request dataset collection."""
rd = self.test_data.get_rd('cancm4_tas')
geom = 'state_boundaries'
select_ugid = [23]
field = rd.get()
ops = OcgOperations(dataset=field, snippet=True, geom=geom, select_ugid=select_ugid)
ret = ops.execute()
field_out_from_field = ret[23]['tas']
self.assertEqual(field_out_from_field.shape, (1, 1, 1, 4, 3))
ops = OcgOperations(dataset=rd, snippet=True, geom=geom, select_ugid=select_ugid)
ret = ops.execute()
field_out_from_rd = ret[23]['tas']
self.assertNumpyAll(field_out_from_field.variables['tas'].value, field_out_from_rd.variables['tas'].value)
示例13: test_calculate_operations
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_calculate_operations(self):
rd = self.test_data.get_rd('cancm4_tas')
slc = [None,None,None,[0,10],[0,10]]
calc_icclim = [{'func':'icclim_TG','name':'TG'}]
calc_ocgis = [{'func':'mean','name':'mean'}]
_calc_grouping = [['month'],['month','year']]
for cg in _calc_grouping:
ops_ocgis = OcgOperations(calc=calc_ocgis,calc_grouping=cg,slice=slc,
dataset=rd)
ret_ocgis = ops_ocgis.execute()
ops_icclim = OcgOperations(calc=calc_icclim,calc_grouping=cg,slice=slc,
dataset=rd)
ret_icclim = ops_icclim.execute()
self.assertNumpyAll(ret_ocgis[1]['tas'].variables['mean'].value,
ret_icclim[1]['tas'].variables['TG'].value)
示例14: test_keyed
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_keyed(self):
raise(SkipTest('keyed format currently deprecated'))
ds = self.dataset
# ds.append(self.albisccp.copy())
ds.append(self.tasmin.copy())
ops = OcgOperations(dataset=ds,geom=self.california,output_format='numpy')
ret = ops.execute()
ref = ret[25].variables
self.assertEqual(ref['tasmax']._use_for_id,['gid','tid'])
self.assertEqual(ref['tasmin']._use_for_id,[])
# for key in ['albisccp','Prcp']:
# self.assertEqual(ret[25].variables[key]._use_for_id,['gid','tid'])
ops = OcgOperations(dataset=ds,geom=self.california,output_format='keyed',snippet=True)
ret = ops.execute()
示例15: test_calculate
# 需要导入模块: from ocgis.api.operations import OcgOperations [as 别名]
# 或者: from ocgis.api.operations.OcgOperations import execute [as 别名]
def test_calculate(self):
ocgis.env.DIR_BIN = '/home/local/WX/ben.koziol/links/ocgis/bin/QED_2013_dynamic_percentiles'
percentiles = [90, 92.5, 95, 97.5]
operations = ['gt', 'gte', 'lt', 'lte']
calc_groupings = [
['month'],
# ['month','year'],
# ['year']
]
uris_variables = [[
'/home/local/WX/ben.koziol/climate_data/maurer/2010-concatenated/Maurer02new_OBS_tasmax_daily.1971-2000.nc',
'tasmax'],
[
'/home/local/WX/ben.koziol/climate_data/maurer/2010-concatenated/Maurer02new_OBS_tasmin_daily.1971-2000.nc',
'tasmin']]
geoms_select_ugids = [
['qed_city_centroids', None],
['state_boundaries', [39]],
# ['us_counties',[2416,1335]]
]
for tup in itertools.product(percentiles, operations, calc_groupings, uris_variables, geoms_select_ugids):
print(tup)
percentile, operation, calc_grouping, uri_variable, geom_select_ugid = tup
ops = OcgOperations(dataset={'uri': uri_variable[0], 'variable': uri_variable[1],
'time_region': {'year': [1990], 'month': [6, 7, 8]}},
geom=geom_select_ugid[0], select_ugid=geom_select_ugid[1],
calc=[{'func': 'qed_dynamic_percentile_threshold',
'kwds': {'operation': operation, 'percentile': percentile}, 'name': 'dp'}],
calc_grouping=calc_grouping, output_format='numpy')
ret = ops.execute()