Пример #1
0
    def test_empty(self):

        bst = (nel.SpikeTrainArray([[3, 4, 5, 6, 7], [2, 4, 5]],
                                   support=nel.EpochArray([0, 8]),
                                   fs=1).bin(ds=1))

        desc = 'test case for bst'
        bst._desc = desc
        n_series = bst.n_series

        bst1 = bst.empty(inplace=False)
        bst.empty(inplace=True)

        assert bst.binned_support == None
        assert bst.bin_centers == None
        assert bst.bins == None
        assert bst.eventarray.isempty
        assert bst.n_series == n_series
        assert bst._desc == desc
        assert bst.support.isempty

        # Emptying should be consistent whether we do it
        # in place or not
        assert bst1.binned_support == bst.binned_support
        assert bst1.bin_centers == bst.bin_centers
        assert bst1.bins == bst.bins
        assert bst1.eventarray.isempty
        assert bst1._desc == bst._desc
        assert bst1.support.isempty
Пример #2
0
    def test_indexing_1(self):

        bst = (nel.SpikeTrainArray(
            [[1, 2, 3, 4, 5, 6, 7, 8, 9.5, 10, 10.5, 11.4, 15, 18, 19, 20, 21],
             [4, 8, 17]],
            support=nel.EpochArray([[0, 8], [12, 22]]),
            fs=1).bin(ds=1))
        data = bst.data

        bst._desc = 'test case for bst'

        expected_bins = np.array([2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 20, 21, 22])
        expected_bin_centers = np.array(
            [2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 12.5, 13.5, 20.5, 21.5])
        expected_binned_support = np.array([[0, 5], [6, 7], [8, 9]])

        bst_indexed = bst[nel.EpochArray([[2, 8], [9, 14], [19.5, 25]]), 1]

        assert bst_indexed.n_series == 1

        # binned support is an int array and should be exact. The others
        # are floats so we use np.allclose
        assert bst_indexed.binned_support.dtype.kind in ('i', 'u')
        assert np.all(bst_indexed.binned_support == expected_binned_support)
        assert np.allclose(bst_indexed.bins, expected_bins)
        assert np.allclose(bst_indexed.bin_centers, expected_bin_centers)

        # make sure original object's data didn't get mutated when indexing
        assert np.all(bst.data == data)

        # make sure metadata didn't get lost!
        assert bst_indexed._desc == bst._desc
Пример #3
0
    def test_construct(self):

        fs = 1
        series_ids = [21]
        series_labels = ['pyr']
        series_tags = ['CA1']
        label = 'hippocampal units'
        series_label = 'Neuron$'
        sta = nel.SpikeTrainArray(
            [0, 1.5, 3],
            fs=fs,
            label=label,
            series_ids=series_ids,
            series_labels=series_labels,
            series_label=series_label,
            series_tags=series_tags,
        )

        # Verify STA's attributes are same as arguments
        # passed to the constructor
        assert sta.fs == fs
        assert sta.series_ids == series_ids
        assert sta.series_tags == series_tags
        assert sta.series_labels == series_labels
        assert sta.label == label
        assert sta._series_label == series_label

        # Verify other attributes
        assert sta.n_series == 1
def get_base_data(data_path, spike_path, session):
    """
    Load and format data for replay analysis
    """
    # get data session path from mat file
    path = functions.get_session_path(
        os.path.join(data_path, session) + '.mat')
    # load position data from .mat file
    df = functions.load_position(os.path.join(data_path, session) + '.mat')
    # get the size of each maze
    maze_size_cm = functions.get_maze_size_cm(
        os.path.join(data_path, session) + '.mat')
    # get session epochs
    session_epochs = nel.EpochArray(
        functions.get_epochs(os.path.join(data_path, session) + '.mat'))
    # rescale epoch coordinates into cm
    df = rescale_coords(df, session_epochs, maze_size_cm)
    # put position into object
    pos = nel.AnalogSignalArray(timestamps=df.ts,
                                data=[df.x],
                                fs=1 / statistics.mode(np.diff(df.ts)),
                                support=(session_epochs))

    # load spikes & add to object
    spikes = np.load(os.path.join(spike_path, session) + '.npy',
                     allow_pickle=True)
    spikes_ = list(itertools.chain(*spikes))
    session_bounds = nel.EpochArray([min(spikes_), max(spikes_)])
    st = nel.SpikeTrainArray(timestamps=spikes,
                             support=session_bounds,
                             fs=32000)

    return maze_size_cm, pos, st
Пример #5
0
def load_add_spikes(spike_path, session, fs=32000):
    spikes = np.load(os.path.join(spike_path, session) + '.npy',
                     allow_pickle=True)
    spikes_ = list(itertools.chain(*spikes))
    session_bounds = nel.EpochArray([min(spikes_), max(spikes_)])
    return nel.SpikeTrainArray(timestamps=spikes,
                               support=session_bounds,
                               fs=fs)
Пример #6
0
 def test_16(self):
     sta = nel.SpikeTrainArray(
         [[1, 2, 3, 5, 10, 11, 12, 15], [1, 2, 3, 5, 10, 11, 12, 15]], fs=5)
     sta = sta.partition(n_epochs=5)
     for aa, bb in zip(ragged_array([np.array([5, 15]),
                                     np.array([5, 15])]),
                       sta.iloc[[1, 4], :].data):
         assert np.allclose(aa, bb)
Пример #7
0
    def test_copy_without_data(self):

        sta = nel.SpikeTrainArray([[3, 4, 5, 6, 7], [2, 4, 5]],
                                  support=nel.EpochArray([0, 8]),
                                  fs=1)

        desc = 'test case for sta'
        sta._desc = desc

        sta_copied = sta._copy_without_data()

        assert sta_copied.n_series == sta.n_series
        assert sta_copied._desc == sta._desc
        assert sta_copied.isempty
