def load(): # wx Widgets to create a file selection window fname = wx.FileSelector( "Import Ephus file", default_extension="Ephus XSG", default_path=".", wildcard="Matlab Ephus xsg. text import (*.xsg)|*.xsg", flags=wx.OPEN | wx.FILE_MUST_EXIST) data_sio = sio.loadmat(fname, squeeze_me=True) data = data_sio.get('data') trace = data['ephys'].item().item()[0] header = data_sio.get('header') dt = header['ephys'].item().item()[0]['sampleRate'].item() stf.new_window(trace[1:]) stf.set_sampling_interval(1000 / np.double(dt)) stf.set_xunits('ms') stf.set_yunits('pA')
def loadtxt(freq=400): """ Loads an ASCII file with extension *.GoR. This file contains ratiometric fluorescent measurements (i.e Green over Red fluorescence) saved in one column. This function opens a new Stimfit window and sets the x-units to "ms" and y-units to "Delta G over R". Arguments: freq -- (float) the sampling rate (in Hz) for fluorescence acquistion. the default value is 400 Hz """ fname = wx.FileSelector("Import Ca transients" , default_extension="Ratiometric" , default_path="." , wildcard = "Ratiometric fluorescence (*.GoR)|*.GoR" , flags = wx.OPEN | wx.FILE_MUST_EXIST) stf.new_window( np.loadtxt(fname) ) stf.set_xunits('ms') stf.set_yunits('Delta G/R') stf.set_sampling_interval(1.0/freq*1000) # acquisition at 400 Hz
def loadtxt(freq=400): """ Loads an ASCII file with extension *.GoR. This file contains ratiometric fluorescent measurements (i.e Green over Red fluorescence) saved in one column. This function opens a new Stimfit window and sets the x-units to "ms" and y-units to "Delta G over R". Arguments: freq -- (float) the sampling rate (in Hz) for fluorescence acquistion. the default value is 400 Hz """ fname = wx.FileSelector("Import Ca transients", default_extension="Ratiometric", default_path=".", wildcard="Ratiometric fluorescence (*.GoR)|*.GoR", flags=wx.OPEN | wx.FILE_MUST_EXIST) stf.new_window(np.loadtxt(fname)) stf.set_xunits('ms') stf.set_yunits('Delta G/R') stf.set_sampling_interval(1.0 / freq * 1000) # acquisition at 400 Hz
def loadmat(): """ Load electrophysiology recordings from ephysIO HDF5-based Matlab v7.3 (.mat) files """ # Import required modules for file IO from Tkinter import Tk import tkFileDialog from gc import collect # Use file open dialog to obtain file path root = Tk() opt = dict(defaultextension='.mat', filetypes=[('MATLAB v7.3 (HDF5) file', '*.mat'), ('All files', '*.*')]) if 'loadcwd' not in globals(): global loadcwd else: opt['initialdir'] = loadcwd filepath = tkFileDialog.askopenfilename(**opt) root.withdraw() if filepath != '': # Move to file directory and check file version loadcwd = filepath.rsplit('/', 1)[0] from os import chdir print filepath chdir(loadcwd) # Load data into python import ephysIO data = ephysIO.MATload(filepath) # Display data in Stimfit import stf if data.get('xdiff') > 0: if data.get('yunit') == "V": stf.new_window_list(1.0e+3 * np.array(data.get('array')[1::])) stf.set_yunits('m' + data.get('yunit')) elif data.get('yunit') == "A": stf.new_window_list(1.0e+12 * data.get('array')[1::]) stf.set_yunits('p' + data.get('yunit')) else: stf.new_window_list(data.get('array')[1::]) stf.set_yunits(data.get('yunit')) stf.set_sampling_interval(1.0e+3 * data.get('xdiff')) stf.set_xunits('m' + data.get('xunit')) stf.set_trace(0) stf.set_recording_comment('\n'.join(data['notes'])) if data['saved'] != '': date = data['saved'][0:8] date = tuple(map(int, (date[0:4], date[4:6], date[6:8]))) stf.set_recording_date('%s-%s-%s' % date) time = data['saved'][9::] time = tuple(map(int, (time[0:2], time[2:4], time[4:6]))) stf.set_recording_time('%i-%i-%i' % time) elif data.get('xdiff') == 0: raise ValueError("Sample interval is not constant") else: data = {} collect() return
def loadflex(): """ Load raw traces of FlexStation data from CSV files """ # Import required modules from os import chdir import csv import stf import numpy as np from Tkinter import Tk import tkFileDialog from gc import collect # Use file open dialog to obtain file path root = Tk() opt = dict(defaultextension='.csv', filetypes=[('Comma Separated Values file', '*.csv'), ('All files', '*.*')]) if 'loadcwd' not in globals(): global loadcwd else: opt['initialdir'] = loadcwd filepath = tkFileDialog.askopenfilename(**opt) root.withdraw() if filepath != '': # Move to file directory and check file version loadcwd = filepath.rsplit('/', 1)[0] print filepath chdir(loadcwd) # Load data into numpy array with open(filepath, 'rb') as csvfile: csvtext = csv.reader(csvfile) data = [] for row in csvtext: data.append(row) data = np.array(data) time = data.T[0][1::].astype(np.float) sampling_interval = np.mean(np.diff(time)) comment = 'Temperature: %d degrees Centigrade' % np.mean( data.T[1][1::].astype(np.float)) # Plot fluorescence measurements well = data.T[2::, 0] data = data.T[2::, 1::] ridx = [] idx = [] for i in range(96): if np.all(data[i] == ''): ridx.append(i) else: idx.append(i) data = np.delete(data, ridx, 0) data[[data == '']] = 'NaN' data[[data == ' ']] = 'NaN' delrow = np.any(data == 'NaN', 0) didx = [] for i in range(np.size(data, 1)): if np.any(data[::, i] == 'NaN', 0): didx.append(i) time = np.delete(time, didx, 0) data = np.delete(data, didx, 1) data = data.astype(np.float) stf.new_window_list(data) # Set x-units and sampling interval stf.set_xunits('ms') stf.set_yunits(' ') stf.set_sampling_interval(1000 * sampling_interval) # Record temperature comment += '\nTr\tWell' for i in range(len(idx)): comment += '\n%i\t%s' % (i + 1, well[idx[i]]) comment += '\nInitial time point: %.3g' % time[0] print comment stf.set_recording_comment(comment) else: data = {} collect() return
def loadacq4(channel=1): """ Load electrophysiology recording data from acq4 hdf5 (.ma) files. By default the primary recording channel is loaded. If the file is in a folder entitled 000, loadacq4 will load the recording traces from all sibling folders (000,001,002,...) """ # Import required modules for file IO from Tkinter import Tk import tkFileDialog from gc import collect # Use file open dialog to obtain file path root = Tk() opt = dict(defaultextension='.ma', filetypes=[('ACQ4 (HDF5) file', '*.ma'), ('All files', '*.*')]) if 'loadcwd' not in globals(): global loadcwd else: opt['initialdir'] = loadcwd filepath = tkFileDialog.askopenfilename(**opt) root.withdraw() if filepath != '': # Load data into python loadcwd = filepath.rsplit('/', 1)[0] import ephysIO data = ephysIO.MAload(filepath, channel) print filepath # Display data in Stimfit import stf if data.get('yunit') == 'A': stf.new_window_list(1.0e+12 * data.get('array')[1::]) stf.set_yunits('p' + data.get('yunit')) elif data.get('yunit') == 'V': stf.new_window_list(1.0e+3 * data.get('array')[1::]) stf.set_yunits('m' + data.get('yunit')) stf.set_sampling_interval(1.0e+3 * data['xdiff']) stf.set_xunits('m' + data.get('xunit')) stf.set_trace(0) # Import metadata into stimfit stf.set_recording_comment('\n'.join(data['notes'])) date = data['saved'][0:8] date = tuple(map(int, (date[0:4], date[4:6], date[6:8]))) stf.set_recording_date('%s-%s-%s' % date) time = data['saved'][9::] time = tuple(map(int, (time[0:2], time[2:4], time[4:6]))) stf.set_recording_time('%i-%i-%i' % time) else: data = {} collect() return
def combiRec(offset): import os import ephysIO # Import required modules for file IO from Tkinter import Tk import tkFileDialog from gc import collect # Use file open dialog to obtain file path root = Tk() opt = dict(defaultextension='.phy', filetypes=[('ephysIO (HDF5) file', '*.phy'), ('All files', '*.*')]) if 'loadcwd' not in globals(): global loadcwd else: opt['initialdir'] = loadcwd filepath = tkFileDialog.askopenfilename(**opt) root.withdraw() # Set this to file name prefix (i.e. the protocol name) filename = filepath.rsplit('/', 1)[-1] # e.g. "1.phy" dirpath = filepath.rsplit( '/', 1)[0] # e.g. "<path>/pair_000/dual_mixed_eEPSC_000" protocol = (dirpath.rsplit('/', 1)[1]).rsplit('_', 1)[0] # e.g. "dual_mixed_eEPSC" rootdir = dirpath.rsplit('/', 1)[0] # e.g. "<path>/pair_000/" # Load data from channel 1 os.chdir(rootdir) count = 0 allwaves = [] notes = '' holding = [] while True: wavename = protocol + "_" + ("000" + str(count))[-3::] if os.path.isdir(wavename): os.chdir(wavename) data = ephysIO.PHYload(filename) allwaves.append(1.0e+12 * data.get("array")[1]) notes += notes + 'Wave %d\n' % (count) + '\n'.join( data['notes']) + '\n\n' #print data['notes'][9][10::] holding.append(eval(data['notes'][9][10::])) count += 1 os.chdir("..") else: break stf.new_window_list(allwaves) stf.set_xunits('m' + data.get('xunit')) stf.set_yunits('p' + data.get('yunit')) stf.set_sampling_interval(1.0e+3 * data.get('xdiff')) stf.set_recording_comment(notes) gwaves = [stf.get_trace(i) / (holding[i] - offset) for i in range(count)] stf.new_window_list(gwaves) stf.set_recording_comment('Mixed AMPA/NMDA-mediated conductance') gnmda = [stf.get_trace(i) - stf.get_trace(0) for i in range(count)] stf.new_window_list(gnmda) stf.set_recording_comment('NMDA-mediated conductance') ivnmda = [stf.get_trace(i) * (holding[i] - offset) for i in range(count)] stf.new_window_list(ivnmda) stf.set_recording_comment('NMDA-mediated current') return holding