Beispiel #1
0
    def __init__(self, fmf_dir, savedir, fly_id, plot_overlays=False):

        if (savedir[-1] == '/'):
            savedir = savedir[:-1]

        if not os.path.exists(savedir + '/temp_png'):
            os.makedirs(savedir + '/temp_png')

        self._savedir = savedir

        if (fmf_dir[-1] == '/'):
            self._fmf_dir = fmf_dir[:-1]
        else:
            self._fmf_dir = fmf_dir

        self._zoomfmf = FMF.FlyMovie(self._fmf_dir)

        self._plot_overlays = plot_overlays

        self._expdir = fmf_dir.rsplit('/', 2)[0]

        self._bag = utilities.match_fmf_and_bag(self._fmf_dir,
                                                (self._expdir + '/BAGS'))

        #self._wide = utilities.match_wide_to_zoom(self._fmf_dir, (self._expdir + '/'))

        self._handle, __, ___ = utilities.parse_fmftime(self._fmf_dir)

        self._data, self._Tzero = self.get_data()

        self._image_height, self._image_width = self._zoomfmf.get_frame(
            0)[0].shape
Beispiel #2
0
def sync_jaaba_with_ros(FMF_DIR, BAGS, JAABA):

    print "Processing: ", FMF_DIR
    
    JAABA_CSV               = FMF_DIR + '/registered_trx.csv'
    
    FLY_ID, FMF_TIME, GROUP = parse_fmftime(FMF_DIR)
    
    BAG_FILE                = utilities.match_fmf_and_bag(FMF_DIR, BAGS)
    
    WIDE_FMF                = utilities.match_wide_to_zoom(FMF_DIR, JAABA)
    
    jaaba_data = pd.read_csv(JAABA_CSV, sep=',', names=['Timestamp','Length','Width','Theta','Left','Right'], index_col=False)
    jaaba_data[['Length','Width','Left','Right']] = jaaba_data[['Length','Width','Left','Right']].astype(np.float64)
    jaaba_data = utilities.convert_timestamps(jaaba_data)

    # ALIGN LASER STATE DATA
    jaaba_data['Laser1_state'] = binarize_laser_data(BAG_FILE, 'laser1')['Laser_state'].asof(jaaba_data.index).fillna(value=0)  #YAY! 
    jaaba_data['Laser2_state'] = binarize_laser_data(BAG_FILE, 'laser2')['Laser_state'].asof(jaaba_data.index).fillna(value=0)
    
    # COMPUTE AND ALIGN DISTANCE TO NEAREST TARGET
    targets = target_detector.TargetDetector(WIDE_FMF, FMF_DIR)
    targets.plot_targets_on_background()
    jaaba_data['dtarget'] = targets.get_dist_to_nearest_target(BAG_FILE)['dtarget'].asof(jaaba_data.index).fillna(value=0)
    
    jaaba_data['Timestamp'] = jaaba_data.index  #silly pandas bug for subtracting from datetimeindex...
    jaaba_data['synced_time'] = jaaba_data['Timestamp'] - jaaba_data['Timestamp'][jaaba_data[jaaba_data['Laser2_state'] > 0].index[0]]    

    jaaba_data['maxWingAngle'] = get_absmax(jaaba_data[['Left','Right']])


    return jaaba_data
Beispiel #3
0
    def __init__(self, fmf_dir, savedir, fly_id, plot_overlays=False):
        
        if (savedir[-1] == '/' ):
            savedir = savedir[:-1]
        
        if not os.path.exists(savedir + '/temp_png'):
            os.makedirs(savedir + '/temp_png')

        self._savedir = savedir

        if (fmf_dir[-1] == '/'):
            self._fmf_dir  = fmf_dir[:-1]
        else:
            self._fmf_dir  = fmf_dir
            
        
        self._zoomfmf =  FMF.FlyMovie(self._fmf_dir)
        
        
        self._plot_overlays = plot_overlays
        
        self._expdir = fmf_dir.rsplit('/', 2)[0]
        
        
        self._bag = utilities.match_fmf_and_bag(self._fmf_dir, (self._expdir + '/BAGS'))
        
        #self._wide = utilities.match_wide_to_zoom(self._fmf_dir, (self._expdir + '/'))
        
        self._handle, __, ___ = utilities.parse_fmftime(self._fmf_dir)
        
        self._data, self._Tzero = self.get_data()
        
        self._image_height, self._image_width = self._zoomfmf.get_frame(0)[0].shape
