def load_file(self,repnum): global options global basepath # if repnum<10: # upf = basepath + options.upfile + '/00' + str(repnum) + '/Camera/frames.ma' # else: # upf = basepath + options.upfile + '/0' + str(repnum) + '/Camera/frames.ma' upf = basepath + options.upfile + '/Camera/frames.ma' im=[] self.imageData = [] print "loading data from ", upf try: im = MetaArray(file = upf, subset=(slice(0,2), slice(64,128), slice(64,128))) except: print "Error loading upfile: %s\n" % upf return print "data loaded" self.times = im.axisValues('Time').astype('float32') self.imageData = im.view(np.ndarray).astype('float32') #pg.image(self.imageData, title=str(repnum)) #self.ProcessImage() print 'imageData shape:', np.shape(self.imageData) #self.imageData = self.imageData[np.where(self.times>1)] # back = self.imageData[np.where(np.logical_and(self.times>2, self.times<3))] # print 'size of back', np.shape(back) return
def load_file(self, repnum): global options global basepath if repnum < 10: upf = basepath + options.upfile + '/00' + str( repnum) + '/Camera/frames.ma' else: upf = basepath + options.upfile + '/0' + str( repnum) + '/Camera/frames.ma' # upf = basepath + options.upfile + '/Camera/frames.ma' im = [] self.imageData = [] print "loading data from ", upf try: im = MetaArray(file=upf, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) except: print "Error loading upfile: %s\n" % upf return print "data loaded" self.times = im.axisValues('Time').astype('float32') self.imageData = im.view(np.ndarray).astype('float32') pg.image(self.imageData, title=str(repnum)) #self.ProcessImage() print 'imageData shape:', np.shape(self.imageData) #self.imageData = self.imageData[np.where(self.times>1)] back = self.imageData[np.where( np.logical_and(self.times > 2, self.times < 3))] print 'size of back', np.shape(back) self.background = np.mean(back[5:], axis=0) #self.times= self.times-1 # interval1=self.imageData[np.where(np.logical_and(self.times>=1, self.times<=1.25))] # print 'interval1 shape:', np.shape(interval1) # interval2=self.imageData[np.where(np.logical_and(self.times>=2, self.times<=2.25))] # print 'interval2 shape:', np.shape(interval2) # interval3=self.imageData[np.where(np.logical_and(self.times>=3, self.times<=3.25))] # print 'interval3 shape:', np.shape(interval3) # interval4=self.imageData[np.where(np.logical_and(self.times>=4, self.times<=4.25))] # print 'interval4 shape:', np.shape(interval4) # interval5=self.imageData[np.where(np.logical_and(self.times>=5, self.times<=5.25))] # print 'interval5 shape:', np.shape(interval5) # back=self.imageData[np.where(np.logical_and(self.times>0, self.times<1))] # background=np.mean(back,axis=0) # meanimg=np.mean(self.imageData, axis=0) # pg.image(meanimg, title='mean image') #self.imageData = ((interval1+interval2+interval3+interval4+interval5)/5-background)/background print 'imageData shape:', np.shape(self.imageData) #pg.image(background, title='background') #self.imageData=scipy.ndimage.gaussian_filter(self.imageData, sigma=[1,3,3], order=0,mode='reflect',truncate=4.0) return
def load_file(self, loadstr, repnum): global options upf = basepath + loadstr + '/00' + str(repnum) + '/Camera/frames.ma' im = [] self.imageData = [] print "loading data from ", upf try: im = MetaArray(file=upf, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) except: print "Error loading upfile: %s\n" % videoupf return print "data loaded" self.times = im.axisValues('Time').astype('float32') self.imageData = im.view(np.ndarray).astype('float32') return
def parse_and_go(self, argsin=None): global period global binsize parser = OptionParser() # command line options ##### parses all of the options inputted at the command line TFR 11/13/2015 parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE', help="load the up-file") parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE', help="load the down-file") parser.add_option("-D", "--directory", dest="directory", metavar='FILE', help="Use directory for data") parser.add_option("-t", "--test", dest="test", action='store_true', help="Test mode to check calculations", default=False) parser.add_option("-p", '--period', dest="period", default=4.25, type="float", help="Stimulus cycle period") parser.add_option("-c", '--cycles', dest="cycles", default=0, type="int", help="# cycles to analyze") parser.add_option("-b", '--binning', dest="binsize", default=0, type="int", help="bin reduction x,y") parser.add_option("-g", '--gfilter', dest="gfilt", default=0, type="float", help="gaussian filter width") parser.add_option("-f", '--fdict', dest="fdict", default=0, type="int", help="Use dictionary entry") if argsin is not None: (options, args) = parser.parse_args(argsin) else: (options, args) = parser.parse_args() if options.period is not None: measuredPeriod = options.period if options.cycles is not None: self.nCycles = options.cycles if options.binsize is not None: binsize = options.binsize if options.gfilt is not None: gfilt = options.gfilt if options.fdict is not None: if options.fdict in DB.keys(): # populate options options.upfile = DB[options.fdict][0] options.downfile = DB[options.fdict][1] options.period = DB[options.fdict][4] else: print "File %d NOT in DBase\n" % options.fdict return if options.directory is not None: self.directory = options.directory if options.upfile is not None: self.upfile = options.upfile target = 1 if options.downfile is not None: self.downfile = options.downfile target = 2 target = 0 videoupf = None videodwnf = None audioupf = None audiodwnf = None if options.upfile is not None: videoupf = videobasepath + options.upfile + '.ma' audioupf = audiobasepath + options.upfile + '/DaqDevice.ma' if options.downfile is not None: videodwnf = videobasepath + options.downfile + '.ma' audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma' for file in (videoupf, videodwnf): #if options.upfile is not None and options.downfile is not None: if file is None: break im = [] self.imageData = [] print "loading data from ", file try: im = MetaArray(file=file, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) except: print "Error loading upfile: %s\n" % file return print "data loaded" self.times = im.axisValues('Time') self.nFrames = numpy.shape(im)[0] self.imageData = numpy.array(im).astype(numpy.float32, copy=False) print 'min diff', np.amin(np.diff(self.times)) print 'miax diff', np.amax(np.diff(self.times)) dt = numpy.mean(numpy.diff(self.times)) print 'dt:', dt target = target + 1 rawtimes = [] rawimageData = [] rawtimes = im.axisValues('Time').astype('float32') rawimageData = im.view(np.ndarray).astype('float32') print 'size of im', np.shape(rawimageData) indexFile = configfile.readConfigFile(basepath + '.index') timestampup = indexFile.__getitem__('video_' + DB[options.fdict][0] + '.ma')[u'__timestamp__'] timestampdown = indexFile.__getitem__('video_' + DB[options.fdict][1] + '.ma')[u'__timestamp__'] audioupindex = configfile.readConfigFile(audiobasepath + DB[options.fdict][0] + '/.index') audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__'] audiodownindex = configfile.readConfigFile(audiobasepath + DB[options.fdict][1] + '/.index') audiodownstamp = audiodownindex.__getitem__(u'.')[u'__timestamp__'] diffup = audioupstamp - timestampup diffdown = audiodownstamp - timestampdown if file is videoupf: audio = MetaArray(file=audioupf, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) audiotime = audio.axisValues('Time').astype('float32') audiomin = np.min(audiotime) + diffup audiomax = np.max(audiotime) + diffup elif file is videodwnf: audio = MetaArray(file=audiodwnf, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) audiotime = audio.axisValues('Time').astype('float32') audiomin = np.min(audiotime) + diffdown audiomax = np.max(audiotime) + diffdown else: print 'ERROR! Unable to load audio file' print 'audiomin', audiomin print 'audiomax', audiomax adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax + .5, rawtimes >= audiomin)] frame_start = np.amin(np.where(rawtimes >= audiomin)) frame_end = np.amax(np.where(rawtimes <= audiomax)) background = np.mean(rawimageData[10:25, :, :], axis=0) print 'size of background', np.shape(background) adjustedimagedata = rawimageData[frame_start:frame_end, :, :] # print 'adjtime', adjustedtime self.times = [x - np.min(adjustedtime) for x in adjustedtime] self.imageData = adjustedimagedata #print 'self.times:', self.times # print 'length of self.times', np.shape(self.times) # print 'shape of image data', np.shape(self.imageData) print 'size of im', np.shape(self.imageData) im = [] if file is videoupf: upflag = 1 else: upflag = 0 #print 'target:', target framerate = 1 / dt xsize = self.imageData.shape[1] ysize = self.imageData.shape[2] nframes = self.imageData.shape[0] freq = 4 frames = self.imageData.reshape(nframes, xsize * ysize) print 'seize of frames', np.shape(frames) const = np.arange(dt, nframes / framerate, nframes) fourvec = [] for ii in range(const.shape[0]): fourvec[ii] = numpy.exp(2 * np.pi * np.complex(0, 1) * const[ii] * freq) print 'size of fourvec', np.shape(fourvec) data = frames[:, :] * fourvec print 'size of data', np.shape(data) data = np.mean(data, axis=0) data = data.reshape(xsize, ysize) pg.image(data) # pg.image(background) # diffimage=np.zeros(np.shape(self.imageData)) # print 'single:', np.shape(self.imageData[4]) # for i in range(self.imageData.shape[0]): # diffimage[i]=self.imageData[i]/background # #self.imageData[i]/background # print 'size of diffimage', np.shape(diffimage) # refimage=self.imageData[frame_start]/self.imageData[10] # conddiff=np.mean(diffimage,axis=0)-refimage # graphme=conddiff/conddiff.mean()/conddiff.std() # pg.image(graphme,title='graphme') #self.subtract_Background(diffup=diffup) #self.Analysis_FourierMap_TFR(period=measuredPeriod, target = target, bins=binsize, up=upflag) print 'target:', target
def parse_and_go(self, argsin=None): global period parser = OptionParser() # command line options ##### parses all of the options inputted at the command line TFR 11/13/2015 parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE', help="load the up-file") parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE', help="load the down-file") parser.add_option("-D", "--directory", dest="directory", metavar='FILE', help="Use directory for data") parser.add_option("-t", "--test", dest="test", action='store_true', help="Test mode to check calculations", default=False) parser.add_option("-p", '--period', dest="period", default=8.0, type="float", help="Stimulus cycle period") parser.add_option("-c", '--cycles', dest="cycles", default=0, type="int", help="# cycles to analyze") parser.add_option("-b", '--binning', dest="binsize", default=0, type="int", help="bin reduction x,y") parser.add_option("-g", '--gfilter', dest="gfilt", default=0, type="float", help="gaussian filter width") parser.add_option("-f", '--fdict', dest="fdict", default=0, type="int", help="Use dictionary entry") if argsin is not None: (options, args) = parser.parse_args(argsin) else: (options, args) = parser.parse_args() if options.period is not None: measuredPeriod = options.period if options.cycles is not None: self.nCycles = options.cycles if options.binsize is not None: binsize = options.binsize if options.gfilt is not None: gfilt = options.gfilt #TFR- this code generates a test signal for running a test analysis sequence print options.test if options.test is True: print "Running Test Sample" period = 8.0 # period and frame sample rate can be different framerate = 8.0 nper = 1 d = 10.0 * numpy.random.normal(size=(2500, 128, 128)).astype('float32') ds = d.shape self.nFrames = d.shape[0] self.nPhases = 10 maxdel = 50 self.phasex = [] self.phasey = [] for i in range(0, self.nPhases): dx = i * ds[ 1] / self.nPhases # each phase is assigned to a region baseline = 0.0 self.resp = numpy.zeros((self.nFrames, )) phaseDelay = 0.25 * period + period * ( float(i) / self.nPhases ) # phase delay for this region from 0 to nearly the stimulus repeat period # print '********phase delay: ', phaseDelay for j in range(0, nper): # for each period tdelay = (float(j) * period) + phaseDelay # time to phase delay point idelay = int(numpy.floor( tdelay * framerate)) # convert to frame position in frame space # print ' tdel: ', tdelay, ' idel: ', idelay # if idelay < self.nFrames-maxdel: # self.resp[idelay:idelay+maxdel] = (i+1)*numpy.exp(-numpy.linspace(0, 2, maxdel)) # marks amplitudes as well self.resp = numpy.sin( numpy.linspace( 0, 2.0 * numpy.pi * self.nFrames / (period * framerate), self.nFrames) + i * numpy.pi / 8 - numpy.pi / 2.0) d[:, dx:dx + int(ds[1] / self.nPhases), 5:int(ds[2] / 2)] += self.resp[:, numpy.newaxis, numpy.newaxis] self.phasex.append((2 + (dx + int(ds[1] / self.nPhases)) / 2)) self.phasey.append( (6 + int(ds[2] / 2) / 2) ) # make the signal equivalent of digitized one (baseline 3000, signal at 1e-4 of baseline) d = (d * 3000.0 * 1e-4 ) + 3000.0 # scale and offset to match data scaling coming in self.imageData = d.astype( 'int16') # reduce to a 16-bit map to match camera data type self.times = numpy.arange(0, self.nFrames / framerate, 1.0 / framerate) print "Test Image Created" self.Analysis_FourierMap(period=period, target=1, mode=1, bins=binsize) print "Completed Analysis FourierMap" self.plotmaps_pg(mode=2, gfilter=gfilt) print "Completed plot maps" return if options.fdict is not None: if options.fdict in DB.keys(): # populate options options.upfile = DB[options.fdict][0] options.downfile = DB[options.fdict][1] options.period = DB[options.fdict][4] else: print "File %d NOT in DBase\n" % options.fdict return if options.directory is not None: self.directory = options.directory if options.upfile is not None: self.upfile = options.upfile target = 1 if options.downfile is not None: self.downfile = options.downfile target = 2 target = 0 upf = None dwnf = None if options.upfile is not None: upf = basepath + options.upfile + '/Camera/frames.ma' if options.downfile is not None: dwnf = basepath + options.downfile + '/Camera/frames.ma' for file in (upf, dwnf): #if options.upfile is not None and options.downfile is not None: if file is None: break im = [] self.imageData = [] print "loading data from ", file try: im = MetaArray(file=file, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) except: print "Error loading upfile: %s\n" % file return print "data loaded" target = target + 1 self.times = im.axisValues('Time').astype('float32') self.imageData = im.view(np.ndarray).astype('float32') im = [] if file is upf: upflag = 1 else: upflag = 0 measuredPeriod = 1.25 self.Analysis_FourierMap(period=measuredPeriod, target=target, bins=binsize, up=upflag) if target > 0: self.plotmaps_pg(mode=1, target=target, gfilter=gfilt) self.firstframe = pg.image(self.imageData[0], title='first frame of image')
def parse_and_go(self, argsin=None): global period global binsize parser = OptionParser() # command line options ##### parses all of the options inputted at the command line TFR 11/13/2015 parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE', help="load the up-file") parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE', help="load the down-file") parser.add_option("-D", "--directory", dest="directory", metavar='FILE', help="Use directory for data") parser.add_option("-t", "--test", dest="test", action='store_true', help="Test mode to check calculations", default=False) parser.add_option("-p", '--period', dest="period", default=4.25, type="float", help="Stimulus cycle period") parser.add_option("-c", '--cycles', dest="cycles", default=0, type="int", help="# cycles to analyze") parser.add_option("-b", '--binning', dest="binsize", default=0, type="int", help="bin reduction x,y") parser.add_option("-g", '--gfilter', dest="gfilt", default=0, type="float", help="gaussian filter width") parser.add_option("-f", '--fdict', dest="fdict", default=0, type="int", help="Use dictionary entry") if argsin is not None: (options, args) = parser.parse_args(argsin) else: (options, args) = parser.parse_args() if options.test is True: print "Running Test Sample" period = 8.0 # period and frame sample rate can be different framerate = 8.0 nper = 1 d = 10.0 * numpy.random.normal(size=(2500, 128, 128)).astype('float32') ds = d.shape self.nFrames = d.shape[0] self.nPhases = 10 maxdel = 50 self.phasex = [] self.phasey = [] for i in range(0, self.nPhases): dx = i * ds[ 1] / self.nPhases # each phase is assigned to a region baseline = 0.0 self.resp = numpy.zeros((self.nFrames, )) phaseDelay = 0.25 * period + period * ( float(i) / self.nPhases ) # phase delay for this region from 0 to nearly the stimulus repeat period # print '********phase delay: ', phaseDelay for j in range(0, nper): # for each period tdelay = (float(j) * period) + phaseDelay # time to phase delay point idelay = int(numpy.floor( tdelay * framerate)) # convert to frame position in frame space # print ' tdel: ', tdelay, ' idel: ', idelay # if idelay < self.nFrames-maxdel: # self.resp[idelay:idelay+maxdel] = (i+1)*numpy.exp(-numpy.linspace(0, 2, maxdel)) # marks amplitudes as well self.resp = 1000.0 * numpy.sin( numpy.linspace( 0, 2.0 * numpy.pi * self.nFrames / (period * framerate), self.nFrames) + i * numpy.pi / 8.0 - numpy.pi / 2.0) d[:, dx:dx + int(ds[1] / self.nPhases), 5:int(ds[2] / 2)] += self.resp[:, numpy.newaxis, numpy.newaxis] self.phasex.append((2 + (dx + int(ds[1] / self.nPhases)) / 2)) self.phasey.append( (6 + int(ds[2] / 2) / 2) ) # make the signal equivalent of digitized one (baseline 3000, signal at 1e-4 of baseline) d = (d * 3000.0 * 1e-4 ) + 3000.0 # scale and offset to match data scaling coming in self.imageData = d.astype( 'int16') # reduce to a 16-bit map to match camera data type self.times = numpy.arange(0, self.nFrames / framerate, 1.0 / framerate) print "Test Image Created" getout2 = fac_lift(self.imageData, self.times) self.imageData = getout2 self.Analysis_FourierMap_TFR(period=period, target=1, mode=1, bins=binsize) print "Completed Analysis FourierMap" self.plotmaps_pg(mode=2, gfilter=0) print "Completed plot maps" if options.period is not None: measuredPeriod = options.period if options.cycles is not None: self.nCycles = options.cycles if options.binsize is not None: binsize = options.binsize if options.gfilt is not None: gfilt = options.gfilt print 'DB keys', DB.keys() if options.fdict is not None: if options.fdict in DB.keys(): # populate options options.upfile = DB[options.fdict][0] options.downfile = DB[options.fdict][1] options.period = DB[options.fdict][4] else: print "File %d NOT in DBase\n" % options.fdict return if options.directory is not None: self.directory = options.directory if options.upfile is not None: self.upfile = options.upfile target = 1 if options.downfile is not None: self.downfile = options.downfile target = 2 target = 0 videoupf = None videodwnf = None audioupf = None audiodwnf = None if options.upfile is not None: videoupf = videobasepath + options.upfile + '.ma' audioupf = audiobasepath + options.upfile + '/DaqDevice.ma' if options.downfile is not None: videodwnf = videobasepath + options.downfile + '.ma' audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma' # indexFile = configfile.readConfigFile(basepath+'.index') # time = indexFile.__getitem__('video_019.ma')[u'__timestamp__'] #indexFile = configfile.readConfigFile(basepath+'.index') #print 'indexfile', indexfile for file in (videoupf, videodwnf): #if options.upfile is not None and options.downfile is not None: if file is None: break im = [] self.imageData = [] print "loading data from ", file try: im = MetaArray(file=file, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) except: print "Error loading upfile: %s\n" % file return print "data loaded" target = target + 1 # dir = acq4.util.DataManager.getHandle(basepath) # time = dir.info()['__timestamp__'] # print 'time:', time #print 'im:', im # dir(im) rawtimes = [] rawimageData = [] rawtimes = im.axisValues('Time').astype('float32') # print 'time', rawtimes rawimageData = im.view(np.ndarray).astype('float32') # print 'shape of ra image data:', rawimageData.shape ## videobasepath = /......./2016.10.08_000/Intrinsic_Mapping/video_' ## indexFile = configFile.readConfigFile('/...../2016.10.08_000/Intrinsic_Mapping/.index') -> a dictionary # dir = acq4.util.DataManager.getHandle(videoupf) # time = dir.info()['__timestamp__'] # #timestampup = timestamp[options.fdict][0] # audioupstamp = timestamp[options.fdict][1] # #timestampdown = timestamp[options.fdict][2] # audiodownstamp = timestamp[options.fdict][3] # #print 'optioins.dict', options.fdict[0] #reads the timestamps from the files indexFile = configfile.readConfigFile(basepath + '.index') timestampup = indexFile.__getitem__('video_' + DB[options.fdict][0] + '.ma')[u'__timestamp__'] timestampdown = indexFile.__getitem__('video_' + DB[options.fdict][1] + '.ma')[u'__timestamp__'] audioupindex = configfile.readConfigFile(audiobasepath + DB[options.fdict][0] + '/.index') # audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__'] audioupstamp = audioupindex.__getitem__( 'DaqDevice.ma')[u'__timestamp__'] - 13.5 audiodownindex = configfile.readConfigFile(audiobasepath + DB[options.fdict][1] + '/.index') #audiodownstamp = audiodownindex.__getitem__(u'.')[u'__timestamp__'] audiodownstamp = audiodownindex.__getitem__( 'DaqDevice.ma')[u'__timestamp__'] - 13.5 diffup = audioupstamp - timestampup diffdown = audiodownstamp - timestampdown if file is videoupf: audio = MetaArray(file=audioupf, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) audiotime = audio.axisValues('Time').astype('float32') audiomin = np.min(audiotime) + diffup audiomax = np.max(audiotime) + diffup elif file is videodwnf: audio = MetaArray(file=audiodwnf, subset=(slice(0, 2), slice(64, 128), slice(64, 128))) audiotime = audio.axisValues('Time').astype('float32') audiomin = np.min(audiotime) + diffdown audiomax = np.max(audiotime) + diffdown else: print 'ERROR! Unable to load audio file' print 'audiomin', audiomin print 'audiomax', audiomax adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax + 4, rawtimes >= audiomin)] adjustedimagedata = rawimageData[np.logical_and( rawtimes <= audiomax + 4, rawtimes >= audiomin)] # print 'adjtime', adjustedtime self.times = [x - np.min(adjustedtime) for x in adjustedtime] self.imageData = adjustedimagedata background = rawimageData[5:25] background = np.mean(background, axis=0) print 'dimensions of background', np.shape(background) pg.image(background, title='mean background') subtracted = np.zeros(np.shape(self.imageData), float) for i in range(self.imageData.shape[0]): subtracted[i, :, :] = (self.imageData[i, :, :] - background) subtracted = subtracted / subtracted.mean() self.imageData = subtracted #print 'self.times:', self.times # print 'length of self.times', np.shape(self.times) # print 'shape of image data', np.shape(self.imageData) #analyze a quarter of the image #xcut = (self.imageData.shape[1]+1)/8 #ycut = (self.imageData.shape[2]+1)/8 #self.imageData=self.imageData[:,3*xcut-1:7*xcut-1,ycut-1:7*ycut-1] im = [] if file is videoupf: upflag = 1 else: upflag = 0 #print 'target:', target measuredPeriod = 4.25 #self.subtract_Background(diffup=diffup) self.Analysis_FourierMap(period=measuredPeriod, target=target, bins=binsize, up=upflag) print 'target:', target if target > 0: self.plotmaps_pg(mode=1, target=target, gfilter=gfilt) return
def parse_and_go(self, argsin = None): global period global binsize parser=OptionParser() # command line options ##### parses all of the options inputted at the command line TFR 11/13/2015 parser.add_option("-u", "--upfile", dest="upfile", metavar='FILE', help="load the up-file") parser.add_option("-d", "--downfile", dest="downfile", metavar='FILE', help="load the down-file") parser.add_option("-D", "--directory", dest="directory", metavar='FILE', help="Use directory for data") parser.add_option("-t", "--test", dest="test", action='store_true', help="Test mode to check calculations", default=False) parser.add_option("-p", '--period', dest = "period", default=4.25, type="float", help = "Stimulus cycle period") parser.add_option("-c", '--cycles', dest = "cycles", default=0, type="int", help = "# cycles to analyze") parser.add_option("-b", '--binning', dest = "binsize", default=0, type="int", help = "bin reduction x,y") parser.add_option("-g", '--gfilter', dest = "gfilt", default=0, type="float", help = "gaussian filter width") parser.add_option("-f", '--fdict', dest = "fdict", default=0, type="int", help = "Use dictionary entry") if argsin is not None: (options, args) = parser.parse_args(argsin) else: (options, args) = parser.parse_args() if options.test is True: print "Running Test Sample" period = 8.0 # period and frame sample rate can be different framerate = 8.0 nper = 1 d = 10.0*numpy.random.normal(size=(2500,128,128)).astype('float32') ds = d.shape self.nFrames = d.shape[0] self.nPhases = 10 maxdel = 50 self.phasex = [] self.phasey = [] for i in range(0,self.nPhases): dx = i*ds[1]/self.nPhases # each phase is assigned to a region baseline = 0.0 self.resp = numpy.zeros((self.nFrames,)) phaseDelay = 0.25*period+period*(float(i)/self.nPhases) # phase delay for this region from 0 to nearly the stimulus repeat period # print '********phase delay: ', phaseDelay for j in range(0, nper): # for each period tdelay = (float(j) * period) + phaseDelay # time to phase delay point idelay = int(numpy.floor(tdelay*framerate)) # convert to frame position in frame space # print ' tdel: ', tdelay, ' idel: ', idelay # if idelay < self.nFrames-maxdel: # self.resp[idelay:idelay+maxdel] = (i+1)*numpy.exp(-numpy.linspace(0, 2, maxdel)) # marks amplitudes as well self.resp = 1000.0*numpy.sin( numpy.linspace(0, 2.0*numpy.pi*self.nFrames/(period*framerate), self.nFrames)+i*numpy.pi/8.0 - numpy.pi/2.0) d[:, dx:dx+int(ds[1]/self.nPhases), 5:int(ds[2]/2)] += self.resp[:, numpy.newaxis, numpy.newaxis] self.phasex.append( (2+(dx+int(ds[1]/self.nPhases))/2)) self.phasey.append((6+int(ds[2]/2)/2)) # make the signal equivalent of digitized one (baseline 3000, signal at 1e-4 of baseline) d = (d*3000.0*1e-4)+3000.0 # scale and offset to match data scaling coming in self.imageData = d.astype('int16') # reduce to a 16-bit map to match camera data type self.times = numpy.arange(0, self.nFrames/framerate, 1.0/framerate) print "Test Image Created" getout2 = fac_lift(self.imageData, self.times) self.imageData=getout2 self.Analysis_FourierMap_TFR(period=period, target = 1, mode=1, bins=binsize) print "Completed Analysis FourierMap" self.plotmaps_pg(mode = 2, gfilter = 0) print "Completed plot maps" if options.period is not None: measuredPeriod = options.period if options.cycles is not None: self.nCycles = options.cycles if options.binsize is not None: binsize = options.binsize if options.gfilt is not None: gfilt = options.gfilt if options.upfile is not None: self.upfile = options.upfile target = 1 if options.downfile is not None: self.downfile = options.downfile target = 2 target = 0 videoupf = None videodwnf = None audioupf = None audiodwnf = None print 'DB keys', DB.keys() if options.fdict is not None: if options.fdict in DB.keys(): # populate options options.upfile = DB[options.fdict][0] options.downfile = DB[options.fdict][1] options.period = DB[options.fdict][4] else: print "File %d NOT in DBase\n" % options.fdict return if options.directory is not None: self.directory = options.directory if options.upfile is not None: videoupf = videobasepath + options.upfile + '.ma' audioupf = audiobasepath + options.upfile + '/DaqDevice.ma' if options.downfile is not None: videodwnf = videobasepath + options.downfile + '.ma' audiodwnf = audiobasepath + options.downfile + '/DaqDevice.ma' im=[] self.imageData = [] print "loading data from ", videoupf try: im = MetaArray(file = videoupf, subset=(slice(0,2), slice(64,128), slice(64,128))) except: print "Error loading upfile: %s\n" % videoupf return print "data loaded" rawtimes=[] rawimageData=[] rawtimes = im.axisValues('Time').astype('float32') rawimageData = im.view(np.ndarray).astype('float32') # #reads the timestamps from the files indexFile = configfile.readConfigFile(basepath+'.index') timestampup = indexFile.__getitem__('video_'+DB[options.fdict][0]+'.ma')[u'__timestamp__'] audioupindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][0]+'/.index') audioupstamp = audioupindex.__getitem__(u'.')[u'__timestamp__'] diffup = audioupstamp - timestampup audio = MetaArray(file = audioupf, subset=(slice(0,2), slice(64,128), slice(64,128))) audiotime = audio.axisValues('Time').astype('float32') audiomin = np.min(audiotime) + diffup audiomax = np.max(audiotime) + diffup print 'audiomin', audiomin print 'audiomax', audiomax adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)] frame_start=np.amin(np.where(rawtimes >= audiomin)) frame_end=np.amax(np.where(rawtimes <= audiomax+0.5)) adjustedimagedata = rawimageData[frame_start:frame_end] #adjustedimagedata = rawimageData[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)] self.times = [x-np.min(adjustedtime) for x in adjustedtime] #self.imageData = adjustedimagedata # self.imageData=np.mean(self.imageData, axis=0) #self.imageData=np.mean(self.imageData) outofbounds = 2*adjustedimagedata.std() for i in range(adjustedimagedata.shape[0]): for j in range(adjustedimagedata.shape[1]): for k in range(adjustedimagedata.shape[2]): if adjustedimagedata[i,j,k]< outofbounds: adjustedimagedata[i,j,k]=1 pg.image(np.mean(adjustedimagedata,axis=0),title='remove extremes') self.imageData = adjustedimagedata print 'newmean', adjustedimagedata.mean() #############loaded file #1################### # for background file im2=[] self.imageData2 = [] adjustedimagedata = [] print "loading data from ", videodwnf try: im2 = MetaArray(file = videodwnf, subset=(slice(0,2), slice(64,128), slice(64,128))) except: print "Error loading upfile: %s\n" % videodwnf return print "data loaded" rawtimes=[] rawimageData=[] rawtimes = im2.axisValues('Time').astype('float32') rawimageData = im2.view(np.ndarray).astype('float32') # #reads the timestamps from the files indexFile = configfile.readConfigFile(basepath+'.index') timestampdwn = indexFile.__getitem__('video_'+DB[options.fdict][1]+'.ma')[u'__timestamp__'] audiodwnindex = configfile.readConfigFile(audiobasepath+DB[options.fdict][1]+'/.index') audiodwnstamp = audiodwnindex.__getitem__(u'.')[u'__timestamp__'] diffdwn = audiodwnstamp - timestampdwn audio = MetaArray(file = audiodwnf, subset=(slice(0,2), slice(64,128), slice(64,128))) audiotime = audio.axisValues('Time').astype('float32') audiomin = np.min(audiotime) + diffdwn audiomax = np.max(audiotime) + diffdwn print 'audiomin', audiomin print 'audiomax', audiomax adjustedtime = rawtimes[np.logical_and(rawtimes <= audiomax+.5, rawtimes >= audiomin)] frame_start=np.amin(np.where(rawtimes >= audiomin)) frame_end=np.amax(np.where(rawtimes <= audiomax+0.5)) adjustedimagedata = rawimageData[frame_start:frame_end] self.times = [x-np.min(adjustedtime) for x in adjustedtime] outofbounds = 2*adjustedimagedata.std() for i in range(adjustedimagedata.shape[0]): for j in range(adjustedimagedata.shape[1]): for k in range(adjustedimagedata.shape[2]): if adjustedimagedata[i,j,k]< outofbounds: adjustedimagedata[i,j,k]=1 pg.image(np.mean(adjustedimagedata,axis=0),title='remove extremes') self.imageData2 = adjustedimagedata print 'newmean', adjustedimagedata.mean() # self.imageData2 = adjustedimagedata # self.imageData2=np.mean(self.imageData2, axis=0) print 'size of imagedata', self.imageData2.shape ##############loaded file #2############## diffframes = np.mean(self.imageData)/np.mean(self.imageData2) print 'mean:', diffframes.mean() print 'std:', diffframes.std() procimage=diffframes/diffframes.mean()/diffframes.std() self.avgframes = pg.image(diffframes, title='Average across frames') self.diff_frames = pg.image(procimage, title='Normalized Average across frames') #self.avgframes = pg.image(procimage, title='Average across frames') return