Exemplo n.º 1
0
class AnalysisDataStructure1D(AnalysisDataStructure):
    """
    Data structure representing 1D data.
    All data corresponds to the same axis name and units.
    Explicitly specifies the axis - their name and units.
    Note that at this stage we do not assume the structure in which the data
    is stored.
    Also the class can hold multiple instances of 1D data.

    It uses the quantities package to specify units.
    If at all possible all data stored in numpy arrays should be quantities
    arrays with matching units!

    Parameters
    ---------- 
    y_axis_units : quantities
          The quantities units of y axis.
    """

    x_axis_name = SString(doc="the name of the x axis.")
    y_axis_name = SString(doc="the name of the y axis.")

    def __init__(self, x_axis_units, y_axis_units, **params):
        AnalysisDataStructure.__init__(self, **params)
        self.y_axis_units = y_axis_units
        self.x_axis_units = x_axis_units
Exemplo n.º 2
0
class AnalysisDataStructure(MozaikParametrized):
    """
    Encapsulates data that a certain Analysis class generates.

    The four parameters that are common to all AnalysisDataStructure classes are `identified`, `analysis_algorithm`, `neuron`, `sheet_name` and `stimulus_id`.
    """

    identifier = SString(doc="The identifier of the analysis data structure")
    analysis_algorithm = SString(
        doc="The identifier of the analysis data structure")

    neuron = SInteger(
        default=None,
        doc=
        "Neuron id to which the datastructure belongs. None if it is not neuron specific"
    )
    sheet_name = SString(
        default=None,
        doc=
        "The sheet for which this results were computed. None if they do not belong to specific sheet"
    )
    stimulus_id = SString(
        default=None,
        doc=
        "The stimulus for which the results were computed. None if they are not related to specific stimulus"
    )

    def __init__(self, tags=[], **params):
        MozaikParametrized.__init__(self, **params)
        self.tags = tags
Exemplo n.º 3
0
class Connections(AnalysisDataStructure):
    """
    Data structure holding connections.

    Parameters
    ---------- 
    weights : list
            List of tuples (i,j,w) where i is index of pre-synaptic neuron in sheet source_name and j is index of post-synaptic neuron in sheet target_name, and w is the weights.
    
    delays : list
            List of tuples (i,j,d) where i is index of pre-synaptic neuron in sheet source_name and j is index of post-synaptic neuron in sheet target_name, and d is the delay.
    
    """

    proj_name = SString(doc="Projection name.")
    source_name = SString(doc="The name of the source sheet.")
    target_name = SString(doc="The name of the target sheet.")

    def __init__(self, weights, delays, source_size, target_size, **params):
        AnalysisDataStructure.__init__(self,
                                       identifier='Connections',
                                       **params)
        self.weights = weights
        self.delays = delays
        self.source_size = source_size
        self.target_size = target_size
Exemplo n.º 4
0
class NaturalImageWithEyeMovement(TopographicaBasedVisualStimulus):
    """
    A visual stimulus that simulates an eye movement over a static image.

    This is a movie that is generated by translating a 
    static image along a pre-specified path (presumably containing path
    that corresponds to eye-movements).
    
    """
    size = SNumber(
        degrees,
        doc="The length of the longer axis of the image in visual degrees")
    eye_movement_period = SNumber(
        ms,
        doc=
        "The time between two consequitve eye movements recorded in the eye_path file"
    )
    image_location = SString(doc="Location of the image")
    eye_path_location = SString(
        doc="Location of file containing the eye path (two columns of numbers)"
    )

    def frames(self):
        self.time = 0
        f = open(self.eye_path_location, 'r')
        self.eye_path = pickle.load(f)
        self.pattern_sampler = imagen.image.PatternSampler(
            size_normalization='fit_longest',
            whole_pattern_output_fns=[MaximumDynamicRange()])

        image = imagen.image.FileImage(
            filename=self.image_location,
            x=0,
            y=0,
            orientation=0,
            xdensity=self.density,
            ydensity=self.density,
            size=self.size,
            bounds=BoundingBox(points=((-self.size_x / 2, -self.size_y / 2),
                                       (self.size_x / 2, self.size_y / 2))),
            scale=2 * self.background_luminance,
            pattern_sampler=self.pattern_sampler)

        while True:
            location = self.eye_path[int(
                numpy.floor(self.frame_duration * self.time /
                            self.eye_movement_period))]
            image.x = location[0]
            image.y = location[1]
            yield (image(), [self.time])
            self.time += 1