Beispiel #4
0
    def get_stims_from_bag(self, FMF_DIR, BAGS, EXPDIR):

        print "Processing: ", FMF_DIR

        #JAABA_CSV               = FMF_DIR + '/registered_trx.csv'

        FLY_ID, FMF_TIME, GROUP = utilities.parse_fmftime(FMF_DIR)

        BAG_FILE = utilities.match_fmf_and_bag(FMF_DIR, BAGS)

        WIDE_FMF = utilities.match_wide_to_zoom(FMF_DIR, EXPDIR)

        #jaaba_data = pd.read_csv(JAABA_CSV, sep=',', names=['Timestamp','Length','Width','Theta','Left','Right'], index_col=False)
        #jaaba_data[['Length','Width','Left','Right']] = jaaba_data[['Length','Width','Left','Right']].astype(np.float64)

        # ALIGN LASER STATE DATA
        jaaba_data = DataFrame(index=self._zoomfmf.get_all_timestamps())
        jaaba_data['Timestamp'] = self._zoomfmf.get_all_timestamps()
        jaaba_data = utilities.convert_timestamps(jaaba_data)
        jaaba_data['Laser1_state'] = utilities.binarize_laser_data(
            BAG_FILE, 2).resample('10ms', how='max')['Laser_state'].asof(
                jaaba_data.index).fillna(value=0)  #YAY!
        jaaba_data['Laser2_state'] = utilities.binarize_laser_data(
            BAG_FILE, 4).resample('10ms', how='max')['Laser_state'].asof(
                jaaba_data.index).fillna(value=0)
        """
        # COMPUTE AND ALIGN DISTANCE TO NEAREST TARGET
        targets = target_detector.TargetDetector(WIDE_FMF, FMF_DIR)
        targets.plot_targets_on_background()
        jaaba_data['dtarget'] = targets.get_dist_to_nearest_target(BAG_FILE)['dtarget'].asof(jaaba_data.index).fillna(value=0)
        """
        jaaba_data[
            'Timestamp'] = jaaba_data.index  #silly pandas bug for subtracting from datetimeindex...
        try:
            jaaba_data['synced_time'] = jaaba_data[
                'Timestamp'] - jaaba_data.Timestamp[
                    (jaaba_data.Laser2_state +
                     jaaba_data.Laser1_state) > 0].index[0]
        except:
            print "WARNING:   Cannot synchronize by stimulus. Setting T0 to frame0. "
            jaaba_data['synced_time'] = jaaba_data[
                'Timestamp'] - jaaba_data.Timestamp.index[0]
        """
        #DISCARD BOGUS WING ANGLE VALUES:
        jaaba_data['Left'][jaaba_data['Left'] < -2.09 ]= np.nan   #2.09 for 120degrees
        jaaba_data['Right'][jaaba_data['Right'] > 2.09] = np.nan
        
        jaaba_data['maxWingAngle'] = jaaba_data[['Left','Right']].abs().max(axis=1)
        
        """
        return jaaba_data
Beispiel #5
0
def sync_jaaba_with_ros(FMF_DIR, BAGS, JAABA):

    print "Processing: ", FMF_DIR

    JAABA_CSV = FMF_DIR + '/registered_trx.csv'

    FLY_ID, FMF_TIME, GROUP = parse_fmftime(FMF_DIR)

    BAG_FILE = utilities.match_fmf_and_bag(FMF_DIR, BAGS)

    WIDE_FMF = utilities.match_wide_to_zoom(FMF_DIR, JAABA)

    jaaba_data = pd.read_csv(
        JAABA_CSV,
        sep=',',
        names=['Timestamp', 'Length', 'Width', 'Theta', 'Left', 'Right'],
        index_col=False)
    jaaba_data[['Length', 'Width', 'Left',
                'Right']] = jaaba_data[['Length', 'Width', 'Left',
                                        'Right']].astype(np.float64)
    jaaba_data = utilities.convert_timestamps(jaaba_data)

    # ALIGN LASER STATE DATA
    jaaba_data['Laser1_state'] = binarize_laser_data(
        BAG_FILE,
        'laser1')['Laser_state'].asof(jaaba_data.index).fillna(value=0)  #YAY!
    jaaba_data['Laser2_state'] = binarize_laser_data(
        BAG_FILE,
        'laser2')['Laser_state'].asof(jaaba_data.index).fillna(value=0)

    # COMPUTE AND ALIGN DISTANCE TO NEAREST TARGET
    targets = target_detector.TargetDetector(WIDE_FMF, FMF_DIR)
    targets.plot_targets_on_background()
    print targets.get_targets()
    jaaba_data['dtarget'] = targets.get_dist_to_nearest_target(
        BAG_FILE)['dtarget'].asof(jaaba_data.index).fillna(value=0)

    jaaba_data[
        'Timestamp'] = jaaba_data.index  #silly pandas bug for subtracting from datetimeindex...
    jaaba_data['synced_time'] = jaaba_data['Timestamp'] - jaaba_data[
        'Timestamp'][jaaba_data[jaaba_data['Laser2_state'] > 0].index[0]]

    #DISCARD BOGUS WING ANGLE VALUES:
    jaaba_data['Left'][
        jaaba_data['Left'] < -2.3] = np.nan  #2.09 for 120degrees
    jaaba_data['Right'][jaaba_data['Right'] > 2.3] = np.nan

    jaaba_data['maxWingAngle'] = get_absmax(jaaba_data[['Left', 'Right']])

    return jaaba_data
