Exemplo n.º 1
0
 def step_2(self):
     """
     Generate the required template dictionary for the second step.
     """
     context = common.get_from_session(KEY_REGION_CONTEXT)
     selected_stimulus_gid = context.selected_stimulus
     left_side_interface = self.get_select_existent_entities(
         'Load Region Stimulus:', StimuliRegion, selected_stimulus_gid)
     template_specification = dict(
         title="Spatio temporal - Region stimulus")
     template_specification[
         'mainContent'] = 'spatial/stimulus_region_step2_main'
     template_specification[
         'next_step_url'] = '/spatial/stimulus/region/step_2_submit'
     template_specification[
         'existentEntitiesInputList'] = left_side_interface
     default_weights = context.get_weights()
     if len(default_weights) == 0:
         selected_connectivity = ABCAdapter.load_entity_by_gid(
             context.get_session_connectivity())
         default_weights = StimuliRegion.get_default_weights(
             selected_connectivity.number_of_regions)
     template_specification['node_weights'] = json.dumps(default_weights)
     template_specification[common.KEY_PARAMETERS_CONFIG] = False
     template_specification.update(
         self.display_connectivity(context.get_session_connectivity()))
     return self.fill_default_attributes(template_specification)
Exemplo n.º 2
0
    def step_2(self):
        """
        Generate the required template dictionary for the second step.
        """
        current_region_stimulus = common.get_from_session(KEY_REGION_STIMULUS)
        region_stim_selector_form = StimulusRegionSelectorForm(
            common.get_current_project().id)
        region_stim_selector_form.region_stimulus.data = current_region_stimulus.gid.hex
        region_stim_selector_form.display_name.data = common.get_from_session(
            KEY_REGION_STIMULUS_NAME)

        template_specification = dict(
            title="Spatio temporal - Region stimulus")
        template_specification[
            'mainContent'] = 'spatial/stimulus_region_step2_main'
        template_specification[
            'next_step_url'] = '/spatial/stimulus/region/step_2_submit'
        template_specification[
            'regionStimSelectorForm'] = region_stim_selector_form

        default_weights = current_region_stimulus.weight
        if len(default_weights) == 0:
            selected_connectivity = ABCAdapter.load_entity_by_gid(
                current_region_stimulus.connectivity.hex)
            default_weights = StimuliRegion.get_default_weights(
                selected_connectivity.number_of_regions)

        template_specification['node_weights'] = json.dumps(
            default_weights.tolist())
        template_specification[common.KEY_PARAMETERS_CONFIG] = False
        template_specification.update(
            self.display_connectivity(
                current_region_stimulus.connectivity.hex))
        return self.fill_default_attributes(template_specification)
Exemplo n.º 3
0
 def set_connectivity(self, **param):
     current_region_stim = common.get_from_session(KEY_REGION_STIMULUS)
     connectivity_form_field = RegionStimulusCreatorForm(common.get_current_project().id).connectivity
     connectivity_form_field.fill_from_post(param)
     current_region_stim.connectivity = connectivity_form_field.value
     conn_index = ABCAdapter.load_entity_by_gid(connectivity_form_field.value.hex)
     current_region_stim.weight = StimuliRegion.get_default_weights(conn_index.number_of_regions)
