try:
                        thesemice[os.path.basename(k)] = mice[os.path.join(mkbase,os.path.basename(k))]
                    except KeyError:
                        print >>sys.stderr, 'key %s not found; skip' % os.path.join(mkbase,os.path.basename(k))
                
        #print >> sys.stderr, 'write %s mice to %s' % (len(thesemice),new_base+'.mice')
        open(new_base+'.mice','w').write(thesemice.__repr__())

    #if we need to link ground:
    if not os.path.exists(new_base+'.ground'):
        #print >> sys.stderr, 'link %s from %s' % (new_base+'.ground',source_base+'.ground')
        os.system('ln -s %s %s' % (os.path.join(os.getcwd(),source_base+'.ground'), os.path.join(os.getcwd(),new_base+'.ground') ) )

    #if we need to compute frame avg:
    if not os.path.exists(new_base+'.frame'):
        frameav = vidtools.average_frames(vidtools.load_normed_arrays(new_ims[i:i+segment_step],pixav))
        frameav.tofile(new_base+'.frame')

frameavs = sorted(glob(new_outroot+'/*.frame'))
print >> sys.stderr, 'compute activity matrices from frame averages (%s frame averages found)' % len(frameavs)
for i,f in enumerate(frameavs):
    actmatf = os.path.splitext(f)[0]+'.actmat'
    if not os.path.exists(actmatf) and i>0 and i<len(frameavs)-1:
        actmat = Util.zscore(numpy.fromfile(frameavs[i-1]).reshape(shape) - numpy.fromfile(frameavs[i+1]).reshape(shape))
        actmat.tofile(actmatf)
    




# switches cumulative activity calc to activity below an artificial "lowest ground" - should fix squirrely groundfinding
if not images:
    raise ValueError, 'no images found in '+imagedir


if mask == 'None':
    try:
        mask = Util.file_in_path('mask',imagedir)
        print >> sys.stderr, 'mask in path (%s) exists; using' % mask
    except ValueError:
        print >> sys.stderr, 'no mask in path'
else:
    print >> sys.stderr, 'mask found? %s\n' % os.path.exists(mask) 
        

SHAPE=vidtools.load_normed_arrays(images[:1])[0].shape

#print >> sys.stderr, opts

print >> sys.stderr,'xybounds: %s\nburrow entrance at: %s\nground anchors at: %s\nhill_bounds: %s' \
      % (opts['xybounds'],opts['burrow_entrance_xy'],opts['ground_anchors'],opts['hill_bounds'])

match = re.search('([\d\.]+)fps',imagedir)
if match:
    fps = float(match.groups()[0])
    segment_step = int(seglen)* fps
    print >> sys.stderr, 'segment length will be %s frames (%s seconds, %s fps)\n' % (segment_step,seglen,fps)
    unit = 'sec'
else:
    fps = 1.0
    segment_step = int(seglen)
示例#3
0
                            mkbase, os.path.basename(k))

        #print >> sys.stderr, 'write %s mice to %s' % (len(thesemice),new_base+'.mice')
        open(new_base + '.mice', 'w').write(thesemice.__repr__())

    #if we need to link ground:
    if not os.path.exists(new_base + '.ground'):
        #print >> sys.stderr, 'link %s from %s' % (new_base+'.ground',source_base+'.ground')
        os.system('ln -s %s %s' %
                  (os.path.join(os.getcwd(), source_base + '.ground'),
                   os.path.join(os.getcwd(), new_base + '.ground')))

    #if we need to compute frame avg:
    if not os.path.exists(new_base + '.frame'):
        frameav = vidtools.average_frames(
            vidtools.load_normed_arrays(new_ims[i:i + segment_step], pixav))
        frameav.tofile(new_base + '.frame')

frameavs = sorted(glob(new_outroot + '/*.frame'))
print >> sys.stderr, 'compute activity matrices from frame averages (%s frame averages found)' % len(
    frameavs)
for i, f in enumerate(frameavs):
    actmatf = os.path.splitext(f)[0] + '.actmat'
    if not os.path.exists(actmatf) and i > 0 and i < len(frameavs) - 1:
        actmat = Util.zscore(
            numpy.fromfile(frameavs[i - 1]).reshape(shape) -
            numpy.fromfile(frameavs[i + 1]).reshape(shape))
        actmat.tofile(actmatf)

# switches cumulative activity calc to activity below an artificial "lowest ground" - should fix squirrely groundfinding
if not images:
    raise ValueError, "no images found in " + imagedir


if mask == "None":
    try:
        mask = Util.file_in_path("mask", imagedir)
        print >>sys.stderr, "mask in path (%s) exists; using" % mask
    except ValueError:
        print >>sys.stderr, "no mask in path"
else:
    print >>sys.stderr, "mask found? %s\n" % os.path.exists(mask)


SHAPE = vidtools.load_normed_arrays(images[:1])[0].shape

# print >> sys.stderr, opts

print >>sys.stderr, "xybounds: %s\nburrow entrance at: %s\nground anchors at: %s\nhill_bounds: %s" % (
    opts["xybounds"],
    opts["burrow_entrance_xy"],
    opts["ground_anchors"],
    opts["hill_bounds"],
)

match = re.search("([\d\.]+)fps", imagedir)
if match:
    fps = float(match.groups()[0])
    segment_step = int(seglen) * fps
    print >>sys.stderr, "segment length will be %s frames (%s seconds, %s fps)\n" % (segment_step, seglen, fps)