本文整理匯總了Python中tvb.core.adapters.input_tree.InputTreeManager.fill_defaults方法的典型用法代碼示例。如果您正苦於以下問題:Python InputTreeManager.fill_defaults方法的具體用法?Python InputTreeManager.fill_defaults怎麽用?Python InputTreeManager.fill_defaults使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tvb.core.adapters.input_tree.InputTreeManager
的用法示例。
在下文中一共展示了InputTreeManager.fill_defaults方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_region_stimulus
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def load_region_stimulus(self, region_stimulus_gid, from_step=None):
"""
Loads the interface for the selected region stimulus.
"""
selected_region_stimulus = ABCAdapter.load_entity_by_gid(region_stimulus_gid)
temporal_eq = selected_region_stimulus.temporal
spatial_eq = selected_region_stimulus.spatial
connectivity = selected_region_stimulus.connectivity
weights = selected_region_stimulus.weight
temporal_eq_type = temporal_eq.__class__.__name__
spatial_eq_type = spatial_eq.__class__.__name__
default_dict = {'temporal': temporal_eq_type, 'spatial': spatial_eq_type,
'connectivity': connectivity.gid, 'weight': json.dumps(weights)}
for param in temporal_eq.parameters:
prepared_name = 'temporal_parameters_option_' + str(temporal_eq_type)
prepared_name = prepared_name + '_parameters_parameters_' + str(param)
default_dict[prepared_name] = str(temporal_eq.parameters[param])
for param in spatial_eq.parameters:
prepared_name = 'spatial_parameters_option_' + str(spatial_eq_type) + '_parameters_parameters_' + str(param)
default_dict[prepared_name] = str(spatial_eq.parameters[param])
input_list = self.get_creator_and_interface(REGION_STIMULUS_CREATOR_MODULE,
REGION_STIMULUS_CREATOR_CLASS, StimuliRegion())[1]
input_list = InputTreeManager.fill_defaults(input_list, default_dict)
context = common.get_from_session(KEY_REGION_CONTEXT)
context.reset()
context.update_from_interface(input_list)
context.equation_kwargs[DataTypeMetaData.KEY_TAG_1] = selected_region_stimulus.user_tag_1
context.set_active_stimulus(region_stimulus_gid)
return self.do_step(from_step)
示例2: get_template_for_adapter
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def get_template_for_adapter(self, project_id, step_key, stored_adapter, submit_url, session_reset=True, is_burst=True):
""" Get Input HTML Interface template or a given adapter """
try:
if session_reset:
self.context.clean_from_session()
group = None
# Cache some values in session, for performance
previous_tree = self.context.get_current_input_tree()
previous_sub_step = self.context.get_current_substep()
if not session_reset and previous_tree is not None and previous_sub_step == stored_adapter.id:
adapter_interface = previous_tree
else:
adapter_interface = self.flow_service.prepare_adapter(project_id, stored_adapter)
self.context.add_adapter_to_session(stored_adapter, adapter_interface)
category = self.flow_service.get_category_by_id(step_key)
title = "Fill parameters for step " + category.displayname.lower()
if group:
title = title + " - " + group.displayname
current_defaults = self.context.get_current_default()
if current_defaults is not None:
#Change default values in tree, according to selected input
adapter_interface = InputTreeManager.fill_defaults(adapter_interface, current_defaults)
template_specification = dict(submitLink=submit_url, inputList=adapter_interface, title=title)
self._populate_section(stored_adapter, template_specification, is_burst)
return template_specification
except OperationException, oexc:
self.logger.error("Inconsistent Adapter")
self.logger.exception(oexc)
common.set_warning_message('Inconsistent Adapter! Please review the link (development problem)!')
示例3: _get_stimulus_interface
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def _get_stimulus_interface(self):
"""
Returns a dictionary which contains the data needed
for creating the interface for a stimulus.
"""
context = common.get_from_session(KEY_REGION_CONTEXT)
input_list = self.get_creator_and_interface(REGION_STIMULUS_CREATOR_MODULE,
REGION_STIMULUS_CREATOR_CLASS, StimuliRegion())[1]
context.equation_kwargs.update({SCALING_PARAMETER: context.get_weights()})
input_list = InputTreeManager.fill_defaults(input_list, context.equation_kwargs)
input_list, any_scaling = self._remove_scaling(input_list)
template_specification = {'inputList': input_list, common.KEY_PARAMETERS_CONFIG: False}
return self._add_extra_fields_to_interface(template_specification), any_scaling
示例4: _get_stimulus_interface
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def _get_stimulus_interface(self):
"""
Returns a dictionary which contains the interface for a surface stimulus.
"""
context = common.get_from_session(KEY_SURFACE_CONTEXT)
input_list = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface(),
lock_midpoint_for_eq=[1])[1]
input_list = InputTreeManager.fill_defaults(input_list, context.equation_kwargs)
input_list, focal_points_list = self._remove_focal_points(input_list)
input_list = self.prepare_entity_interface(input_list)
input_list['selectedFocalPoints'] = focal_points_list
return self._add_extra_fields_to_interface(input_list)
示例5: update_default_values
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def update_default_values(portlet_interface, portlet_configuration):
"""
:param portlet_interface: a list of AdapterConfiguration entities.
:param portlet_configuration: a PortletConfiguration entity.
Update the defaults from each AdapterConfiguration entity with the
values stored in the corresponding workflow step held in the
PortletConfiguration entity.
"""
# Check for any defaults first in analyzer steps
if portlet_configuration.analyzers:
for adapter_idx in xrange(len(portlet_interface[:-1])):
saved_configuration = portlet_configuration.analyzers[adapter_idx]
replaced_defaults_dict = InputTreeManager.fill_defaults(portlet_interface[adapter_idx].interface,
saved_configuration.static_param)
portlet_interface[adapter_idx].interface = replaced_defaults_dict
# Check for visualization defaults
if portlet_configuration.visualizer:
saved_configuration = portlet_configuration.visualizer
replaced_defaults_dict = InputTreeManager.fill_defaults(portlet_interface[-1].interface,
saved_configuration.static_param)
portlet_interface[-1].interface = replaced_defaults_dict
示例6: index
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def index(self):
"""Get on burst main page"""
# todo : reuse load_burst here for consistency.
template_specification = dict(mainContent="burst/main_burst", title="Simulation Cockpit",
baseUrl=TvbProfile.current.web.BASE_URL,
includedResources='project/included_resources')
portlets_list = self.burst_service.get_available_portlets()
session_stored_burst = common.get_from_session(common.KEY_BURST_CONFIG)
if session_stored_burst is None or session_stored_burst.id is None:
if session_stored_burst is None:
session_stored_burst = self.burst_service.new_burst_configuration(common.get_current_project().id)
common.add2session(common.KEY_BURST_CONFIG, session_stored_burst)
adapter_interface = self.cached_simulator_input_tree
if session_stored_burst is not None:
current_data = session_stored_burst.get_all_simulator_values()[0]
adapter_interface = InputTreeManager.fill_defaults(adapter_interface, current_data, True)
### Add simulator tree to session to be available in filters
self.context.add_adapter_to_session(self.cached_simulator_algorithm, adapter_interface, current_data)
template_specification['inputList'] = adapter_interface
selected_portlets = session_stored_burst.update_selected_portlets()
template_specification['burst_list'] = self.burst_service.get_available_bursts(common.get_current_project().id)
template_specification['portletList'] = portlets_list
template_specification['selectedPortlets'] = json.dumps(selected_portlets)
template_specification['draw_hidden_ranges'] = True
template_specification['burstConfig'] = session_stored_burst
### Prepare PSE available metrics
### We put here all available algorithms, because the metrics select area is a generic one,
### and not loaded with every Burst Group change in history.
algorithm = self.flow_service.get_algorithm_by_module_and_class(MEASURE_METRICS_MODULE, MEASURE_METRICS_CLASS)
adapter_instance = ABCAdapter.build_adapter(algorithm)
if adapter_instance is not None and hasattr(adapter_instance, 'available_algorithms'):
template_specification['available_metrics'] = [metric_name for metric_name
in adapter_instance.available_algorithms.keys()]
else:
template_specification['available_metrics'] = []
template_specification[common.KEY_PARAMETERS_CONFIG] = False
template_specification[common.KEY_SECTION] = 'burst'
return self.fill_default_attributes(template_specification)
示例7: get_reduced_simulator_interface
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def get_reduced_simulator_interface(self):
"""
Get a simulator interface that only contains the inputs that are marked
as KEY_PARAMETER_CHECKED in the current session.
"""
burst_config = common.get_from_session(common.KEY_BURST_CONFIG)
simulator_config = burst_config.simulator_configuration
## Fill with stored defaults, and see if any parameter was checked by user ##
default_values, any_checked = burst_config.get_all_simulator_values()
simulator_input_tree = self.cached_simulator_input_tree
simulator_input_tree = InputTreeManager.fill_defaults(simulator_input_tree, default_values)
## In case no values were checked just skip tree-cut part and show entire simulator tree ##
if any_checked:
simulator_input_tree = InputTreeManager.select_simulator_inputs(simulator_input_tree, simulator_config)
### Add simulator tree to session to be available in filters
self.context.add_adapter_to_session(self.cached_simulator_algorithm, simulator_input_tree, default_values)
template_specification = {"inputList": simulator_input_tree,
common.KEY_PARAMETERS_CONFIG: False,
'draw_hidden_ranges': True}
return self.fill_default_attributes(template_specification)
示例8: configure_simulator_parameters
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def configure_simulator_parameters(self):
"""
Return the required input tree to generate the simulator interface for
the burst page in 'configuration mode', meaning with checkboxes next to
each input that are checked or not depending on if the user selected
them so, and with the user filled defaults.
"""
burst_config = common.get_from_session(common.KEY_BURST_CONFIG)
default_values, any_checked = burst_config.get_all_simulator_values()
simulator_input_tree = self.cached_simulator_input_tree
simulator_input_tree = InputTreeManager.fill_defaults(simulator_input_tree, default_values)
### Add simulator tree to session to be available in filters
self.context.add_adapter_to_session(self.cached_simulator_algorithm, simulator_input_tree, default_values)
template_vars = {}
self.fill_default_attributes(template_vars)
template_vars.update({
"inputList": simulator_input_tree,
common.KEY_PARAMETERS_CONFIG: True,
'none_checked': not any_checked,
'selectedParametersDictionary': burst_config.simulator_configuration
})
return template_vars
示例9: get_template_from_context
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def get_template_from_context(self):
"""
Return the parameters for the local connectivity in case one is stored in context. Load the entity
and use it to populate the defaults from the interface accordingly.
"""
context = common.get_from_session(KEY_LCONN_CONTEXT)
selected_local_conn = ABCAdapter.load_entity_by_gid(context.selected_entity)
cutoff = selected_local_conn.cutoff
equation = selected_local_conn.equation
surface = selected_local_conn.surface
default_dict = {'surface': surface.gid, 'cutoff': cutoff}
if equation is not None:
equation_type = equation.__class__.__name__
default_dict['equation'] = equation_type
for param in equation.parameters:
prepared_name = 'equation_parameters_option_' + str(equation_type)
prepared_name = prepared_name + '_parameters_parameters_' + str(param)
default_dict[prepared_name] = equation.parameters[param]
else:
msg = "There is no equation specified for this local connectivity. "
msg += "The default equation is displayed into the spatial field."
self.logger.warning(msg)
common.set_info_message(msg)
default_dict[DataTypeMetaData.KEY_TAG_1] = selected_local_conn.user_tag_1
input_list = self.get_creator_and_interface(LOCAL_CONN_CREATOR_MODULE,
LOCAL_CONN_CREATOR_CLASS, LocalConnectivity(),
lock_midpoint_for_eq=[1])[1]
input_list = self._add_extra_fields_to_interface(input_list)
input_list = InputTreeManager.fill_defaults(input_list, default_dict)
template_specification = {'inputList': input_list, common.KEY_PARAMETERS_CONFIG: False,
'equationViewerUrl': '/spatial/localconnectivity/get_equation_chart',
'equationsPrefixes': json.dumps(self.plotted_equations_prefixes)}
return template_specification
示例10: load_surface_stimulus
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def load_surface_stimulus(self, surface_stimulus_gid, from_step):
"""
Loads the interface for the selected surface stimulus.
"""
context = common.get_from_session(KEY_SURFACE_CONTEXT)
selected_surface_stimulus = ABCAdapter.load_entity_by_gid(surface_stimulus_gid)
temporal_eq = selected_surface_stimulus.temporal
spatial_eq = selected_surface_stimulus.spatial
surface = selected_surface_stimulus.surface
focal_points_surface = selected_surface_stimulus.focal_points_surface
focal_points_triangles = selected_surface_stimulus.focal_points_triangles
temporal_eq_type = temporal_eq.__class__.__name__
spatial_eq_type = spatial_eq.__class__.__name__
default_dict = {'temporal': temporal_eq_type, 'spatial': spatial_eq_type,
'surface': surface.gid, 'focal_points_surface': json.dumps(focal_points_surface),
'focal_points_triangles': json.dumps(focal_points_triangles)}
for param in temporal_eq.parameters:
prepared_name = 'temporal_parameters_option_' + str(temporal_eq_type)
prepared_name = prepared_name + '_parameters_parameters_' + str(param)
default_dict[prepared_name] = str(temporal_eq.parameters[param])
for param in spatial_eq.parameters:
prepared_name = 'spatial_parameters_option_' + str(spatial_eq_type) + '_parameters_parameters_' + str(param)
default_dict[prepared_name] = str(spatial_eq.parameters[param])
default_dict[DataTypeMetaData.KEY_TAG_1] = selected_surface_stimulus.user_tag_1
input_list = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface(),
lock_midpoint_for_eq=[1])[1]
input_list = InputTreeManager.fill_defaults(input_list, default_dict)
context.reset()
context.update_from_interface(input_list)
context.equation_kwargs[DataTypeMetaData.KEY_TAG_1] = selected_surface_stimulus.user_tag_1
context.set_active_stimulus(surface_stimulus_gid)
return self.do_step(from_step)
示例11: fill_defaults
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import fill_defaults [as 別名]
def fill_defaults(adapter_interface, data, fill_unselected_branches=False):
""" Change the default values in the Input Interface Tree."""
return InputTreeManager.fill_defaults(adapter_interface, data, fill_unselected_branches)