Package reflectometry :: Package reduction :: Module normcor

Source Code for Module reflectometry.reduction.normcor

 1  # This program is public domain 
 2   
 3  """ 
 4  Monitor normalization correction. 
 5  """ 
 6   
 7  from numpy import sqrt 
 8  from reflectometry.reduction.correction import Correction 
 9  from reflectometry.reduction import err1d 
10   
11 -class Normalize(Correction):
12 - def __init__(self, base='auto'):
13 """ 14 Define the kind of monitor normalization. 15 base is 'time', 'counts', 'power', 'auto' or 'none'. 16 """ 17 self.base = base
18
19 - def apply(self, data):
20 base = data.monitor.base if self.base == 'auto' else self.base 21 C = data.detector.counts 22 varC = C # Poisson stats 23 if base == 'counts': 24 M = data.monitor.counts 25 varM = M # Poisson stats 26 units = 'counts per monitor count' 27 elif base == 'time': 28 M = data.monitor.count_time 29 # Uniform distribution has variance of interval/12 30 varM = data.monitor.time_step/12. 31 units = 'counts per second' 32 elif base == 'power': 33 M = data.monitor.source_power 34 varM = 0 35 units = 'counts per '+data.monitor.source_power_units 36 elif base == 'none': 37 M = 1 38 varM = 0 39 units = 'counts' 40 else: 41 raise ValueError,\ 42 "Expected normalization of auto, counts, time, power or none" 43 data.R,data.varR = err1d.div(C,varC,M,varM) 44 data.vunits = units 45 data.vlabel = 'Intensity'
46
47 - def __str__(self):
48 return "Normalize('%s')"%self.base
49