ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/cal_module.py
(Generate patch)
# Line 1 | Line 1
1   """
2 < cal: Calibration module for SPRI data in a ba class.
3 < Christopher Lausted, Institute for Systems Biology,
4 < OSPRAI developers
5 < Last modified on 101116 (yymmdd)
6 <
7 < Example:
8 < #import cal_module as cal
9 < #io_module as io
10 < #baC = io.readsprit("calibrationdata.txt")
11 < #ba1 = io.readsprit("spritdata.txt")
12 < #ba2 = cal.calibrate(ba1, baCal, t1, t2, n1, n2)
13 < #cal.bgset(ba2, bgroi)
14 < #ba3 = cal.bgsubt(ba2)
2 > cal_module
3 > ----------
4 >
5 > Calibration module for SPRI data in a ba_class.
6 > This uses a known jump in index to turn arbitrary units into RIU.
7 > Other routines provide background subtraction and data rearrangement.
8 >
9 > .. moduleauthor:: Christopher Lausted,
10 >                  Institute for Systems Biology,
11 >                  OSPRAI developers.                      
12 > Examples::
13 >
14 >  >>> import cal_module as cal
15 >  >>> io_module as io
16 >  >>> baC = io.readsprit("calibrationdata.txt")
17 >  >>> ba1 = io.readsprit("spritdata.txt")
18 >  >>> ba2 = cal.calibrate(ba1, baCal, t1, t2, n1, n2)
19 >  >>> cal.bgset(ba2, bgroi)
20 >  >>> ba3 = cal.bgsubt(ba2)
21   """
22 < __version__ = "100426"
22 > __version__ = "110204"
23  
24  
25   ## Import libraries
# Line 26 | Line 32
32      """
33      Use data in baCal to calibrate ba0.
34      A simple two-point linear calibration using timepoints t1 and t2 and
35 <    corresponding refractive indices n1 and n2. If n1 and n2 are not given,  
30 <    assume 1x PBS (n1=1335700uRIU) and 2xPBS (n2=1336600uRIU).
35 >    corresponding refractive indices n1 and n2.
36      Average 30 seconds of data (t-15 to 5+15 seconds).
37      The ba object returned will remember the slopes and intercepts used.
38 +    
39 +    :param ba0: Object containing the data to be calibrated.
40 +    :type ba0: ba_class
41 +    :param baCal: Object containing the data to be calibrated.
42 +    :type baCal: ba_class
43 +    :param t1: Timepoint where refractive index = n1
44 +    :type t1: float
45 +    :param t2: Timepoint where refractive index = n2
46 +    :type t2: float
47 +    :param n1: First refractive index. Default=1335700 (~1x PBS).
48 +    :type n1: float
49 +    :param n2: Second refractive index. Default=1336600 (~2x PBS).
50 +    :type n2: float
51 +    :returns: nothing
52      """
53      ## Error checking
54      if (len(ba0.roi) != len(baCal.roi)):
# Line 49 | Line 68
68          ba2.roi[i].calibB = intercept
69          ba2.roi[i].value = ba0.roi[i].value * slope + intercept  ## type np.array.
70      return ba2
71 <    ## End of calibrate().
71 >    """End of calibrate()"""
72      
73      
74   def bgsubt(ba0):
75 <    """Apply the background subtraction and return a new ba object."""
75 >    """
76 >    Apply the background subtraction and return a new ba object.
77 >    
78 >    :param ba0: Object containing the source data.
79 >    :type ba0: ba_class
80 >    :returns: A new ba object
81 >    """
82      ba1 = deepcopy(ba0)
83      for i in range(len(ba0.roi)):
84          bg = ba0.roi[i].bgroi[0]  ## TODO: Only uses first bgroi for now.
85          bg -= 1                   ## Decide if index or id base 0 or 1.
86          ba1.roi[i].value = ba0.roi[i].value - ba0.roi[bg].value  ## type np.array.
87      return ba1
88 <    ## End of bgsubt().
88 >    """End of bgsubt()"""
89      
90        
91   def bgset(ba0, i):
92 <    """Set i as the background ROI for all of the ROIs."""
92 >    """
93 >    Set i as the background ROI for all of the ROIs.
94 >    
95 >    :param ba0: Object containing the data to be calibrated.
96 >    :type ba0: ba_class
97 >    :param i: Object containing the data to be calibrated.
98 >    :type i: ba_class
99 >    :returns: nothing
100 >    """
101      for iroi in ba0.roi: iroi.bgroi = [i]
102      return
103 <    ## End of bgset().
103 >    """End of bgset()"""
104  
105  
106   def copyinterval(ba0, t1, t2):
107 <    """Copy data from the interval between t1 and t2 and return a new ba object."""
107 >    """
108 >    Copy data from the interval between t1 and t2 and return a new ba object.
109 >    
110 >    :param ba0: Object containing the source data.
111 >    :type ba0: ba_class
112 >    :param t1: Beginning timepoint.
113 >    :type t1: float
114 >    :param t2: Ending timepoint.
115 >    :type t2: float
116 >    :returns: A new ba object
117 >    """
118      ba1 = deepcopy(ba0)
119      for i in range(len(ba0.roi)):
120          dp1 = ba0.roi[i].time2dp(t1)
# Line 79 | Line 122
122          ba1.roi[i].time = ba1.roi[i].time[dp1:dp2]
123          ba1.roi[i].value = ba1.roi[i].value[dp1:dp2]
124      return ba1
125 <    ## End of copyinterval().
125 >    """End of copyinterval()"""
126  
127  
128   def zerotime(ba):
129 <    """Adjust sensorgrams to start at time[0]=0."""
129 >    """
130 >    Adjust sensorgrams to start at time[0]=0.
131 >    
132 >    :param ba: Object containing the data.
133 >    :type ba: ba_class
134 >    :returns: nothing
135 >    """
136      for roi in ba.roi:
137          if (len(roi.time) > 0):
138              roi.time -= roi.time[0]
139      return
140 <    ## End of zerotime().
140 >    """End of zerotime()"""
141      
142      
143   def zerovalue(ba):
144 <    """Adjust sensorgrams to start at value[0]=0."""
144 >    """
145 >    Adjust sensorgrams to start at value[0]=0.
146 >    
147 >    :param ba: Object containing the data.
148 >    :type ba: ba_class
149 >    :returns: nothing
150 >    """
151      for roi in ba.roi:
152          if (len(roi.value) > 0):
153              roi.value -= roi.value[0]
154      return
155 <    ## End of zerovalue().
155 >    """End of zerovalue()"""
156  
102 ################################# End of module #################################
157 + ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines