def __init__(self, around, aroundTS, dbName, begkey, Signame, TSName): self.lastMove = None self.Sig = np.memmap(Signame, dtype=np.float32, mode='r') self.SigCh = [self.Sig[i::NChan] for i in range(NChan)] ts = np.loadtxt(TSName, unpack=True) self.P1 = ts[1][find(ts[0] == 1)] / freq self.P2 = ts[1][find(ts[0] == -1)] / freq self.around = around self.aroundTS = aroundTS self.key = begkey self.db = recogdb.openDB(dbName, 'rw') if key != 0: self.k = struct.pack('=q', key) self.k, self.bindata = self.db.set_location(self.k) else: self.k, self.bindata = self.db.first() self.k, self.bindata = self.db.set_location(self.k) self.read_data = recogdb.parseDBHeader(self.bindata) self.off, = struct.unpack('=q', self.k) print('key:\t%d' % self.off) print('time: %s' % self.sec2hms(self.off / freq, None)) for a, b in recogdb.dicFields.items(): print('%s:\t%s' % (a, self.read_data[b])) self.formatterX = FuncFormatter(self.sec2hms) self.f = plt.figure(1, figsize=(25, 20)) self.ax1 = self.f.add_subplot(111) self.sigs = [None for i in range(NChan)] for i in range(NChan): self.sigs[i], = self.ax1.plot((), (), 'k-') self.P1Lines = [None for j in range(self.aroundTS)] self.P2Lines = [None for j in range(self.aroundTS)] for j in range(self.aroundTS): self.P1Lines[j], = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'b-', alpha=0.4) self.P2Lines[j], = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'r-', alpha=0.4) self.strongLine, = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'k-') self.newLine, = self.ax1.plot((0, 0), (-10, 5 * (NChan + 1)), 'k-') self.f.canvas.mpl_connect('button_press_event', self.spikeClick) self.f.canvas.mpl_connect('motion_notify_event', self.spikeMove) self.f.canvas.mpl_connect('button_release_event', self.spikeRelease) self.init_data() self.plotStuff() self.makeButtons() self.adjustAxes()
import numpy as np import recogdb import struct import sys keybeg = 356604502 keyend = 356637225 db = recogdb.openDB(sys.argv[1], 'rw') kb = struct.pack('=q', keybeg) ke = struct.pack('=q', keyend) off, bindata = db.set_location(kb) off, = struct.unpack('=q', off) read_data = recogdb.parseDBHeader(bindata) while (off <= keyend): key = recogdb.verifyKey(db, off) sys.stdout.write('%d\r' % off) sys.stdout.flush() oldFish = read_data[recogdb.dicFields['presentFish']] oldCorrectedPosA = read_data[recogdb.dicFields['correctedPosA']] oldCorrectedPosB = read_data[recogdb.dicFields['correctedPosB']] oldDistA = read_data[recogdb.dicFields['distA']] oldDistB = read_data[recogdb.dicFields['distB']] oldDistAB = read_data[recogdb.dicFields['distAB']] if oldFish == 1: newFish = 2
import numpy as np import recogdb import struct import sys freq = 45454.545454 fish = 2 keybeg = 169451424 keyend = 169498558 mov = -0.0028 #ms mov = int(mov*freq) db = recogdb.openDB('/ssd/Junho2016/16428000_512.db', 'rw') kb = struct.pack('=q', keybeg) ke = struct.pack('=q', keyend) off, bindata = db.set_location(kb) off, = struct.unpack('=q', off) read_data = recogdb.parseDBHeader(bindata) while (off <= keyend): key = recogdb.verifyKey(db, off) sys.stdout.write('%d\r'%off) sys.stdout.flush() oldFish = read_data[ recogdb.dicFields['presentFish'] ] oldCorrectedPosA = read_data[ recogdb.dicFields['correctedPosA'] ] oldCorrectedPosB = read_data[ recogdb.dicFields['correctedPosB'] ]
#!/usr/env python import recogdb import numpy as np import sys import struct nproc = 8 nchan = 7 A = np.memmap(sys.argv[1], mode='r', dtype=np.float32) tamChunk = (A.size // nchan) // nproc DBout = recogdb.openDB('merge.db', 'w') for i in range(nproc): print(i) DBin = recogdb.openDB('%d.db' % i, 'r') pos = i * tamChunk for k in DBin.keys(): key, = struct.unpack('=q', k) key += pos codedkey = struct.pack('=q', key) off, read_data, spkdata = recogdb.readHeaderEntry(DBin, k) read_data = list(read_data) if read_data[recogdb.dicFields['presentFish']] == 1: read_data[recogdb.dicFields['correctedPosA']] += pos elif read_data[recogdb.dicFields['presentFish']] == 2:
import recogdb NumChannels = 11 #importar isso do arquivo C? def usage(): print "Usage: python DetectIPIs.py filename.db outfile.ipi" sys.exit(-1) if len(sys.argv) != 3: usage() if not os.path.isfile(sys.argv[1]): usage() db = recogdb.openDB(sys.argv[1],'w') f = open(sys.argv[2],'w') # Variables for each fish SpikesLidos = { 'A':0, 'B':0, } Derivada = { 'A':None, 'B':None, } NPontosJanela = { 'A': 0, 'B': 0, } NPontosJanelaAnterior = { 'A': 0, 'B': 0, }
#!/usr/bin/env python import numpy as np import recogdb import sys import struct freq = 50000. A = np.loadtxt(sys.argv[1],unpack=True,dtype=np.int) P1 = A[1][ A[0] == 1] P2 = A[1][ A[0] ==-1] DB = recogdb.openDB( sys.argv[2], 'rw') IPI1 = np.diff(P1) / freq IPI2 = np.diff(P2) / freq idx1 = np.where(IPI1 < 0.0002) rem1 = P1[idx1] idx2 = np.where(IPI2 < 0.0002) rem2 = P2[idx2] print(rem1) print(rem2) ### Remove duplicates for k in DB.keys(): raw_data = recogdb.readHeaderEntry(DB, k) if raw_data is not None: read_data = raw_data[1] else: