Пример #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
Пример #2
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
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
0
def make_pngs(zoom_fmf, savedir, overlays_value):

    
    #os.system(ffmpeg -f image2 -r 15 -i _tmp%05d.png -vcodec mpeg4 -y (_VIDEO_DIR + '/flymad_annotated.mp4'))

    vid = bag_movies.FlyPanel(zoom_fmf, savedir, utilities.parse_fmftime(zoom_fmf)[0], overlays_value, args.lasermode)

    
    image_height = vid.get_frame(0)[0].shape[0]
    
    image_width = vid.get_frame(0)[0].shape[1]
    
    for frame_number in np.arange(vid.get_n_frames()):
                
        if os.path.exists(savedir + '/temp_png/_tmp%05d.png'%(frame_number)):
            continue
        fig = plt.figure(figsize=(image_width*2/100, image_height/100), dpi=200.399, frameon=False )
        make_panel(vid, 0, 0, frame_number, fig)
        
        plt.savefig(savedir + '/temp_png/_tmp%05d.png'%(frame_number), bbox_inches='tight', pad_inches=0)
        plt.close('all')    
    utilities.call_command("ffmpeg -f image2 -r 15 -i "+ savedir + "/temp_png/_tmp%05d.png -vf scale=iw/2:-1 -vcodec mpeg4 -b 8000k -y " + savedir[:-1] + ".mp4;")
    utilities.call_command("rm -r " + savedir)
        type=str,
        required=False,
        default="Experiment",
        help=
        'Label for bottom data. example: P1>CsCHRIMSON & $\mathregular{SHIBIRE^{TS}}$'
    )
    args = parser.parse_args()

    top_fmf = args.topfmf
    bottom_fmf = args.bottomfmf
    savedir = args.savedir

    #os.system(ffmpeg -f image2 -r 15 -i _tmp%05d.png -vcodec mpeg4 -y (_VIDEO_DIR + '/flymad_annotated.mp4'))

    ctrlfly = data_movies.FlyPanel(top_fmf, savedir,
                                   utilities.parse_fmftime(top_fmf)[0])

    expfly = data_movies.FlyPanel(bottom_fmf, savedir,
                                  utilities.parse_fmftime(bottom_fmf)[0])

    image_height = ctrlfly.get_frame(0)[0].shape[0] + expfly.get_frame(
        0)[0].shape[0]

    image_width = expfly.get_frame(0)[0].shape[1] * 3
    for frame_number in range(9450):  #ctrlfly.get_n_frames()):

        if os.path.exists(savedir + '/temp_png/_tmp%05d.png' % (frame_number)):
            continue
        fig = plt.figure(figsize=(image_width / 100, image_height / 100),
                         dpi=200.399)