Пример #8
0
    def copy_without_data(self):

        bst = (nel.SpikeTrainArray([[3, 4, 5, 6, 7], [2, 4, 5]],
                                   support=nel.EpochArray([0, 8]),
                                   fs=1).bin(ds=1))

        desc = 'test case for bst'
        bst._desc = desc

        bst_copied = bst._copy_without_data()

        assert bst_copied.n_series == bst.n_series
        assert bst._desc == desc
        assert bst.isempty
        assert bst.eventarray.isempty
Пример #9
0
    def test_indexing_2(self):

        # support indexing by list
        bst = (nel.SpikeTrainArray(
            [1, 2, 3, 4, 5, 6, 7, 8, 9.5, 10, 10.5, 11.4, 15, 18, 19, 20, 21],
            support=nel.EpochArray([[0, 8], [10, 12], [15, 22]]),
            fs=1).bin(ds=1))

        bst_indexed = bst[[0, 1, 2]]
        assert bst_indexed.n_intervals == 3

        # Now test if we don't take all epochs, the original object
        # should not have been mutated
        bst_indexed = bst[[1, 2]]
        assert bst_indexed.n_intervals == 2
        assert bst.n_intervals == 3
Пример #10
0
    def test_indexing(self):

        sta = (nel.SpikeTrainArray(
            [[1, 2, 3, 4, 5, 6, 7, 8, 9.5, 10, 10.5, 11.4, 15, 18, 19, 20, 21],
             [4, 8, 17]],
            support=nel.EpochArray([[0, 8], [12, 22]]),
            fs=1).bin(ds=1))
        sta._desc = 'test case for sta'
        data = sta.data

        sta_indexed = sta[nel.EpochArray([[2, 8], [9, 14], [19.5, 25]]), 1]

        assert sta_indexed.n_series == 1

        # make sure original object's data didn't get mutated when indexing
        assert np.all(sta.data == data)

        # make sure metadata didn't get lost!
        assert sta_indexed._desc == sta._desc
Пример #11
0
    def test_construct_with_sta(self):

        fs = 1
        series_ids = [21]
        series_labels = ['pyr']
        series_tags = ['CA1']
        label = 'hippocampal units'
        sta = nel.SpikeTrainArray([0, 1.5, 3],
                                  fs=fs,
                                  label=label,
                                  series_ids=series_ids,
                                  series_labels=series_labels,
                                  series_tags=series_tags)

        ds = 0.2
        bst = nel.BinnedSpikeTrainArray(sta, ds=ds)

        # Verify BST's attributes are same as those
        # passed to the constructor
        assert bst.ds == ds

        # Verify BST's attributes are inherited from STA
        assert bst.fs == sta.fs
        assert bst.series_ids == sta.series_ids
        assert bst.series_labels == sta.series_labels
        assert bst.series_tags == sta.series_tags
        assert bst.label == sta.label

        # Verify BST's eventarray's attributes are also
        # inherited from STA
        assert bst.eventarray.fs == sta.fs
        assert bst.eventarray.series_ids == sta.series_ids
        assert bst.eventarray.series_labels == sta.series_labels
        assert bst.eventarray.series_tags == sta.series_tags
        assert bst.eventarray.label == sta.label

        # Verify other attributes
        assert bst.n_series == 1
Пример #12
0
    def test_empty(self):

        sta = nel.SpikeTrainArray([[3, 4, 5, 6, 7], [2, 4, 5]],
                                  support=nel.EpochArray([0, 8]),
                                  fs=1)

        desc = 'test case for sta'
        sta._desc = desc
        n_series = sta.n_series

        sta1 = sta.empty(inplace=False)
        sta.empty(inplace=True)

        assert sta.n_series == n_series
        assert sta._desc == desc  # ensure metadata preserved
        assert sta.isempty
        assert sta.support.isempty

        # Emptying should be consistent whether we do it
        # in place or not
        assert sta1.n_series == sta.n_series
        assert sta1._desc == sta._desc
        assert sta1.isempty
        assert sta1.support.isempty
Пример #13
0
 def test_14(self):
     sta = nel.SpikeTrainArray([[3, 4], [4], [2]])
     assert sta.n_units == 3
Пример #14
0
 def test_13(self):
     sta = nel.SpikeTrainArray([[[3, 4], [4],
                                 [2]]])  # failed before updates
     assert sta.n_units == 3
Пример #15
0
 def test_12(self):
     sta = nel.SpikeTrainArray(empty=True)
     assert sta.n_units == 0
Пример #16
0
 def test_11(self):
     sta = nel.SpikeTrainArray([[1, 2, 3], []])
     assert sta.n_units == 2
Пример #17
0
 def test_8(self):
     sta = nel.SpikeTrainArray([[1, 2], [3, 4]])
     assert sta.n_units == 2
Пример #18
0
 def test_7(self):
     sta = nel.SpikeTrainArray(1)
     assert sta.n_units == 1
Пример #19
0
 def test_4(self):
     sta = nel.SpikeTrainArray([1])
     assert sta.n_units == 1
Пример #20
0
 def test_3(self):
     sta = nel.SpikeTrainArray([[1], [2], [3]])
     assert sta.n_units == 3  # failed before updates
Пример #21
0
 def test_2(self):
     sta = nel.SpikeTrainArray([[], [], [3]])
     assert sta.n_units == 3
Пример #22
0
 def test_6(self):
     sta = nel.SpikeTrainArray([[]])
     assert sta.n_units == 1  # failed before updates
Пример #23
0
 def test_10(self):
     sta = nel.SpikeTrainArray([1, 2, 3])
     assert sta.n_units == 1