Exemple #1
0
    def get_data(
            self, variables='all', gather=True, clear=False, annotations=None):
        """ Return a Neo `Block` containing the data\
            (spikes, state variables) recorded from the Assembly.

        :param variables: either a single variable name or a list of variable\
            names. Variables must have been previously recorded, otherwise an
            Exception will be raised.
        :type variables: str or list
        :param gather: Whether to collect data from all MPI nodes or just the\
            current node.

            .. note::
                This is irrelevant on sPyNNaker, which always behaves as if
                this parameter is True.

        :type gather: bool
        :param clear: \
            Whether recorded data will be deleted from the `Assembly`.
        :type clear: bool
        :param annotations: annotations to put on the neo block
        :type annotations: dict
        :rtype: neo.Block
        """
        if not gather:
            logger.warning(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")
        if annotations is not None:
            warn_once(
                logger, "Annoations Parameter is not standard PyNN so may not "
                        "be supported by all platformd.")

        return self._extract_neo_block(variables, None, clear, annotations)
Exemple #2
0
    def record(self, variables, to_file=None, sampling_interval=None,
               indexes=None):
        """ Record the specified variable or variables for all cells in the\
            Population or view.

        :param variables: either a single variable name or a list of variable\
            names. For a given celltype class, `celltype.recordable` contains\
            a list of variables that can be recorded for that celltype.
        :type variables: str or list(str)
        :param to_file: a file to automatically record to (optional).\
            `write_data()` will be automatically called when `end()` is called.
        :type to_file: a Neo IO instance
        :param sampling_interval: a value in milliseconds, and an integer\
            multiple of the simulation timestep.
        :type sampling_interval: int
        :param indexes: The indexes of neurons to record from.\
        This is none Standard PyNN and equivelent to creating a view with\
        these indexes and asking the View to record.
        """
        # pylint: disable=arguments-differ
        if indexes is not None:
            warn_once(
                logger, "record indexes parameter is non-standard PyNN, "
                "so may not be portable to other simulators. "
                "It is now deprecated and replaced with views")
        self._record_with_indexes(
            variables, to_file, sampling_interval, indexes)
    def get(self, parameter_names, gather=True, simplify=True):
        """ Get the values of a parameter for every local cell in the\
            population.

        :param parameter_names: Name of parameter. This is either a single\
            string or a list of strings
        :type parameter_names: str or iterable(str)
        :param bool gather: pointless on sPyNNaker
        :param bool simplify: ignored
        :return: A single list of values (or possibly a single value) if\
            paramter_names is a string, or a dict of these if parameter names\
            is a list.
        :rtype: str or list(str) or dict(str,str) or dict(str,list(str))
        """
        if not gather:
            warn_once(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")
        if simplify is not True:
            warn_once(logger,
                      "The simplify value is ignored if not set to true")
        if not self._vertex_population_settable:
            raise KeyError("Population does not support setting")
        if isinstance(parameter_names, string_types):
            return self.__vertex.get_value(parameter_names)
        results = dict()
        for parameter_name in parameter_names:
            results[parameter_name] = self.__vertex.get_value(parameter_name)
        return results
Exemple #4
0
    def get_data(self,
                 variables='all',
                 gather=True,
                 clear=False,
                 annotations=None):
        """ Return a Neo Block containing the data(spikes, state variables)\
            recorded from the Population.

        :param variables: Either a single variable name or a list of variable\
            names. Variables must have been previously recorded, otherwise an\
            Exception will be raised.
        :param gather: For parallel simulators, if gather is True, all data\
            will be gathered to all nodes and the Neo Block will contain data\
            from all nodes. \
            Otherwise, the Neo Block will contain only data from the cells\
            simulated on the local node.

            .. note::
                SpiNNaker always gathers.

        :param clear: If True, recorded data will be deleted from the\
            Population.
         :param annotations: annotations to put on the neo block
       """
        if not gather:
            logger.warning("SpiNNaker only supports gather=True. We will run "
                           "as if gather was set to True.")
        if annotations is not None:
            warn_once(
                logger, "Annoations Parameter is not standard PyNN so may not "
                "be supported by all platformd.")

        return self.__population.get_data_by_indexes(variables,
                                                     self.__indexes,
                                                     clear=clear)
Exemple #5
0
    def write_data(self, io, variables='all', gather=True, clear=False,
                   annotations=None):
        """ Write recorded data to file, using one of the file formats\
            supported by Neo.

        :param io: \
            a Neo IO instance, or a string for where to put a neo instance
        :type io: neo instance or str
        :param variables: \
            either a single variable name or a list of variable names.\
            Variables must have been previously recorded, otherwise an\
            Exception will be raised.
        :type variables: str or list(str)
        :param gather: pointless on sPyNNaker
        :param clear: \
            clears the storage data if set to true after reading it back
        :param annotations: annotations to put on the neo block
        """
        # pylint: disable=too-many-arguments
        if not gather:
            logger_utils.warn_once(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")

        if isinstance(io, string_types):
            io = neo.get_io(io)

        data = self._extract_neo_block(variables, None, clear, annotations)
        # write the neo block to the file
        io.write(data)
    def __init__(self, safe=True, callback=None, verbose=False, rng=None):
        """
        :param bool safe: if True, check that weights and delays have valid
            values. If False, this check is skipped. (NB: SpiNNaker always
            checks.)
        :param callable callback: Ignored
        :param bool verbose:
        :param rng:
            Seeded random number generator, or None to make one when needed
        :type rng: ~pyNN.random.NumpyRNG or None
        """
        if callback is not None:
            warn_once(logger, "sPyNNaker ignores connector callbacks.")
        self.__safe = safe
        self.__space = None
        self.__verbose = verbose

        self._rng = rng

        self.__n_clipped_delays = numpy.int64(0)
        self.__min_delay = 0
        self.__param_seeds = dict()
        self.__synapse_info = None

        self.requires_spike_mapping = False
        self.needs_dma_weights = True
    def _generate_weights(self, sources, targets, n_connections,
                          connection_slices, pre_slice, post_slice,
                          synapse_info):
        """ Generate weight values.

        :param int n_connections:
        :param list(slice) connection_slices:
        :param ~pacman.model.graphs.common.Slice pre_slice:
        :param ~pacman.model.graphs.common.Slice post_slice:
        :param SynapseInformation synapse_info:
        :rtype: ~numpy.ndarray
        """
        weights = self._generate_values(synapse_info.weights, sources, targets,
                                        n_connections, connection_slices,
                                        pre_slice, post_slice, synapse_info)
        if self.__safe:
            if not weights.size:
                warn_once(logger, "No connection in " + str(self))
            elif numpy.amin(weights) < 0 < numpy.amax(weights):
                raise SpynnakerException(
                    "Weights must be either all positive or all negative"
                    " in projection {}->{}".format(
                        synapse_info.pre_population.label,
                        synapse_info.post_population.label))
        return numpy.abs(weights)
Exemple #8
0
 def save(
         self, attribute_names, file, format='list',  # @ReservedAssignment
         gather=True, with_address=True):
     """ Print synaptic attributes (weights, delays, etc.) to file. In the\
         array format, zeros are printed for non-existent connections.\
         Values will be expressed in the standard PyNN units (i.e., \
         millivolts, nanoamps, milliseconds, microsiemens, nanofarads, \
         event per second).
     """
     if not gather:
         warn_once(
             logger, "sPyNNaker only supports gather=True. We will run "
             "as if gather was set to True.")
     if isinstance(attribute_names, string_types):
         attribute_names = [attribute_names]
     # pylint: disable=too-many-arguments
     if attribute_names in (['all'], ['connections']):
         attribute_names = \
             self._projection_edge.post_vertex.synapse_dynamics.\
             get_parameter_names()
     metadata = {"columns": attribute_names}
     if with_address:
         metadata["columns"] = ["i", "j"] + list(metadata["columns"])
     self._get_data(
         attribute_names, format, with_address,
         notify=functools.partial(self.__save_callback, file, metadata))
Exemple #9
0
    def record(self, variables, to_file, sampling_interval, indexes):
        """ Same as record but without non-standard PyNN warning

        This method is non-standard PyNN and is intended only to be called by
        record in a Population, View or Assembly

        :param variables: either a single variable name or a list of variable
            names. For a given celltype class, ``celltype.recordable`` contains
            a list of variables that can be recorded for that celltype.
            Can also be ``None`` to reset the list of variables.
        :type variables: str or list(str) or None
        :param to_file: a file to automatically record to (optional).
            :py:meth:`write_data` will be automatically called when
            `sim.end()` is called.
        :type to_file: ~neo.io or ~neo.rawio or str
        :param int sampling_interval: a value in milliseconds, and an integer
            multiple of the simulation timestep.
        :param indexes: The indexes of neurons to record from.
            This is non-standard PyNN and equivalent to creating a view with
            these indexes and asking the View to record.
        :type indexes: None or list(int)
        """
        if variables is None:  # reset the list of things to record
            if sampling_interval is not None:
                raise ConfigurationException(
                    "Clash between parameters in record."
                    "variables=None turns off recording,"
                    "while sampling_interval!=None implies turn on recording")
            if indexes is not None:
                warn_once(
                    logger,
                    "View.record with variable None is non-standard PyNN. "
                    "Only the neurons in the view have their record turned "
                    "off. Other neurons already set to record will remain "
                    "set to record")

            # note that if record(None) is called, its a reset
            self.turn_off_all_recording(indexes)
            # handle one element vs many elements
        elif isinstance(variables, str):
            # handle special case of 'all'
            if variables == "all":
                warn_once(
                    logger, 'record("all") is non-standard PyNN, and '
                    'therefore may not be portable to other simulators.')

                # iterate though all possible recordings for this vertex
                for variable in self.get_all_possible_recordable_variables():
                    self.turn_on_record(variable, sampling_interval, to_file,
                                        indexes)
            else:
                # record variable
                self.turn_on_record(variables, sampling_interval, to_file,
                                    indexes)

        else:  # list of variables, so just iterate though them
            for variable in variables:
                self.turn_on_record(variable, sampling_interval, to_file,
                                    indexes)
 def test_two(self):
     with LogCapture() as lc:
         logger_utils.warn_once(logger, "a log warning")
         logger_utils.warn_once(logger, "another log warning")
         log_checker.assert_logs_contains_once("WARNING", lc.records,
                                               "a log warning")
         log_checker.assert_logs_contains_once("WARNING", lc.records,
                                               "another log warning")
Exemple #11
0
 def mean_spike_count(self, gather=True):
     """ Returns the mean number of spikes per neuron.
     """
     if not gather:
         warn_once(
             logger, "sPyNNaker only supports gather=True. We will run "
             "as if gather was set to True.")
     counts = self.get_spike_counts()
     return sum(itervalues(counts)) / len(counts)
 def test_error(self):
     with LogCapture() as lc:
         logger_utils.error_once(logger, "a log Error")
         logger_utils.warn_once(logger, "another log error")
         logger_utils.warn_once(logger, "a log warning")
         logger_utils.error_once(logger, "a log Error")
         log_checker.assert_logs_contains_once("ERROR", lc.records,
                                               "a log Error")
         log_checker.assert_logs_error_not_contains(lc.records,
                                                    "another log error")
Exemple #13
0
    def __read_in_signal(self, segment, block, signal_array, data_indexes,
                         view_indexes, variable, recording_start_time,
                         sampling_interval, units, label):
        """ Reads in a data item that's not spikes (likely v, gsyn e, gsyn i)\
            and saves this data to the segment.

        :param ~neo.core.Segment segment: Segment to add data to
        :param ~neo.core.Block block: neo block
        :param ~numpy.ndarray signal_array: the raw signal data
        :param list(int) data_indexes: The indexes for the recorded data
        :param view_indexes: The indexes for which data should be returned.
            If ``None``, all data (view_index = data_indexes)
        :type view_indexes: list(int) or None
        :param str variable: the variable name
        :param recording_start_time: when recording started
        :type recording_start_time: float or int
        :param sampling_interval: how often a neuron is recorded
        :type sampling_interval: float or int
        :param units: the units of the recorded value
        :type units: quantities.quantity.Quantity or str
        :param str label: human readable label
        """
        # pylint: disable=too-many-arguments, no-member
        t_start = recording_start_time * quantities.ms
        sampling_period = sampling_interval * quantities.ms
        if view_indexes is None:
            if len(data_indexes) != self.__population.size:
                warn_once(logger, self._SELECTIVE_RECORDED_MSG)
            indexes = numpy.array(data_indexes)
        elif view_indexes == data_indexes:
            indexes = numpy.array(data_indexes)
        else:
            # keep just the view indexes in the data
            indexes = [i for i in view_indexes if i in data_indexes]
            # keep just data columns in the view
            map_indexes = [data_indexes.index(i) for i in indexes]
            signal_array = signal_array[:, map_indexes]

        ids = list(map(self.__population.index_to_id, indexes))
        data_array = neo.AnalogSignal(signal_array,
                                      units=units,
                                      t_start=t_start,
                                      sampling_period=sampling_period,
                                      name=variable,
                                      source_population=label,
                                      source_ids=ids)
        channel_index = self.__get_channel_index(indexes, block)
        data_array.channel_index = channel_index
        data_array.shape = (data_array.shape[0], data_array.shape[1])
        segment.analogsignals.append(data_array)
        channel_index.analogsignals.append(data_array)
    def _record(self,
                variable,
                sampling_interval=None,
                to_file=None,
                indexes=None):
        """ tells the vertex to record data

        :param variable: the variable to record, valued variables to record
        are: 'gsyn_exc', 'gsyn_inh', 'v', 'spikes'
        :param sampling_interval: the interval to record them
        :param indexes: List of indexes to record or None for all
        :return:  None
        """

        get_simulator().verify_not_running()
        # tell vertex its recording
        if variable == "spikes":
            if not isinstance(self._population._vertex,
                              AbstractSpikeRecordable):
                raise Exception("This population does not support the "
                                "recording of spikes!")
            self._population._vertex.set_recording_spikes(
                sampling_interval=sampling_interval, indexes=indexes)
        elif variable == "all":
            raise Exception("Illegal call with all")
        else:
            if not isinstance(self._population._vertex,
                              AbstractNeuronRecordable):
                raise Exception("This population does not support the "
                                "recording of {}!".format(variable))
            self._population._vertex.set_recording(
                variable, sampling_interval=sampling_interval, indexes=indexes)

        # update file writer
        self._write_to_files_indicators[variable] = to_file

        if variable == "gsyn_exc":
            if not isinstance(self._population._vertex.input_type,
                              InputTypeConductance):
                logger_utils.warn_once(
                    logger, "You are trying to record the excitatory "
                    "conductance from a model which does not use conductance "
                    "input. You will receive current measurements instead.")
        elif variable == "gsyn_inh":
            if not isinstance(self._population._vertex.input_type,
                              InputTypeConductance):
                logger_utils.warn_once(
                    logger, "You are trying to record the inhibtatory "
                    "conductance from a model which does not use conductance "
                    "input. You will receive current measurements instead.")
Exemple #15
0
    def turn_on_record(self,
                       variable,
                       sampling_interval=None,
                       to_file=None,
                       indexes=None):
        """ Tell the vertex to record data.

        :param str variable: The variable to record, supported variables to
            record are: ``gsyn_exc``, ``gsyn_inh``, ``v``, ``spikes``.
        :param int sampling_interval: the interval to record them
        :param to_file: If set, a file to write to (by handle or name)
        :type to_file: neo.io.baseio.BaseIO or str or None
        :param indexes: List of indexes to record or None for all
        :type indexes: list(int) or None
        """

        get_simulator().verify_not_running()
        # tell vertex its recording
        if variable == "spikes":
            if not isinstance(self.__vertex, AbstractSpikeRecordable):
                raise Exception("This population does not support the "
                                "recording of spikes!")
            self.__vertex.set_recording_spikes(
                sampling_interval=sampling_interval, indexes=indexes)
        elif variable == "all":
            raise Exception("Illegal call with all")
        else:
            if not isinstance(self.__vertex, AbstractNeuronRecordable):
                raise Exception("This population does not support the "
                                "recording of {}!".format(variable))
            self.__vertex.set_recording(variable,
                                        sampling_interval=sampling_interval,
                                        indexes=indexes)

        # update file writer
        self.__write_to_files_indicators[variable] = to_file

        if variable == "gsyn_exc":
            if not self.__vertex.conductance_based:
                warn_once(
                    logger, "You are trying to record the excitatory "
                    "conductance from a model which does not use conductance "
                    "input. You will receive current measurements instead.")
        elif variable == "gsyn_inh":
            if not self.__vertex.conductance_based:
                warn_once(
                    logger, "You are trying to record the inhibitory "
                    "conductance from a model which does not use conductance "
                    "input. You will receive current measurements instead.")
Exemple #16
0
    def print_gsyn(self, filename, gather=True):
        """
        .. deprecated:: 5.0
            Use ``write_data(file, ['gsyn_exc', 'gsyn_inh'])`` instead.

        .. note::
            Method signature is the PyNN0.7 one
        """
        if not gather:
            warn_once(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")
        logger.warning(
            'print_gsyn is deprecated. Call transfered to '
            'write_data(file, ["gsyn_exc", "gsyn_inh"], gatherer) instead.')
        self.write_data(filename, ['gsyn_exc', 'gsyn_inh'], gather=True)
    def _generate_weights(self, values, n_connections, connection_slices):
        """ Generate weight values.
        """
        weights = self._generate_values(values, n_connections,
                                        connection_slices)
        if self._safe:
            if not weights.size:
                logger_utils.warn_once(logger, "No connection in " + str(self))
#                logger.warning("No connection in " + str(self))
            elif numpy.amin(weights) < 0 < numpy.amax(weights):
                raise Exception(
                    "Weights must be either all positive or all negative"
                    " in projection {}->{}".format(
                        self._pre_population.label,
                        self._post_population.label))
        return numpy.abs(weights)
Exemple #18
0
    def print_v(self, filename, gather=True):
        """
        .. warning::
            Deprecated. Use `write_data(file, 'v')` instead.

        .. note::
            Method signature is the PyNN0.7 one
        """
        if not gather:
            warn_once(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")
        logger.warning(
            'print_v is deprecated. '
            'Call transfered to write_data(file, "v", gatherer) instead.')
        self.write_data(filename, 'v', gather=True)
    def _generate_weights(self, values, n_connections, connection_slices):
        """ Generate weight values.
        """
        weights = self._generate_values(
            values, n_connections, connection_slices)
        if self._safe:
            if not weights.size:
                logger_utils.warn_once(logger,
                                       "No connection in " + str(self))
#                logger.warning("No connection in " + str(self))
            elif numpy.amin(weights) < 0 < numpy.amax(weights):
                raise Exception(
                    "Weights must be either all positive or all negative"
                    " in projection {}->{}".format(
                        self._pre_population.label,
                        self._post_population.label))
        return numpy.abs(weights)
    def _record(self, variable, sampling_interval=None, to_file=None,
                indexes=None):
        """ Tell the vertex to record data.

        :param variable: the variable to record, valued variables to record\
            are: 'gsyn_exc', 'gsyn_inh', 'v', 'spikes'
        :param sampling_interval: the interval to record them
        :param indexes: List of indexes to record or None for all
        :return: None
        """

        get_simulator().verify_not_running()
        # tell vertex its recording
        if variable == "spikes":
            if not isinstance(self._population._vertex,
                              AbstractSpikeRecordable):
                raise Exception("This population does not support the "
                                "recording of spikes!")
            self._population._vertex.set_recording_spikes(
                sampling_interval=sampling_interval, indexes=indexes)
        elif variable == "all":
            raise Exception("Illegal call with all")
        else:
            if not isinstance(self._population._vertex,
                              AbstractNeuronRecordable):
                raise Exception("This population does not support the "
                                "recording of {}!".format(variable))
            self._population._vertex.set_recording(
                variable, sampling_interval=sampling_interval, indexes=indexes)

        # update file writer
        self._write_to_files_indicators[variable] = to_file

        if variable == "gsyn_exc":
            if not self._population._vertex.conductance_based:
                logger_utils.warn_once(
                    logger, "You are trying to record the excitatory "
                    "conductance from a model which does not use conductance "
                    "input. You will receive current measurements instead.")
        elif variable == "gsyn_inh":
            if not self._population._vertex.conductance_based:
                logger_utils.warn_once(
                    logger, "You are trying to record the inhibitory "
                    "conductance from a model which does not use conductance "
                    "input. You will receive current measurements instead.")
    def get_spike_counts(self, spikes, gather=True):
        """ Return the number of spikes for each neuron.

        Defined by
        http://neuralensemble.org/docs/PyNN/reference/populations.html

        :param gather: pointless on sPyNNaker
        """
        if not gather:
            warn_once(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")
        n_spikes = {}
        counts = numpy.bincount(spikes[:, 0].astype(dtype=numpy.int32),
                                minlength=self.__vertex.n_atoms)
        for i in range(self.__vertex.n_atoms):
            n_spikes[i] = counts[i]
        return n_spikes
Exemple #22
0
    def _record_with_indexes(
            self, variables, to_file, sampling_interval, indexes):
        """ Same as record but without non-standard PyNN warning

        This method is non-standard PyNN and is intended only to be called by\
        record in a Population, View or Assembly
        """
        if variables is None:  # reset the list of things to record
            if sampling_interval is not None:
                raise ConfigurationException(
                    "Clash between parameters in record."
                    "variables=None turns off recording,"
                    "while sampling_interval!=None implies turn on recording")
            if indexes is not None:
                warn_once(
                    logger,
                    "View.record with variable None is non-standard PyNN. "
                    "Only the neurons in the view have their record turned "
                    "off. Other neurons already set to record will remain "
                    "set to record")

            # note that if record(None) is called, its a reset
            Recorder._turn_off_all_recording(self, indexes)
            # handle one element vs many elements
        elif isinstance(variables, string_types):
            # handle special case of 'all'
            if variables == "all":
                warn_once(
                    logger, 'record("all") is non-standard PyNN, and '
                    'therefore may not be portable to other simulators.')

                # get all possible recordings for this vertex
                variables = self._get_all_possible_recordable_variables()

                # iterate though them
                for variable in variables:
                    self._record(variable, sampling_interval, to_file, indexes)
            else:
                # record variable
                self._record(variables, sampling_interval, to_file, indexes)

        else:  # list of variables, so just iterate though them
            for variable in variables:
                self._record(variable, sampling_interval, to_file, indexes)
Exemple #23
0
    def get_data(self,
                 variables='all',
                 gather=True,
                 clear=False,
                 annotations=None):
        """ Return a Neo Block containing the data(spikes, state variables)\
            recorded from the Population.

        :param variables: Either a single variable name or a list of variable
            names. Variables must have been previously recorded, otherwise an
            Exception will be raised.
        :type variables: str or list(str)
        :param bool gather: For parallel simulators, if gather is True, all
            data will be gathered to all nodes and the Neo Block will contain
            data from all nodes.
            Otherwise, the Neo Block will contain only data from the cells
            simulated on the local node.

            .. note::
                SpiNNaker always gathers.

        :param bool clear:
            If True, recorded data will be deleted from the Population.
        :param annotations: annotations to put on the neo block
        :type annotations: dict(str, ...)
        :rtype: ~neo.core.Block
        :raises \
            ~spinn_front_end_common.utilities.exceptions.ConfigurationException:
            If the variable or variables have not been previously set to
            record.
        """
        if not gather:
            logger.warning("SpiNNaker only supports gather=True. We will run "
                           "as if gather was set to True.")
        if annotations is not None:
            warn_once(
                logger, "Annotations parameter is not standard PyNN so may "
                "not be supported by all platforms.")

        return self.__population.get_data_by_indexes(variables,
                                                     self.__indexes,
                                                     clear=clear)
Exemple #24
0
    def mean_spike_count(self, gather=True):
        """ Returns the mean number of spikes per neuron.

        :param bool gather:
            For parallel simulators, if this is True, all data will be gathered
            to all nodes and the Neo Block will contain data from all nodes.
            Otherwise, the Neo Block will contain only data from the cells
            simulated on the local node.

            .. note::
                SpiNNaker always gathers.

        :rtype: float
        """
        if not gather:
            warn_once(
                logger, "sPyNNaker only supports gather=True. We will run "
                "as if gather was set to True.")
        counts = self.get_spike_counts()
        return sum(counts.values()) / len(counts)
Exemple #25
0
    def spinnaker_get_data(self, variable):
        """ Public accessor for getting data as a numpy array, instead of\
            the neo based object

        :param variable: \
            either a single variable name or a list of variable names.\
            Variables must have been previously recorded, otherwise an\
            Exception will be raised.
        :return: numpy array of the data
        """
        warn_once(
            logger, "spinnaker_get_data is non-standard PyNN and therefore "
            "may not be portable to other simulators. Nor do we guarantee "
            "that this function will exist in future releases.")
        if isinstance(variable, list):
            if len(variable) == 1:
                variable = variable[0]
            else:
                msg = "Only one type of data at a time is supported"
                raise ConfigurationException(msg)
        if variable == SPIKES:
            return self._get_spikes()
        return self._get_recorded_pynn7(variable)
Exemple #26
0
    def read_in_signal(self, segment, block, signal_array, data_indexes,
                       view_indexes, variable, recording_start_time,
                       sampling_interval, units, label):
        """ Reads in a data item that's not spikes (likely v, gsyn e, gsyn i)\
        and saves this data to the segment.

        :param segment: Segment to add data to
        :type segment: neo.Segment
        :param block: neo block
        :type block: neo.Block
        :param signal_array: the raw signal data
        :type signal_array: nparray
        :param data_indexes: The indexes for the recorded data
        :type data_indexes: list(int)
        :param view_indexes: The indexes for which data should be returned.\
            If None all data (view_index = data_indexes)
        :type view_indexes: list(int)
        :param variable: the variable name
        :param recording_start_time: when recording started
        :param sampling_interval: how often a neuron is recorded
        :param units: the units of the recorded value
        :param label: human readable label
        """
        # pylint: disable=too-many-arguments
        t_start = recording_start_time * quantities.ms
        sampling_period = sampling_interval * quantities.ms
        if view_indexes is None:
            if not numpy.array_equal(data_indexes, self._all_ids):
                msg = "Warning getting data on a whole population when " \
                      "selective recording is active will result in only " \
                      "the requested neurons being returned in numerical " \
                      "order and without repeats."
                logger_utils.warn_once(logger, msg)
            indexes = numpy.array(data_indexes)
        elif view_indexes == data_indexes:
            indexes = numpy.array(data_indexes)
        else:
            # keep just the view indexes in the data
            indexes = [i for i in view_indexes if i in data_indexes]
            # keep just data columns in the view
            map_indexes = [data_indexes.index(i) for i in indexes]
            signal_array = signal_array[:, map_indexes]

        ids = list(map(self._population.index_to_id, indexes))
        if pynn8_syntax:
            data_array = neo.AnalogSignalArray(signal_array,
                                               units=units,
                                               t_start=t_start,
                                               sampling_period=sampling_period,
                                               name=variable,
                                               source_population=label,
                                               channel_index=indexes,
                                               source_ids=ids)
            data_array.shape = (data_array.shape[0], data_array.shape[1])
            segment.analogsignalarrays.append(data_array)
        else:
            data_array = neo.AnalogSignal(signal_array,
                                          units=units,
                                          t_start=t_start,
                                          sampling_period=sampling_period,
                                          name=variable,
                                          source_population=label,
                                          source_ids=ids)
            channel_index = _get_channel_index(indexes, block)
            data_array.channel_index = channel_index
            data_array.shape = (data_array.shape[0], data_array.shape[1])
            segment.analogsignals.append(data_array)
            channel_index.analogsignals.append(data_array)
Exemple #27
0
 def get(self, parameter_names, gather=False, simplify=True):
     if simplify is not True:
         logger_utils.warn_once(
             logger, "The simplify value is ignored if not set to true")
     return PyNNPopulationCommon.get(self, parameter_names, gather)