本文整理匯總了Python中tvb.core.adapters.input_tree.InputTreeManager.select_simulator_inputs方法的典型用法代碼示例。如果您正苦於以下問題:Python InputTreeManager.select_simulator_inputs方法的具體用法?Python InputTreeManager.select_simulator_inputs怎麽用?Python InputTreeManager.select_simulator_inputs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tvb.core.adapters.input_tree.InputTreeManager
的用法示例。
在下文中一共展示了InputTreeManager.select_simulator_inputs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_select_simulator_inputs
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import select_simulator_inputs [as 別名]
def test_select_simulator_inputs(self):
"""
Test that given a dictionary of selected inputs as it would arrive from UI, only
the selected simulator inputs are kept.
"""
simulator_input_tree = self.flow_service.prepare_adapter(self.test_project.id, self.sim_algorithm)
child_parameter = ''
checked_parameters = {simulator_input_tree[0][ABCAdapter.KEY_NAME]: {model.KEY_PARAMETER_CHECKED: True,
model.KEY_SAVED_VALUE: 'new_value'},
simulator_input_tree[1][ABCAdapter.KEY_NAME]: {model.KEY_PARAMETER_CHECKED: True,
model.KEY_SAVED_VALUE: 'new_value'}}
#Look for a entry from a subtree to add to the selected simulator inputs
for idx, entry in enumerate(simulator_input_tree):
found_it = False
if idx not in (0, 1) and entry.get(ABCAdapter.KEY_OPTIONS, False):
for option in entry[ABCAdapter.KEY_OPTIONS]:
if option[ABCAdapter.KEY_VALUE] == entry[ABCAdapter.KEY_DEFAULT]:
if option[ABCAdapter.KEY_ATTRIBUTES]:
child_parameter = option[ABCAdapter.KEY_ATTRIBUTES][0][ABCAdapter.KEY_NAME]
checked_parameters[entry[ABCAdapter.KEY_NAME]] = {model.KEY_PARAMETER_CHECKED: False,
model.KEY_SAVED_VALUE: entry[
ABCAdapter.KEY_DEFAULT]}
checked_parameters[child_parameter] = {model.KEY_PARAMETER_CHECKED: True,
model.KEY_SAVED_VALUE: 'new_value'}
found_it = True
break
if found_it:
break
self.assertTrue(child_parameter != '', "Could not find any sub-tree entry in simulator interface.")
subtree = InputTreeManager.select_simulator_inputs(simulator_input_tree, checked_parameters)
#After the select method we expect only the checked parameters entries to remain with
#the new values updated accordingly.
expected_outputs = [{ABCAdapter.KEY_NAME: simulator_input_tree[0][ABCAdapter.KEY_NAME],
ABCAdapter.KEY_DEFAULT: 'new_value'},
{ABCAdapter.KEY_NAME: simulator_input_tree[1][ABCAdapter.KEY_NAME],
ABCAdapter.KEY_DEFAULT: 'new_value'},
{ABCAdapter.KEY_NAME: child_parameter,
ABCAdapter.KEY_DEFAULT: 'new_value'}]
self.assertEqual(len(expected_outputs), len(subtree),
"Some entries that should not have been displayed still are.")
for idx, entry in enumerate(expected_outputs):
self.assertEqual(expected_outputs[idx][ABCAdapter.KEY_NAME], subtree[idx][ABCAdapter.KEY_NAME])
self.assertEqual(expected_outputs[idx][ABCAdapter.KEY_DEFAULT], subtree[idx][ABCAdapter.KEY_DEFAULT],
'Default value not update properly.')
示例2: get_reduced_simulator_interface
# 需要導入模塊: from tvb.core.adapters.input_tree import InputTreeManager [as 別名]
# 或者: from tvb.core.adapters.input_tree.InputTreeManager import select_simulator_inputs [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)