Exemplo n.º 5
0
class TextureBasedVisualStimulus(VisualStimulus):
    """
    As we do not handle transparency in texture stimuli (i.e. all pixels of all stimuli difned here will have 0% transparancy)
    in this abstract class we disable the transparent flag defined by the :class:`mozaik.stimuli.visual_stimulus.VisualStimulus`, to improve efficiency.

    We require a path to the image from which we generate stimuli
    """
    texture_path = SString(
        doc="path to the image from which we generate stimuli")
    texture = SString(
        doc="name of the original texture from which we generate stimuli")

    def __init__(self, **params):
        VisualStimulus.__init__(self, **params)
Exemplo n.º 6
0
class DriftingGratingWithEyeMovement(TopographicaBasedVisualStimulus):
    """
    A visual stimulus that simulates an eye movement over a drifting  gratings.

    This is a movie that is generated by translating a 
    full-field drifting sinusoidal gratings along a pre-specified path 
    (presumably containing path that corresponds to eye-movements).
    """

    orientation = SNumber(rad,
                          period=pi,
                          bounds=[0, pi],
                          doc="Grating orientation")
    spatial_frequency = SNumber(cpd, doc="Spatial frequency of grating")
    temporal_frequency = SNumber(Hz, doc="Temporal frequency of grating")
    contrast = SNumber(dimensionless,
                       bounds=[0, 100.0],
                       doc="Contrast of the stimulus")
    eye_movement_period = SNumber(
        ms,
        doc=
        "The time between two consequitve eye movements recorded in the eye_path file"
    )
    eye_path_location = SString(
        doc="Location of file containing the eye path (two columns of numbers)"
    )

    def frames(self):

        f = open(self.eye_path_location, 'r')
        self.eye_path = pickle.load(f)
        self.time = 0
        self.current_phase = 0
        while True:
            location = self.eye_path[int(
                numpy.floor(self.frame_duration * self.time /
                            self.eye_movement_period))]

            image = imagen.SineGrating(
                orientation=self.orientation,
                x=location[0],
                y=location[1],
                frequency=self.spatial_frequency,
                phase=self.current_phase,
                bounds=BoundingBox(points=((-self.size_x / 2,
                                            -self.size_y / 2),
                                           (self.size_x / 2,
                                            self.size_y / 2))),
                offset=self.background_luminance * (100.0 - self.contrast) /
                100.0,
                scale=2 * self.background_luminance * self.contrast / 100.0,
                xdensity=self.density,
                ydensity=self.density)()
            self.current_phase += 2 * pi * (self.frame_duration /
                                            1000.0) * self.temporal_frequency
            yield (image, [self.time])
            self.time = self.time + 1
Exemplo n.º 7
0
class PerNeuronPairValue(AnalysisDataStructure):
    """
    Data structure holding values for each pair of neurons.
    
    Parameters
    ---------- 
    
    values : numpy.nd_array
           The 2D array holding the values. 

    value_units : quantities
                Quantities unit describing the units of the value
    
    ids : list(int)
        The ids of the neurons which are stored, in the same order as in the values (along both axis).
    """
    value_name = SString(doc="The name of the value.")
    period = SNumber(
        units=None,
        default=None,
        doc="The period of the value. If value is not periodic period=None")

    def __init__(self, values, idds, value_units, **params):
        AnalysisDataStructure.__init__(self,
                                       identifier='PerNeuronValue',
                                       **params)
        self.value_units = value_units
        self.values = numpy.array(values)
        self.ids = list(idds)
        assert values.shape == (len(idds), len(idds))

    def get_value_by_ids(self, idds1, idds2):
        """
        Parameters
        ---------- 
        idds1 : int or list(int)
            The ids for which the return the values along first dimension.
        
        idds2 : int or list(int)
            The ids for which the return the values along first dimension.
        
        Returns
        -------
        ids : scaler or array
            Array or scalar of values corresponding to `idds`.
        """
        if (isinstance(idds1, list) or isinstance(idds1, numpy.ndarray)) and (
                isinstance(idds2, list) or isinstance(idds2, numpy.ndarray)):
            return numpy.array(self.values)[
                [list(self.ids).index(i)
                 for i in idds1], :][:,
                                     [list(self.ids).index(i) for i in idds2]]
        else:
            return self.values[list(self.ids).index(idds1),
                               list(self.ids).index(idds2)]
