本文整理汇总了Python中tvb.core.services.flow_service.FlowService.prepare_parameters方法的典型用法代码示例。如果您正苦于以下问题:Python FlowService.prepare_parameters方法的具体用法?Python FlowService.prepare_parameters怎么用?Python FlowService.prepare_parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvb.core.services.flow_service.FlowService
的用法示例。
在下文中一共展示了FlowService.prepare_parameters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fire_simulation
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import prepare_parameters [as 别名]
def fire_simulation(project_id=1, **kwargs):
project = dao.get_project_by_id(project_id)
flow_service = FlowService()
# below the holy procedure to launch with the correct parameters taken from the defaults
_, algo_group = flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS)
simulator_adapter = flow_service.build_adapter_instance(algo_group)
flatten_interface = simulator_adapter.flaten_input_interface()
prepared_flatten_interface = flow_service.prepare_parameters(flatten_interface, project.id,
algo_group.fk_category)
launch_args = {}
for entry in prepared_flatten_interface:
value = entry['default']
if isinstance(value, dict):
value = str(value)
if hasattr(value, 'tolist'):
value = value.tolist()
launch_args[entry['name']] = value
launch_args.update(**kwargs)
# end of magic
launched_operation = flow_service.fire_operation(simulator_adapter, project.administrator,
project.id, **launch_args)[0]
return launched_operation
示例2: ModelValidator
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import prepare_parameters [as 别名]
class ModelValidator(object):
overwrites = {}
def __init__(self, overwrites=None, settings_file=None):
""" Parameters can be overwritten either from a settigns file or from a dictionary. """
if overwrites is not None:
self.overwrites.update(overwrites)
if settings_file is not None:
settings = open(sys.argv[1]).read()
for line in settings.split('\n'):
key, value = line.split('=')
self.overwrites[key.strip()] = value.strip()
if KEY_PROJECT not in self.overwrites:
raise Exception("Settings file should contain the id of the project: %s=1" % KEY_PROJECT)
self.project = dao.get_project_by_id(self.overwrites[KEY_PROJECT])
self.flow_service = FlowService()
self.operation_service = OperationService()
def launch_validation(self):
"""
Prepare the arguments to be submitted and launch actual operations group.
TODO: Now get the results and check if any errors
"""
_, algo_group = self.flow_service.get_algorithm_by_module_and_class(SIMULATOR_MODULE, SIMULATOR_CLASS)
simulator_adapter = self.flow_service.build_adapter_instance(algo_group)
launch_args = {}
flatten_interface = simulator_adapter.flaten_input_interface()
prepared_flatten_interface = self.flow_service.prepare_parameters(flatten_interface, self.project.id,
algo_group.fk_category)
for entry in prepared_flatten_interface:
value = entry['default']
if isinstance(value, dict):
value = str(value)
if hasattr(value, 'tolist'):
value = value.tolist()
launch_args[entry['name']] = value
launch_args.update(self.overwrites)
nr_of_operations = 1
for key in self.overwrites:
if key.startswith(PARAM_RANGE_PREFIX):
range_values = self.operation_service.get_range_values(launch_args, key)
nr_of_operations *= len(range_values)
do_launch = False
print "Warning! This will launch %s operations. Do you agree? (yes/no)" % nr_of_operations
while 1:
accept = raw_input()
if accept.lower() == 'yes':
do_launch = True
break
if accept.lower() == 'no':
do_launch = False
break
print "Please type either yes or no"
if do_launch:
self.launched_operations = self.flow_service.fire_operation(simulator_adapter, self.project.administrator,
self.project.id, **launch_args)
return self.validate_results(0)
else:
return "Operation canceled by user."
def validate_results(self, last_verified_index):
error_count = 0
while last_verified_index < len(self.launched_operations):
operation_to_check = self.launched_operations[last_verified_index]
operation = dao.get_operation_by_id(operation_to_check.id)
if operation.status == STATUS_STARTED:
sleep(10)
if operation.status == STATUS_ERROR:
sys.stdout.write("E(" + str(operation_to_check.id) + ")")
error_count += 1
last_verified_index += 1
sys.stdout.flush()
if operation.status == STATUS_FINISHED:
last_verified_index += 1
sys.stdout.write('.')
sys.stdout.flush()
if error_count:
return "%s operations in error; %s operations successfully." % (error_count,
len(self.launched_operations) - error_count)
return "All operations finished successfully!"
示例3: SpatioTemporalController
# 需要导入模块: from tvb.core.services.flow_service import FlowService [as 别名]
# 或者: from tvb.core.services.flow_service.FlowService import prepare_parameters [as 别名]
class SpatioTemporalController(BaseController):
"""
Base class which contains methods related to spatio-temporal actions.
"""
def __init__(self):
BaseController.__init__(self)
self.flow_service = FlowService()
self.logger = get_logger(__name__)
editable_entities = [dict(link='/spatial/stimulus/region/step_1_submit/1/1', title='Region Stimulus',
subsection='regionstim', description='Create a new Stimulus on Region level'),
dict(link='/spatial/stimulus/surface/step_1_submit/1/1', title='Surface Stimulus',
subsection='surfacestim', description='Create a new Stimulus on Surface level')]
self.submenu_list = editable_entities
@expose_page
@settings
def index(self, **data):
"""
Displays the main page for the spatio temporal section.
"""
template_specification = {'title': "Spatio temporal", 'data': data, 'mainContent': 'header_menu'}
return self.fill_default_attributes(template_specification)
@staticmethod
def display_surface(surface_gid):
"""
Generates the HTML for displaying the surface with the given ID.
"""
surface = ABCAdapter.load_entity_by_gid(surface_gid)
common.add2session(PARAM_SURFACE, surface_gid)
url_vertices_pick, url_normals_pick, url_triangles_pick = surface.get_urls_for_pick_rendering()
url_vertices, url_normals, _, url_triangles = surface.get_urls_for_rendering()
return {
'urlVerticesPick': json.dumps(url_vertices_pick),
'urlTrianglesPick': json.dumps(url_triangles_pick),
'urlNormalsPick': json.dumps(url_normals_pick),
'urlVertices': json.dumps(url_vertices),
'urlTriangles': json.dumps(url_triangles),
'urlNormals': json.dumps(url_normals),
'brainCenter': json.dumps(surface.center())
}
@staticmethod
def prepare_entity_interface(input_list):
"""
Prepares the input tree obtained from a creator.
"""
return {'inputList': input_list,
common.KEY_PARAMETERS_CONFIG: False}
def get_creator_and_interface(self, creator_module, creator_class, datatype_instance, lock_midpoint_for_eq=None):
"""
Returns a Tuple: a creator instance and a dictionary for the creator interface.
The interface is prepared for rendering, it is populated with existent data, in case of a
parameter of type DataType. The name of the attributes are also prefixed to identify groups.
"""
algo_group = self.flow_service.get_algorithm_by_module_and_class(creator_module, creator_class)[1]
group, _ = self.flow_service.prepare_adapter(common.get_current_project().id, algo_group)
#I didn't use the interface(from the above line) returned by the method 'prepare_adapter' from flow service
# because the selects that display dataTypes will also have the 'All' entry.
datatype_instance.trait.bound = traited_interface.INTERFACE_ATTRIBUTES_ONLY
input_list = datatype_instance.interface[traited_interface.INTERFACE_ATTRIBUTES]
if lock_midpoint_for_eq is not None:
for idx in lock_midpoint_for_eq:
input_list[idx] = self._lock_midpoints(input_list[idx])
category = self.flow_service.get_visualisers_category()
input_list = self.flow_service.prepare_parameters(input_list, common.get_current_project().id, category.id)
input_list = ABCAdapter.prepare_param_names(input_list)
return self.flow_service.build_adapter_instance(group), input_list
@staticmethod
def get_series_json(data, label):
""" For each data point entry, build the FLOT specific JSON. """
return '{"data": %s, "label": "%s"}' % (json.dumps(data), label)
@staticmethod
def build_final_json(list_of_series):
""" Given a list with all the data points, build the final FLOT json. """
return '[' + ','.join(list_of_series) + ']'
@staticmethod
def get_ui_message(list_of_equation_names):
"""
The message returned by this method should be displayed if
the equation with the given name couldn't be evaluated in all points.
"""
if list_of_equation_names:
return ("Could not evaluate the " + ", ".join(list_of_equation_names) + " equation(s) "
#.........这里部分代码省略.........