Beispiel #6
0
    def __init__(self, fmf_dir, savedir, fly_id, plot_overlays=False):

        if (savedir[-1] == '/'):
            savedir = savedir[:-1]

        if not os.path.exists(savedir + '/temp_png'):
            os.makedirs(savedir + '/temp_png')

        self._savedir = savedir

        if (fmf_dir[-1] == '/'):
            self._fmf_dir = fmf_dir[:-1]
        else:
            self._fmf_dir = fmf_dir

        self._plot_overlays = plot_overlays

        self._expdir = fmf_dir.rsplit('/', 1)[0]

        self._bag = utilities.match_fmf_and_bag(self._fmf_dir,
                                                (self._expdir + '/BAGS'))

        self._wide = utilities.match_wide_to_zoom(self._fmf_dir,
                                                  (self._expdir + '/'))

        self._widefmf = FMF.FlyMovie(self._wide)

        self._handle, __, ___ = utilities.parse_fmftime(self._fmf_dir)

        self._zoomfmf, self._data, self._Tzero = self.get_data()

        if self._data.Laser0_state.mean(
        ) >= 0.5:  #SOME EXPERIMENTS ARE DONE WITH lASER0 OFF.
            if self._data.Laser0_state.mean(
            ) <= 0.99:  #SOME BAGFILES HAVE A FEW MSGS BEFORE LASER CONFIG
                self.ILLUMINATED_WITH_LASER0 = 1
            else:
                self.ILLUMINATED_WITH_LASER0 = 0
        else:
            self.ILLUMINATED_WITH_LASER0 = 0

        self._image_height, self._image_width = self._zoomfmf.get_frame(
            0)[0].shape
Beispiel #7
0
    def get_stims_from_bag(self, FMF_DIR, BAGS, EXPDIR):

        print "Processing: ", FMF_DIR
        
        #JAABA_CSV               = FMF_DIR + '/registered_trx.csv'
        
        FLY_ID, FMF_TIME, GROUP = utilities.parse_fmftime(FMF_DIR)
        
        BAG_FILE                = utilities.match_fmf_and_bag(FMF_DIR, BAGS)
        
        WIDE_FMF                = utilities.match_wide_to_zoom(FMF_DIR, EXPDIR)
        
        #jaaba_data = pd.read_csv(JAABA_CSV, sep=',', names=['Timestamp','Length','Width','Theta','Left','Right'], index_col=False)
        #jaaba_data[['Length','Width','Left','Right']] = jaaba_data[['Length','Width','Left','Right']].astype(np.float64)
        
        
        # ALIGN LASER STATE DATA
        jaaba_data = DataFrame(index=self._zoomfmf.get_all_timestamps())
        jaaba_data['Timestamp'] = self._zoomfmf.get_all_timestamps()
        jaaba_data = utilities.convert_timestamps(jaaba_data)
        jaaba_data['Laser1_state'] = utilities.binarize_laser_data(BAG_FILE, 2).resample('10ms', how='max')['Laser_state'].asof(jaaba_data.index).fillna(value=0)  #YAY! 
        jaaba_data['Laser2_state'] = utilities.binarize_laser_data(BAG_FILE, 4).resample('10ms', how='max')['Laser_state'].asof(jaaba_data.index).fillna(value=0)
        """
        # COMPUTE AND ALIGN DISTANCE TO NEAREST TARGET
        targets = target_detector.TargetDetector(WIDE_FMF, FMF_DIR)
        targets.plot_targets_on_background()
        jaaba_data['dtarget'] = targets.get_dist_to_nearest_target(BAG_FILE)['dtarget'].asof(jaaba_data.index).fillna(value=0)
        """
        jaaba_data['Timestamp'] = jaaba_data.index  #silly pandas bug for subtracting from datetimeindex...
        try:
            jaaba_data['synced_time'] = jaaba_data['Timestamp'] - jaaba_data.Timestamp[(jaaba_data.Laser2_state + jaaba_data.Laser1_state) > 0].index[0]
        except:
            print "WARNING:   Cannot synchronize by stimulus. Setting T0 to frame0. "
            jaaba_data['synced_time'] = jaaba_data['Timestamp'] - jaaba_data.Timestamp.index[0]   
        """
        #DISCARD BOGUS WING ANGLE VALUES:
        jaaba_data['Left'][jaaba_data['Left'] < -2.09 ]= np.nan   #2.09 for 120degrees
        jaaba_data['Right'][jaaba_data['Right'] > 2.09] = np.nan
        
        jaaba_data['maxWingAngle'] = jaaba_data[['Left','Right']].abs().max(axis=1)
        
        """
        return jaaba_data
