Exemplo n.º 1
0
def load_flies_skies(rootDir, baseDirs):
    skies, flies = {}, {}
    for b, baseDir in enumerate(baseDirs):
        sks, fls = {}, {}
        dNames = os.listdir(os.path.join(rootDir,baseDir))
        flyDirNames = [D for D in dNames if D[:3] == 'fly']
        flyDirNames.sort(compare_dir_names)

        for dNum, dName in enumerate(flyDirNames):
            dirName=os.path.join(rootDir,baseDir,dName)
            print dirName
            fly = flypod.analyze_directory(dirName)
            fls[dNum] = fly.copy()
            sky = sky_times.analyze_directory(dirName)
            sks[dNum] = sky.copy()
            
        flies[baseDir] = fls
        skies[baseDir] = sks
    return flies, skies
Exemplo n.º 2
0
def make_frames(inDirName,outDirName):
    """saves frames in movie with orientation superimposed
    
    arguments:      
    inDirName       directory with fly, sky, and .fmf files
    outDirName      directory to save frames to
    
    example:
    make_frames('/media/weir05/data/rotator/white/diffuserPol/12trials/fly08','./frames/')
    """ 
    fly = flypod.analyze_directory(inDirName)
    sky = sky_times.analyze_directory(inDirName)
    
    FRAMESTEP = 65 #130
    
    circleCenterX, circleCenterY, circleRadius = circle_fit(fly['x'],fly['y']) #NOTE:should have been saving this info from start.
    
    fmf = FMF.FlyMovie(join(inDirName,fly['fileName']))

    nFrames = fmf.get_n_frames()
    timestamps = np.ma.masked_all(len(range(0,int(nFrames),FRAMESTEP)))
    
    fig = pylab.figure()
    ax = fig.add_subplot(111)
    for fn,frameNumber in enumerate(range(0,int(nFrames),FRAMESTEP)):
        frame,timestamps[fn] = fmf.get_frame(frameNumber)

        #pylab.imsave(join(outDirName,'frame')+("%05d" %(fn+1))+'.png',frame,format='png',cmap='gray')
        ax.imshow(frame,cmap='gray')
        lineX = [fly['x'][frameNumber]+fly['ROI'][2], circleCenterX+fly['ROI'][2]]
        lineY = [fly['y'][frameNumber]+fly['ROI'][1], circleCenterY+fly['ROI'][1]]
        ax.plot(lineX,lineY,'b-', linewidth=2)
        ax.set_axis_off()
        fig.savefig(join(outDirName,'frame')+("%05d" %(fn+1))+'.png')
        ax.cla()
    print 'frame rate = ' + str(1/np.mean(np.diff(timestamps)))
Exemplo n.º 3
0
    flies
except NameError:
    print "loading flies"
    skies, flies = {}, {}
    for b, baseDir in enumerate(baseDirs):
        sks, fls = {}, {}
        dNames = os.listdir(os.path.join(rootDir, baseDir))
        flyDirNames = [D for D in dNames if D[:3] == "fly"]
        flyDirNames.sort(compare_dir_names)

        for dNum, dName in enumerate(flyDirNames):
            dirName = os.path.join(rootDir, baseDir, dName)
            print dirName
            fly = flypod.analyze_directory(dirName)
            fls[dNum] = fly
            sky = sky_times.analyze_directory(dirName)
            sks[dNum] = sky

        flies[baseDir] = fls
        skies[baseDir] = sks

