示例#1
0
def make_false_landing_and_flyby_datasets(dataset_nopost):

    #shift_list = shift_datasets(dataset_nopost, nshifts=nshifts)
    #shift = fa.add_datasets(shift_list)

    shift = dataset_nopost

    fa.calc_func(shift, classify_false_post)
    fa.calc_func(shift, calc_frame_of_landing)

    dataset_nopost_landing = make_behavior_dataset(
        shift, filename='dataset_nopost_landing_3cm', behavior='landing')

    dataset_nopost_flyby = make_behavior_dataset(
        shift, filename='dataset_nopost_flyby_3cm', behavior='flyby')

    fa.prep_dataset(dataset_nopost_landing)
    fa.calc_func(dataset_nopost_landing, saccade_analysis.calc_last_saccade)

    fa.prep_dataset(dataset_nopost_flyby)
    fa.calc_func(dataset_nopost_flyby, saccade_analysis.calc_last_saccade)

    #fa.save(dataset_nopost_landing, 'dataset_nopost_landing')
    fa.save(dataset_nopost_flyby, 'dataset_nopost_flyby_3cm')

    return dataset_nopost_landing, dataset_nopost_flyby
def make_false_landing_and_flyby_datasets(dataset_nopost):
    
    #shift_list = shift_datasets(dataset_nopost, nshifts=nshifts)
    #shift = fa.add_datasets(shift_list)
    
    shift = dataset_nopost
    
    fa.calc_func(shift, classify_false_post)
    fa.calc_func(shift, calc_frame_of_landing)
    
    dataset_nopost_landing = make_behavior_dataset(shift, filename='dataset_nopost_landing_3cm', behavior='landing')
    
    dataset_nopost_flyby = make_behavior_dataset(shift, filename='dataset_nopost_flyby_3cm', behavior='flyby')
    
    fa.prep_dataset(dataset_nopost_landing)
    fa.calc_func(dataset_nopost_landing, saccade_analysis.calc_last_saccade)
    
    fa.prep_dataset(dataset_nopost_flyby)
    fa.calc_func(dataset_nopost_flyby, saccade_analysis.calc_last_saccade)
    
    #fa.save(dataset_nopost_landing, 'dataset_nopost_landing')
    fa.save(dataset_nopost_flyby, 'dataset_nopost_flyby_3cm')
    
    return dataset_nopost_landing, dataset_nopost_flyby
示例#3
0
def make_behavior_dataset(dataset,
                          filename='dataset_nopost_landing',
                          behavior='landing'):

    REQUIRED_LENGTH = 30
    REQUIRED_DIST = 0.1

    new_dataset = ffa.Dataset(like=dataset)
    if type(behavior) is not list:
        behavior = [behavior]
    for k, trajec in dataset.trajecs.items():
        trajec.key = k
        if trajec.behavior in behavior:

            calc_frame_of_landing(trajec)
            fa.normalize_dist_to_stim_r(trajec)
            saccade_analysis.calc_saccades2(trajec)

            if trajec.behavior == 'landing':
                if trajec.dist_to_stim_r_normed[0] >= REQUIRED_DIST:
                    #if np.max(trajec.positions[:,2]) < 0 and np.min(trajec.positions[:,2]) > -0.15:
                    if np.min(trajec.positions[:, 2]) > -0.15:
                        trajec.frames = np.arange(
                            fa.get_frame_at_distance(trajec, REQUIRED_DIST),
                            trajec.frame_of_landing).tolist()
                        if trajec.frame_of_landing > REQUIRED_LENGTH:
                            if np.max(trajec.positions[trajec.frames, 2]
                                      ) < 0.15:  # no real altitude check
                                #classify(trajec, dfar=REQUIRED_DIST, dnear=0.005)
                                new_dataset.trajecs.setdefault(k, trajec)

                                first_frame = 0
                                trajec.frames_below_post = np.arange(
                                    first_frame,
                                    trajec.frame_of_landing + 1).tolist()

            elif trajec.behavior == 'flyby':
                frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
                print k
                if frame_nearest_to_post > 10 and np.max(
                        trajec.dist_to_stim_r[0:frame_nearest_to_post]
                ) > REQUIRED_DIST:
                    if np.min(trajec.positions[:, 2]) > -0.15:
                        if trajec.dist_to_stim_r[frame_nearest_to_post] < 0.1:
                            fs = np.arange(frame_nearest_to_post,
                                           len(trajec.speed)).tolist()
                            try:
                                last_frame = get_frame_at_distance(
                                    trajec, REQUIRED_DIST, frames=fs)
                            except:
                                last_frame = len(trajec.speed) - 1
                            first_frame = fa.get_frame_at_distance(
                                trajec,
                                REQUIRED_DIST,
                                frames=np.arange(
                                    0, frame_nearest_to_post).tolist())

                            trajec.frames = np.arange(first_frame,
                                                      last_frame).tolist()

                            # get frame at 8cm away, prior to nearest approach
                            frame_nearest_to_post = np.argmin(
                                trajec.dist_to_stim_r)
                            trajec.frame_nearest_to_post = frame_nearest_to_post
                            frames = np.arange(0,
                                               frame_nearest_to_post).tolist()
                            trajec.frames_of_flyby = frames
                            frame_at_distance = fa.get_frame_at_distance(
                                trajec, 0.08, singleframe=True, frames=frames)

                            last_frame = np.min([
                                frame_nearest_to_post + 20,
                                len(trajec.speed) - 1
                            ])

                            sacs = [s[0] for s in trajec.sac_ranges]
                            sac_sgns = np.array(sacs) - frame_at_distance
                            sac_negs = np.where(sac_sgns < 0)[0]
                            if len(sac_negs) > 0:
                                sac_neg = sac_negs[0]
                            else:
                                sac_neg = 0
                            first_frame = sac_neg + 1

                            try:
                                trajec.frames_of_flyby = np.arange(
                                    first_frame, last_frame).tolist()
                                new_dataset.trajecs.setdefault(k, trajec)
                            except:
                                print 'ignored key: ', k, first_frame, last_frame

                            new_dataset.trajecs.setdefault(k, trajec)

    fa.save(new_dataset, filename)

    return new_dataset
def make_behavior_dataset(dataset, filename='dataset_nopost_landing', behavior='landing'):

    REQUIRED_LENGTH = 30
    REQUIRED_DIST = 0.1

    new_dataset = ffa.Dataset(like=dataset)
    if type(behavior) is not list:
        behavior = [behavior]
    for k,trajec in dataset.trajecs.items():
        trajec.key = k
        if trajec.behavior in behavior:
            
            calc_frame_of_landing(trajec)
            fa.normalize_dist_to_stim_r(trajec)
            saccade_analysis.calc_saccades2(trajec)
            
            if trajec.behavior == 'landing':
                if trajec.dist_to_stim_r_normed[0] >= REQUIRED_DIST:
                    #if np.max(trajec.positions[:,2]) < 0 and np.min(trajec.positions[:,2]) > -0.15:
                    if np.min(trajec.positions[:,2]) > -0.15:
                        trajec.frames = np.arange(fa.get_frame_at_distance(trajec, REQUIRED_DIST), trajec.frame_of_landing).tolist()
                        if trajec.frame_of_landing > REQUIRED_LENGTH:
                            if np.max(trajec.positions[trajec.frames,2]) < 0.15: # no real altitude check
                                #classify(trajec, dfar=REQUIRED_DIST, dnear=0.005)
                                new_dataset.trajecs.setdefault(k, trajec)
                                
                                first_frame = 0
                                trajec.frames_below_post = np.arange(first_frame, trajec.frame_of_landing+1).tolist()

            elif trajec.behavior == 'flyby':
                frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
                print k
                if frame_nearest_to_post > 10 and np.max(trajec.dist_to_stim_r[0:frame_nearest_to_post]) > REQUIRED_DIST:
                    if np.min(trajec.positions[:,2]) > -0.15:
                        if trajec.dist_to_stim_r[frame_nearest_to_post] < 0.1:
                            fs = np.arange(frame_nearest_to_post,len(trajec.speed)).tolist()
                            try:
                                last_frame = get_frame_at_distance(trajec, REQUIRED_DIST, frames=fs)
                            except:
                                last_frame = len(trajec.speed)-1
                            first_frame = fa.get_frame_at_distance(trajec, REQUIRED_DIST, frames=np.arange(0,frame_nearest_to_post).tolist())
                            
                            trajec.frames = np.arange(first_frame, last_frame).tolist()
                            
                            # get frame at 8cm away, prior to nearest approach
                            frame_nearest_to_post = np.argmin(trajec.dist_to_stim_r)
                            trajec.frame_nearest_to_post = frame_nearest_to_post
                            frames = np.arange(0, frame_nearest_to_post).tolist()
                            trajec.frames_of_flyby = frames
                            frame_at_distance = fa.get_frame_at_distance(trajec, 0.08, singleframe=True, frames=frames)
                            
                            last_frame = np.min( [frame_nearest_to_post+20, len(trajec.speed)-1]) 
                            
                            sacs = [s[0] for s in trajec.sac_ranges]
                            sac_sgns = np.array(sacs) - frame_at_distance
                            sac_negs = np.where(sac_sgns<0)[0]
                            if len(sac_negs) > 0:
                                sac_neg = sac_negs[0]
                            else:
                                sac_neg = 0
                            first_frame = sac_neg + 1
                            
                            try:
                                trajec.frames_of_flyby = np.arange(first_frame, last_frame).tolist()
                                new_dataset.trajecs.setdefault(k, trajec)
                            except:
                                print 'ignored key: ', k, first_frame, last_frame
                            
                            new_dataset.trajecs.setdefault(k, trajec)
                            
            
    fa.save(new_dataset, filename)

    return new_dataset