Пример #8
0
        '--overlays',
        type=bool,
        required=False,
        default=False,
        help='turn on overlays to plot wing angles and distance bars')
    args = parser.parse_args()

    zoom_fmf = args.zoom
    wide_fmf = args.wide
    savedir = args.savedir
    overlays_value = args.overlays

    #os.system(ffmpeg -f image2 -r 15 -i _tmp%05d.png -vcodec mpeg4 -y (_VIDEO_DIR + '/flymad_annotated.mp4'))

    vid = data_movies.FlyPanel(zoom_fmf, savedir,
                               utilities.parse_fmftime(zoom_fmf)[0],
                               overlays_value)

    image_height = vid.get_frame(0)[0].shape[0]

    image_width = vid.get_frame(0)[0].shape[1]

    for frame_number in range(vid.get_n_frames()):

        if os.path.exists(savedir + '/temp_png/_tmp%05d.png' % (frame_number)):
            continue
        fig = plt.figure(figsize=(image_width / 100, image_height * 1.2 / 100),
                         dpi=200.399,
                         frameon=False)

        make_panel(vid, 0, 0, frame_number)
                        help='path to fmf directory') 
    parser.add_argument('--savedir', type=str, required=True,
                        help='path to save directory') 
    parser.add_argument('--toplabel', type=str, required=False, default="Control",
                        help='label for top data') 
    parser.add_argument('--bottomlabel', type=str, required=False, default="Experiment",
                        help='Label for bottom data. example: P1>CsCHRIMSON & $\mathregular{SHIBIRE^{TS}}$') 
    args = parser.parse_args()
    
    top_fmf = args.topfmf
    bottom_fmf = args.bottomfmf
    savedir = args.savedir  
    
    #os.system(ffmpeg -f image2 -r 15 -i _tmp%05d.png -vcodec mpeg4 -y (_VIDEO_DIR + '/flymad_annotated.mp4'))

    ctrlfly = data_movies.FlyPanel(top_fmf, savedir, utilities.parse_fmftime(top_fmf)[0])
    
    expfly = data_movies.FlyPanel(bottom_fmf, savedir, utilities.parse_fmftime(bottom_fmf)[0])
        
    image_height = ctrlfly.get_frame(0)[0].shape[0] + expfly.get_frame(0)[0].shape[0]
    
    image_width = expfly.get_frame(0)[0].shape[1] *3
    for frame_number in range(9450):#ctrlfly.get_n_frames()):
           
        if os.path.exists(savedir + '/temp_png/_tmp%05d.png'%(frame_number)):
            continue
        fig = plt.figure(figsize=(image_width/100, image_height/100), dpi=200.399 )
           
        make_panel(ctrlfly, 0, 0, frame_number, args.toplabel)
        make_panel(expfly, 30, 0, frame_number, args.bottomlabel )
        #plt.show()
Пример #10
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
Пример #11
0
                        help='path to zoom fmf') 
    parser.add_argument('--wide', type=str, required=False,
                        help='path to wide fmf') 
    parser.add_argument('--savedir', type=str, required=True,
                        help='path to save directory') 
    parser.add_argument('--overlays', type=bool, required=False, default=False, help='turn on overlays to plot wing angles and distance bars')
    args = parser.parse_args()
    
    zoom_fmf = args.zoom
    wide_fmf = args.wide
    savedir = args.savedir  
    overlays_value = args.overlays
    
    #os.system(ffmpeg -f image2 -r 15 -i _tmp%05d.png -vcodec mpeg4 -y (_VIDEO_DIR + '/flymad_annotated.mp4'))

    vid = data_movies.FlyPanel(zoom_fmf, savedir, utilities.parse_fmftime(zoom_fmf)[0], overlays_value)
    
    
    
    image_height = vid.get_frame(0)[0].shape[0]
    
    image_width = vid.get_frame(0)[0].shape[1]
    
    for frame_number in range(8000):
                
        if os.path.exists(savedir + '/temp_png/_tmp%05d.png'%(frame_number)):
            continue
        fig = plt.figure(figsize=(image_width/100, image_height*1.2/100), dpi=200.399, frameon=False )
           
        make_panel(vid, 0, 0, frame_number)
        
    
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--fmf', type=str, required=True,
                        help='path to fmf directory') 
    parser.add_argument('--savedir', type=str, required=True,
                        help='path to save directory') 
    parser.add_argument('--label', type=str, required=False, default="Control",
                        help='label for top data') 
    args = parser.parse_args()
    
    fmf = args.fmf
    savedir = args.savedir  
    
    #os.system(ffmpeg -f image2 -r 15 -i _tmp%05d.png -vcodec mpeg4 -y (_VIDEO_DIR + '/flymad_annotated.mp4'))

    fly = data_movies.FlyPanel(fmf, savedir, utilities.parse_fmftime(fmf)[0])
    
        
    image_height = (fly.get_frame(0)[0].shape[0] )*2
    
    image_width = fly.get_frame(0)[0].shape[1] *2:
    if not os.path.exists(savedir + '/temp_png):
        os.makedirs(savedir + '/temp_png) 
    for frame_number in range(fly.get_n_frames()):
           
        if os.path.exists(savedir + '/temp_png/_tmp%05d.png'%(frame_number)):
            continue
        fig = plt.figure(figsize=(image_width/100, image_height/100), dpi=200.399 )
           
        make_panel(fly, 0, 0, frame_number, args.label)
        #plt.show()