def load_Bag_Folders(bag_folders_path = opjD('runs')):
	BF_dic = {}

	bag_folders_paths_list = sorted(gg(opj(bag_folders_path,'*')),key=natural_keys)

	for bfp in bag_folders_paths_list:

		run_name = bfp.split('/')[-1]

		preprocessed_dir,left_image_bound_to_data_name = get_preprocess_dir_name_info(bfp)

		if len(gg(opj(bfp,preprocessed_dir,'Bag_Folder.pkl'))) == 1:
			print('')
			cprint(opj(run_name,preprocessed_dir,'Bag_Folder.pkl')+' exists, loading it.','yellow','on_red')
			BF = load_obj(opj(bfp,preprocessed_dir,'Bag_Folder.pkl'))
		else:
			if False:
				BF = Bag_Folder.init(bfp,
					preprocessed_dir=preprocessed_dir,
					left_image_bound_to_data_name=left_image_bound_to_data_name,
					NUM_STATE_ONE_STEPS=NUM_STATE_ONE_STEPS)
				save_obj(BF,opj(bfp,preprocessed_dir,'Bag_Folder.pkl'))
			cprint('ERROR!!! '+opj(run_name,preprocessed_dir,'Bag_Folder.pkl')+' does not exist!','yellow','on_red')
			assert(False)

		if run_name in BF_dic:
			cprint('ERROR!!! '+run_name+' already in BF_dic!','yellow','on_red')
			assert(False)
		BF_dic[run_name] = BF

	return BF_dic
def preprocess_Bag_Folder(bag_folders_path=opjD("runs"), NUM_STATE_ONE_STEPS=30, graphics=True):

    bag_folders_paths_list = sorted(gg(opj(bag_folders_path, "*")), key=natural_keys)

    try:
        for bfp in bag_folders_paths_list:

            run_name = bfp.split("/")[-1]

            preprocessed_dir, left_image_bound_to_data_name = get_preprocess_dir_name_info(bfp)

            if len(gg(opj(bfp, preprocessed_dir, "Bag_Folder.pkl"))) == 1:
                print("")
                cprint(opj(run_name, preprocessed_dir, "Bag_Folder.pkl") + " exists, loading it.", "yellow", "on_red")
                BF = load_obj(opj(bfp, preprocessed_dir, "Bag_Folder.pkl"))
            else:
                BF = Bag_Folder.init(
                    bfp,
                    preprocessed_dir=preprocessed_dir,
                    left_image_bound_to_data_name=left_image_bound_to_data_name,
                    NUM_STATE_ONE_STEPS=NUM_STATE_ONE_STEPS,
                )
                save_obj(BF, opj(bfp, preprocessed_dir, "Bag_Folder.pkl"))

            if graphics:
                figure(run_name + " timecourses")
                plot(BF["data"]["raw_timestamps"], 100 * BF["data"]["encoder"], "y")
                plot(BF["data"]["raw_timestamps"], BF["data"]["state_one_steps"], "bo-")
                plot(BF["data"]["good_start_timestamps"], zeros(len(BF["data"]["good_start_timestamps"])) + 100, "go")
                plot(BF["data"]["raw_timestamps"], 2000 * BF["data"]["raw_timestamp_deltas"], "r")
                ylim(0, 1000)

                figure(run_name + " raw_timestamp_deltas")
                rtd = BF["data"]["raw_timestamp_deltas"].copy()
                rtd[rtd > 0.08] = 0.08
                hist(rtd)
                # plot(BF['data']['raw_timestamps'],100*BF['data']['state'],'r')
                # plot(BF['data']['raw_timestamps'],100*BF['data']['acc_z'],'r')

                figure(run_name + " scatter")
                plot(
                    BF["data"]["steer"][BF["data"]["good_start_indicies"]],
                    BF["data"]["gyro_x"][BF["data"]["good_start_indicies"]],
                    "o",
                )

                plt.pause(0.001)

    except Exception as e:
        cprint("********** Exception ***********************", "red")
        print(e.message, e.args)
