ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/cal_module.py
Revision: 12
Committed: Tue Apr 13 01:33:13 2010 UTC (9 years, 3 months ago) by clausted
File size: 1774 byte(s)
Log Message:
Addition of cal_module to provide a calibration tool and related features.  Added the time2val function to the ba class.  It has a bug now, but it will be useful for the calibration tool.
Line User Rev File contents
1 clausted 12 """
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 100412 (yymmdd)
6    
7     Example:
8     #import cal_module as cal
9     #io_module as io
10     #ba1 = io.readsprit("spritdata.txt")
11     #ba2 = cal.calibrate(ba1, (t1,t2), (n1,n2))
12     """
13     __version__ = "100412"
14    
15    
16     ## Import libraries
17     import ba_class as ba
18     import numpy as np
19     from copy import deepcopy
20    
21    
22     def calibrate(ba0, ba1, t1, t2, n1=1335700, n2=1336600):
23     """
24     Use data in ba1 to calibrate ba0.
25     A simple two-point linear calibration using timepoints t1 and t2 and
26     corresponding refractive indices n1 and n2. If n1 and n2 are not given,
27     assume 1x PBS (n1=1335700uRIU) and 2xPBS (n2=1336600uRIU).
28     Average 30 seconds of data (t-15 to 5+15 seconds).
29     The ba object returned will remember the slopes and intercepts used.
30     """
31     ## Error checking
32     if (len(ba0.roi) != len(ba1.roi)):
33     print "Error: The ba objects are of different size."
34     return ba0
35     ## Continue.
36     ba2 = deepcopy(ba0)
37     for i, iroi in enumerate(ba1.roi):
38     ## Average values of camera units around t1 and t2.
39     cu1 = np.average(iroi.time2val(t1-15, t1+15))
40     cu2 = np.average(iroi.time2val(t2-15, t2+15))
41     ## Calculate and record slope and intercept parameters.
42     slope = (n2 - n1) / (cu2 - cu1)
43     intercept = n2 - (slope * cu2)
44     ## Apply the calibration to the new ba object.
45     ba2.roi[i].calibM = slope
46     ba2.roi[i].calibB = intercept
47     ba2.roi[i].value = ba0.value * slope + intercept ## type np.array
48     return ba2
49     ## End of calibrate().
50    
51     ################################# End of module #################################