Beispiel #8
0
    def sync_jaaba_with_ros(self, FMF_DIR, BAGS, JAABA):

        print "Processing: ", FMF_DIR

        JAABA_CSV = FMF_DIR + '/registered_trx.csv'

        FLY_ID, FMF_TIME, GROUP = utilities.parse_fmftime(FMF_DIR)

        BAG_FILE = utilities.match_fmf_and_bag(FMF_DIR, BAGS)

        WIDE_FMF = utilities.match_wide_to_zoom(FMF_DIR, JAABA)

        jaaba_data = pd.read_csv(
            JAABA_CSV,
            sep=',',
            names=['Timestamp', 'Length', 'Width', 'Theta', 'Left', 'Right'],
            index_col=False)
        jaaba_data[['Length', 'Width', 'Left', 'Right'
                    ]] = jaaba_data[['Length', 'Width', 'Left',
                                     'Right']].astype(np.float64)
        jaaba_data = utilities.convert_timestamps(jaaba_data)

        # ALIGN LASER STATE DATA

        laser_states = utilities.get_laser_states(BAG_FILE)
        try:
            jaaba_data['Laser0_state'] = laser_states['Laser0_state'].asof(
                jaaba_data.index).fillna(value=0)
            jaaba_data['Laser1_state'] = laser_states['Laser1_state'].asof(
                jaaba_data.index).fillna(value=0)  #YAY!
            jaaba_data['Laser2_state'] = laser_states['Laser2_state'].asof(
                jaaba_data.index).fillna(value=0)
        except:
            print "\t ERROR: problem interpreting laser current values."
            jaaba_data['Laser0_state'] = 0
            jaaba_data['Laser2_state'] = 0
            jaaba_data['Laser1_state'] = 0

        # COMPUTE AND ALIGN DISTANCE TO NEAREST TARGET
        targets = target_detector.TargetDetector(WIDE_FMF, FMF_DIR)
        targets.plot_targets_on_background()
        jaaba_data['dtarget'] = targets.get_dist_to_nearest_target(
            BAG_FILE)['dtarget'].asof(jaaba_data.index).fillna(value=0)

        jaaba_data[
            'Timestamp'] = jaaba_data.index  #silly pandas bug for subtracting from datetimeindex...
        try:
            jaaba_data['synced_time'] = jaaba_data[
                'Timestamp'] - jaaba_data.Timestamp[
                    (jaaba_data.Laser2_state +
                     jaaba_data.Laser1_state) > 0].index[0]

        except:
            print "WARNING:   Cannot synchronize by stimulus. Setting T0 to frame0. "
            jaaba_data['synced_time'] = jaaba_data[
                'Timestamp'] - jaaba_data.Timestamp.index[0]

        #DISCARD BOGUS WING ANGLE VALUES:
        jaaba_data['Left'][
            jaaba_data['Left'] < -2.09] = np.nan  #2.09 for 120degrees
        jaaba_data['Right'][jaaba_data['Right'] > 2.09] = np.nan

        jaaba_data['maxWingAngle'] = jaaba_data[['Left',
                                                 'Right']].abs().max(axis=1)

        return jaaba_data
Beispiel #9
0
import flymad_jaaba.utilities as utilities
import flymad_jaaba.target_detector as target_detector

import matplotlib.pyplot as plt


fmf_file = '/media/DBATH_5/150107/DB201-GP-costim_wide_20150107_174101.fmf'

bagdir = '/media/DBATH_5/150107/BAGS'


tempdir = '/groups/dickson/home/bathd/Desktop/150119'


bag_file = utilities.match_fmf_and_bag(fmf_file, bagdir)

targs = target_detector.TargetDetector(fmf_file, tempdir)
targs.plot_trajectory_on_background(bag_file)

positions = utilities.get_positions_from_bag(bag_file)
distances = targs.get_dist_to_nearest_target(bag_file)


plt.plot(distances)
plt.show()

plt.plot(positions.fly_x, positions.fly_y)#, alpha=distances.values)
plt.show()