Beispiel #1
1
def test_ndtuples():
    t = rand_int_tuple()
    k = ndtuples(*t)
    uk = np.unique(k.ravel())
    uk.sort()
    assert_array_equal(uk, np.arange(max(t)))
Beispiel #2
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))
Beispiel #3
0
def distance_map(nshanks, electrodes_per_shank, within_shank, between_shank,
                 metric='wminkowski', p=2.0):
    """Create an electrode distance map.

    Parameters
    ----------
    nshanks, electrodes_per_shank : int

    within_shank, between_shank : float

    metric : str or callable, optional
        The distance measure to use to compute the distance between electrodes.

    p : number, optional
        See :py:mod:`scipy.spatial.distance` for more details.

    Raises
    ------
    AssertionError
        * If `nshanks` < 1 or `nshanks` is not an integer
        * If neither of those same conditions holds for `electrodes_per_shank`
        * If `metric` is not a string or callable or
        * If `p` is not an instance of ``numbers.Real`` and ``<= 0``

    Returns
    -------
    dists : DataFrame
        DataFrame of pairwise distances between electrodes.
    """
    assert nshanks >= 1, 'must have at least one shank'
    assert isinstance(nshanks, numbers.Integral), 'nshanks must be an integer'
    assert electrodes_per_shank >= 1, \
        'must have at least one electrode per shank'
    assert isinstance(electrodes_per_shank, numbers.Integral), \
        '"electrodes_per_shank" must be an integer'
    assert isinstance(metric, basestring) or callable(metric), \
        '"metric" must be a string or callable'
    assert isinstance(p, numbers.Real) and p > 0, \
        '"p" must be a positive real number'

    locs = ndtuples(electrodes_per_shank, nshanks)

    if locs.ndim == 1:
        locs = locs[:, np.newaxis]

    w = np.asanyarray((between_shank, within_shank), dtype=float)

    return squareform(pdist(locs, metric=metric, p=p, w=w))
Beispiel #4
0
 def test_ndtuples_3(self):
     m, n, l = randint(2, 3), randint(2, 4), randint(3, 4)
     x = ndtuples(m, n, l)
     self.assertTupleEqual((m * n * l, 3), x.shape)
Beispiel #5
0
 def test_ndtuples_2(self):
     m, n = randint(2, 5), randint(2, 4)
     x = ndtuples(m, n)
     self.assertTupleEqual((m * n, 2), x.shape)
Beispiel #6
0
 def test_ndtuples_1(self):
     n = randint(1, 3)
     x = ndtuples(n)
     assert_array_equal(x, np.arange(n))