Exemplo n.º 8
0
class PerNeuronValue(AnalysisDataStructure):
    """
    Data structure holding single value per neuron.
    
    Parameters
    ---------- 
    
    values : list
           The vector of values one per neuron

    value_units : quantities
                Quantities unit describing the units of the value
    
    ids : list(int)
        The ids of the neurons which are stored, in the same order as in the values
    """
    value_name = SString(doc="The name of the value.")
    period = SNumber(
        units=None,
        default=None,
        doc="The period of the value. If value is not periodic period=None")

    def __init__(self, values, idds, value_units, **params):
        AnalysisDataStructure.__init__(self,
                                       identifier='PerNeuronValue',
                                       **params)
        self.value_units = value_units
        self.values = numpy.array(values)
        self.ids = list(idds)
        assert len(values) == len(idds), '%s %s' % (str(values), str(idds))

    def get_value_by_id(self, idds):
        """
        Parameters
        ---------- 
        idd : int or list(int)
            The ids for which the return the values.
        
        Returns
        -------
        ids : AnalogSignal or list(AnalogSignal)
            List (or single) of AnalogSignal objects corresponding to ids in `idd`.
        """
        if isinstance(idds, list) or isinstance(idds, numpy.ndarray):
            return [self.values[list(self.ids).index(i)] for i in idds]
        else:
            return numpy.array(self.values)[list(self.ids).index(idds)]
Exemplo n.º 9
0
class SingleValue(AnalysisDataStructure):
    """
    Data structure holding single value. This can be per model, if sheet parameter is None,
    or per sheet if sheet is specified. In principle it can also be per neuron if the neuron
    parameter is specified, but in most cases you probably want to use :class:`.PerNeuronValue`
    instead.
    """

    value = SNumber(units=None, default=None, doc="The value.")
    value_name = SString(doc="The name of the value.")
    period = SNumber(
        units=None,
        default=None,
        doc="The period of the value. If value is not periodic period=None")

    def __init__(self, **params):
        AnalysisDataStructure.__init__(self,
                                       identifier='SingleValue',
                                       **params)
Exemplo n.º 10
0
class SingleValueList(AnalysisDataStructure):
    """
    Data structure holding a list of single values. This can be per model, if sheet parameter
    is None, or per sheet if sheet is specified.

    All values need to have the same unit.

    Parameters
    ----------
    values : list
                List of values
    values_unit : quantities
                Quantities unit describing the unit of the values
    """
    value_name = SString(doc="The name of the value.")

    def __init__(self, values, values_unit, **params):
        AnalysisDataStructure.__init__(self, identifier='SingleValueList', **params)
        self.values = values
        self.values_unit = values_unit
Exemplo n.º 11
0
class BaseStimulus(MozaikParametrized):
    """
    The abstract stimulus class. It defines the parameters common to all stimuli and
    the list of function each stimulus has to provide.
    """
    frame_duration = SNumber(qt.ms, doc="The duration of single frame")
    duration = SNumber(qt.ms, doc="The duration of stimulus")
    trial = SInteger(doc="The trial of the stimulus")
    direct_stimulation_name = SString(
        default="None", doc="The name of the artifical stimulation protocol")

    def __init__(self, **params):
        MozaikParametrized.__init__(self, **params)
        self.input = None
        self._frames = self.frames()
        self.n_frames = numpy.inf  # possibly very dangerous. Don't do 'for i in range(stim.n_frames)'!

    def __eq__(self, other):
        """
        Are the name and all parameters of two stimuli are equivallent?
        """
        return self.equalParams(other) and (self.__class__ == other.__class__)

    def number_of_parameters(self):
        """
        Returns number of parameters of the stimulus.
        """
        return len(self.get_param_values())

    def frames(self):
        """
        Return a generator which yields the frames of the stimulus in sequence.
        Each frame is returned as a tuple `(frame, variables)` where
        `frame` is a numpy array containing the stimulus at the given time and
        `variables` is a list of variable values (e.g., orientation) associated
        with that frame.

        See topographica_based for examples.
        """
        raise NotImplementedError("Must be implemented by child class.")

    def update(self):
        """
        Sets the current frame to the next frame in the sequence.
        """
        raise NotImplementedError("Must be implemented by child class.")

    def reset(self):
        """
        Reset to the first frame in the sequence.
        """
        raise NotImplementedError("Must be implemented by child class.")

    def export(self, path=None):
        """
        Save the frames to disk. Returns a list of paths to the individual
        frames.

        path - the directory in which the individual frames will be saved. If
               path is None, then a temporary directory is created.
        """
        raise NotImplementedError("Must be implemented by child class.")