本文整理汇总了Python中tvb.core.services.operation_service.OperationService.initiate_prelaunch方法的典型用法代码示例。如果您正苦于以下问题:Python OperationService.initiate_prelaunch方法的具体用法?Python OperationService.initiate_prelaunch怎么用?Python OperationService.initiate_prelaunch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvb.core.services.operation_service.OperationService
的用法示例。
在下文中一共展示了OperationService.initiate_prelaunch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestOperationService
# 需要导入模块: from tvb.core.services.operation_service import OperationService [as 别名]
# 或者: from tvb.core.services.operation_service.OperationService import initiate_prelaunch [as 别名]
#.........这里部分代码省略.........
row = {'description': 'test.',
'default': 'None',
'required': True,
'label': 'test: ',
'attributes': None,
'elementType': 'str',
'type': 'array',
'options': None,
'name': 'test'}
output = string2array(input_data_string, ',', row['elementType'])
assert output.shape == (2, 3)
assert output[0][2] == 'wrong', 'String data not converted properly'
input_data_string = '[ [1,2 3] [4,5,6]]'
output = string2array(input_data_string, ',', row['elementType'])
assert output[0][1] == '2 3'
def test_reduce_dimension_component(self):
"""
This method tests if the data passed to the launch method of
the NDimensionArrayAdapter adapter is correct. The passed data should be a list
of arrays with one dimension.
"""
inserted_count = FlowService().get_available_datatypes(self.test_project.id,
"tvb.datatypes.arrays.MappedArray")[1]
assert inserted_count == 0, "Expected to find no data."
#create an operation
algorithm_id = FlowService().get_algorithm_by_module_and_class('tvb.tests.framework.adapters.ndimensionarrayadapter',
'NDimensionArrayAdapter').id
operation = model.Operation(self.test_user.id, self.test_project.id, algorithm_id, 'test params',
meta=json.dumps({DataTypeMetaData.KEY_STATE: "RAW_DATA"}),
status=model.STATUS_FINISHED)
operation = dao.store_entity(operation)
#save the array wrapper in DB
adapter_instance = NDimensionArrayAdapter()
PARAMS = {}
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
inserted_data = FlowService().get_available_datatypes(self.test_project.id,
"tvb.datatypes.arrays.MappedArray")[0]
assert len(inserted_data) == 1, "Problems when inserting data"
gid = inserted_data[0][2]
entity = dao.get_datatype_by_gid(gid)
#from the 3D array do not select any array
PARAMS = {"python_method": "reduce_dimension", "input_data": gid,
"input_data_dimensions_0": "requiredDim_1",
"input_data_dimensions_1": "",
"input_data_dimensions_2": ""}
try:
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
raise AssertionError("Test should not pass. The resulted array should be a 1D array.")
except Exception:
# OK, do nothing; we were expecting to produce a 1D array
pass
#from the 3D array select only a 1D array
first_dim = [gid + '_1_0', 'requiredDim_1']
PARAMS = {"python_method": "reduce_dimension", "input_data": gid,
"input_data_dimensions_0": first_dim,
"input_data_dimensions_1": gid + "_2_1"}
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
expected_result = entity.array_data[:, 0, 1]
actual_result = adapter_instance.launch_param
assert len(actual_result) == len(expected_result), "Not the same size for results!"
assert numpy.equal(actual_result, expected_result).all()
#from the 3D array select a 2D array
first_dim = [gid + '_1_0', gid + '_1_1', 'requiredDim_2']
PARAMS = {"python_method": "reduce_dimension", "input_data": gid,
"input_data_dimensions_0": first_dim,
"input_data_dimensions_1": gid + "_2_1"}
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
expected_result = entity.array_data[slice(0, None), [0, 1], 1]
actual_result = adapter_instance.launch_param
assert len(actual_result) == len(expected_result), "Not the same size for results!"
assert numpy.equal(actual_result, expected_result).all()
#from 3D array select 1D array by applying SUM function on the first
#dimension and average function on the second dimension
PARAMS = {"python_method": "reduce_dimension", "input_data": gid,
"input_data_dimensions_0": ["requiredDim_1", "func_sum"],
"input_data_dimensions_1": "func_average",
"input_data_dimensions_2": ""}
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
aux = numpy.sum(entity.array_data, axis=0)
expected_result = numpy.average(aux, axis=0)
actual_result = adapter_instance.launch_param
assert len(actual_result) == len(expected_result), "Not the same size of results!"
assert numpy.equal(actual_result, expected_result).all()
#from 3D array select a 2D array and apply op. on the second dimension
PARAMS = {"python_method": "reduce_dimension", "input_data": gid,
"input_data_dimensions_0": ["requiredDim_2", "func_sum",
"expected_shape_x,512", "operations_x,>"],
"input_data_dimensions_1": "",
"input_data_dimensions_2": ""}
try:
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
raise AssertionError("Test should not pass! The second dimension of the array should be >512.")
except Exception:
# OK, do nothing;
pass
示例2: OperationServiceTest
# 需要导入模块: from tvb.core.services.operation_service import OperationService [as 别名]
# 或者: from tvb.core.services.operation_service.OperationService import initiate_prelaunch [as 别名]
#.........这里部分代码省略.........
output = string2array(input_data_string, ",", row["elementType"])
self.assertEqual(output[0][1], "2 3")
def test_reduce_dimension_component(self):
"""
This method tests if the data passed to the launch method of
the NDimensionArrayAdapter adapter is correct. The passed data should be a list
of arrays with one dimension.
"""
inserted_count = FlowService().get_available_datatypes(
self.test_project.id, "tvb.datatypes.arrays.MappedArray"
)[1]
self.assertEqual(inserted_count, 0, "Expected to find no data.")
# create an operation
algorithm_id = (
FlowService()
.get_algorithm_by_module_and_class(
"tvb.tests.framework.adapters.ndimensionarrayadapter", "NDimensionArrayAdapter"
)[0]
.id
)
operation = model.Operation(
self.test_user.id,
self.test_project.id,
algorithm_id,
"test params",
meta=json.dumps({DataTypeMetaData.KEY_STATE: "RAW_DATA"}),
status=model.STATUS_FINISHED,
)
operation = dao.store_entity(operation)
# save the array wrapper in DB
adapter_instance = NDimensionArrayAdapter()
PARAMS = {}
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
inserted_data = FlowService().get_available_datatypes(self.test_project.id, "tvb.datatypes.arrays.MappedArray")[
0
]
self.assertEqual(len(inserted_data), 1, "Problems when inserting data")
gid = inserted_data[0][2]
entity = dao.get_datatype_by_gid(gid)
# from the 3D array do not select any array
PARAMS = {
"python_method": "reduce_dimension",
"input_data": gid,
"input_data_dimensions_0": "requiredDim_1",
"input_data_dimensions_1": "",
"input_data_dimensions_2": "",
}
try:
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
self.fail("Test should not pass. The resulted array should be a 1D array.")
except Exception:
# OK, do nothing; we were expecting to produce a 1D array
pass
# from the 3D array select only a 1D array
first_dim = [gid + "_1_0", "requiredDim_1"]
PARAMS = {
"python_method": "reduce_dimension",
"input_data": gid,
"input_data_dimensions_0": first_dim,
"input_data_dimensions_1": gid + "_2_1",
}
self.operation_service.initiate_prelaunch(operation, adapter_instance, {}, **PARAMS)
expected_result = entity.array_data[:, 0, 1]
actual_result = adapter_instance.launch_param
self.assertEqual(len(actual_result), len(expected_result), "Not the same size for results!")