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 twopoint 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 (t15 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(t115, t1+15))

40 


cu2 = np.average(iroi.time2val(t215, 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 ################################# 