def launch(self, **kwargs):
        """
        Used for creating a `StimuliRegion` instance
        """
        stimuli_region = StimuliRegion(storage_path=self.storage_path)
        stimuli_region.connectivity = kwargs['connectivity']
        stimuli_region.weight = kwargs['weight']
        stimuli_region.temporal = Equation.build_equation_from_dict('temporal', kwargs)

        return stimuli_region
示例#2
0
    def launch(self, **kwargs):
        """
        Used for creating a `StimuliRegion` instance
        """
        stimuli_region = StimuliRegion(storage_path=self.storage_path)
        stimuli_region.connectivity = kwargs['connectivity']
        stimuli_region.weight = kwargs['weight']
        stimuli_region.temporal = Equation.build_equation_from_dict(
            'temporal', kwargs)

        return stimuli_region
示例#3
0
    def launch(self, view_model):
        # type: (RegionStimulusCreatorModel) -> [StimuliRegionIndex]
        """
        Used for creating a `StimuliRegion` instance
        """
        stimuli_region = StimuliRegion()
        stimuli_region.connectivity = Connectivity()
        stimuli_region.connectivity.gid = view_model.connectivity
        stimuli_region.weight = view_model.weight
        stimuli_region.temporal = view_model.temporal
        self.generic_attributes.user_tag_1 = view_model.display_name

        stimuli_region_idx = self.store_complete(stimuli_region)
        return stimuli_region_idx
示例#4
0
    def create_stimulus(self, connectivity):
        """
        :param connectivity: Connectivity to create stimuli for its regions
        :return: persisted region Stimuli instance
        """

        operation, _, storage_path = self.__create_operation()
        stimuli_region = StimuliRegion(storage_path=storage_path)
        stimuli_region.connectivity = connectivity
        stimuli_region.weight = numpy.random.random((connectivity.number_of_regions, 1)).tolist()
        stimuli_region.temporal = PulseTrain()

        adapter_instance = StoreAdapter([stimuli_region])
        OperationService().initiate_prelaunch(operation, adapter_instance, {})
        return stimuli_region
示例#5
0
    def create_stimulus(self, connectivity):
        """
        :param connectivity: Connectivity to create stimuli for its regions
        :return: persisted region Stimuli instance
        """

        operation, _, storage_path = self.__create_operation()
        stimuli_region = StimuliRegion(storage_path=storage_path)
        stimuli_region.connectivity = connectivity
        stimuli_region.weight = numpy.random.random((connectivity.number_of_regions, 1)).tolist()
        stimuli_region.temporal = PulseTrain()

        adapter_instance = StoreAdapter([stimuli_region])
        OperationService().initiate_prelaunch(operation, adapter_instance, {})
        return stimuli_region
    def launch(self, **kwargs):
        """
        Used for creating a StimuliRegion instance
        """
        stimuli_region = StimuliRegion(storage_path=self.storage_path)
        stimuli_region.connectivity = kwargs['connectivity']
        stimuli_region.weight = kwargs['weight']
        #spatial_eq = parameters_factory.get_traited_instance_for_name(kwargs['spatial'], equations_data.EquationData,
        #                                                                {'parameters': kwargs['spatial_parameters'].get('parameters', {})})
        temporal_eq = parameters_factory.get_traited_instance_for_name(kwargs['temporal'], equations_data.EquationData,
                                                                        {'parameters': kwargs['temporal_parameters'].get('parameters', {})})
        #stimuli_region.spatial = spatial_eq
        stimuli_region.temporal = temporal_eq

        return stimuli_region
示例#7
0
    def launch(self, view_model):
        # type: (RegionStimulusCreatorModel) -> [StimuliRegionIndex]
        """
        Used for creating a `StimuliRegion` instance
        """
        stimuli_region = StimuliRegion()
        stimuli_region.connectivity = Connectivity()
        stimuli_region.connectivity.gid = view_model.connectivity
        stimuli_region.weight = view_model.weight
        stimuli_region.temporal = view_model.temporal

        stimuli_region_idx = StimuliRegionIndex()
        stimuli_region_idx.fill_from_has_traits(stimuli_region)

        h5.store_complete(stimuli_region, self.storage_path)
        return stimuli_region_idx
示例#8
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)
示例#9
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)
示例#10
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)
示例#11
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)
示例#12
0
    def get_input_tree(self):
        """
        Returns the input interface for this adapter.
        """
        stimuli_region = StimuliRegion()
        stimuli_region.trait.bound = interface.INTERFACE_ATTRIBUTES_ONLY
        inputList = stimuli_region.interface[interface.INTERFACE_ATTRIBUTES]

        return inputList
示例#13
0
 def create_stimulus(self):
     """
     Creates a stimulus from the given data.
     """
     context = common.get_from_session(KEY_REGION_CONTEXT)
     local_connectivity_creator = self.get_creator_and_interface(
         REGION_STIMULUS_CREATOR_MODULE, REGION_STIMULUS_CREATOR_CLASS,
         StimuliRegion())[0]
     context.equation_kwargs.update(
         {'weight': json.dumps(context.get_weights())})
     self.flow_service.fire_operation(local_connectivity_creator,
                                      common.get_logged_user(),
                                      common.get_current_project().id,
                                      **context.equation_kwargs)
     common.set_important_message(
         "The operation for creating the stimulus was successfully launched."
     )
示例#14
0
    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)
 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)
示例#16
0
 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
示例#17
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()