def __savetiledclips__(act,cr,info,path,nclips=3):
    if not os.path.exists(path):
        os.makedirs(path)
        
    clips = __getclips__(act,cr,info,rowidx=slice(nclips))
    for subject,crossings in clips.groupby(level=['subject']):
#        fpath = os.path.join(path,subject)
#        if not os.path.exists(fpath):
#            os.makedirs(fpath)
        vidclips = __processclips__(crossings.iterrows(),ycrop=slice(320,-1))
        frames = __tileclips__(it.izip(*vidclips),1,nclips)
        fname = str.format("{0}_manipulations.avi",subject)
        vidpath = os.path.join(path,fname)
        activitymovies.savemovie(frames,vidpath,frames_per_second)
Exemple #2
0
def __savetiledclips__(act, cr, info, path, nclips=3):
    if not os.path.exists(path):
        os.makedirs(path)

    clips = __getclips__(act, cr, info, rowidx=slice(nclips))
    for subject, crossings in clips.groupby(level=['subject']):
        #        fpath = os.path.join(path,subject)
        #        if not os.path.exists(fpath):
        #            os.makedirs(fpath)
        vidclips = __processclips__(crossings.iterrows(), ycrop=slice(320, -1))
        frames = __tileclips__(it.izip(*vidclips), 1, nclips)
        fname = str.format("{0}_manipulations.avi", subject)
        vidpath = os.path.join(path, fname)
        activitymovies.savemovie(frames, vidpath, frames_per_second)
def __saveselectedtiledclips__(clips,info,path,suffix='.avi'):
    if not os.path.exists(path):
        os.makedirs(path)    
    
    moviepath = activitymovies.getmoviepath(info)
    for ((subject,session),group),indices in it.izip(info.groupby(level=['subject',
                                                                        'session']),
                                                     clips):
        crossings = pd.DataFrame(indices)
        crossings['path'] = moviepath.loc[(subject,session)]
        vidclips = __processclips__(crossings.iterrows(),ycrop=slice(320,-1))
        frames = __tileclips__(it.izip(*vidclips),1,len(crossings))
        fname = str.format("{0}"+suffix,subject)
        vidpath = os.path.join(path,fname)
        activitymovies.savemovie(frames,vidpath,frames_per_second)
Exemple #4
0
def __saveselectedtiledclips__(clips, info, path, suffix='.avi'):
    if not os.path.exists(path):
        os.makedirs(path)

    moviepath = activitymovies.getmoviepath(info)
    for ((subject, session),
         group), indices in it.izip(info.groupby(level=['subject', 'session']),
                                    clips):
        crossings = pd.DataFrame(indices)
        crossings['path'] = moviepath.loc[(subject, session)]
        vidclips = __processclips__(crossings.iterrows(), ycrop=slice(320, -1))
        frames = __tileclips__(it.izip(*vidclips), 1, len(crossings))
        fname = str.format("{0}" + suffix, subject)
        vidpath = os.path.join(path, fname)
        activitymovies.savemovie(frames, vidpath, frames_per_second)
def figure2a3(act,info,path):
    if not os.path.exists(path):
        os.makedirs(path)    
    
    mframes = __getmanipulationframes__(act,info)
    mframes = mframes.join(info)
    mframes = mframes[mframes.frame != 0]
    mframes = mframes.query('subject not in ["JPAK_26","JPAK_27","JPAK_28","JPAK_29"]')
    mframes = mframes.join(activitymovies.getmoviepath(mframes))
    mframes = activitytables.groupbylesionvolumes(mframes[['path','frame','side']],mframes)
    mframes.reset_index()
    
    vidclips = __processclips__(mframes.iterrows(),ycrop=slice(320,-1))
    vidclips = [__transposeclips__(clip) for clip in vidclips]
    frames = __tileclips__(it.izip(*vidclips),len(mframes)/2,2)
    frames = __transposeclips__(frames)
    frames = __resizeclips__(frames,dsize=(1280,896))
    fname = str.format("manipulations_big_lesion.avi")
    vidpath = os.path.join(path,fname)
    activitymovies.savemovie(frames,vidpath,frames_per_second)
Exemple #6
0
def figure2a3(act, info, path):
    if not os.path.exists(path):
        os.makedirs(path)

    mframes = __getmanipulationframes__(act, info)
    mframes = mframes.join(info)
    mframes = mframes[mframes.frame != 0]
    mframes = mframes.query(
        'subject not in ["JPAK_26","JPAK_27","JPAK_28","JPAK_29"]')
    mframes = mframes.join(activitymovies.getmoviepath(mframes))
    mframes = activitytables.groupbylesionvolumes(
        mframes[['path', 'frame', 'side']], mframes)
    mframes.reset_index()

    vidclips = __processclips__(mframes.iterrows(), ycrop=slice(320, -1))
    vidclips = [__transposeclips__(clip) for clip in vidclips]
    frames = __tileclips__(it.izip(*vidclips), len(mframes) / 2, 2)
    frames = __transposeclips__(frames)
    frames = __resizeclips__(frames, dsize=(1280, 896))
    fname = str.format("manipulations_big_lesion.avi")
    vidpath = os.path.join(path, fname)
    activitymovies.savemovie(frames, vidpath, frames_per_second)
info = pd.read_hdf(lesionshamcache, info_key)
info = info.query("protocol == 'stabletocenterfree'")
crossings = pd.read_hdf(lesionshamcache, visiblecrossings_key)
mtrials, fliptrials = manipulationtrials(crossings)

folders = sessionpath(info)
act = pd.concat([
    read_sessions(path, selector=lambda x: x.loc[time, :])
    for path, time in zip(folders, mtrials.timeslice)
])

# Save movies
dirname = os.path.join(lesionshamanalysis, 'Movies')
if not os.path.exists(dirname):
    os.mkdir(dirname)

for (subject, session), sact in act.groupby(level=['subject', 'session']):
    sinfo = info.ix[[(subject, session)], :]
    frames = getmovieframes(sinfo, sact.frame)
    fname = str.format('manipulation_{0}.avi', shuffle.index(subject))
    tname = os.path.splitext(fname)[0] + '.csv'
    print str.format("Processing {0}...", fname)
    fname = os.path.join(dirname, fname)
    tname = os.path.join(dirname, tname)
    if os.path.exists(fname):
        continue
    savemovie(frames, fname, 120, flip=fliptrials.get(subject, None))
    sact.reset_index().time.to_csv(tname,
                                   index=False,
                                   date_format='%Y-%m-%dT%H:%M:%S.%f+00:00')