Exemplo n.º 1
0
def pdf_book(config, dataset, save_figure_path=''):
    if save_figure_path == '':
        figure_path = os.path.join(config.path, config.figure_path)
        save_figure_path=os.path.join(figure_path, 'odor_traces/')

    threshold_odor=10
        
    for odor in [True, False]:
        
        key_set = {}
        for odor_stimulus in config.odor_stimulus.keys():
            #keys_tmp = opa.get_keys_with_odor_before_post(config, dataset, threshold_odor=threshold_odor, odor_stimulus=odor_stimulus, threshold_distance_min=0.1, odor=odor)
            keys_tmp = fad.get_keys_with_attr(dataset, 'odor_stimulus', odor_stimulus)
            
            keys = []
            for key in keys_tmp:
                if '20120924' in key or '20120925' in key:
                    pass
                else:
                    continue
                trajec = dataset.trajecs[key]
                add_key = True
                if trajec.positions[0,0] < 0.3:
                    add_key = False
                if odor:
                    frames_in_odor = np.where(trajec.odor > threshold_odor)[0]
                    if len(frames_in_odor) < 20:
                        add_key = False
                if add_key:
                    keys.append(key)
            
            print odor_stimulus, keys
            if len(keys) > 0:    
                key_set.setdefault(odor_stimulus, keys)

        for odor_stimulus, keys in key_set.items():
            print 'Odor Book, Chapter: ', odor_stimulus
            
            if len(keys) < 250:
                keys_to_plot = keys
            else:
                keys_to_plot = keys[250:500]
                
            book_name = 'odor_trace_book_' + odor_stimulus + '_' + str(odor) + '.pdf'
                
            plot_odor_traces_book(config.path, config, dataset, keys=keys_to_plot, show_saccades=False, frames_to_show_before_odor=100, frames_to_show_after_odor=100, odor_multiplier=1, book_name=book_name)
def get_orientation_data(dataset, config, visual_stimulus='none', odor_stimulus=None, odor=None, threshold_odor=10, eccentricity_threshold=0.7):

    threshold_odor = 10
    key_sets = {}
    
    if odor_stimulus is not None:
        keys_odor = fad.get_keys_with_attr(dataset, ['odor_stimulus', 'visual_stimulus'], [odor_stimulus, visual_stimulus])
    else:
        keys_odor = dataset.trajecs.keys()
        
    if odor is None:
        keys = keys_odor
    else:
        if odor is True:
            keys = []
            for key in keys_odor:
                trajec = dataset.trajecs[key]
                if np.max(trajec.odor) > threshold_odor:
                    keys.append(key)
        elif odor is False:
            keys = []
            for key in keys_odor:
                trajec = dataset.trajecs[key]
                if np.max(trajec.odor) < threshold_odor:
                    keys.append(key)

    orientations = []
    eccentricities = []
    airheadings = []
    groundheadings = []
    speeds = []
    airspeeds = []
    
    for key in keys:
        trajec = dataset.trajecs[key]
        
        try:
            frames = trajec.frames_with_orientation
        except:
            continue
        
        if len(trajec.frames_with_orientation) < 5:
            continue
            
        frames_to_use = []
        saccade_frames = saccade_frames = [item for sublist in trajec.saccades for item in sublist]
        
        for i, f in enumerate(trajec.frames_with_orientation):
            if 1:
                if f in saccade_frames:
                    continue
                if np.abs(trajec.positions[f,2]) > 0.1:
                    continue
                if np.abs(trajec.velocities[f,2]) > 0.25:
                    continue
                if trajec.eccentricity[i] > eccentricity_threshold:
                    continue
                if len(trajec.frames_with_orientation) < 10:
                    continue
                
            frames_to_use.append(f)
            
        indices = [trajec.frames_with_orientation.index(f) for f in frames_to_use]
        
        orientations.extend(np.array(trajec.orientation)[indices].tolist())
        eccentricities.extend(np.array(trajec.eccentricity)[indices].tolist())
        airheadings.extend(trajec.airheading_smooth[frames_to_use].tolist())
        groundheadings.extend(trajec.heading_smooth[frames_to_use].tolist())
        speeds.extend(trajec.speed[frames_to_use].tolist())
        
        as_tmp = [np.linalg.norm(trajec.airvelocities[f]) for f in frames_to_use]
        airspeeds.extend(as_tmp)

    orientations = np.array(orientations)
    eccentricities = np.array(eccentricities)
    airheadings = np.array(airheadings)
    groundheadings = np.array(groundheadings)
    speeds = np.array(speeds)
    airspeeds = np.array(airspeeds)
    
    return orientations, airheadings, groundheadings, eccentricities, speeds, airspeeds