Beispiel #1
0
    def __getitem__(self, idx):
        sliced_spikes = self.spikes[idx]
        sliced_tuning = self.tuning_curves[idx]

        if type(sliced_spikes) == np.ndarray and type(
                sliced_tuning) == np.ndarray:
            return nept.Neurons(sliced_spikes, sliced_tuning)
        else:
            return nept.Neurons(np.array([sliced_spikes]),
                                np.array([sliced_tuning]))
Beispiel #2
0
    def time_slice(self, t_starts, t_stops):
        """ Gets the neuron spikes corresponding to the time slices of
        the original between (and including) times t_starts and t_stops. Setting
        either parameter to None uses infinite endpoints for the time interval.

        Parameters
        ----------
        neurons : nept.Neurons
        t_starts : float or list or None
        t_stops : float or list or None

        Returns
        -------
        sliced_spikes : list of nept.SpikeTrain

        """
        if t_starts is None:
            t_starts = [-np.inf]

        if t_stops is None:
            t_stops = [np.inf]

        if isinstance(t_starts, (int, float)):
            t_starts = [t_starts]

        if isinstance(t_stops, (int, float)):
            t_stops = [t_stops]

        sliced_spikes = [
            spiketrain.time_slice(t_starts, t_stops)
            for spiketrain in self.spikes
        ]

        return nept.Neurons(np.array(sliced_spikes), self.tuning_curves)
Beispiel #3
0
def test_neurons_get_tuning_shape():
    spikes = np.array([
        nept.SpikeTrain(np.array([0.5]), 'test'),
        nept.SpikeTrain(np.array([1.5]), 'test'),
        nept.SpikeTrain(np.array([2.5]), 'test')
    ])

    tuning = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.]])

    neurons = nept.Neurons(spikes, tuning)

    assert np.allclose(neurons.tuning_shape, tuning[0].shape)
Beispiel #4
0
def test_neurons_basic():
    spikes = np.array([
        nept.SpikeTrain(np.array([0.5]), 'test'),
        nept.SpikeTrain(np.array([1.5]), 'test'),
        nept.SpikeTrain(np.array([2.5]), 'test')
    ])

    tuning = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.]])

    neurons = nept.Neurons(spikes, tuning)

    assert np.allclose(neurons.spikes[0].time, spikes[0].time)
    assert np.allclose(neurons.tuning_curves, tuning)
Beispiel #5
0
def test_neurons_getitem_single():
    spikes = np.array([
        nept.SpikeTrain(np.array([0.5]), 'test'),
        nept.SpikeTrain(np.array([1.5]), 'test'),
        nept.SpikeTrain(np.array([2.5]), 'test')
    ])

    tuning = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.]])

    neurons = nept.Neurons(spikes, tuning)

    sliced = neurons[1]

    assert np.allclose(sliced.spikes[0].time, np.array([1.5]))
    assert np.allclose(sliced.tuning_curves[0], np.array([0., 1., 0., 0.]))
Beispiel #6
0
def test_neurons_n_wrong():
    spikes = np.array([
        nept.SpikeTrain(np.array([0.5]), 'test'),
        nept.SpikeTrain(np.array([1.5]), 'test'),
        nept.SpikeTrain(np.array([2.5]), 'test')
    ])

    tuning = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.]])

    with pytest.raises(ValueError) as excinfo:
        neurons = nept.Neurons(spikes, tuning)

    assert str(
        excinfo.value
    ) == 'spikes and tuning curves must have the same number of neurons'
Beispiel #7
0
def test_neurons_slicing_specified_stop():
    spikes = np.array([
        nept.SpikeTrain(np.array([0.5]), 'test'),
        nept.SpikeTrain(np.array([1.5]), 'test'),
        nept.SpikeTrain(np.array([2.5]), 'test')
    ])

    tuning = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.]])

    neurons = nept.Neurons(spikes, tuning)

    t_stop = 2.0

    sliced_neurons = neurons.time_slice(None, t_stop)

    assert np.allclose(sliced_neurons.spikes[0].time, np.array([0.5]))
    assert np.allclose(sliced_neurons.spikes[1].time, np.array([1.5]))
    assert np.allclose(sliced_neurons.spikes[2].time, np.array([]))
    assert np.allclose(neurons.tuning_curves, tuning)
Beispiel #8
0
def test_neurons_slicing_mult():
    spikes = np.array([
        nept.SpikeTrain(np.array([0.5]), 'test'),
        nept.SpikeTrain(np.array([1.5]), 'test'),
        nept.SpikeTrain(np.array([2.5]), 'test')
    ])

    tuning = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.]])

    neurons = nept.Neurons(spikes, tuning)

    t_starts = [0.0, 2.0]
    t_stops = [1.0, 3.0]

    sliced_neurons = neurons.time_slice(t_starts, t_stops)

    assert np.allclose(sliced_neurons.spikes[0].time, np.array([0.5]))
    assert np.allclose(sliced_neurons.spikes[1].time, np.array([]))
    assert np.allclose(sliced_neurons.spikes[2].time, np.array([2.5]))
    assert np.allclose(neurons.tuning_curves, tuning)