prelast_masked[prelast_mm] = numpy.mean(prelast_avg[:50,:50]) last_masked = last_avg.copy() last_masked[last_mm] = numpy.mean(last_avg[:50,:50]) this_masked = this_avg.copy() this_masked[this_mm] = numpy.mean(this_avg[:50,:50]) if opts.antfarm_config: #antfarm-specific analysis steps digdiffs.append(prelast_masked-this_masked) if len(digdiffs) > 3: nll = digdiffs.pop(0) if newactols and newactols[-1]: prevactmask += reduce(lambda x,y:x+y, [vidtools.shrink_mask(vidtools.mask_from_outline(ol,this_masked.shape),1) for ol in newactols[-1]]) if len(digdiffs) > 1: m = digdiffs[-2] > 0.2 #ARBITRARY m[last_mm] = True #add mousemask to burrow area m[vidtools.grow_mask(vidtools.shrink_mask(prevactmask,1),1)] = False #MASK PREVIOUS DIGGING m[groundmask] = False #AND EVERYTHING ABOVE FIRST GROUND if opts.outline_engine == 'homebrew': newactols.append(vidtools.chain_outlines_from_mask(m,preshrink=1,grow_by=1,debug=False,return_termini=False,order_points=True,sort_outlines=False)) prevol = vidtools.chain_outlines_from_mask(prevactmask,preshrink=1,grow_by=1,debug=False,return_termini=False,order_points=True,sort_outlines=False) elif opts.outline_engine == 'shapely': newactols.append(vidtools.chain_outlines_from_mask_shapely(m,preshrink=1,grow_by=1)) prevol = vidtools.chain_outlines_from_mask_shapely(prevactmask,preshrink=1,grow_by=1) else: print >> sys.stderr, 'outline_engine must be one of %s' % (['homebrew','shapely']) raise ValueError digol = newactols[-1] else: digol = [] prevol = []
depress_ground = 0 framefiles = sorted(glob(segment_summ_dir+'/*.frame'))[start:stop] print >> sys.stderr, 'frames: %s' % [(f,os.path.getsize(f)) for f in framefiles] frames = [numpy.fromfile(f).reshape(shape) for f in framefiles] print >> sys.stderr, 'loaded %s frames' % len(frames) for i,f in enumerate(frames[1:-1]): # this throws off numbering--must be i+1 for current index! #construct output filenames, check for pre-existing files. Skip if present. filebase = micefiles[i+1].rsplit('.',1)[0] actmatf = filebase+'.actmat' mouselocsf = filebase+'.mouselocs' locsummf = filebase+'.locsumm' # if all([os.path.exists(f) for f in (actmatf,mouselocsf,locsummf)]): # continue mouselocs = {} g = grounds[i+1] + depress_ground actmat = Util.zscore(frames[i] - frames[i+2]) actmask = actmat > actzcut #output actmask! (use frame output model from summarize) print >>sys.stderr,actmatf,len(actmat),len(actmat[0]) actmat.tofile(actmatf) actmask = vidtools.grow_mask(actmask,pad_mask) for mk, mv in mice[i+1].items(): mouselocs[mk] = vidtools.classify_mouse(mv,g,actmask) open(mouselocsf,'w').write(mouselocs.__repr__()) summ = Util.countdict(mouselocs.values()) open(locsummf,'w').write(summ.__repr__())
this_masked[this_mm] = numpy.mean(this_avg[:50, :50]) if opts.antfarm_config: #antfarm-specific analysis steps digdiffs.append(prelast_masked - this_masked) if len(digdiffs) > 3: nll = digdiffs.pop(0) if newactols and newactols[-1]: prevactmask += reduce(lambda x, y: x + y, [ vidtools.shrink_mask( vidtools.mask_from_outline(ol, this_masked.shape), 1) for ol in newactols[-1] ]) if len(digdiffs) > 1: m = digdiffs[-2] > 0.2 #ARBITRARY m[last_mm] = True #add mousemask to burrow area m[vidtools.grow_mask(vidtools.shrink_mask(prevactmask, 1), 1)] = False #MASK PREVIOUS DIGGING m[groundmask] = False #AND EVERYTHING ABOVE FIRST GROUND if opts.outline_engine == 'homebrew': newactols.append( vidtools.chain_outlines_from_mask(m, preshrink=1, grow_by=1, debug=False, return_termini=False, order_points=True, sort_outlines=False)) prevol = vidtools.chain_outlines_from_mask( prevactmask, preshrink=1, grow_by=1, debug=False,
framefiles = sorted(glob(segment_summ_dir + '/*.frame'))[start:stop] print >> sys.stderr, 'frames: %s' % [(f, os.path.getsize(f)) for f in framefiles] frames = [numpy.fromfile(f).reshape(shape) for f in framefiles] print >> sys.stderr, 'loaded %s frames' % len(frames) for i, f in enumerate( frames[1:-1] ): # this throws off numbering--must be i+1 for current index! #construct output filenames, check for pre-existing files. Skip if present. filebase = micefiles[i + 1].rsplit('.', 1)[0] actmatf = filebase + '.actmat' mouselocsf = filebase + '.mouselocs' locsummf = filebase + '.locsumm' # if all([os.path.exists(f) for f in (actmatf,mouselocsf,locsummf)]): # continue mouselocs = {} g = grounds[i + 1] + depress_ground actmat = Util.zscore(frames[i] - frames[i + 2]) actmask = actmat > actzcut #output actmask! (use frame output model from summarize) print >> sys.stderr, actmatf, len(actmat), len(actmat[0]) actmat.tofile(actmatf) actmask = vidtools.grow_mask(actmask, pad_mask) for mk, mv in mice[i + 1].items(): mouselocs[mk] = vidtools.classify_mouse(mv, g, actmask) open(mouselocsf, 'w').write(mouselocs.__repr__()) summ = Util.countdict(mouselocs.values()) open(locsummf, 'w').write(summ.__repr__())