def setUp(self): _, self.connectivity = DatatypesFactory().create_connectivity() self.test_user = TestFactory.create_user(username="******") self.test_project = TestFactory.create_project(self.test_user, "Test") burst_conf = BurstConfiguration(self.test_project.id) burst_conf._simulator_configuration = self.CONF_HOPFIELD_HEUN_STOCH_RANGES burst_conf.prepare_after_load() burst_conf.simulator_configuration['connectivity'] = {'value': self.connectivity.gid} self.s_manager = SerializationManager(burst_conf) self.empty_manager = SerializationManager(BurstConfiguration(None))
def transactional_setup_method(self): self.test_user = TestFactory.create_user(username="******") self.test_project = TestFactory.create_project(self.test_user, "Test") zip_path = path.join(path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip') TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path, "John") self.connectivity = TestFactory.get_entity(self.test_project, ConnectivityIndex) sim_conf = Simulator(model=ModelsEnum.HOPFIELD.get_class()(), integrator=HeunStochastic()) self.s_manager = SerializationManager(sim_conf) self.empty_manager = SerializationManager(None)
def index(self): current_user_id = common.get_logged_user().id # In case the number of dynamics gets big we should add a filter in the ui. dynamics = dao.get_dynamics_for_user(current_user_id) if not dynamics: return self.no_dynamics_page() burst_config = common.get_from_session(common.KEY_BURST_CONFIG) des = SerializationManager(burst_config) connectivity = des.get_connectivity() params = ConnectivityViewer.get_connectivity_parameters(connectivity) params.update({ 'title': 'Model parameters', 'mainContent': 'burst/model_param_region', 'isSingleMode': True, 'submit_parameters_url': '/burst/modelparameters/regions/submit_model_parameters', 'dynamics': dynamics, 'dynamics_json': self._dynamics_json(dynamics), 'initial_dynamic_ids': json.dumps(burst_config.dynamic_ids) }) return self.fill_default_attributes(params, 'regionmodel')
def submit_model_parameters(self, node_values): """ Collects the model parameters values from all the models used for the connectivity nodes. Assumes that the array indices are consistent with the node order. """ dynamic_ids = json.loads(node_values) dynamics = [dao.get_dynamic(did) for did in dynamic_ids] for dynamic in dynamics[1:]: if dynamic.model_class != dynamics[0].model_class: raise Exception("All dynamics must have the same model type") model_name = dynamics[0].model_class burst_config = common.get_from_session(common.KEY_BURST_CONFIG) # update model parameters in burst config des = SerializationManager(burst_config) model_parameters = [ dict(json.loads(d.model_parameters)) for d in dynamics ] des.write_model_parameters(model_name, model_parameters) # update dynamic ids in burst config burst_config.dynamic_ids = dynamic_ids # Update in session BURST configuration for burst-page. # todo was this needed? as the burst config in session has already been changed #common.add2session(common.KEY_BURST_CONFIG, burst_config.clone()) raise cherrypy.HTTPRedirect("/burst/")
def submit_model_parameters(self, node_values): """ Collects the model parameters values from all the models used for the connectivity nodes. Assumes that the array indices are consistent with the node order. """ dynamic_ids = json.loads(node_values) dynamics = [dao.get_dynamic(did) for did in dynamic_ids] for dynamic in dynamics[1:]: if dynamic.model_class != dynamics[0].model_class: raise Exception("All dynamics must have the same model type") model_name = dynamics[0].model_class burst_config = common.get_from_session(common.KEY_BURST_CONFIG) simulator_config = common.get_from_session(common.KEY_SIMULATOR_CONFIG) # update model parameters in burst config des = SerializationManager(simulator_config) model_parameters = [ dict(json.loads(d.model_parameters)) for d in dynamics ] des.write_model_parameters(model_name, model_parameters) # update dynamic ids in burst config burst_config.dynamic_ids = json.dumps(dynamic_ids) # Update in session the simulator configuration and the current form URL in wizzard for burst-page. common.add2session(common.KEY_BURST_CONFIG, burst_config) common.add2session(common.KEY_LAST_LOADED_FORM_URL, SimulatorWizzardURLs.SET_INTEGRATOR_URL) raise cherrypy.HTTPRedirect("/burst/")
def index(self): des = SerializationManager(self.simulator_context.simulator) conn_idx = load.load_entity_by_gid(des.conf.connectivity) model = des.conf.model integrator = des.conf.integrator state_vars = model.state_variables noise_values = self.init_noise_config_values(model, integrator, conn_idx) initial_noise = self.group_noise_array_by_state_var( noise_values, state_vars, conn_idx.number_of_regions) current_project = common.get_current_project() file_handler = FilesHelper() conn_path = file_handler.get_project_folder( current_project, str(conn_idx.fk_from_operation)) params = ConnectivityViewer.get_connectivity_parameters( conn_idx, conn_path) params.update({ 'title': 'Noise configuration', 'mainContent': 'burst/noise', 'isSingleMode': True, 'submit_parameters_url': '/burst/noise/submit', 'stateVars': state_vars, 'stateVarsJson': json.dumps(state_vars), 'noiseInputValues': initial_noise[0], 'initialNoiseValues': json.dumps(initial_noise) }) return self.fill_default_attributes(params, 'regionmodel')
def get_data_from_burst_configuration(self): """ Returns the model and surface instances from the burst configuration. """ des = SerializationManager( common.get_from_session(common.KEY_BURST_CONFIG)) ### Read from session current burst-configuration if des.conf is None: return None, None if des.has_model_pse_ranges(): common.set_error_message( "When configuring model parameters you are not allowed to specify range values." ) raise cherrypy.HTTPRedirect("/burst/") try: model, integrator = des.make_model_and_integrator() except Exception: self.logger.exception( "Some of the provided parameters have an invalid value.") common.set_error_message( "Some of the provided parameters have an invalid value.") raise cherrypy.HTTPRedirect("/burst/") surface = des.get_surface() return model, surface
def index(self): current_user_id = common.get_logged_user().id # In case the number of dynamics gets big we should add a filter in the ui. dynamics = dao.get_dynamics_for_user(current_user_id) if not dynamics: return self.no_dynamics_page() burst_config = common.get_from_session(common.KEY_BURST_CONFIG) des = SerializationManager(burst_config) connectivity = des.get_connectivity() if connectivity is None: msg = 'You have to select a connectivity before setting up the region Model. ' common.set_error_message(msg) raise ValueError(msg) current_project = common.get_current_project() file_handler = FilesHelper() conn_path = file_handler.get_project_folder(current_project, str(connectivity.fk_from_operation)) params = ConnectivityViewer.get_connectivity_parameters(connectivity, conn_path) params.update({ 'title': 'Model parameters', 'mainContent': 'burst/model_param_region', 'isSingleMode': True, 'submit_parameters_url': '/burst/modelparameters/regions/submit_model_parameters', 'dynamics': dynamics, 'dynamics_json': self._dynamics_json(dynamics), 'initial_dynamic_ids': json.dumps(burst_config.dynamic_ids) }) return self.fill_default_attributes(params, 'regionmodel')
def submit(self, node_values): """ Submit noise dispersions :param node_values: A map from state variable names to noise dispersion arrays. Ex {'V': [1,2...74]} """ des = SerializationManager( common.get_from_session(common.KEY_BURST_CONFIG)) des.write_noise_parameters(json.loads(node_values)) raise cherrypy.HTTPRedirect("/burst/")
def submit(self, node_values): """ Submit noise dispersions :param node_values: A map from state variable names to noise dispersion arrays. Ex {'V': [1,2...74]} """ des = SerializationManager(self.simulator_context.simulator) des.write_noise_parameters(json.loads(node_values)) self.simulator_context.add_last_loaded_form_url_to_session(SimulatorWizzardURLs.SET_NOISE_PARAMS_URL) raise cherrypy.HTTPRedirect("/burst/")
def submit(self, node_values): """ Submit noise dispersions :param node_values: A map from state variable names to noise dispersion arrays. Ex {'V': [1,2...74]} """ des = SerializationManager(common.get_from_session(common.KEY_SIMULATOR_CONFIG)) des.write_noise_parameters(json.loads(node_values)) common.add2session(common.KEY_LAST_LOADED_FORM_URL, SimulatorWizzardURLs.SET_NOISE_PARAMS_URL) raise cherrypy.HTTPRedirect("/burst/")
def get_data_from_burst_configuration(self): """ Returns the model and surface instances from the burst configuration. """ des = SerializationManager(self.simulator_context.simulator) ### Read from session current burst-configuration if des.conf is None: return None, None # if des.has_model_pse_ranges(): # common.set_error_message("When configuring model parameters you are not allowed to specify range values.") # raise cherrypy.HTTPRedirect("/burst/") try: model = des.conf.model except Exception: self.logger.exception( "Some of the provided parameters have an invalid value.") common.set_error_message( "Some of the provided parameters have an invalid value.") raise cherrypy.HTTPRedirect("/burst/") cortex = des.conf.surface return model, cortex
def index(self): des = SerializationManager( common.get_from_session(common.KEY_BURST_CONFIG)) connectivity = des.get_connectivity() model, integrator = des.make_model_and_integrator() state_vars = model.state_variables noise_values = self.init_noise_config_values(model, integrator, connectivity) initial_noise = self.group_noise_array_by_state_var( noise_values, state_vars, connectivity.number_of_regions) params = ConnectivityViewer.get_connectivity_parameters(connectivity) params.update({ 'title': 'Noise configuration', 'mainContent': 'burst/noise', 'isSingleMode': True, 'submit_parameters_url': '/burst/noise/submit', 'stateVars': state_vars, 'stateVarsJson': json.dumps(state_vars), 'noiseInputValues': initial_noise[0], 'initialNoiseValues': json.dumps(initial_noise) }) return self.fill_default_attributes(params, 'regionmodel')