def test_create_stimulus_surface_with_operation(self):
        surface_stimulus_creator = SurfaceStimulusCreator()

        view_model = surface_stimulus_creator.get_view_model_class()()
        view_model.surface = self.surface.gid
        view_model.focal_points_triangles = numpy.array([1, 2, 3])
        view_model.spatial = SpatialEquationsEnum.SIGMOID.instance
        view_model.spatial.parameters['radius'] = 5.5
        view_model.spatial.parameters['offset'] = 0.1
        view_model.spatial_amp = 1.0
        view_model.spatial_sigma = 1.0
        view_model.spatial_offset = 0.0
        view_model.temporal = TemporalEquationsEnum.ALPHA.instance
        view_model.temporal.parameters['alpha'] = 15.0
        view_model.temporal.parameters['beta'] = 40.0

        OperationService().fire_operation(surface_stimulus_creator, self.test_user, self.test_project.id,
                                          view_model=view_model)
        surface_stimulus_index = TestFactory.get_entity(self.test_project, StimuliSurfaceIndex)

        assert surface_stimulus_index.spatial_equation == 'Sigmoid'
        assert surface_stimulus_index.temporal_equation == 'Alpha'
        assert surface_stimulus_index.fk_surface_gid == self.surface.gid

        spatial_eq_params = json.loads(surface_stimulus_index.spatial_parameters)
        assert spatial_eq_params['radius'] == 5.5
        assert spatial_eq_params['offset'] == 0.1

        temporal_eq_params = json.loads(surface_stimulus_index.temporal_parameters)
        assert temporal_eq_params['alpha'] == 15.0
        assert temporal_eq_params['beta'] == 40.0
    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:
            current_surface_stim = common.get_from_session(KEY_SURFACE_STIMULI)
            current_surface_stim.focal_points_triangles = numpy.array(json.loads(focal_points))
            min_time = common.get_from_session(KEY_TMP_FORM).min_tmp_x.value or 0
            max_time = common.get_from_session(KEY_TMP_FORM).max_tmp_x.value or 100

            stimuli_surface = SurfaceStimulusCreator.prepare_stimuli_surface_from_view_model(current_surface_stim, True)
            stimuli_surface.configure_space()
            time = numpy.arange(min_time, max_time, 1)
            time = time[numpy.newaxis, :]
            stimuli_surface.configure_time(time)
            current_surface_stim._temporal_pattern = stimuli_surface.temporal_pattern
            current_surface_stim._spatial_pattern = stimuli_surface.spatial_pattern

            data = []
            max_value = numpy.max(stimuli_surface())
            min_value = numpy.min(stimuli_surface())
            for i in range(min(CHUNK_SIZE, stimuli_surface.temporal_pattern.shape[1])):
                step_data = stimuli_surface(i).tolist()
                data.append(step_data)
            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 as ex:
            return {'allSeries': 'error', 'errorMsg': ex}
Example #3
0
    def test_create_stimulus_surface(self):
        surface_stimulus_creator = SurfaceStimulusCreator()

        view_model = surface_stimulus_creator.get_view_model_class()()
        view_model.surface = UUID(self.surface.gid)
        view_model.focal_points_triangles = numpy.array([1, 2, 3])
        view_model.spatial = FiniteSupportEquation()
        view_model.spatial_amp = 1.0
        view_model.spatial_sigma = 1.0
        view_model.spatial_offset = 0.0
        view_model.temporal = TemporalApplicableEquation()
        view_model.temporal.parameters['a'] = 1.0
        view_model.temporal.parameters['b'] = 0.0

        surface_stimulus_index = surface_stimulus_creator.launch(view_model)

        assert surface_stimulus_index.spatial_equation == 'FiniteSupportEquation'
        assert surface_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
        assert surface_stimulus_index.surface_gid == self.surface.gid
Example #4
0
    def test_create_stimulus_surface_with_operation(self):
        surface_stimulus_creator = SurfaceStimulusCreator()

        view_model = surface_stimulus_creator.get_view_model_class()()
        view_model.surface = UUID(self.surface.gid)
        view_model.focal_points_triangles = numpy.array([1, 2, 3])
        view_model.spatial = FiniteSupportEquation()
        view_model.spatial_amp = 1.0
        view_model.spatial_sigma = 1.0
        view_model.spatial_offset = 0.0
        view_model.temporal = TemporalApplicableEquation()
        view_model.temporal.parameters['a'] = 1.0
        view_model.temporal.parameters['b'] = 0.0

        FlowService().fire_operation(surface_stimulus_creator, self.test_user, self.test_project.id,
                                     view_model=view_model)
        surface_stimulus_index = TestFactory.get_entity(self.test_project, StimuliSurfaceIndex)

        assert surface_stimulus_index.spatial_equation == 'FiniteSupportEquation'
        assert surface_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
        assert surface_stimulus_index.surface_gid == self.surface.gid
    def test_create_stimulus_surface(self, operation_factory):
        surface_stimulus_creator = SurfaceStimulusCreator()

        view_model = surface_stimulus_creator.get_view_model_class()()
        view_model.surface = self.surface.gid
        view_model.focal_points_triangles = numpy.array([1, 2, 3])
        view_model.spatial = SpatialEquationsEnum.MEXICAN_HAT.instance
        view_model.spatial.parameters['amp_1'] = 0.75
        view_model.spatial.parameters['amp_2'] = 1.25
        view_model.spatial_amp = 1.0
        view_model.spatial_sigma = 1.0
        view_model.spatial_offset = 0.0
        view_model.temporal = TemporalEquationsEnum.SINUSOID.instance
        view_model.temporal.parameters['amp'] = 1.1
        view_model.temporal.parameters['frequency'] = 0.025

        operation = operation_factory(test_user=self.test_user, test_project=self.test_project)
        surface_stimulus_creator.extract_operation_data(operation)
        surface_stimulus_index = surface_stimulus_creator.launch(view_model)

        assert surface_stimulus_index.spatial_equation == 'DoubleGaussian'
        assert surface_stimulus_index.temporal_equation == 'Sinusoid'
        assert surface_stimulus_index.fk_surface_gid == self.surface.gid

        spatial_eq_params = json.loads(surface_stimulus_index.spatial_parameters)
        assert spatial_eq_params['amp_1'] == 0.75
        assert spatial_eq_params['amp_2'] == 1.25

        temporal_eq_params = json.loads(surface_stimulus_index.temporal_parameters)
        assert temporal_eq_params['amp'] == 1.1
        assert temporal_eq_params['frequency'] == 0.025
    def test_create_stimulus_surface(self, operation_factory):
        surface_stimulus_creator = SurfaceStimulusCreator()

        view_model = surface_stimulus_creator.get_view_model_class()()
        view_model.surface = self.surface.gid
        view_model.focal_points_triangles = numpy.array([1, 2, 3])
        view_model.spatial = FiniteSupportEquation()
        view_model.spatial_amp = 1.0
        view_model.spatial_sigma = 1.0
        view_model.spatial_offset = 0.0
        view_model.temporal = TemporalApplicableEquation()
        view_model.temporal.parameters['a'] = 1.0
        view_model.temporal.parameters['b'] = 0.0

        operation = operation_factory(test_user=self.test_user,
                                      test_project=self.test_project)
        surface_stimulus_creator.extract_operation_data(operation)
        surface_stimulus_index = surface_stimulus_creator.launch(view_model)

        assert surface_stimulus_index.spatial_equation == 'FiniteSupportEquation'
        assert surface_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
        assert surface_stimulus_index.fk_surface_gid == self.surface.gid