Commit 0b8018d5 authored by Samuel Debionne's avatar Samuel Debionne
Browse files

[CLIENT] Add simulator 4M script

parent 975146ac
#!/bin/python3
import json
acq_params = {
"acq": {
"expo_time": 10,
"latency_time": 990,
"nb_frames": 20
},
"xfer": {
"time_slice": { "start":0, "count": 20}
},
#"img": {
# "roi": {"topleft": {"x": 128, "y": 128}, "dimensions": {"x": 256, "y": 256}}
#}
"det": {
"pixel_type": "gray16",
'generator_type': 'gauss',
'nb_prefetch_frames': 2,
'grow_factor': 0.3,
'peaks': [{'x0': 1024.0 + 128.0, 'y0': 1024.0 - 256.0, 'fwhm': 128.0, 'max': 100.0}]
}
}
params_base = "/nobackup/lid29pwr9/shared/lima2/detectors/simulator/data/processing"
fai_kernels_base = "/users/debionne/source/.vs/lima2/53b0100f-6e47-4325-9d48-81117e566430/src/processings/common/fai/kernels"
proc_params = {
"fifo": {
"nb_fifo_frames": 1000
},
"saving_dense": {
"base_path": "/nobackup/lid29pwr92/tmp",
"filename_prefix" : "output_dense",
"nb_frames_per_file": 10,
"file_exists_policy": "overwrite"
},
"saving_sparse": {
"base_path": "/nobackup/lid29pwr92/tmp",
"filename_prefix" : "output_sparse",
"nb_frames_per_file": 10,
"file_exists_policy": "overwrite"
},
"counters": {
"rois": [{"topleft": {"x": 128, "y": 128}, "dimensions": {"x": 256, "y": 256}}]
},
"gpu" :{
"device_idx": 0
},
"jfrau" :{
"gain_path": params_base + "/simulator_4M/gains.h5",
"pedestal_path": params_base + "/simulator_4M/pedestals.h5",
},
"fai": {
#"mask_path": fai_params_base + "/jungfrau_500k_307/mask_wg.h5",
"csr_path": params_base + "/simulator_4M/csr.h5",
"radius2d_path": params_base + "/simulator_4M/r_center.h5",
"radius1d_path": params_base + "/simulator_4M/bin_centers.h5",
"dummy": 0.0,
"delta_dummy": 0.0,
"normalization_factor": 1.0,
"cutoff_clip": 5.0,
"cycle": 5,
#"empty": 0.0,
"noise": 1.0,
"cutoff_pick": 3.0,
"cl_source_path": fai_kernels_base
}
}
import gevent
import sys
import tango
from Lima2.Client.Detector import Detector
from uuid import uuid1
device = Detector("id00/limacontrol/sam_simulator_smx", "id00/limareceiver/sam_simulator_smx")
def run_acquisition(device):
# FSM follower
def state_monitor(follower):
for state in follower:
print(f'Monitor: state={state}')
print('Monitor finished!')
follower = device.createStateFollower()
monitor = gevent.spawn(state_monitor, follower)
try:
device.acq_params.update(device.AcqParams(acq_params))
print(device.acq_params)
device.proc_params.update(device.ProcParams(proc_params))
print(device.proc_params)
uuid = uuid1()
print(f'UUID={uuid}')
with device.prepareAcq(uuid) as proc:
print(f'State={device.getState()}')
print(f'Counters={proc.counters}')
roi_counters = []
peak_counters = []
device.startAcq()
print(f'State={device.getState()}')
event = device.getNotStateEvent(Detector.State.Running)
# Simulate a Stop when about half of the frames are in the pipeline
nb_frames_before_stop = device.acq_params.acq.nb_frames
while not event.ready() and device.nb_frames_xferred < nb_frames_before_stop:
print(f'nb_frames_xferred={device.nb_frames_xferred}')
print(f'Counters={proc.counters}')
# ROI counter acquisition 5 at a time
rc = proc.popRoiCounters(5)
roi_counters.append(rc)
# Peak counter acquisition 5 at a time
pc = proc.popPeakCounters(5)
peak_counters.append(pc)
gevent.sleep(1.0)
# If acquisition is still running, stop it
if device.getState() == Detector.State.Running:
print(f'##### STOP #####')
device.stopAcq()
print(f'State={device.getState()}')
print(f'nb_frames_xferred={device.nb_frames_xferred}')
print(f'Counters={proc.counters}')
# Wait for the end of the processing
while not proc.is_finished(device.nb_frames_xferred):
print(f'Counters={proc.counters}')
gevent.sleep(1.0)
print(f'Counters={proc.counters}')
while rc := proc.popRoiCounters(5):
# ROI counter acquisition
roi_counters.append(rc)
gevent.sleep(1.0)
#print(f'ROI Counters={roi_counters}')
#print(f'Frame={proc.getFrame(device.nb_frames_xferred - 1)}')
if device.getState() == Detector.State.Closing:
event = device.getStateEvent(Detector.State.Idle)
input('Press Enter to close')
except tango.DevFailed as e:
print(e)
finally:
sys.exc_info()
monitor.join()
run_acquisition(device)
Supports Markdown
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