MAX_NUM_STOPS = 6
SAVEFIGS = False
CHANGEBUFFER = 10
STARTBUFFER = 0
STOPBUFFER = 0
COLORS = dict(N="b", E="y", S="r", W="g")
ROTATIONS = dict(N=0, E=90, S=180, W=270)
SPEED = 0.5
DMAX = 330  # 800
Dist = {}
def make_frames(inDirName,outDirName):
    """saves frames in movie with orientation superimposed
    
    arguments:      
    inDirName       directory with fly, sky, and .fmf files
    outDirName      directory to save frames to
    
    example:
    make_frames('/media/weir05/data/rotator/white/diffuserPol/12trials/fly08','./frames/')
    """ 
    fly = flypod.analyze_directory(inDirName)
    sky = sky_times.analyze_directory(inDirName)
    
    orientations = fly['orientations'].copy() + 180
    times = fly['times'].copy()
    
    rotatorStateEachFrame = -np.ones(times.shape) # we will store frame-based rotator state in here
    
    COLORS = dict({'U': 'm', 'R': 'c'})
    ROTATOR_CODE = dict({'U': 0, 'R': 1})
    FRAMESTEP = 65 #130
    
    circleCenterX, circleCenterY, circleRadius = circle_fit(fly['x'],fly['y']) #NOTE:should have been saving this info from start.
    
    fmf = FMF.FlyMovie(join(inDirName,fly['fileName']))

    nFrames = fmf.get_n_frames()
    timestamps = np.ma.masked_all(len(range(0,int(nFrames),FRAMESTEP)))
    
    fig = pylab.figure()
    frameAxes = fig.add_axes([0.1, 0.3, 0.5, 0.6])
    timePlotAxes = fig.add_axes([0.1, 0.1, 0.8, 0.15])
    polarTopAxes = fig.add_axes([0.55, 0.6, 0.4, 0.25],polar=True)
    polarBottomAxes = fig.add_axes([0.55, 0.3, 0.4, 0.25],polar=True)
    
    timePlotAxes.plot(times,orientations,'k')
    for i, cT in enumerate(sky['changeTimes'][:-1]):
        timePlotAxes.axvspan(cT, sky['changeTimes'][i+1], facecolor=COLORS[sky['rotatorState'][i]], alpha=0.2)
        startInd = np.argmin(abs(times-cT))
        endInd = np.argmin(abs(times-sky['changeTimes'][i+1]))
        rotatorStateEachFrame[startInd:endInd] = ROTATOR_CODE[sky['rotatorState'][i]]
    unrotatedOrientations = np.ma.masked_where(rotatorStateEachFrame != 0,orientations)
    rotatedOrientations = np.ma.masked_where(rotatorStateEachFrame != 1,orientations)
    if sum(np.isnan(orientations)) > 0:
        for trackingErrorTime in times[np.isnan(orientations)]:
            timePlotAxes.axvline(trackingErrorTime,linewidth=2,color='k')
    if fly.has_key('stopTimes'):
        for i, sT in enumerate(fly['stopTimes']):
            timePlotAxes.axvspan(sT, fly['startTimes'][i], facecolor='r', alpha=0.5)
    timePlotAxes.set_axis_off()
    for fn,frameNumber in enumerate(range(0,int(nFrames),FRAMESTEP)):
        frame,timestamps[fn] = fmf.get_frame(frameNumber)

        frameAxes.imshow(frame,cmap='gray',origin='lower')
        lineX = [circleCenterX+fly['ROI'][2], 2*(circleCenterX+fly['ROI'][2])-(fly['x'][frameNumber]+fly['ROI'][2])]
        lineY = [circleCenterY+fly['ROI'][1], 2*(circleCenterY+fly['ROI'][1])-(fly['y'][frameNumber]+fly['ROI'][1])]
        frameAxes.plot(lineX,lineY,'b', linewidth=2)
        frameAxes.set_axis_off()
        
        movingDot = timePlotAxes.scatter(times[frameNumber],orientations[frameNumber])
        timePlotAxes.set_ylim((-10,370))
        
        orw,n,b,bc,ax = flypod.rose(unrotatedOrientations[:frameNumber].compressed(),360,ax=polarTopAxes,plotArgs = dict(color=COLORS['U']))
        polarTopAxes.set_rmax(.25)
        polarTopAxes.set_rgrids([1],'')
        polarTopAxes.set_thetagrids([0,90,180,270],['','','',''])
        
        orw,n,b,bc,ax = flypod.rose(rotatedOrientations[:frameNumber].compressed(),360,ax=polarBottomAxes,plotArgs = dict(color=COLORS['R']))
        polarBottomAxes.set_rmax(.25)
        polarBottomAxes.set_rgrids([1],'')
        polarBottomAxes.set_thetagrids([0,90,180,270],['','','',''])
        
        fig.savefig(join(outDirName,'frame')+("%05d" %(fn+1))+'.png')
        polarTopAxes.cla()
        polarBottomAxes.cla()
        frameAxes.cla()
        movingDot.remove()
    print 'frame rate = ' + str(1/np.mean(np.diff(timestamps)))