def loadsweeptimesnogap(path): '''loads sweep timing corrected for computer - monitor delay''' datapath = path + ".dat" metapath = path + ".meta" channels,_ = loadmeta(metapath) # m = open(metapath) # meta = m.readlines() # # channels = int(meta[7].split(' = ')[1]) # #samplerate = int(meta[10].split(' = ')[1]) # #duration = len(data)/channels/samplerate data = loadbinary(datapath, channels=channels) sweeptrace = np.array(data[:, (channels-5)]) vsynctrace = np.array(data[:, (channels-4)]) diodetrace = np.array(data[:, (channels-3)]) # d = open(datapath) # data = np.fromfile(d,np.int16) # datareshaped = np.transpose(np.reshape(data,(len(data)/channels,channels))) # del data # # sweeptrace = datareshaped[(channels-3),:] # vsynctrace = datareshaped[(channels-2),:] # diodetrace = datareshaped[(channels-1),:] # del datareshaped temp = findlevel(sweeptrace, 4000, 'up') sthr = -1*(np.ptp(sweeptrace)/4) sweep = findlevels(sweeptrace, sthr, 3000, 'up') sweep = insert(sweep, 0, temp) sweep = delete(sweep, len(sweep)-1, 0) sweepdown = findlevels(sweeptrace, sthr, 3000, 'down') if len(sweepdown) > len(sweep): sweepdown = delete(sweepdown, len(sweepdown)-1, 0) sweep = np.column_stack([sweep, sweepdown]) vthr = -1*(np.ptp(vsynctrace)/5) vsync = findlevels(vsynctrace, vthr, 300, 'up') dthr = np.ptp(diodetrace)/4 diode = findlevels(diodetrace, dthr, 200, 'both') #diode = np.reshape(diode, (len(diode)/2, 2)) diode = np.delete(diode,[0,1],0) #corrects for delay between computer and monitor delay = vsync[0] - diode[0] + 0.0 print "***monitor lag:", (delay/20000) if delay > 0: print "ERROR: diode before vsync" sys.exit('diode error') sweep -= delay #converts to time sweeptiming = sweep + 0.0 sweeptiming /= 20000 return sweeptiming
def getsync(syncpath, stimuluscondition): '''stimuluscondition to synccondition''' print "loading stimulus sync from:",syncpath sync = sio.loadmat(syncpath) syncframe = sync['syncframe'] syncdata = sync['syncdata'] del sync '''test integrity of sync signal''' thr = np.amin(syncdata)+(0.75*(np.ptp(syncdata))) temp = findlevels(syncdata, thr, 100, 'both') levellen = np.ediff1d(temp, to_begin=temp[0]) fframe = findlevel(levellen, 256, 'down') print "first frame:", fframe test = np.where(levellen>256) if amax(test) > fframe: print "SYNC ERROR!!" sys.exit('Problems with the sync data') else: print "Sync is good!" '''stimulus frame to acquisition frame''' synccondition = np.zeros((size(stimuluscondition,0),size(stimuluscondition,1))) for i in range(len(stimuluscondition)): start = stimuluscondition[i,0] + fframe end = stimuluscondition[i,1] + fframe temp = [] temp = np.where(syncframe[0][:] == start) synccondition[i,0] = int(floor(temp[0][0]/256/8)) temp = [] temp = np.where(syncframe[0][:] == end) synccondition[i,1] = int(floor(temp[0][0]/256/8)) synccondition[:,2:] = stimuluscondition[:,2:] return synccondition
def offstim(logpath, modality): '''segregates stimuluscondition into offstim (when fg object off monitor) and on stim (when fg object on monitor)''' offon = offwindow(logpath) (stimuluscondition, sweeplength, constring) = getSweepTimesOP(logpath, modality) stimoff = [] stimon = [] for i in range(len(stimuluscondition)): sweepst = stimuluscondition[i,0] sweepend = stimuluscondition[i,1] startp = findlevel(offon[:,0], sweepst, 'up') - 1 if sweepst < offon[startp,1]: '''start of sweep when OFF''' if sweepend < offon[startp,1]: tin = array(sweepst, sweepend, stimuluscondition[i,2], stimuluscondition[i,3], stimuluscondition[i,4], stimuluscondition[i,5], stimuluscondition[i,6]) if sweepend > offon[startp,1]: tin = array(sweepst, offon[startp,1], stimuluscondition[i,2], stimuluscondition[i,3], stimuluscondition[i,4], stimuluscondition[i,5], stimuluscondition[i,6]) stimoff = append(stimuluscondition, i, tin, 0) else: '''start of sweep when ON'''