def print_tp_stats( filepath): #FIXME this only works if there is only ONE epoch #FIXME also need to make all of these things work with NEGATIVE test pulses! (just use the sign on the step) raw = AxonIO(filepath) #raw,block,segments,header=load_abf(filepath) try: header = raw.read_header() except FileNotFoundError: return None starts, lengths, volts = find_rs_test(header) #TODO match commands to the proper recording channels (analog signals) if not volts: #implies that none of the waveforms was on return None else: segments = raw.read_block().segments sigit = range(len(starts)) Taus, Rss, Rs_ests, Rms = [], [], [], [] for segment in segments: for analogsignal, i in zip(segment.analogsignals, sigit): A, Tau, C, Q, Rs, Rs_est, Rm, rest_baseline, pulse_baseline, fit_start_index = compute_test_pulse_statistics( analogsignal, starts[i], lengths[i], volts[i]) Taus.append(Tau) Rss.append(Rs) Rs_ests.append(Rs_est) Rms.append(Rm) Taus = ['%3.2f ' % (t * 1000) for t in Taus if t] Rss = ['%3.2f ' % t for t in Rss if t] Rs_ests = ['%3.2f ' % t for t in Rs_ests if t] Rms = ['%3.2f ' % t for t in Rms if t] print('Taus', Taus) print('Rses', Rss) print('Rs_ests', Rs_ests) print('Rms', Rms) return Taus, Rss, Rs_ests, Rms
def print_tp_stats(filepath): #FIXME this only works if there is only ONE epoch #FIXME also need to make all of these things work with NEGATIVE test pulses! (just use the sign on the step) raw=AxonIO(filepath) #raw,block,segments,header=load_abf(filepath) try: header=raw.read_header() except FileNotFoundError: return None starts,lengths,volts=find_rs_test(header) #TODO match commands to the proper recording channels (analog signals) if not volts: #implies that none of the waveforms was on return None else: segments=raw.read_block().segments sigit=range(len(starts)) Taus,Rss,Rs_ests,Rms=[],[],[],[] for segment in segments: for analogsignal,i in zip(segment.analogsignals,sigit): A,Tau,C,Q,Rs,Rs_est,Rm,rest_baseline,pulse_baseline,fit_start_index=compute_test_pulse_statistics(analogsignal, starts[i], lengths[i], volts[i]) Taus.append(Tau) Rss.append(Rs) Rs_ests.append(Rs_est) Rms.append(Rm) Taus=['%3.2f '%(t*1000) for t in Taus if t ] Rss=['%3.2f '%t for t in Rss if t ] Rs_ests=['%3.2f '%t for t in Rs_ests if t ] Rms=['%3.2f '%t for t in Rms if t ] print('Taus',Taus) print('Rses',Rss) print('Rs_ests',Rs_ests) print('Rms',Rms) return Taus,Rss,Rs_ests,Rms
def importabf(self): self.abffiletoimport = input('Type (a) to process all files in folder, otherwise type in file number (ex:0012)') if self.abffiletoimport != 'a': print ('Searching files:') self.abffiletoimport = [file for file in self.abffiles if re.search(self.abffiletoimport, file)] print('Found: ', self.abffiletoimport) self.foundfile = ''.join(self.abffiletoimport) print(self.foundfile) self.fullfilepath = os.path.join(self.fileloc, self.foundfile) print('Full file path: ', self.fullfilepath) self.abf = AxonIO(filename=self.fullfilepath) else: pass
class filemanage: def __init__(self): self.fileloc = None def directimport(self): print('IMPORTING DIRECTORIES') self.homefolder = input('Are the files in the folder /home/pi/ephys/ (y or n)?') if self.homefolder == 'y': self.homefolder = '/home/pi/ephys/' else: self.homefolder = input('enter the datapath in /folder/subfolder/ format:') print('Experiments should be stored in subfolder by date in yyyy-mm-dd format.') self.experdate = input('Enter the experiment date in yyyy-mm-dd format ') print('Subfolders within home folder:') print(os.listdir(self.homefolder)) self.fileloc = os.path.join(self.homefolder, self.experdate) if (os.path.exists(self.fileloc)): print('Files within experiment date folder') print(os.listdir(os.path.join(self.homefolder, self.experdate))) self.fileloclist = os.listdir(os.path.join(self.homefolder, self.experdate)) else: print('The file does not exist, check the path and date.') return () def findabffile(self): print('ISOLATING ABF FILES...') self.abffiles = [extension for extension in self.fileloclist if re.search("\.abf$", extension)] self.abffiles.sort() print('*.abf files in folder:') print(self.abffiles) def importabf(self): self.abffiletoimport = input('Type (a) to process all files in folder, otherwise type in file number (ex:0012)') if self.abffiletoimport != 'a': print ('Searching files:') self.abffiletoimport = [file for file in self.abffiles if re.search(self.abffiletoimport, file)] print('Found: ', self.abffiletoimport) self.foundfile = ''.join(self.abffiletoimport) print(self.foundfile) self.fullfilepath = os.path.join(self.fileloc, self.foundfile) print('Full file path: ', self.fullfilepath) self.abf = AxonIO(filename=self.fullfilepath) else: pass def exploreabf(self): self.numblocks = self.abf.block_count() self.samplingrate = self.abf.get_signal_sampling_rate() self.abf.
def get_segments_with_step(filepath): try: raw=AxonIO(filepath) header=raw.read_header() except FileNotFoundError as e: print(e) del(raw) return None,None,None,None starts,lengths,volts=find_rs_test(header) if not volts: return None,None,None,None else: segments=raw.read_block().segments del(raw) return segments,starts,lengths,volts
def get_segments_with_step(filepath): try: raw = AxonIO(filepath) header = raw.read_header() except FileNotFoundError as e: print(e) del (raw) return None, None, None, None starts, lengths, volts = find_rs_test(header) if not volts: return None, None, None, None else: segments = raw.read_block().segments del (raw) return segments, starts, lengths, volts
def plot_stuff(args): path, fn = args print(path) segments, starts, lengths, volts = get_segments_with_step(path + fn) if segments: plot_all_tp_stats(segments, starts, lengths, volts) else: try: segments = AxonIO(path + fn).read_block().segments except FileNotFoundError as e: print(e) return None
def main(): from rig.ipython import embed test_files=[ '2013_12_13_0045.abf', '2013_12_13_0046.abf', '2013_12_13_0047.abf', '2013_12_13_0048.abf', '2013_12_13_0049.abf', '2013_12_13_0050.abf', '2013_12_13_0051.abf', '2013_12_13_0052.abf', '2013_12_13_0053.abf', '2013_12_13_0054.abf', ] more=[ '2013_12_13_0055.abf', '2013_12_13_0056.abf', '2013_12_13_0057.abf', '2013_12_13_0058.abf', '2013_12_13_0059.abf', '2013_12_13_0060.abf', '2013_12_13_0061.abf', '2013_12_13_0062.abf', '2013_12_13_0063.abf', '2013_12_13_0064.abf', '2013_12_13_0065.abf', '2013_12_13_0066.abf', '2013_12_13_0067.abf', '2013_12_13_0068.abf', ] test_files=[ '/mnt/tstr/db/Dropbox/mlab/chlr project/20140305_0011 Cs.abf', '/mnt/str/tom/mlab_data/clampex/2014_03_21_0120.abf', #this file is an example of the sampling seq bug '/mnt/str/tom/mlab_data/clampex/13n29011.abf', ] #dat_dir='/home/tom/mlab_data/clampex/' #test_files=np.sort(os.listdir(dat_dir))[-133:] fig=plt.figure(figsize=(10,10)) for filename in test_files: #raw=AxonIO(dat_dir+filename) raw=AxonIO(filename) header=raw.read_header() #print(repr(header)) blk=raw.read_block() waveforms=build_waveform(header) scale=1 downsample=10 embed() #break n_plots=len(waveforms)+len(blk.segments[0].analogsignals) tmax=0 for s in blk.segments: c_plot=1 count = 0 for signal in s.analogsignals: plt.subplot(n_plots,1,c_plot) c_plot+=1 plt.plot(signal.base[::downsample],'r-',linewidth=.5) plt.title(signal.name) plt.xlim(0,len(signal)/(scale*downsample)) plt.ylabel(signal.units) waveform=waveforms.get(signal.channel_index) if waveform: plt.subplot(n_plots,1,c_plot) c_plot+=1 #plt.plot(waveform[count][::downsample],'k-') plt.plot(waveform[count],'k-') plt.title('Command') #plt.xlim(0,len(signal)/(scale*downsample)) nmax=np.max(waveform) if nmax > tmax: tmax = nmax #plt.ylim(-1.2*tmax,1.2*tmax) count+=1 plt.savefig('/tmp/test%s.png'%filename[-8:-4]) plt.clf()
def load_abf(filepath): raw=AxonIO(filename=filepath) block=raw.read_block(lazy=False,cascade=True) segments=block.segments header=raw.read_header() return raw,block,segments,header
from neo import AxonIO from scipy import signal import numpy as np import quantities as pq from matplotlib import pyplot as plt #matplotlib.use('TKAgg') fname = "/Users/macbookair/Downloads/20180913/18913005.abf" reader = AxonIO(filename=fname) #fig = plt.figure() #ax = fig.add_axes([0.15, 0.1, 0.7, 0.7]) #l,b,w,h fig, ax = plt.subplots(figsize=(10, 5)) bl = reader.read() # reads the entire blocks for i in range(0, 10): #print(bl.readable_objects) seg = bl[0].segments[i] #seg = reader.read_segment() data, units = enumerate(seg.analogsignals) si = seg.analogsignals[0].sampling_rate print(seg.analogsignals[0].units) print(seg.analogsignals[0].sampling_rate) print(seg.analogsignals[0].t_start) print(seg.analogsignals[0].t_stop) print(seg.analogsignals[0].times) if (i == 0): t = np.arange(seg.analogsignals[0].t_start, seg.analogsignals[0].t_stop, 1 / seg.analogsignals[0].sampling_rate) t = np.asmatrix(t) t = t.reshape(np.size(t), 1)
def main(): from rig.ipython import embed test_files = [ '2013_12_13_0045.abf', '2013_12_13_0046.abf', '2013_12_13_0047.abf', '2013_12_13_0048.abf', '2013_12_13_0049.abf', '2013_12_13_0050.abf', '2013_12_13_0051.abf', '2013_12_13_0052.abf', '2013_12_13_0053.abf', '2013_12_13_0054.abf', ] more = [ '2013_12_13_0055.abf', '2013_12_13_0056.abf', '2013_12_13_0057.abf', '2013_12_13_0058.abf', '2013_12_13_0059.abf', '2013_12_13_0060.abf', '2013_12_13_0061.abf', '2013_12_13_0062.abf', '2013_12_13_0063.abf', '2013_12_13_0064.abf', '2013_12_13_0065.abf', '2013_12_13_0066.abf', '2013_12_13_0067.abf', '2013_12_13_0068.abf', ] test_files = [ '/mnt/tstr/db/Dropbox/mlab/chlr project/20140305_0011 Cs.abf', '/mnt/str/tom/mlab_data/clampex/2014_03_21_0120.abf', #this file is an example of the sampling seq bug '/mnt/str/tom/mlab_data/clampex/13n29011.abf', ] #dat_dir='/home/tom/mlab_data/clampex/' #test_files=np.sort(os.listdir(dat_dir))[-133:] fig = plt.figure(figsize=(10, 10)) for filename in test_files: #raw=AxonIO(dat_dir+filename) raw = AxonIO(filename) header = raw.read_header() #print(repr(header)) blk = raw.read_block() waveforms = build_waveform(header) scale = 1 downsample = 10 embed() #break n_plots = len(waveforms) + len(blk.segments[0].analogsignals) tmax = 0 for s in blk.segments: c_plot = 1 count = 0 for signal in s.analogsignals: plt.subplot(n_plots, 1, c_plot) c_plot += 1 plt.plot(signal.base[::downsample], 'r-', linewidth=.5) plt.title(signal.name) plt.xlim(0, len(signal) / (scale * downsample)) plt.ylabel(signal.units) waveform = waveforms.get(signal.channel_index) if waveform: plt.subplot(n_plots, 1, c_plot) c_plot += 1 #plt.plot(waveform[count][::downsample],'k-') plt.plot(waveform[count], 'k-') plt.title('Command') #plt.xlim(0,len(signal)/(scale*downsample)) nmax = np.max(waveform) if nmax > tmax: tmax = nmax #plt.ylim(-1.2*tmax,1.2*tmax) count += 1 plt.savefig('/tmp/test%s.png' % filename[-8:-4]) plt.clf()
def load_abf(filepath): raw = AxonIO(filename=filepath) block = raw.read_block(lazy=False, cascade=True) segments = block.segments header = raw.read_header() return raw, block, segments, header
import sys import os import numpy as np from matplotlib import pyplot as plt import neo from neo import AxonIO from cv_bridge import CvBridge, CvBridgeError from thllib import flylib as flb import rosbag fly = flb.NetFly(1525) abfreader = AxonIO(fly.abfpaths[0]) abffile = abfreader.read() block = abffile[0] segment = block.segments[0] analogsignals = segment.analogsignals times = np.array(analogsignals[0].times) signal_idxs = { 'abf_electrode': 0, 'abf_wba_left_amp': 1, 'abf_wba_right_amp': 2, 'abf_sync': 3, 'abf_freq': 4, 'abf_left_hutchen': 5, 'abf_right_hutchen': 6, 'abf_led_pulse': 7, 'abf_kinefly_lmr': 8, 'abf_kinefly_left': 9, 'abf_kinefly_right': 10,
import pyabf from matplotlib import pyplot as plt from neo import AxonIO fname = "/Volumes/Anup_2TB/raw_data/beiquelab/zen/data_anup/20190627/C3/2019_06_27_0152.abf" abf = pyabf.ABF(fname) nabf = AxonIO(filename=fname) fig = plt.figure(figsize=(8, 5)) ax1 = fig.add_subplot(311) ax1.grid(alpha=.2) ax1.set_title("Digital Outputs") ax1.set_ylabel("Digital Outputs") # plot the digital output of the first sweep abf.setSweep(sweepNumber=0, channel=0) # ax1.plot(abf.sweepX, abf.sweepD(0), color='red') # ax1.plot(abf.sweepX, abf.sweepD(1), color='green') # ax1.plot(abf.sweepX, abf.sweepD(2), color='blue') # ax1.plot(abf.sweepX, abf.sweepD(3), color='black') # ax1.plot(abf.sweepX, abf.sweepD(4), color='red') # ax1.plot(abf.sweepX, abf.sweepD(5), color='green') # ax1.plot(abf.sweepX, abf.sweepD(6), color='blue') # ax1.plot(abf.sweepX, abf.sweepD(7), color='black') ax1.set_yticks([0, 1]) ax1.set_yticklabels(["OFF", "ON"]) ax1.axes.set_ylim(-.5, 1.5)
from neo import AxonIO import numpy as np import re import os homefolder = '/home/pi/ephys/2021-02-16/2021_02_16_0009.abf' # abf = AxonIO(filename=homefolder) reader = AxonIO(filename=homefolder) nblocks = reader.block_count() si = reader.get_signal_sampling_rate() samplesize = reader.get_signal_size(block_index=0, seg_index=0) tstart = reader.segment_t_start(block_index=0, seg_index=0) tstop = reader.segment_t_stop(block_index=0, seg_index=0) header = reader.header nchannels = reader.signal_channels_count() gseg = reader.segment_count(block_index=0) channelspecs = reader.header["signal_channels"].dtype.names # bl = reader.read_block(lazy= False) seg = reader.read_segment(block_index=0, seg_index=1) print(seg.analogsignals) protocol = reader.read_protocol() rawprotocol = reader.read_raw_protocol() print('numberblocks: ', nblocks) print('samplerate: ', si) print('timestart: ', tstart) print('timestop: ', tstop)
from neo import AxonIO import numpy as np from matplotlib import pyplot as plt import datetime # fname = "/Volumes/Anup_2TB/raw_data/beiquelab/zen/data_anup/20190627/C3/2019_06_27_0152.abf" fname = "/Volumes/Anup_2TB/raw_data/beiquelab/o2p/ephys/20200213/C1/20213008.abf" reader = AxonIO(filename=fname) print(dir(reader)) # print('block count: ',reader.block_count()) # print('segment count: ',reader.segment_count(0)) # print('signal_channels_count: ',reader.signal_channels_count()) # print('signal sampling rate: ',reader.get_signal_sampling_rate()) # print('segment t_start: ', reader.segment_t_start(block_index=0,seg_index=0)) # print('segment t_start: ',reader.segment_t_stop(block_index=0,seg_index=0)) # print('header: ',reader.header) - implemented # print('analog_signal_size: ',reader.get_signal_size(block_index=0,seg_index=0)) print(type(reader.get_analogsignal_chunk())) print('filename', reader.filename) # print('print_annotations',reader.print_annotations()) print('raw_annotations', reader.raw_annotations) rawannot = reader.raw_annotations # print(rawannot.keys()) # print(rawannot["blocks"]) # print(rawannot["blocks"][0].keys()) # doe = rawannot['blocks'][0]["rec_datetime"] # print(doe.time()) # print(rawannot['blocks'][0]['segments'][0]) # print("protocol",reader.read_protocol()) # protocol_seg=reader.read_protocol() # print(dir(protocol_seg[0]))