Esempio n. 1
0
def get_data_considering_high_low_steer():
	global ctr_low
	global ctr_high
	global low_steer
	global high_steer

	if ctr_low >= len_low_steer:
		ctr_low = -1
	if ctr_high >= len_high_steer:
		ctr_high = -1
	if ctr_low == -1:
		random.shuffle(low_steer) # shuffle data before using (again)
		ctr_low = 0
	if ctr_high == -1:
		random.shuffle(high_steer)
		ctr_high = 0
		
	if random.random() < 0.5: # len_high_steer/(len_low_steer+len_high_steer+0.0): # with some probability choose a low_steer element
		choice = low_steer[ctr_low]
		ctr_low += 1
	else:
		choice = high_steer[ctr_high]
		ctr_high += 1
	run_code = choice[3]
	seg_num = choice[0]
	offset = choice[1]

	data = get_data_with_hdf5.get_data(run_code,seg_num,offset,N_STEPS,offset+0,N_FRAMES,ignore=ignore,require_one=require_one,use_states=use_states)

	return data
def get_data_ids(d):
    all_index = d['all_index']

    choice = all_steer[all_index]
    run_code = choice[3]
    seg_num = choice[0]
    offset = choice[1]

    run_name = get_data_with_hdf5.Segment_Data['run_codes'][run_code]
    #print run_name
    """
	if run_name not in Aruco_Steering_Trajectories.keys():
		#print('Run name '+run_name+' not in Aruco_Steering_Trajectories')
		return None
	if len(Aruco_Steering_Trajectories[run_name].keys()) < 2:
		#print('len(Aruco_Steering_Trajectories[run_name].keys()) <= 2')
		return None
	"""
    #print 'here!'
    seg_num_str = str(seg_num)
    #aruco_matches = []
    #print(run_code,seg_num,offset,N_STEPS,offset+0,N_FRAMES)
    for i in [0]:  #range(N_FRAMES):
        timestamp = get_data_with_hdf5.Segment_Data['runs'][run_name][
            'segments'][seg_num_str]['left_timestamp'][offset + i]
        behavioral_mode = np.random.choice([
            'Direct_Arena_Potential_Field',
            #'Furtive_Arena_Potential_Field',
            'Follow_Arena_Potential_Field'
        ])
        #'Play_Arena_Potential_Field'])
        desired_direction = np.random.choice([0, 1])
        """
		if timestamp in Aruco_Steering_Trajectories[run_name][behavioral_mode][desired_direction].keys():
			aruco_matches.append(timestamp)
		if len(aruco_matches) < 1:
			print(d2s('no aruco match',time.time()))
			return None
		"""
    data = get_data_with_hdf5.get_data(run_code,
                                       seg_num,
                                       offset,
                                       N_STEPS,
                                       offset + 0,
                                       N_FRAMES,
                                       ignore=ignore,
                                       require_one=require_one,
                                       no_images=True)
    if data != None:
        data['behavioral_mode'] = behavioral_mode
        data['desired_direction'] = desired_direction
        #for topic in Aruco_Steering_Trajectories[run_name][behavioral_mode][desired_direction][timestamp]:
        #	data[topic] = Aruco_Steering_Trajectories[run_name][behavioral_mode][desired_direction][timestamp][topic]
        data['id'] = (run_name, behavioral_mode, desired_direction, timestamp,
                      run_code, seg_num, offset)

    return data
