Ejemplo n.º 1
0
def raw_pursuits_pdf(ci=[1], is_control=True):
    #ci = [3]
    #is_control = True
    txt = 'free' if is_control else 'tp'
    pdf_out = PdfPages('/tmp/raw_pursuits'+str(ci)+'_'+txt+'.pdf')
    
    data, segs = get_pooled(ci)
    data, segs = filter_by_treatment(data, segs, is_control)

    #print 'segs: ' + str(len(segs))
    
    grp, segs = zip(*segs)
    groups = np.rec.fromrecords(grp, names='session_id,lap')
    data = data[ data['g_direction_q'] > 0.4 ]

    for (sid, lap), d in groupby_multiple(data, ('session_id', 'lap')):
        seg = [segs[k] for k in np.flatnonzero((groups.session_id == sid) & 
                                               (groups.lap == lap))]
        #if (len(seg) == 0): continue
        seg = np.hstack(seg).view(np.recarray)
        seg = seg[seg.n > 12]

        plt.figure()
        
        ax1 = plt.subplot(211)
        plt.title(str(sid) + ', ' + str(lap))
        plt.plot(d['dist'], d['scenecam_x'], ',k')
        for s in seg:
            plt.plot([s.t0, s.t1], [s.d0[0], s.d1[0]], '-r')
        plt.ylim([-10,50])
        plt.ylabel('horiz.gaze (deg)')
        
        ax2 = plt.subplot(212, sharex=ax1)
        plt.plot(d['dist'], d['scenecam_y'], ',k')
        for s in seg:
            plt.plot([s.t0, s.t1], [s.d0[1], s.d1[1]], '-r')
        plt.ylim([-15,15])
        plt.ylabel('vert.gaze (deg)')
        plt.xlabel('ts')
        pdf_out.savefig()
        plt.close()

    pdf_out.close()
Ejemplo n.º 2
0
def get_pursuit_fits(start, end):
    from segreg import piecewise_linear_regression_pseudo_em, segmentation_to_table

    data = get_angled_range_data2(start, end)
    data = data[data["g_direction_q"] > 0.2]

    params = ((1.5, 1.5), 0.5)

    grouping = ("session_id", "lap")
    grps = []
    for i, (grp, d) in enumerate(groupby_multiple(data, grouping)):
        t = d["ts"]
        g = np.vstack((d["scenecam_x"], d["scenecam_y"])).T

        splits, valid, winner, params = memorize(piecewise_linear_regression_pseudo_em)(t, g, *params)
        seg = segmentation_to_table(splits, t[valid], g[valid])
        print tuple(grp)
        grps.append((tuple(grp), seg))

    return grps
Ejemplo n.º 3
0
def get_pooled_data(cis, is_control):
    arr_desc = [('sid', int), ('bend', int), ('yaw', float), ('speed', float)]
    table = np.array([], dtype=arr_desc)
    
    #cis = [1,2,3]
    for ci in cis:
        data = get_angled_range_data2(CORNERING[ci][0], CORNERING[ci][1])
        segs = get_pursuit_fits(CORNERING[ci][0], CORNERING[ci][1])
        
        data, segs = filter_by_treatment(data, segs, is_control)
        
        data.sort(order=['session_id', 'ts'])
        grp, segs = zip(*segs)
        groups = np.rec.fromrecords(grp, names='session_id,lap')

        for (sid, lap), d in groupby_multiple(data, ('session_id', 'lap')):
            #if (np.sum(d['g_direction_q'] < 0.2) > 0.25*(len(d))): continue
            seg = [segs[k] for k in np.flatnonzero((groups.session_id == sid) & 
                                                   (groups.lap == lap))]
            if (len(seg) == 0): continue
            seg = np.hstack(seg).view(np.recarray)
            seg = seg[seg.n > 12]
            
            lap_dpoints = []
            for s in seg:
                dt = s.t1 - s.t0
                if dt == 0: continue
                gspeed = -((s.d1[0]-s.d0[0]) / dt)
                slice = d[(d['ts'] >= s.t0) &
                          (d['ts'] <= s.t1)]
                ym = np.mean(toyota_yaw_rate_in_degrees(slice['c_yaw']))
                lap_dpoints.append((ym, gspeed))
            
            lap_dpoints = np.array(lap_dpoints)
            
            if (len(lap_dpoints > 0)):
                yaw = np.mean(lap_dpoints[:,0])
                speed = np.median(lap_dpoints[:,1])
                arr = np.array([(sid,ci,yaw,speed)], dtype=arr_desc)
                table = np.append(table, arr)
    return table