class StimuliRegionData(SpatioTemporalPatternData): """ A class that bundles the temporal profile of the stimulus, together with the list of scaling weights of the regions where it will applied. """ connectivity = connectivity_module.Connectivity(label="Connectivity", order=1) spatial = equations.DiscreteEquation(label="Spatial Equation", default=equations.DiscreteEquation, fixed_type=True, order=-1) weight = basic.List(label="scaling", locked=True, order=4)
def test_stimuliregion(self): conn = connectivity.Connectivity(load_default=True) conn.configure() dt = patterns.StimuliRegion() dt.connectivity = conn dt.spatial = equations.DiscreteEquation() dt.temporal = equations.Gaussian() dt.weight = [0 for _ in range(conn.number_of_regions)] dt.configure_space() assert dt.summary_info['Type'] == 'StimuliRegion' assert dt.connectivity is not None assert dt.space.shape == (76, 1) assert dt.spatial_pattern.shape == (76, 1) assert isinstance(dt.temporal, equations.Gaussian) assert dt.temporal_pattern is None assert dt.time is None
def test_stimuliregion(self): conn = connectivity.Connectivity() conn.configure() dt = patterns.StimuliRegion() dt.connectivity = conn dt.spatial = equations.DiscreteEquation() dt.temporal = equations.Gaussian() dt.weight = [0 for _ in range(conn.number_of_regions)] dt.configure_space() self.assertEqual(dt.summary_info['Type'], 'StimuliRegion') self.assertTrue(dt.connectivity is not None) self.assertEqual(dt.space.shape, (74, 1)) self.assertEqual(dt.spatial_pattern.shape, (74, 1)) self.assertTrue(isinstance(dt.temporal, equations.Gaussian)) self.assertTrue(dt.temporal_pattern is None) self.assertTrue(dt.time is None)
def test_stimulisurface(self): srf = surfaces.CorticalSurface.from_file() srf.configure() dt = patterns.StimuliSurface() dt.surface = srf dt.spatial = equations.DiscreteEquation() dt.temporal = equations.Gaussian() dt.focal_points_triangles = numpy.array([0, 1, 2]) dt.configure() dt.configure_space() summary = dt.summary_info() assert summary['Type'] == "StimuliSurface" assert dt.space.shape == (16384, 3) assert isinstance(dt.spatial, equations.DiscreteEquation) assert dt.spatial_pattern.shape == (16384, 1) assert dt.surface is not None assert isinstance(dt.temporal, equations.Gaussian) assert dt.temporal_pattern is None assert dt.time is None
def __init__(self, connectivity=None, spatial=None, weight=None, *args, **kwargs): if connectivity is None: connectivity = conn.Connectivity() self.connectivity = connectivity # lives in base class if spatial is None: spatial = equations.DiscreteEquation() if weight is None: weight = [] self.weight = weight super(StimuliRegion, self).__init__(*args, spatial=spatial, **kwargs)
class StimuliRegion(SpatioTemporalPattern): """ A class that bundles the temporal profile of the stimulus, together with the list of scaling weights of the regions where it will applied. """ connectivity = connectivity.Connectivity(label="Connectivity", order=1) spatial = equations.DiscreteEquation(label="Spatial Equation", default=equations.DiscreteEquation, fixed_type=True, order=-1) weight = basic.List(label="scaling", locked=True, order=4) @staticmethod def get_default_weights(number_of_regions): """ Returns a list with a number of elements equal to the given number of regions. """ return [0.0] * number_of_regions @property def weight_array(self): """ Wrap weight List into a Numpy array, as it is requested by the simulator. """ return numpy.array(self.weight)[:, numpy.newaxis] def configure_space(self, region_mapping=None): """ Do necessary preparations in order to use this stimulus. NOTE: this was previously done in simulator configure_stimuli() method. It no needs to be used in stimulus viewer also. """ if region_mapping is not None: #TODO: smooth at surface region boundaries distance = self.weight_array[region_mapping, :] else: distance = self.weight_array super(StimuliRegion, self).configure_space(distance)
def test_stimulisurface(self): srf = surfaces.CorticalSurface(load_default=True) srf.configure() dt = patterns.StimuliSurface() dt.surface = srf dt.spatial = equations.DiscreteEquation() dt.temporal = equations.Gaussian() dt.focal_points_surface = [0, 1, 2] dt.focal_points_triangles = [0, 1, 2] dt.configure() dt.configure_space() summary = dt.summary_info self.assertEqual(summary['Type'], "StimuliSurface") self.assertEqual(dt.space.shape, (16384, 3)) self.assertTrue(isinstance(dt.spatial, equations.DiscreteEquation)) self.assertEqual(dt.spatial_pattern.shape, (16384, 1)) self.assertTrue(dt.surface is not None) self.assertTrue(isinstance(dt.temporal, equations.Gaussian)) self.assertTrue(dt.temporal_pattern is None) self.assertTrue(dt.time is None)
def test_discrete(self): dt = equations.DiscreteEquation() assert dt.parameters == {}
def test_discrete(self): dt = equations.DiscreteEquation() self.assertEqual(dt.parameters, {})