def get_data_considering_high_low_steer_and_valid_trajectory_timestamp():
    #print "get_data_considering_high_low_steer_and_valid_trajectory_timestamp"
    global ctr_low
    global ctr_high
    global low_steer
    global high_steer
    global counts
    global high_loss_key_ctr
    global high_loss_keys

    if ctr_low >= len_low_steer:
        ctr_low = -1
    if ctr_high >= len_high_steer:
        ctr_high = -1
    if ctr_low == -1:
        random.shuffle(low_steer)  # shuffle data before using (again)
        ctr_low = 0
    if ctr_high == -1:
        random.shuffle(high_steer)
        ctr_high = 0

    if random.random(
    ) < 0.5:  # len_high_steer/(len_low_steer+len_high_steer+0.0): # with some probability choose a low_steer element
        choice = low_steer[ctr_low]
        ctr_low += 1
    else:
        choice = high_steer[ctr_high]
        ctr_high += 1
    run_code = choice[3]
    seg_num = choice[0]
    offset = choice[1]

    run_name = get_data_with_hdf5.Segment_Data['run_codes'][run_code]
    #print run_name
    if run_name not in Aruco_Steering_Trajectories.keys():
        #print('Run name '+run_name+' not in Aruco_Steering_Trajectories')
        return None
    if len(Aruco_Steering_Trajectories[run_name].keys()) < 2:
        #print('len(Aruco_Steering_Trajectories[run_name].keys()) <= 2')
        return None

    #print 'here!'
    seg_num_str = str(seg_num)
    aruco_matches = []
    #print(run_code,seg_num,offset,N_STEPS,offset+0,N_FRAMES)
    for i in [0]:  #range(N_FRAMES):
        timestamp = get_data_with_hdf5.Segment_Data['runs'][run_name][
            'segments'][seg_num_str]['left_timestamp'][offset + i]
        behavioral_mode = np.random.choice([
            'Direct_Arena_Potential_Field',
            #'Furtive_Arena_Potential_Field',
            'Follow_Arena_Potential_Field'
        ])
        #'Play_Arena_Potential_Field'])
        desired_direction = np.random.choice([0, 1])

        if timestamp in Aruco_Steering_Trajectories[run_name][behavioral_mode][
                desired_direction].keys():
            aruco_matches.append(timestamp)
        if len(aruco_matches) < 1:
            return None
    data = get_data_with_hdf5.get_data(run_code,
                                       seg_num,
                                       offset,
                                       N_STEPS,
                                       offset + 0,
                                       N_FRAMES,
                                       ignore=ignore,
                                       require_one=require_one)
    if data != None:
        data['behavioral_mode'] = behavioral_mode
        data['desired_direction'] = desired_direction
        for topic in Aruco_Steering_Trajectories[run_name][behavioral_mode][
                desired_direction][timestamp]:
            data[topic] = Aruco_Steering_Trajectories[run_name][
                behavioral_mode][desired_direction][timestamp][topic]
        data['id'] = (run_name, behavioral_mode, desired_direction, timestamp,
                      run_code, seg_num, offset)

    return data
def get_data_considering_high_low_steer_and_valid_trajectory_timestamp__with_data_id(
        d):
    all_index = d['all_index']
    #print "get_data_considering_high_low_steer_and_valid_trajectory_timestamp"

    global counts
    global high_loss_key_ctr
    global high_loss_keys

    choice = all_steer[all_index]
    run_code = choice[3]
    seg_num = choice[0]
    offset = choice[1]

    run_name = get_data_with_hdf5.Segment_Data['run_codes'][run_code]
    #print run_name
    #if run_name not in Aruco_Steering_Trajectories.keys():
    #print('Run name '+run_name+' not in Aruco_Steering_Trajectories')
    #	return None
    #if len(Aruco_Steering_Trajectories[run_name].keys()) < 2:
    #print('len(Aruco_Steering_Trajectories[run_name].keys()) <= 2')
    #	return None

    #print 'here!'
    seg_num_str = str(seg_num)
    #aruco_matches = []
    #print(run_code,seg_num,offset,N_STEPS,offset+0,N_FRAMES)
    for i in [0]:  #range(N_FRAMES):
        timestamp = get_data_with_hdf5.Segment_Data['runs'][run_name][
            'segments'][seg_num_str]['left_timestamp'][offset + i]
        behavioral_mode = np.random.choice([
            'Direct_Arena_Potential_Field',
            #'Furtive_Arena_Potential_Field',
            'Follow_Arena_Potential_Field'
        ])
        #'Play_Arena_Potential_Field'])
        desired_direction = np.random.choice([0, 1])

    #	if timestamp in Aruco_Steering_Trajectories[run_name][behavioral_mode][desired_direction].keys():
    #		aruco_matches.append(timestamp)
    #	if len(aruco_matches) < 1:
    #		return None
    data = get_data_with_hdf5.get_data(run_code,
                                       seg_num,
                                       offset,
                                       N_STEPS,
                                       offset + 0,
                                       N_FRAMES,
                                       ignore=ignore,
                                       require_one=require_one)
    if data != None:
        data['behavioral_mode'] = behavioral_mode
        data['desired_direction'] = desired_direction
        for topic in Aruco_Steering_Trajectories[run_name][behavioral_mode][
                desired_direction][timestamp]:
            data[topic] = Aruco_Steering_Trajectories[run_name][
                behavioral_mode][desired_direction][timestamp][topic]
        data['id'] = (run_name, behavioral_mode, desired_direction, timestamp,
                      run_code, seg_num, offset)
    else:
        return None  #assert(False)
    return data