コード例 #1
0
def extract_line(data, ofs, vec, mid=True):
    '''extracts intensity values from a volume at points
    at unit length intervals along a line

    Usage: (vals, coords) = extract_line(data, ofs, vec)

    Inputs:
          data = volume to extract from
          ofs = point on line
          vec = direction of line
    Outputs:
          vals = returned values from volume
          coords = co-ordinates of extracted points'''

    if mid:
        mid_ = 0.5
    else:
        mid_ = 0.
    maxval = n.array( data.shape ) - 1

    # ensure inputs are numpy arrays
    ofs = n.asarray( ofs )
    vec = unitvec( vec )

    if n.alltrue( ofs <= maxval + mid_ ) and n.alltrue( ofs >= mid_ ):
        max_cnr = n.where(vec > 0, maxval, zeros(data.ndim)) + mid_
        min_cnr = n.where(vec < 0, maxval, zeros(data.ndim)) + mid_
        #print max_cnr
        #print min_cnr

        # work out how many steps before ofs
        presteps = (n.abs( min_cnr - ofs ) / n.abs( vec ) \
                    ).min().astype(int)

        # ... and how many after ofs
        poststeps = (n.abs( max_cnr - ofs ) / n.abs( vec ) \
                     ).min().astype(int)

        # construct list of steps ( in delta vecs )
        if presteps > 0:
            steps = [(presteps - i) * -1 \
                     for i in range( presteps + 1)]
                     # +1 to add 0 pt (at ofs)
        else:
            steps = [0]

        if poststeps > 0:
            steps += [(i + 1) for i in range( poststeps )]

        steps = n.array(steps)[newaxis,...]

        # construct array of actual pts
        pts = ofs[...,newaxis] + steps * vec[...,newaxis]
        #print pts
        val = ninterpol( data, pts, mid=mid )
        return val, pts
        
    else:
        raise ValueError("[extract_line] Offset must be within bounds of data.")
        return None
コード例 #2
0
ファイル: test_regress.py プロジェクト: amcmorl/motorlab
def test_glm_any_model():
    nbin = 10
    align = 'hold'
    lag = 0.1 # s

    ds = datasets['small']
    dc = DataCollection(ds.get_files())
    dc.add_unit(ds.get_units()[0], lag)
    bnd = dc.make_binned(nbin=nbin, align=align)
    ntask, nrep, nunit, nbin = bnd.shape

    # make perfect test counts
    # direction-only model
    tp = radians([20, 10]) # degrees
    b0 = log(10) # log(Hz)
    pd = pol2cart(tp)

    drn = kinematics.get_idir(bnd.pos, axis=2)
    rate = exp(dot(drn, pd) + b0)
    window_size = diff(bnd.bin_edges, axis=2)
    count_mean = rate * window_size
    count = poisson(count_mean)
    count = count[:,:,None]
    bnd.set_PSTHs(count)

    # now fit data for pd
    count, pos, time = bnd.get_for_regress()
    bnom, bse_nom = glm_any_model(count, pos, time, model='kd')
    pd_exp = unitvec(bnom['d'])
    tp_exp = cart2pol(pd_exp)
    
    acceptable_err = 0.05 # about 3 degrees absolute error
    err = abs(tp - tp_exp)
    assert_array_less(err, acceptable_err)
コード例 #3
0
ファイル: kinematics.py プロジェクト: amcmorl/motorlab
def get_dir(pos, tax=-2, spax=-1):
    '''Get instantaneous direction

    Parameters
    ----------
    pos : array_like

    tax : int, optional
      time axis, defaults to 0
    '''    
    dp = np.diff(pos, axis=tax)
    return unitvec(dp, axis=spax)
コード例 #4
0
ファイル: test_kinematics.py プロジェクト: amcmorl/motorlab
def test_get_dir():
    pos = np.array([[ 0, 0,  0],
                    [ 1, 2, -1],
                    [ 2, 4, -2],
                    [ 3, 6, -3]]) # shape (4,3)
    dir = kin.get_dir(pos, tax=0, spax=-1)
    correct_dir = unitvec(np.array([[1,2,-1], [1,2,-1], [1,2,-1]]), axis=1)

    # default case
    assert_array_equal(dir, correct_dir)

    # switched axes case
    dir = kin.get_dir(pos.T, tax=1, spax=0)
    assert_array_equal(dir, correct_dir.T)

    # additional axes case
    pos = np.tile(pos[None], (2,1,1))
    dir = kin.get_dir(pos, tax=1, spax=-1)
    correct_dir = np.tile(correct_dir[None], (2,1,1))
    assert_array_equal(dir, correct_dir)
コード例 #5
0
ファイル: hand_plot.py プロジェクト: amcmorl/motorlab
 def __init__(self,
              parent=None,
              length=1.,
              attachment=None,
              ref_vec=array([0,1,0])):
     '''
     Parameters
     ----------
     parent : Bone
       bone to which this one is attached
     length : scalar
       length of bone
     attachment : function
       callable to get attachment point of bone
     ref_vec : ndarray
       vector describing reference orientation of bone
       (that occurring at all zero angles)
     '''
     self.get_pta = attachment
     self.vec = unitvec(ref_vec) * length
     self.child = None
     self.parent = parent