本文整理汇总了Python中tvb.tests.framework.datatypes.datatypes_factory.DatatypesFactory.create_stimulus方法的典型用法代码示例。如果您正苦于以下问题:Python DatatypesFactory.create_stimulus方法的具体用法?Python DatatypesFactory.create_stimulus怎么用?Python DatatypesFactory.create_stimulus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvb.tests.framework.datatypes.datatypes_factory.DatatypesFactory
的用法示例。
在下文中一共展示了DatatypesFactory.create_stimulus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimulatorAdapterTest
# 需要导入模块: from tvb.tests.framework.datatypes.datatypes_factory import DatatypesFactory [as 别名]
# 或者: from tvb.tests.framework.datatypes.datatypes_factory.DatatypesFactory import create_stimulus [as 别名]
#.........这里部分代码省略.........
## Estimation when the surface input parameter is set
params['surface'] = "GID_surface"
estimation2 = self.simulator_adapter.get_execution_time_approximation(**params)
self.assertEqual(estimation1, estimation2 / 500)
params['surface'] = ""
## Modify integration step and simulation length:
initial_simulation_length = float(params['simulation_length'])
initial_integration_step = float(params['integrator_parameters']['dt'])
for factor in (2, 4, 10):
params['simulation_length'] = initial_simulation_length * factor
params['integrator_parameters']['dt'] = initial_integration_step / factor
estimation3 = self.simulator_adapter.get_execution_time_approximation(**params)
self.assertEqual(estimation1, estimation3 / factor / factor)
## Check that no division by zero happens
params['integrator_parameters']['dt'] = 0
estimation4 = self.simulator_adapter.get_execution_time_approximation(**params)
self.assertTrue(estimation4 > 0)
## even with length zero, still a positive estimation should be returned
params['simulation_length'] = 0
estimation5 = self.simulator_adapter.get_execution_time_approximation(**params)
self.assertTrue(estimation5 > 0)
def test_noise_2d_bad_shape(self):
"""
Test a simulation with noise. Pass a wrong shape and expect exception to be raised.
"""
params = copy(SIMULATOR_PARAMETERS)
params['integrator'] = u'HeunStochastic'
noise_4d_config = [[1 for _ in xrange(self.CONNECTIVITY_NODES)] for _ in xrange(4)]
params['integrator_parameters_option_HeunStochastic_dt'] = u'0.01220703125'
params['integrator_parameters_option_HeunStochastic_noise'] = u'Additive'
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_nsig'] = str(noise_4d_config)
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_ntau'] = u'0.0'
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_random_stream'] = u'RandomStream'
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_random_stream_parameters_option_RandomStream_init_seed'] = u'42'
filtered_params = self.simulator_adapter.prepare_ui_inputs(params)
self.simulator_adapter.configure(**filtered_params)
if hasattr(self.simulator_adapter, 'algorithm'):
self.assertEqual((4, 74), self.simulator_adapter.algorithm.integrator.noise.nsig.shape)
else:
self.fail("Simulator adapter was not initialized properly")
self.assertRaises(Exception, OperationService().initiate_prelaunch, self.operation,
self.simulator_adapter, {}, **params)
def test_noise_2d_happy_flow(self):
"""
Test a simulation with noise.
"""
params = copy(SIMULATOR_PARAMETERS)
params['integrator'] = u'HeunStochastic'
noise_2d_config = [[1 for _ in xrange(self.CONNECTIVITY_NODES)] for _ in xrange(2)]
params['integrator_parameters_option_HeunStochastic_dt'] = u'0.01220703125'
params['integrator_parameters_option_HeunStochastic_noise'] = u'Additive'
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_nsig'] = str(noise_2d_config)
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_ntau'] = u'0.0'
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_random_stream'] = u'RandomStream'
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_random_stream_parameters_option_RandomStream_init_seed'] = u'42'
self._launch_and_check_noise(params, (2, 74))
sim_result = dao.get_generic_entity(TimeSeriesRegion, 'TimeSeriesRegion', 'type')[0]
self.assertEquals(sim_result.read_data_shape(), (32, 1, self.CONNECTIVITY_NODES, 1))
params['integrator_parameters_option_HeunStochastic_noise_parameters_option_Additive_nsig'] = '[1]'
self._launch_and_check_noise(params, (1,))
def _launch_and_check_noise(self, params, expected_noise_shape):
filtered_params = self.simulator_adapter.prepare_ui_inputs(params)
self.simulator_adapter.configure(**filtered_params)
if hasattr(self.simulator_adapter, 'algorithm'):
self.assertEqual(expected_noise_shape, self.simulator_adapter.algorithm.integrator.noise.nsig.shape)
else:
self.fail("Simulator adapter was not initialized properly")
OperationService().initiate_prelaunch(self.operation, self.simulator_adapter, {}, **params)
def test_simulation_with_stimulus(self):
"""
Test a simulation with noise.
"""
params = copy(SIMULATOR_PARAMETERS)
params["stimulus"] = self.datatypes_factory.create_stimulus(self.connectivity).gid
filtered_params = self.simulator_adapter.prepare_ui_inputs(params)
self.simulator_adapter.configure(**filtered_params)
OperationService().initiate_prelaunch(self.operation, self.simulator_adapter, {}, **params)