Exemplo n.º 4
0
    def step_2(self):
        """
        Generate the required template dictionary for the second step.
        """
        current_region_stimulus = common.get_from_session(KEY_REGION_STIMULUS)
        region_stim_selector_form = StimulusRegionSelectorForm(common.get_current_project().id)
        region_stim_selector_form.region_stimulus.data = current_region_stimulus.gid.hex
        region_stim_selector_form.display_name.data = common.get_from_session(KEY_REGION_STIMULUS_NAME)

        template_specification = dict(title="Spatio temporal - Region stimulus")
        template_specification['mainContent'] = 'spatial/stimulus_region_step2_main'
        template_specification['next_step_url'] = '/spatial/stimulus/region/step_2_submit'
        template_specification['regionStimSelectorForm'] = self.render_adapter_form(region_stim_selector_form)

        default_weights = current_region_stimulus.weight
        if len(default_weights) == 0:
            selected_connectivity = ABCAdapter.load_entity_by_gid(current_region_stimulus.connectivity.hex)
            if selected_connectivity is None:
                common.set_error_message(self.MSG_MISSING_CONNECTIVITY)
                default_weights = numpy.array([])
            else:
                default_weights = StimuliRegion.get_default_weights(selected_connectivity.number_of_regions)

        template_specification['baseUrl'] = self.base_url
        self.plotted_equation_prefixes = {
            self.DISPLAY_NAME_FIELD: region_stim_selector_form.display_name.name
        }
        template_specification['fieldsWithEvents'] = json.dumps(self.plotted_equation_prefixes)
        template_specification['node_weights'] = json.dumps(default_weights.tolist())
        template_specification[common.KEY_PARAMETERS_CONFIG] = False
        template_specification.update(self.display_connectivity(current_region_stimulus.connectivity.hex))
        return self.fill_default_attributes(template_specification)
 def step_2(self):
     """
     Generate the required template dictionary for the second step.
     """
     context = common.get_from_session(KEY_REGION_CONTEXT)
     selected_stimulus_gid = context.selected_stimulus
     left_side_interface = self.get_select_existent_entities('Load Region Stimulus:',
                                                             StimuliRegion, selected_stimulus_gid)
     template_specification = dict(title="Spatio temporal - Region stimulus")
     template_specification['mainContent'] = 'spatial/stimulus_region_step2_main'
     template_specification['next_step_url'] = '/spatial/stimulus/region/step_2_submit'
     template_specification['existentEntitiesInputList'] = left_side_interface
     default_weights = context.get_weights()
     if len(default_weights) == 0:
         selected_connectivity = ABCAdapter.load_entity_by_gid(context.get_session_connectivity())
         default_weights = StimuliRegion.get_default_weights(selected_connectivity.number_of_regions)
     template_specification['node_weights'] = json.dumps(default_weights)
     template_specification[common.KEY_PARAMETERS_CONFIG] = False
     template_specification.update(self.display_connectivity(context.get_session_connectivity()))
     return self.fill_default_attributes(template_specification)
Exemplo n.º 6
0
    def configure(self,
                  dt=2**-3,
                  model=ModelsEnum.GENERIC_2D_OSCILLATOR.get_class(),
                  speed=4.0,
                  coupling_strength=0.00042,
                  method=HeunDeterministic,
                  surface_sim=False,
                  default_connectivity=True,
                  with_stimulus=False):
        """
        Create an instance of the Simulator class, by default use the
        generic plane oscillator local dynamic model and the deterministic 
        version of Heun's method for the numerical integration.
        
        """
        self.method = method

        if default_connectivity:
            white_matter = Connectivity.from_file()
            region_mapping = RegionMapping.from_file(
                source_file="regionMapping_16k_76.txt")
        else:
            white_matter = Connectivity.from_file(
                source_file="connectivity_192.zip")
            region_mapping = RegionMapping.from_file(
                source_file="regionMapping_16k_192.txt")
        region_mapping.surface = CorticalSurface.from_file()

        white_matter_coupling = coupling.Linear(
            a=numpy.array([coupling_strength]))
        white_matter.speed = numpy.array(
            [speed])  # no longer allow scalars to numpy array promotion

        dynamics = model()

        if issubclass(method, IntegratorStochastic):
            hisss = noise.Additive(nsig=numpy.array([2**-11]))
            integrator = method(dt=dt, noise=hisss)
        else:
            integrator = method(dt=dt)

        if surface_sim:
            local_coupling_strength = numpy.array([2**-10])
            default_cortex = Cortex.from_file()
            default_cortex.region_mapping_data = region_mapping
            default_cortex.coupling_strength = local_coupling_strength
            if default_connectivity:
                default_cortex.local_connectivity = LocalConnectivity.from_file(
                )
            else:
                default_cortex.local_connectivity = LocalConnectivity()
            default_cortex.local_connectivity.surface = default_cortex.region_mapping_data.surface
            # TODO stimulus
        else:
            default_cortex = None
            if with_stimulus:
                weights = StimuliRegion.get_default_weights(
                    white_matter.weights.shape[0])
                weights[self.stim_nodes] = 1.
                stimulus = StimuliRegion(temporal=Linear(parameters={
                    "a": 0.0,
                    "b": self.stim_value
                }),
                                         connectivity=white_matter,
                                         weight=weights)

        # Order of monitors determines order of returned values.
        self.sim = simulator.Simulator()
        self.sim.surface = default_cortex
        self.sim.model = dynamics
        self.sim.integrator = integrator
        self.sim.connectivity = white_matter
        self.sim.coupling = white_matter_coupling
        self.sim.monitors = self.monitors
        if with_stimulus:
            self.sim.stimulus = stimulus
        self.sim.configure()