示例#1
0
    def test1(self):
        global test_file
        hdf5file = test_file[:-4]+'.hdf5'
    
        elems_indxs = [('CFS_Accelerator_Pedal_Position', 0),
                       ('SCC_Spline_Lane_Deviation', 1),
                       ('SCC_Spline_Lane_Deviation', 3),
                       ('VDS_Tire_Weight_On_Wheels', slice(0,4))]
                     
        daq = Daq()
        daq.read_hd5(os.path.join('data', hdf5file))
#        print(daq['VDS_Tire_Weight_On_Wheels'].frames.shape)
        fig = daq.plot_ts(elems_indxs, fslice(6000, None))
        fig.savefig('./output/daq_plots_test.png')
示例#2
0
 def test3(self):
     x = self.x
     rs = np.array([[24,245,6325,2435,245,1234,14,234,548]])
     ds = x[:, fslice(3000, 3009)]
     assert_array_equal(ds, rs)
示例#3
0
 def test2(self):
     x = self.x
     rs = np.array([[24,6325,245,14,548]])
     assert_array_equal(x[:, fslice(None, None, 2)], rs)
示例#4
0
 def test1(self):
     x = self.x
     rs = np.array([[   245.,  6325.,  2435.]])
     assert_array_equal(x[:, fslice(3001, 3004)], rs)
示例#5
0
 def test00(self):
     x = self.x
     rs = np.array([3000, 3001, 3002, 3003])
     assert_array_equal(x[:, fslice(3004)].frames, rs)
                     i*10+3 in daq.etc['epochs']):

                # encountered partial trial
                continue
            
            scenario = daq.etc['scen_order'][i]
            
            # unpack the start frame of the 1-to-2 lane addition transition
            # and the stop frame of the 2-to-1 lane reduction transition
            f0 = daq.etc['epochs'][i*10+1].start
            fend = daq.etc['epochs'][i*10+3].stop

            print("    on scenario %i [f%i:f%i]..."%(scenario, f0, fend))
            
            # next we need to linearly interpolate speed by distance
            veh_dist = daq['VDS_Veh_Dist'][0, fslice(f0, fend)].flatten()
            veh_dist -= veh_dist[0]
            
            veh_spd = daq['VDS_Veh_Speed'][0, fslice(f0, fend)].flatten()
            veh_spd_ip = np.interp(veh_dist_ip, veh_dist, veh_spd)

            # store interpolated speed so we can plot it
            interp_spds_by_scenario[scenario].append(veh_spd_ip)

    print('\nStep 2. Plot speeds...')

    # names of scenarios
    scenario_names = ['Baseline', 
                      'Advisory', 
                      'Reg', 
                      'Reg + Adv', 
                     i*10+3 in daq.etc['epochs']):

                # encountered partial trial
                continue

            scenario = daq.etc['scen_order'][i]

            # unpack the start frame of the 1-to-2 lane addition transition
            # and the stop frame of the 2-to-1 lane reduction transition
            f0 = daq.etc['epochs'][i * 10 + 1].start
            fend = daq.etc['epochs'][i * 10 + 3].stop

            print("    on scenario %i [f%i:f%i]..." % (scenario, f0, fend))

            # next we need to linearly interpolate speed by distance
            veh_dist = daq['VDS_Veh_Dist'][0, fslice(f0, fend)].flatten()
            veh_dist -= veh_dist[0]

            veh_spd = daq['VDS_Veh_Speed'][0, fslice(f0, fend)].flatten()
            veh_spd_ip = np.interp(veh_dist_ip, veh_dist, veh_spd)

            # store interpolated speed so we can plot it
            interp_spds_by_scenario[scenario].append(veh_spd_ip)

    print('\nStep 2. Plot speeds...')

    # names of scenarios
    scenario_names = [
        'Baseline', 'Advisory', 'Reg', 'Reg + Adv', 'Chevrons', 'Lines',
        'Narrowing', 'Parallax', 'Force Rh', 'Lines w/ mid'
    ]
