def get_spatial_equation_chart(self, **form_data):
     """
     Returns the HTML which contains the chart in which is plotted the temporal equation.
     """
     try:
         min_x, max_x, ui_message = self.get_x_axis_range(
             form_data['min_space_x'], form_data['max_space_x'])
         surface_stimulus_creator = self.get_creator_and_interface(
             SURFACE_STIMULUS_CREATOR_MODULE,
             SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface())[0]
         form_data = surface_stimulus_creator.prepare_ui_inputs(
             form_data, validation_required=False)
         equation = surface_stimulus_creator.get_spatial_equation(form_data)
         series_data, display_ui_message = equation.get_series_data(
             min_range=min_x, max_range=max_x)
         json_data = self.get_series_json(series_data, "Spatial")
         all_series = self.build_final_json([json_data])
         ui_message = ''
         if display_ui_message:
             ui_message = self.get_ui_message(["spatial"])
         return {
             'allSeries': all_series,
             'prefix': 'spatial',
             'message': ui_message
         }
     except NameError, ex:
         self.logger.exception(ex)
         return {
             'allSeries': None,
             'errorMsg': "Incorrect parameters for equation passed."
         }
    def get_input_tree(self):
        """
        Returns the input interface for this adapter.
        """
        stimuli_surface = StimuliSurface()
        stimuli_surface.trait.bound = interface.INTERFACE_ATTRIBUTES_ONLY
        inputList = stimuli_surface.interface[interface.INTERFACE_ATTRIBUTES]

        return inputList
 def view_stimulus(self, focal_points):
     """
     Just create the stimulus to view the actual data, don't store to db.
     Hold the entity in session without the surface, so the next time you need
     data just get from that one.
     """
     try:
         context = common.get_from_session(KEY_SURFACE_CONTEXT)
         context.set_focal_points(focal_points)
         kwargs = copy.deepcopy(context.equation_kwargs)
         surface_stimulus_creator = self.get_creator_and_interface(
             SURFACE_STIMULUS_CREATOR_MODULE,
             SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface())[0]
         min_time = float(kwargs.get('min_tmp_x', 0))
         max_time = float(kwargs.get('max_tmp_x', 100))
         kwargs = surface_stimulus_creator.prepare_ui_inputs(kwargs)
         stimulus = surface_stimulus_creator.launch(**kwargs)
         surface_gid = common.get_from_session(PARAM_SURFACE)
         surface = ABCAdapter.load_entity_by_gid(surface_gid)
         stimulus.surface = surface
         stimulus.configure_space()
         time = numpy.arange(min_time, max_time, 1)
         time = time[numpy.newaxis, :]
         stimulus.configure_time(time)
         data = []
         max_value = numpy.max(stimulus())
         min_value = numpy.min(stimulus())
         for i in range(min(CHUNK_SIZE,
                            stimulus.temporal_pattern.shape[1])):
             step_data = stimulus(i).tolist()
             data.append(step_data)
         stimulus.surface = surface.gid
         common.add2session(KEY_STIMULUS, stimulus)
         result = {
             'status': 'ok',
             'max': max_value,
             'min': min_value,
             'data': data,
             "time_min": min_time,
             "time_max": max_time,
             "chunk_size": CHUNK_SIZE
         }
         return result
     except (NameError, ValueError, SyntaxError):
         return {
             'status':
             'error',
             'errorMsg':
             "Could not generate stimulus data. Some of the parameters hold invalid characters."
         }
     except Exception, ex:
         return {'allSeries': 'error', 'errorMsg': ex.message}
Example #4
0
 def _get_stimulus_interface(self):
     """
     Returns a dictionary which contains the interface for a surface stimulus.
     """
     context = base.get_from_session(KEY_SURFACE_CONTEXT)
     input_list = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
                                                 SURFACE_STIMULUS_CREATOR_CLASS, StimuliSurface(),
                                                 lock_midpoint_for_eq=[1])[1]
     input_list = ABCAdapter.fill_defaults(input_list, context.equation_kwargs)
     input_list, focal_points_list = self._remove_focal_points(input_list)
     input_list = self.prepare_entity_interface(input_list)
     input_list['selectedFocalPoints'] = focal_points_list
     return self._add_extra_fields_to_interface(input_list)
    def load_surface_stimulus(self, surface_stimulus_gid, from_step):
        """
        Loads the interface for the selected surface stimulus.
        """
        context = common.get_from_session(KEY_SURFACE_CONTEXT)
        selected_surface_stimulus = ABCAdapter.load_entity_by_gid(
            surface_stimulus_gid)
        temporal_eq = selected_surface_stimulus.temporal
        spatial_eq = selected_surface_stimulus.spatial
        surface = selected_surface_stimulus.surface
        focal_points_surface = selected_surface_stimulus.focal_points_surface
        focal_points_triangles = selected_surface_stimulus.focal_points_triangles

        temporal_eq_type = temporal_eq.__class__.__name__
        spatial_eq_type = spatial_eq.__class__.__name__
        default_dict = {
            'temporal': temporal_eq_type,
            'spatial': spatial_eq_type,
            'surface': surface.gid,
            'focal_points_surface': json.dumps(focal_points_surface),
            'focal_points_triangles': json.dumps(focal_points_triangles)
        }
        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])

        default_dict[
            DataTypeMetaData.KEY_TAG_1] = selected_surface_stimulus.user_tag_1

        input_list = self.get_creator_and_interface(
            SURFACE_STIMULUS_CREATOR_MODULE,
            SURFACE_STIMULUS_CREATOR_CLASS,
            StimuliSurface(),
            lock_midpoint_for_eq=[1])[1]
        input_list = ABCAdapter.fill_defaults(input_list, default_dict)
        context.reset()
        context.update_from_interface(input_list)
        context.equation_kwargs[
            DataTypeMetaData.KEY_TAG_1] = selected_surface_stimulus.user_tag_1
        context.set_active_stimulus(surface_stimulus_gid)
        return self.do_step(from_step)
