Package qubx :: Module data_tacidl
[hide private]
[frames] | no frames]

Source Code for Module qubx.data_tacidl

  1  """ 
  2  Reads idealized data from TacFit table of transitions, saved with extension .tacidl. 
  3   
  4  Copyright 2008-2011 Research Foundation State University of New York  
  5  This file is part of QUB Express.                                           
  6   
  7  QUB Express is free software; you can redistribute it and/or modify           
  8  it under the terms of the GNU General Public License as published by  
  9  the Free Software Foundation, either version 3 of the License, or     
 10  (at your option) any later version.                                   
 11   
 12  QUB Express is distributed in the hope that it will be useful,                
 13  but WITHOUT ANY WARRANTY; without even the implied warranty of        
 14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
 15  GNU General Public License for more details.                          
 16   
 17  You should have received a copy of the GNU General Public License,    
 18  named LICENSE.txt, in the QUB Express program directory.  If not, see         
 19  <http://www.gnu.org/licenses/>.                                       
 20   
 21  """ 
 22   
 23  from qubx.data_types import * 
 24   
25 -def OpenTACidl(path, progressf):
26 data = QubData() 27 data.path = path 28 data.signals.append({"Name" : "Current", "Units" : "pA"}) 29 30 # default sampling, amps, stds 31 sampling = [0.0] 32 first = [0] 33 segi = [0] 34 class_count = 10 35 amps = [1.0*i for i in xrange(class_count)] 36 stds = [0.1] * class_count 37 classes = [] 38 durations = [] 39 40 def set_seg_dwells(): 41 if not classes: 42 return 43 # first event has unknown duration -- set to smallest encountered: 44 durations[0] = min(durations) 45 cc = numpy.array(classes, dtype='int32') 46 dd = numpy.array(durations, dtype='float32') 47 ff = numpy.zeros(shape=cc.shape, dtype='int32') 48 ll = numpy.zeros(shape=cc.shape, dtype='int32') 49 aa = [x for x in amps] 50 ss = [x for x in stds] 51 sampling[0] = sampling[0] or (numpy.min(dd) / 12.0) 52 data.sampling = sampling[0] * 1e-3 53 dw_samp_ct = numpy.array(dd, copy=True) 54 dw_samp_ct /= sampling[0] 55 dw_samp_ct += 0.5 56 dw_samp_ct = dw_samp_ct.astype('int32') 57 f = first[0] 58 for i in xrange(len(cc)): 59 nextf = f + dw_samp_ct[i] 60 ff[i] = f 61 ll[i] = nextf - 1 62 f = nextf 63 data.segmentation.add_seg(first[0], f-1, first[0]*data.sampling*1e3) 64 data.ideal[0].idl.set_dwells(len(cc), ff, ll, cc) 65 data.ideal[0].seg[ segi[0] ].amp = aa 66 data.ideal[0].seg[ segi[0] ].std = ss 67 first[0] = f 68 segi[0] = segi[0] + 1
69 70 seg_ix = -1 71 last_secs = 0.0 72 last_level = 0 73 74 dwell_pat = re.compile(r"^(\d\S*)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)") 75 for line in open(path, "r"): 76 match = dwell_pat.match(line) 77 if match: 78 sweep, secs, preamp, amp, level, tag = [match.group(i) for i in (1,2,3,4,5,6)] 79 sweep, level = int(sweep), int(level) 80 secs, preamp, amp, tag = map(float, (secs, preamp, amp, tag)) 81 if seg_ix != sweep: 82 set_seg_dwells() 83 classes[:] = [] 84 durations[:] = [] 85 last_level = 0 86 seg_ix = sweep 87 88 if secs < last_secs: 89 last_secs = 0.0 90 dt = 1e3 * (secs - last_secs) 91 last_secs = secs 92 93 classes.append(last_level) 94 durations.append(dt) 95 while len(amps) <= level: 96 amps.append(0.0) 97 amps[level] = amp * 1e12 98 last_level = level 99 if durations: 100 classes.append(last_level) 101 durations.append(min(durations)) 102 set_seg_dwells() 103 104 return data 105 106 SetReader('.tacidl', 'TacFit transition table', OpenTACidl) 107