Commits

Anonymous committed 1c89430

initial commit, work in progress

Comments (0)

Files changed (2)

+syntax: glob
+*.pyc
+*~
+.ropeproject
+eegquant.egg-info*
+TAGS
+\#*
+\.\#*

atfwriter/__init__.py

+"""
+naive library to write axon (pClamp) stimulus files in atf format
+
+comparions:
+the _neo project
+the _stimfit project, specifically the stimio module
+
+abfload in matlab
+"""
+
+def atf_write_basic(file_name, timearr_ms, signalarr_mv, typedescription="stimulus file"):
+    """write a two column time, signal atf file
+    in units of ms and mV
+    attmpt to follow format of axon's atf
+    """
+    fp = file(file_name, "wb")
+    # write the header for a two column file, expects dos "\r\n" line endings I believe
+    fp.write("ATF\t1\r\n")
+    fp.write("8\t2     \r\n")
+    fp.write('"Type=%s"\r\n"' % typedescription)
+    # fp.write('"BinWidth=0.1"\r\n') # not sure if this is necessary
+    fp.write('"Time (ms)"\t"Amplitude (mV)"\r\n')   # note, it's not clear to me yet what sort of units this needs to convert to
+    for ii in xrange(len(timearr_ms)):
+        fp.write("%f\t%f\r\n" % (timearr_ms[ii], signalarr_mv[ii])) # do it the slow way for now
+
+    fp.close()
+
+
+def atf_write_basic_in_volts(file_name, timearr_ms, signalarr_mv, typedescription="stimulus file"):
+    """write a two column time, signal atf file
+    in units of ms and mV
+    attmpt to follow format of axon's atf
+    """
+    fp = file(file_name, "wb")
+    # write the header for a two column file, expects dos "\r\n" line endings I believe
+    fp.write("ATF\t1\r\n")
+    fp.write("1\t2     \r\n")
+    fp.write('"Type=%s"\r\n"' % typedescription)
+    # fp.write('"BinWidth=0.1"\r\n') # not sure if this is necessary
+    fp.write('"Time (ms)"\t"Amplitude (V)"\r\n')   # note, it's not clear to me yet what sort of units this needs to convert to
+    for ii in xrange(len(timearr_ms)):
+        fp.write("%f\t%f\r\n" % (timearr_ms[ii], signalarr_mv[ii]/1000.0)) # do it the slow way for now
+
+    fp.close()
+    
+    
+def atf_write_basic_in_volts_one_column(file_name, timearr_ms, signalarr_mv, typedescription="stimulus file"):
+    """write a one  signal atf file
+    for use as a stimulus waveform in pClamp 10
+    output units are volts, input units are mV
+    attmpt to follow format of axon's atf
+    """
+    fp = file(file_name, "wb")
+    # write the header for a two column file, expects dos "\r\n" line endings I believe
+    fp.write("ATF\t1\r\n")
+    num_optional_lines =1
+    num_data_fields = 1
+    fp.write("%d\t%d     \r\n" % (num_optional_lines, num_data_fields)) # n (number optional data records)\t m (number of columns of data)
+    fp.write('"Type=%s"\r\n"' % typedescription)
+    # fp.write('"BinWidth=0.1"\r\n') # not sure if this is necessary
+    fp.write('"Amplitude (V)"\r\n')   # note, it's not clear to me yet what sort of units this needs to convert to
+    for ii in xrange(len(timearr_ms)):
+        fp.write("%f\t%f\r\n" % (timearr_ms[ii], signalarr_mv[ii]/1000.0)) # do it the slow way for now
+    fp.close()   
+
+
+def atf_write_stimulus_file_in_volts_N_column(file_name, signalmatrix_v, typedescription="stimulus file"):
+    """write a one  signal atf file
+    for use as a stimulus waveform in pClamp 10
+    @signalmatrix_v is a numpy ndarray like matrix with
+    signalmatrix_v.shape = (nrow, ncol)
+    output units are volts, input units are Volts
+    attmpt to follow format of axon's atf
+    """
+    nrow,ncol = signalmatrix_v.shape
+    fp = file(file_name, "wb")
+    # write the header for a two column file, expects dos "\r\n" line endings I believe
+    fp.write("ATF\t1\r\n")
+    num_optional_lines =1
+    num_data_fields = ncol
+    fp.write("%d\t%d     \r\n" % (num_optional_lines, num_data_fields)) # n (number optional data records)\t m (number of columns of data)
+    fp.write('"Type=%s"\r\n"' % typedescription)
+    # fp.write('"BinWidth=0.1"\r\n') # not sure if this is necessary
+    for ii in xrange(ncol):
+        header.append('"Amplitude (V)"')   # note, it's not clear to me yet what sort of units this needs to convert to
+    fp.write("\t".join(header))
+    fp.write('\r\n')   # note, it's not clear to me yet what sort of units this needs to convert to
+    
+    # do it the slow way first
+    for ii in xrange(nrow):
+        row = []
+        for jj in xrange(ncol):
+            row.append("%f" % signalmatrix_v[ii][jj]) 
+        fp.write("\t".join(row))
+        fp.write("\r\n")
+
+    fp.close()