Example #6
0
    def create_stimulus(self):
        """
        Creates a stimulus from the given data.
        """
        try:
            context = common.get_from_session(KEY_SURFACE_CONTEXT)
            surface_stimulus_creator = self.get_creator_and_interface(SURFACE_STIMULUS_CREATOR_MODULE,
                                                                      SURFACE_STIMULUS_CREATOR_CLASS,
                                                                      StimuliSurface())[0]
            self.flow_service.fire_operation(surface_stimulus_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.")
            context.selected_stimulus = None

        except (NameError, ValueError, SyntaxError), _:
            common.set_error_message("The operation failed due to invalid parameter input.")
            return False
    def prepare_stimuli_surface_from_view_model(view_model, load_full_surface=False):
        # type: (SurfaceStimulusCreatorModel, bool) -> StimuliSurface
        stimuli_surface = StimuliSurface()

        stimuli_surface.focal_points_triangles = view_model.focal_points_triangles
        stimuli_surface.spatial = view_model.spatial
        stimuli_surface.temporal = view_model.temporal

        surface_index = SurfaceStimulusCreator.load_entity_by_gid(view_model.surface.hex)
        if load_full_surface:
            stimuli_surface.surface = h5.load_from_index(surface_index)
        else:
            stimuli_surface.surface = CorticalSurface()
            stimuli_surface.gid = view_model.surface
            surface_h5 = h5.h5_file_for_index(surface_index)
            # We need to load surface triangles on stimuli because focal_points_surface property needs to acces them
            stimuli_surface.surface.triangles = surface_h5.triangles.load()
            surface_h5.close()

        return stimuli_surface
Example #8
0
    def prepare_stimuli_surface_from_view_model(self,
                                                view_model,
                                                load_full_surface=False):
        # type: (SurfaceStimulusCreatorModel, bool) -> StimuliSurface
        stimuli_surface = StimuliSurface()

        stimuli_surface.focal_points_triangles = view_model.focal_points_triangles
        stimuli_surface.spatial = view_model.spatial
        stimuli_surface.temporal = view_model.temporal

        if load_full_surface:
            stimuli_surface.surface = self.load_traited_by_gid(
                view_model.surface)
        else:
            stimuli_surface.surface = CorticalSurface()
            stimuli_surface.gid = view_model.surface
            # We need to load surface triangles on stimuli because focal_points_surface property needs to acces them
            with h5.h5_file_for_gid(view_model.surface) as surface_h5:
                stimuli_surface.surface.triangles = surface_h5.triangles.load()

        return stimuli_surface
    def launch(self, **kwargs):
        """
        Used for creating a StimuliSurface instance
        """
        stimuli_surface = StimuliSurface(storage_path=self.storage_path)
        stimuli_surface.surface = kwargs['surface']
        triangles_indices = kwargs['focal_points_triangles']
        focal_points = []
        fp_triangle_indices = []
        for triangle_index in triangles_indices:
            focal_points.append(int(stimuli_surface.surface.triangles[triangle_index][0]))
            fp_triangle_indices.append(int(triangle_index))
        stimuli_surface.focal_points_triangles = fp_triangle_indices
        stimuli_surface.focal_points_surface = focal_points
        stimuli_surface.spatial = self.get_spatial_equation(kwargs)
        stimuli_surface.temporal = self.get_temporal_equation(kwargs)

        return stimuli_surface
    def launch(self, **kwargs):
        """
        Used for creating a `StimuliSurface` instance
        """
        stimuli_surface = StimuliSurface(storage_path=self.storage_path)
        stimuli_surface.surface = kwargs['surface']
        triangles_indices = kwargs['focal_points_triangles']
        focal_points = []
        fp_triangle_indices = []
        for triangle_index in triangles_indices:
            focal_points.append(int(stimuli_surface.surface.triangles[triangle_index][0]))
            fp_triangle_indices.append(int(triangle_index))
        stimuli_surface.focal_points_triangles = fp_triangle_indices
        stimuli_surface.focal_points_surface = focal_points
        stimuli_surface.spatial = self.get_spatial_equation(kwargs)
        stimuli_surface.temporal = self.get_temporal_equation(kwargs)

        return stimuli_surface