Commit 16cd9bd9 authored by Emmanuel Papillon's avatar Emmanuel Papillon
Browse files

fit shutter calibration debug

parent 7d55accc
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function, division
import sys, numpy as np, pylab as pl import sys, numpy as np, pylab as pl
...@@ -33,8 +31,6 @@ def fitshutter_all( x, y ): ...@@ -33,8 +31,6 @@ def fitshutter_all( x, y ):
returns: y_cut, xcuts[N], signs[N], xerrs[N] returns: y_cut, xcuts[N], signs[N], xerrs[N]
""" """
print(x)
print(y)
first_cut = 0.5*( y.max() + y.min() ) # mid-height first_cut = 0.5*( y.max() + y.min() ) # mid-height
beam_on = y[ y > first_cut ] # y-vals in beam beam_on = y[ y > first_cut ] # y-vals in beam
beam_off = y[ y < first_cut ] # y-vals in dark beam_off = y[ y < first_cut ] # y-vals in dark
......
from bliss.config.settings import HashObjSetting from bliss.config.settings import HashObjSetting
from bliss import current_session from bliss import current_session
from .fshuttercalibration import FastShutterCalibration from .fshuttercalib import FastShutterCalibration
class FastShutter: class FastShutter:
...@@ -104,6 +104,6 @@ class FastShutter: ...@@ -104,6 +104,6 @@ class FastShutter:
raise RuntimeError("No shutter calibration available !!") raise RuntimeError("No shutter calibration available !!")
return self.__calib return self.__calib
def measure(self): def measure(self, open_time=1., acq_time=100e-6, delay=200e-3):
self.calibration.measure() self.calibration.measure(open_time, acq_time, delay)
...@@ -61,17 +61,18 @@ class FastShutterCalibration(object): ...@@ -61,17 +61,18 @@ class FastShutterCalibration(object):
chain = AcquisitionChain() chain = AcquisitionChain()
musst_time_factor = musst.get_timer_factor() musst_time_factor = self.__musst.get_timer_factor()
musst_master = MusstAcquisitionMaster(self.__musst, program_data=_MUSST_PRG, musst_master = MusstAcquisitionMaster(self.__musst, program_data=_MUSST_PRG,
program_start_name="SHUTTER", program_start_name="SHUTTER",
vars={'START_DELAY':int(delay*musst_time_factor), vars={'START_DELAY':int(delay*musst_time_factor),
'GATEWIDTH':int(open_time*musst_time_factor)}) 'GATEWIDTH':int(open_time*musst_time_factor)})
npoints = int((delay + open_time + 2*self.__shutter.shutter_time)/acq_time) npoints = int((open_time + 2*self.__shutter.shutter_time)/acq_time)
dead_time = 1e-6
p201_master = CT2AcquisitionMaster(self.__p201, p201_master = CT2AcquisitionMaster(self.__p201,
npoints=npoints, npoints=npoints,
acq_mode=AcqMode.ExtTrigSingle, acq_mode=AcqMode.ExtTrigSingle,
acq_expo_time=acq_time-1e-6, acq_expo_time=acq_time-dead_time,
acq_point_period=acq_time) acq_point_period=acq_time)
chain.add(musst_master,p201_master) chain.add(musst_master,p201_master)
...@@ -80,21 +81,22 @@ class FastShutterCalibration(object): ...@@ -80,21 +81,22 @@ class FastShutterCalibration(object):
chain.add(p201_master, acq_device) chain.add(p201_master, acq_device)
#calc #calc
class _CumSum(object): class TimeCumSum(object):
def __init__(self, cnt_name): def __init__(self, cnt_name, dead_time=0.):
self.previous_time = 0 self.previous_time = 0
self.cnt_name = cnt_name self.cnt_name = cnt_name
self.dead_time = dead_time
def __call__(self, sender, data_dict): def __call__(self, sender, data_dict):
data = data_dict.get(self.cnt_name) data = data_dict.get(self.cnt_name)
if data is None: if data is None:
return {} return {}
data = data + self.dead_time
data = numpy.cumsum(data) + self.previous_time data = numpy.cumsum(data) + self.previous_time
self.previous_time = data[-1] self.previous_time = data[-1]
return {'time': data} return {'time': data}
calc_device = CalcChannelAcquisitionSlave('time_cumsum',(acq_device,), calc_device = CalcChannelAcquisitionSlave('time_cumsum',(acq_device,),
_CumSum(self.__timer.name), TimeCumSum(self.__timer.name, dead_time),
(AcquisitionChannel('time',numpy.float,()),)) (AcquisitionChannel('time',numpy.float,()),))
chain.add(p201_master, calc_device) chain.add(p201_master, calc_device)
...@@ -108,12 +110,16 @@ class FastShutterCalibration(object): ...@@ -108,12 +110,16 @@ class FastShutterCalibration(object):
scan.run() scan.run()
print("Scan finished.") print("Scan finished.")
data= scan.get_data() self.__data= scan.get_data()
self.measurement_fit(data, open_time) time_data = self.__data["time"]
sig_data = self.__data[self.__diode.fullname]
print("Running fit procedure ...")
self.measurement_fit(time_data, sig_data, open_time)
def measurement_fit(self, data, exp_time): def measurement_fit(self, timedata, sigdata, exp_time):
data_timer = data[self.__timer.name] o, c, oe, ce = fitshutter(timedata, sigdata, exp_time, plot_title="Fast Shutter Calibration")
data_diode = data[self.__diode.name] print("Fit Results:")
o, c, oe, ce = fitshutter(data_timer, data_diode, exp_time, plot_title="Fast Shutter Calibration") print(f" Open time : {o:f} +/- {oe:f} sec")
print("Shutter Open: %f +/- %f , Close %f +/- %f"%(o, oe, c, ce )) print(f" Close time : {c:f} +/- {ce:f} sec")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment