Пример #1
0
def _create_xcorr_inds(nchannels):
    """Create a ``MultiIndex`` for `nchannels` channels.

    Parameters
    ----------
    nchannels : int

    Returns
    -------
    xc_inds : MultiIndex
    """
    from span.tdt.spikeglobals import Indexer

    channel_i, channel_j = 'channel i', 'channel j'
    channel_names = channel_i, channel_j

    lr = DataFrame(ndtuples(nchannels, nchannels), columns=channel_names)
    left, right = lr[channel_i], lr[channel_j]

    srt_idx = Indexer.sort('channel').reset_index(drop=True)

    lshank, rshank = srt_idx.shank[left], srt_idx.shank[right]
    lshank.name, rshank.name = 'shank i', 'shank j'

    return MultiIndex.from_arrays((left, right, lshank, rshank))
Пример #2
0
    def _read_tsq(self, event_name):
        """Read the metadata (TSQ) file of a TDT Tank.

        Returns
        -------
        b : pandas.DataFrame
            Recording metadata
        """
        # create the path name
        tsq_name = self.path + os.extsep + self.header_ext

        # read in the raw data as a numpy rec array and convert to DataFrame
        b = DataFrame(np.fromfile(tsq_name, dtype=self.tsq_dtype))

        # zero based indexing
        b.channel -= 1
        b.channel = b.channel.astype(f8)

        # -1s are invalid
        b.channel[b.channel == -1] = np.nan

        b.type = EventTypes[b.type].reset_index(drop=True)
        b.format = DataTypes[b.format].reset_index(drop=True)

        b.timestamp[np.logical_not(b.timestamp)] = np.nan
        b.fs[np.logical_not(b.fs)] = np.nan

        # fragile subtraction (i.e., what if TDT changes this value?)
        b.size -= 10

        # create some new indices based on the electrode array
        srt = Indexer.sort('channel').reset_index(drop=True)
        shank = srt.shank[b.channel].reset_index(drop=True)

        tsq = b.join(shank)

        # convert the event_name to a number
        name = name2num(event_name)

        # get the row of the metadata where its value equals the name-number
        row = tsq.name == name

        # make sure there's at least one event
        assert row.any(), 'no event named %s in tank: %s' % (event_name,
                                                             self.path)

        # get all the metadata for those events
        tsq = tsq[row]

        # convert to integer where possible
        tsq.channel = tsq.channel.astype(int)
        tsq.shank = tsq.shank.astype(int)

        return tsq, row
Пример #3
0
def create_stsq(size=None, typ='stream',
                name=span.utils.name2num('Spik'), nchannels=16, sort_code=0,
                fmt=np.float32, fs=4882.8125,
                samples_per_channel=None):
    if size is None:
        size = randint(2 ** 5, 2 ** 6)

    if samples_per_channel is None:
        samples_per_channel = randint(2 ** 6, 2 ** 7)

    names = ('size', 'type', 'name', 'channel', 'sort_code', 'timestamp',
             'fp_loc', 'format', 'fs', 'shank')
    nsamples = samples_per_channel * nchannels
    index = Int64Index(np.arange(nsamples))

    size = Series(size, index=index, name='size')
    typ = Series(typ, index=index, name='type')
    name = Series(name, index=index, name='name')
    channel = Series(np.tile(np.arange(nchannels),
                             (samples_per_channel, 1))[:, ::-1].ravel(),
                     index=index, name='channel')
    sort_code = Series(sort_code, index=index, name='sort_code')
    fp_loc = Series(index, name='fp_loc')
    fmt = Series([fmt] * index.size, index=index, name='format')

    start = randrange(100e7, 128e7)
    ts = start + (size[0] / fs) * np.r_[:samples_per_channel]
    ts = np.tile(ts, (nchannels, 1)).T.ravel()
    timestamp = Series(ts, index=index, name='timestamp')

    srt = Indexer.sort('channel').reset_index(drop=True)
    shank = srt.shank[channel].reset_index(drop=True)

    data = (size, typ, name, channel, sort_code, timestamp, fp_loc, fmt, fs,
            shank)

    return DataFrame(dict(zip(names, data)))