def mult_ado_by_pid_plot(pids, page):
    global hdf5_files, scenario_names, latin_square, get_pid

    # initialize plot
    fig = plt.figure(figsize=(11*1.75, 8.5*1.75))
    fig.subplots_adjust(left=.04, right=.96,
                        bottom=.05, top=.97,
                        wspace=.04, hspace=.04)

    # plot will have 2 axis. One is for Vehicle Speed, the other is
    # for relative distance of the DynObjs
    xticks = np.linspace(660,5280*1.25,10)
    xlim = [0, 5280*1.25]

    # speed in MPH
    yticks1 = np.linspace(35,75,5)
    ylim1 = [30,80]

    # relative distance in Feet
    yticks2 = np.linspace(-1500,1500,7)
    ylim2 = [-1750,1750]

    # loop through the hdf5_files that contain
    # data for the requested participants
    for hdf5_file in [hd for hd in hdf5_files if get_pid(hd) in pids]:
    
        print('analyzing "%s"'%hdf5_file)
        
        daq = Daq()
        daq.read_hd5(hdf5_file)
        pid = daq.etc['pid']

        # figure out row number
        rnum = pids.index(pid)

        # find the relevant dynamic objects to plot
        platoon = [do for do in daq.dynobjs.values() if 'Ado' in do.name]
        platoon = sorted(platoon, key=attrgetter('name'))

        # for each trial...
        for i in xrange(10):
            
            if not ( i*10+1 in daq.etc['epochs'] and \
                     i*10+3 in daq.etc['epochs']):

                # encountered partial trial
                continue
                
            scenario = daq.etc['scen_order'][i]
            scenario_name = scenario_names[scenario]
            
            print('  PID: %03i, Passing zone: %i (%s)'%(pid, i, scenario_name))
            
            # unpack the start frame of the 1-to-2 lane addition transition
            # and the stop frame of the 2-to-1 lane reduction transition
            f0 = daq.etc['epochs'][i*10+1].start
            fend = daq.etc['epochs'][i*10+3].stop

            # get axis handle
            ax1 = plt.subplot(8, 10, rnum*10 + scenario + 1)

            distance = daq['VDS_Veh_Dist'][0, fslice(f0, fend)].flatten()
            distance -= distance[0]
            
            speed = daq['VDS_Veh_Speed'][0, fslice(f0, fend)].flatten()
            
            ax1.plot(distance, speed, 'b')
            ax2 = ax1.twinx()
            
            # we need to figure out when the Ados enter the passing lane
            # and exit the passing lane. To do this we need to know where
            # the passing lane starts and ends
            pos0 = daq['VDS_Chassis_CG_Position'][:,findex(f0)]
            posend = daq['VDS_Chassis_CG_Position'][:,findex(fend)]

            # loop through and plot ados
            for j, do in enumerate(platoon):

                # each passing zone has its own set of Ados. This
                # sorts out which are actually defined (should be 
                # defined) for this trial.
                if i*10 <= int(do.name[-2:]) < (i+1)*10:
                    print(do.name)
                    
                    # figure out when the ado enters the 
                    d0 = np.sum((do.pos - pos0)**2., axis=0)**.5
                    dend = np.sum((do.pos - posend)**2., axis=0)**.5
                    
                    # indexes relative to do arrays
                    imin0 = d0.argmin() 
                    iminend = dend.argmin()

                    # now we can plot the Ados relative distance to the
                    # vehicle as a function of distance over the passing
                    # lane
                    if iminend-imin0 > 0:
                        distance = do.distance[0, imin0:iminend]
                        distance -= distance[0]
                        rel_distance = do.relative_distance[0, imin0:iminend]
                        ax2.plot(distance, rel_distance, color='g', alpha=0.4)
                    else:
                        print('    %s did not drive '
                              'through passing zone'%do.name)


            # make things pretty
            ax1.set_ylim(ylim1)
            ax1.set_yticks(yticks1)
            if scenario:
                ax1.set_yticklabels(['' for y in yticks1])
            else:
                ax1.set_yticklabels(yticks1, color='b')
            
            ax2.axhline(0, color='k', linestyle=':')
            ax2.set_ylim(ylim2)
            ax2.set_yticks(yticks2)
            if scenario != 9:
                ax2.set_yticklabels(['' for y in yticks2])
            else:
                ax2.set_yticklabels(yticks2, color='g')
                
            ax2.set_xlim(xlim)
            ax2.set_xticks(xticks)

            if rnum == 0:
                ax1.set_title(scenario_names[scenario])
                
            if rnum == len(pids)-1:
                ax1.set_xticklabels(['%i'%x for x in xticks], 
                                    rotation='vertical')
            else:
                ax1.set_xticklabels(['' for x in xticks])

            if not scenario:
                ax1.text(660,35,'Participant: %03i =>'%pids[rnum], 
                         size='small')

    img_name = 'do_passing_behavior__PAGE%i.png'%page
    fig.savefig(img_name, dpi=300)
    plt.close()
示例#9
0
 def test3(self):
     x = self.x
     rs = np.array([[24, 245, 6325, 2435, 245, 1234, 14, 234, 548]])
     ds = x[:, fslice(3000, 3009)]
     assert_array_equal(ds, rs)
示例#10
0
 def test2(self):
     x = self.x
     rs = np.array([[24, 6325, 245, 14, 548]])
     assert_array_equal(x[:, fslice(None, None, 2)], rs)
示例#11
0
 def test1(self):
     x = self.x
     rs = np.array([[245., 6325., 2435.]])
     assert_array_equal(x[:, fslice(3001, 3004)], rs)
示例#12
0
 def test00(self):
     x = self.x
     rs = np.array([3000, 3001, 3002, 3003])
     assert_array_equal(x[:, fslice(3004)].frames, rs)