Beispiel #3
0
def preprocess_Bag_Folder(bag_folders_path = opjD('runs'),NUM_STATE_ONE_STEPS=30,graphics=True):
	
	bag_folders_paths_list = sorted(gg(opj(bag_folders_path,'*')),key=natural_keys)

	try:
		for bfp in bag_folders_paths_list:

			run_name = bfp.split('/')[-1]

			preprocessed_dir,left_image_bound_to_data_name = get_preprocess_dir_name_info(bfp)

			if len(gg(opj(bfp,preprocessed_dir,'Bag_Folder.pkl'))) == 1:
				print('')
				cprint(opj(run_name,preprocessed_dir,'Bag_Folder.pkl')+' exists, loading it.','yellow','on_red')
				BF = load_obj(opj(bfp,preprocessed_dir,'Bag_Folder.pkl'))
			else:
				BF = Bag_Folder.init(bfp,
					preprocessed_dir=preprocessed_dir,
					left_image_bound_to_data_name=left_image_bound_to_data_name,
					NUM_STATE_ONE_STEPS=NUM_STATE_ONE_STEPS)
				save_obj(BF,opj(bfp,preprocessed_dir,'Bag_Folder.pkl'))

			if graphics:
				figure(run_name+' timecourses')
				plot(BF['data']['raw_timestamps'],100*BF['data']['encoder'],'y')
				plot(BF['data']['raw_timestamps'],BF['data']['state_one_steps'],'bo-')
				plot(BF['data']['good_start_timestamps'],zeros(len(BF['data']['good_start_timestamps']))+100,'go')
				plot(BF['data']['raw_timestamps'],2000*BF['data']['raw_timestamp_deltas'],'r')
				ylim(0,1000)

				figure(run_name+' raw_timestamp_deltas')
				rtd = BF['data']['raw_timestamp_deltas'].copy()
				rtd[rtd>0.08] = 0.08
				hist(rtd)
				#plot(BF['data']['raw_timestamps'],100*BF['data']['state'],'r')
				#plot(BF['data']['raw_timestamps'],100*BF['data']['acc_z'],'r')

				figure(run_name+' scatter')
				plot(BF['data']['steer'][BF['data']['good_start_indicies']],BF['data']['gyro_x'][BF['data']['good_start_indicies']],'o')

				plt.pause(0.001)

	except Exception as e:
		cprint("********** Exception ***********************",'red')
		print(e.message, e.args)			
if False:
    ts = sorted(L.keys())
    dts = [0]
    for i in range(1, len(ts)):
        dts.append(ts[i] - ts[i - 1])
    figure(1)
    plot(ts, dts)
    figure(2)
    hist(dts)

import kzpy3.teg3.data.access.Bag_Folder as Bag_Folder
import kzpy3.teg3.data.access.Bag_File as Bag_File

BF = Bag_Folder.init(
    '/home/karlzipser/Desktop/direct_home_06Dec16_16h01m42s_Mr_Blue',
    preprocessed_dir='.preprocessed2',
    left_image_bound_to_data_name='left_image_bound_to_data.pkl',
    NUM_STATE_ONE_STEPS=10)

#plot(BF['data']['raw_timestamps'],BF['data']['state_one_steps'],'bo-')
plot(BF['data']['good_start_timestamps'],
     zeros(len(BF['data']['good_start_timestamps'])) + 100, 'go')
#plot(BF['data']['raw_timestamps'],2000*np.array(BF['data']['raw_timestamp_deltas']),'r')
#plot(BF['data']['raw_timestamps'],100*BF['data']['encoder'],'r')
#plot(BF['data']['raw_timestamps'],100*BF['data']['state'],'r')
#plot(BF['data']['raw_timestamps'],100*BF['data']['acc_z'],'r')

bf = BF['bag_file_num_dic'][15]
bid = Bag_File.load_images(bf)
bag_left_timestamps = sorted(bid['left'].keys())
plot(bag_left_timestamps, 2000 + np.zeros(bag_left_timestamps), 'go')
Beispiel #5
0
if False:
	ts = sorted(L.keys())
	dts = [0]
	for i in range(1,len(ts)):
		dts.append(ts[i] - ts[i-1])
	figure(1)
	plot(ts,dts)
	figure(2)
	hist(dts)

import kzpy3.teg3.data.access.Bag_Folder as Bag_Folder
import kzpy3.teg3.data.access.Bag_File as Bag_File

BF = Bag_Folder.init('/home/karlzipser/Desktop/direct_home_06Dec16_16h01m42s_Mr_Blue',
	preprocessed_dir='.preprocessed2',
	left_image_bound_to_data_name='left_image_bound_to_data.pkl',
	NUM_STATE_ONE_STEPS=10)



#plot(BF['data']['raw_timestamps'],BF['data']['state_one_steps'],'bo-')
plot(BF['data']['good_start_timestamps'],zeros(len(BF['data']['good_start_timestamps']))+100,'go')
#plot(BF['data']['raw_timestamps'],2000*np.array(BF['data']['raw_timestamp_deltas']),'r')
#plot(BF['data']['raw_timestamps'],100*BF['data']['encoder'],'r')
#plot(BF['data']['raw_timestamps'],100*BF['data']['state'],'r')
#plot(BF['data']['raw_timestamps'],100*BF['data']['acc_z'],'r')

bf = BF['bag_file_num_dic'][15]  
bid = Bag_File.load_images(bf)
bag_left_timestamps = sorted(bid['left'].keys())
plot(bag_left_timestamps,2000+np.zeros(bag_left_timestamps),'go')