Commit 7cb2ce66 authored by bliss administrator's avatar bliss administrator
Browse files

last version of sweep scan + add 'time' mode for musst synchronisation in fasttomo

parent 9201c532
......@@ -36,11 +36,12 @@ class CScanMusstChanTrigCalc(object):
self._source_name = source_name
self._factor = factor
self._dest_name = dest_name
print(source_name)
self._data = numpy.zeros((0), dtype=numpy.int32)
def __call__(self, sender, data_dict):
data = data_dict.get(self._source_name)
print(data)
if data is None:
return {}
......@@ -59,6 +60,7 @@ class CScanMusstChanTrigCalc(object):
mean_data.append((up+down)/2.)
delta_data.append(down-up)
print(mean_data)
if not len(up_data):
return {}
......@@ -120,7 +122,7 @@ class CScanMusstChanStepCalc(object):
class CScanDisplay(object):
def __init__(self,motors,nb_points):
def __init__(self,motors,detector,nb_points):
try:
iter(motors)
except TypeError:
......@@ -132,6 +134,7 @@ class CScanDisplay(object):
for x in motors))
self.motor_display_pos = dict()
self.nb_points = nb_points
self.detector = detector
def on_state(self,state):
return True
......@@ -145,20 +148,20 @@ class CScanDisplay(object):
data_node = nodes.get(acq_device)
if is_zerod(data_node):
channel_name = data_node.name
if channel_name.lower() in self.motors_name:
if channel_name == 'CH3':
channel = data_node
mot_pos = channel.get(-1) # last
nb_pos = len(channel)
last_pos,last_nb_pos,acc_cnt = self.last_motor_pos.get(channel_name.lower())
last_pos,last_nb_pos,acc_cnt = self.last_motor_pos.get('hrsrot')
if last_nb_pos == nb_pos:
continue
acc_cnt += numpy.int32(mot_pos) - numpy.int32(last_pos)
self.last_motor_pos[channel_name.lower()] = (mot_pos,nb_pos,acc_cnt)
start_pos = self.motor_start_position.get(channel_name.lower())
mot = self.motors_name.get(channel_name.lower())
self.last_motor_pos['hrsrot'] = (mot_pos,nb_pos,acc_cnt)
start_pos = self.motor_start_position.get('hrsrot')
mot = self.motors_name.get('hrsrot')
current_pos = start_pos + acc_cnt / _step_per_unit(mot)
display = '%.4f' % current_pos
self.motor_display_pos[channel_name.lower()] = display
self.motor_display_pos['hrsrot'] = display
display = ''
motor_name = None
for motor_name,disp in self.motor_display_pos.items():
......@@ -167,6 +170,8 @@ class CScanDisplay(object):
if motor_name is not None:
_,musst_trig_position,_ = self.last_motor_pos.get(motor_name)
display += 'musst trig (%d/%d) ' % (musst_trig_position/2,self.nb_points)
current_image = self.detector.proxy.last_image_ready+1
display +='image acquired: (%s/%s)' % (current_image,self.nb_points)
if display:
print(display,'\r'),
......
......@@ -23,9 +23,10 @@ from id19.opiom_preset import *
from id19.setup import *
from id19.TomoCcd import *
from id19.ChainPreset import *
from id19.scan_tools import *
def fasttomo(motor, start, end, images, proj_per_group = 0, ctime=0.05, safe_time=0, run=True):
def fasttomo(trigger, motor, start, end, images, proj_per_group = 0, ctime=0.05, safe_time=0, run=True):
if proj_per_group > 0:
nb_ref_groups = int(images/proj_per_group)
......@@ -51,7 +52,7 @@ def fasttomo(motor, start, end, images, proj_per_group = 0, ctime=0.05, safe_tim
start_motor_pos = np.linspace(start,end,nb_ref_groups+1)[:-1]
group_range = float(start_motor_pos[1]-start_motor_pos[0])
group_range = float(end - start)/nb_ref_groups
scan_step_size = group_range / proj_per_group
......@@ -84,12 +85,6 @@ def fasttomo(motor, start, end, images, proj_per_group = 0, ctime=0.05, safe_tim
musst_card.ABORT
enc_channel = musst_card.get_channel_by_name(motor.name)
# --- set encoder value
motor.wait_move()
motor_position = motor.position
enc_channel.value = int(round((motor_position*motor.steps_per_unit+0.5)//1))
mot_chan = enc_channel.channel_id
......@@ -99,7 +94,6 @@ def fasttomo(motor, start, end, images, proj_per_group = 0, ctime=0.05, safe_tim
gatewidth = int(ctime*musst_card.get_timer_factor())
# --- position mode
trigger = 'position'
if trigger == "position":
pos_delta = [scan_step_size*motor.steps_per_unit]*nb_ref_groups
enc_delta = [int(delta) for delta in pos_delta]
......@@ -132,6 +126,29 @@ def fasttomo(motor, start, end, images, proj_per_group = 0, ctime=0.05, safe_tim
"MOTERR" : mot_error[i]
})
if trigger == "time":
time_delta = int(scan_point_time*musst_card.get_timer_factor())
npulses = [proj_per_group]*nb_ref_groups
if last_group_proj != proj_per_group:
npulses[-1] = last_group_proj
first_iter_vars = {"MOTCHAN" : mot_chan,
"MOTZERO" : mot_zero[0],
"PTCHAN" : 0,
"PTDELTA" : time_delta,
"GATEMODE" : 0,
"NPULSES" : npulses[0],
"GATEWIDTH" : gatewidth,
"STOREMASK": storemask
}
musst_vars = [first_iter_vars]
for i in range(1,nb_ref_groups):
musst_vars.append({
"MOTZERO" : mot_zero[i],
"NPULSES" : npulses[i],
})
print(musst_vars)
# MUSST device
store_list = ["TIMER","CH"+str(mot_chan)]
......
......@@ -15,15 +15,26 @@ import bliss
import time
from bliss.common import axis
from bliss.common import event
from bliss import setup_globals
from id19.opiom_preset import *
from id19.setup import *
from id19.scan_tools import *
from id19.TomoCcd import *
def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, latency=0):
def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, safe_time=0):
detector = ScanSettings().get('detector')
detector_device = setup_globals.config.get(detector)
scan_point_time = ctime
readout_time = TomoCcd(detector_device).calibrate_ccd_readout_time(ctime)
if safe_time != 0:
latency_time = safe_time
else:
latency_time = 0.005 if images*ctime/60 >= 5 else 0.002
scan_point_time = ctime + readout_time + latency_time
scan_step_size = float(end - start) / images
......@@ -35,15 +46,14 @@ def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, latenc
motor_master = SweepMotorMaster(motor, start, end, images, time=scan_point_time)
min_undershoot_steps = 40
min_undershoot_steps = 60
if motor_master._undershoot*motor.steps_per_unit < min_undershoot_steps:
print('start margin added')
print('fixing undershoot value at 0.005')
motor_master = SweepMotorMaster(motor, start, end, images, time=scan_point_time, undershoot_start_margin = 0.005)
motor_master = SweepMotorMaster(motor, start, end, images, time=scan_point_time, undershoot = 0.005)
print(motor_master._undershoot_start_margin+motor_master._undershoot)
musst_card = setup_globals.config.get("musst")
......@@ -87,7 +97,7 @@ def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, latenc
calc_data = dict()
if sender.name == 'CH%d'%mot_chan:
enc_pos = channel_data.get(sender.name)
mot_pos = enc_pos[0] / motor.steps_per_unit
mot_pos = enc_pos / motor.steps_per_unit
calc_data[motor.name.upper()] = mot_pos
return calc_data
......@@ -116,7 +126,7 @@ def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, latenc
# store incoming data as [step_time1,step_pos1,step_time2,step_pos2,...]
data.extend(list(channel_data.get(sender.name)))
if len(data) == 2*(images-1):
# when all data are stored, calculate speed
# when all data are stored, calculate speed
calc_data['SPEED_STEP'] = np.array(data[1::2])/np.array(data[0:-1:2])
return calc_data
......@@ -127,13 +137,10 @@ def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, latenc
chain.add(motor_master,musst_device)
detector = ScanSettings().get('detector')
# Lima master
detector_device = setup_globals.config.get(detector)
lima_master = LimaAcquisitionMaster(detector_device,
acq_nb_frames=images,
acq_trigger_mode='EXTERNAL_TRIGGER_MULTI',
acq_trigger_mode='EXTERNAL_GATE',
acq_expo_time=ctime,
save_flag=True,
prepare_once=True,
......@@ -143,47 +150,13 @@ def cont_wo_gap_scan(motor, start, end, images, ctime=0.05, readout=0.05, latenc
chain.add(musst_device,lima_master)
setup_globals.SCAN_SAVING.base_path = '/data/id19/inhouse/clemence'
opiom_mode = ScanSettings().get('opiom_mode')
#opiom_mode = ScanSettings().get('opiom_mode')
opiom_mode = 'HR_FTOMO_PCO_GATE'
chain.add_preset(OpiomSettingsPreset(opiom_mode))
scan = Scan(chain, data_watch_callback=CScanDisplay(motor,images))
scan = Scan(chain, data_watch_callback=CScanDisplay(motor,detector_device,images))
scan.run()
#scan.run()
return scan
class ScanDisplayData(object):
def __init__(self,motor,detector):
self.detector = detector
self.motor = motor
def on_state(self,state):
return True
def __call__(self,data_events,nodes,info):
display = False
for acq_device,events in data_events.items():
data_node = nodes.get(acq_device)
if is_zerod(data_node):
#display = True
#self.display = ''
if data_node.name == 'CH3':
print('trigger position: {}'.format(data_node.get(-1)/self.motor.steps_per_unit))
if data_node.get(-1) == data_node.get(-2) or data_node.get(-1) == data_node.get(0):
print('image acquired: {}'.format(self.detector.proxy.last_image_ready+1))
if display:
print(self.display),
sys.stdout.flush()
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