Commit 4e42fae8 authored by Jibril Mammeri's avatar Jibril Mammeri Committed by bliss administrator
Browse files

Setup and scan_info restructuration

parent 601c955a
......@@ -311,6 +311,8 @@ class Tomo(TomoParameters):
self.scan_prepare = False
self.fasttomo = tomo.FastTomo(self)
self.halftomo = tomo.HalfTomo(self)
self.pcotomo = tomo.PcoTomo(self)
self.topotomo = tomo.TopoTomo(self)
self.sequence = "tomo:basic"
self.field_of_view = "Full"
self.active_tomo = self.fasttomo
......@@ -696,6 +698,143 @@ class Tomo(TomoParameters):
else:
break
def pcotomo_setup(self):
dlg_ntomo = UserIntInput(
label="Number of Consecutive Tomo?", defval=self.pcotomo.parameters.ntomo
)
dlg_nwait = UserIntInput(
label="Number of Waiting Turns between Tomo?",
defval=self.pcotomo.parameters.nwait,
)
dlg_nloop = UserIntInput(
label="Number of Repetitions (Consecutive Tomo + Waiting Turns)?",
defval=self.pcotomo.parameters.nloop,
)
dlg_useroutput = UserIntInput(
label="User Output after Repetition Number?",
defval=self.pcotomo.parameters.user_output,
)
dlg_startturn = UserIntInput(
label="Number of Turns before Starting?",
defval=self.pcotomo.parameters.start_turn,
)
ret = BlissDialog(
[[dlg_ntomo], [dlg_nwait], [dlg_nloop], [dlg_useroutput], [dlg_startturn]],
title="PcoTomo Setup",
).show()
# returns False on cancel
if ret != False:
self.pcotomo.parameters.ntomo = ret[dlg_ntomo]
self.pcotomo.parameters.nwait = ret[dlg_nwait]
self.pcotomo.parameters.nloop = ret[dlg_nloop]
self.pcotomo.parameters.user_output = ret[dlg_useroutput]
self.pcotomo.parameters.start_turn = ret[dlg_startturn]
self.pcotomo_mode_setup()
def pcotomo_mode_setup(self):
self.pcotomo.calculate_parameters()
dlg_trans_rate = UserMsg(
label=f"Transfer Rate: {self.pcotomo.in_pars['transferrate']} MB/s"
)
dlg_roi = UserMsg(
label=f"ROI: {self.tomo.tomo_ccd.detector.image.width} x {self.tomo.tomo_ccd.detector.image.height}\n"
)
dlg_continuous_mode = UserCheckBox(
label="Consecutive Scans Without Waiting Turns"
)
dlg_max_nb_scans = UserMsg(
label=f"You can collect a maximum of {self.pcotomo.in_pars['numberofscans']} scans in the memory"
)
dlg_one_scan_size = UserMsg(
label=f"One scan is {round(self.pcotomo.in_pars['sizeofonescan'] * 1024 * 1024 * 1024, 2)} B or {round(self.pcotomo.in_pars['sizeofonescan'], 2)} GB"
)
dlg_acq_time = UserMsg(
label=f"It means a film of {self.pcotomo.in_pars['totalcontinuoustime']} s ({round(self.pcotomo.in_pars['totalcontinuoustime'] / 60, 2)} min)\n"
)
dlg_saving_time = UserMsg(
label=f"Time to download film: "
f"{round((self.pcotomo.in_pars['sizeofonescan'] * self.pcotomo.in_pars['numberofscans']) / (self.pcotomo.in_pars['transferrate'] / 1024), 2)} s ("
f"{round((self.pcotomo.in_pars['sizeofonescan'] * self.pcotomo.in_pars['numberofscans']) / (self.pcotomo.in_pars['transferrate'] / 1024) / 60, 2)} min)\n"
)
ct1 = Container(
[
dlg_continuous_mode,
dlg_max_nb_scans,
dlg_one_scan_size,
dlg_acq_time,
dlg_saving_time,
],
title="Continuous Mode",
)
dlg_multiple_mode = UserCheckBox(label="Waiting Turns Between Each Scan")
dlg_nb_scans = UserMsg(
label=f"You will collect a total of {self.pcotomo.in_pars['numberofscans']} scans\n"
)
dlg_waiting_turns = UserMsg(
label=f"You will wait {self.parameters.nwait} turns between each scan"
)
dlg_acq_time = UserMsg(
label=f"One scan of {self.pcotomo.in_pars['time']} s every {self.pcotomo.in_pars['frequency']} s during {self.pcotomo.in_pars['totaltime']} s ({round(self.pcotomo.in_pars['totaltime'] / 60, 2)} min) \n"
)
dlg_saving_time = UserMsg(
label=f"Time to download film: {round((self.pcotomo.in_pars['sizeofonescan'] * self.pcotomo.in_pars['numberofscans']) / (self.pcotomo.in_pars['transferrate'] / 1024), 2)} s ("
f"{round((self.pcotomo.in_pars['sizeofonescan'] * self.pcotomo.in_pars['numberofscans']) / (self.pcotomo.in_pars['transferrate'] / 1024) / 60, 2)} min)\n"
)
ct2 = Container(
[
dlg_multiple_mode,
dlg_nb_scans,
dlg_waiting_turns,
dlg_acq_time,
dlg_saving_time,
],
title="Multiple Mode",
)
dlg_endless_mode = UserCheckBox(label="Downloading Between Each Scan")
dlg_waiting_turns = UserMsg(
label=f"You will wait around {self.pcotomo.in_pars['unlimitwaitingturns']} turns between each scan, during this time, scan is downloaded"
)
dlg_acq_time = UserMsg(
label=f"One scan of {self.pcotomo.in_pars['time']} s every {self.pcotomo.in_pars['unlimitfrequency']} s FOREVER \n"
)
dlg_saving_time = UserMsg(
label=f"Time to download one scan: {round(self.pcotomo.in_pars['sizeofonescan'] / (self.pcotomo.in_pars['transferrate'] / 1024), 2)} s "
f"({round(self.pcotomo.in_pars['sizeofonescan'] / (self.pcotomo.in_pars['transferrate'] / 1024) / 60, 2)} min) \n"
)
ct3 = Container(
[dlg_endless_mode, dlg_waiting_turns, dlg_acq_time, dlg_saving_time],
title="Endless Mode",
)
ret = BlissDialog(
[[dlg_trans_rate, dlg_roi], [ct1], [ct2], [ct3]], title="Mode Setup"
).show()
# returns False on cancel
if ret != False:
if ret[dlg_continuous_mode]:
self.pcotomo.parameters.mode = "consecutive"
self.pcotomo.parameters.noread = 1
elif ret[dlg_multiple_mode]:
self.pcotomo.parameters.mode = "multiple"
self.pcotomo.parameters.noread = 1
elif ret[dlg_endless_mode]:
self.pcotomo.parameters = "endless"
self.pcotomo.parameters.noread = 0
self.ppcotomo.arameters.nwait = -1
def return_scan(self, scan_sequence=None, header={}, save=True, run=True):
"""
Acquires static images on scan return.
......@@ -1339,6 +1478,9 @@ class Tomo(TomoParameters):
print(
f"Approximative Estimated Scan Time: {self.in_pars['estimated_time_scan']}"
)
self.active_tomo.scan_info()
print("=================================================================")
def pco_tomo(
......@@ -1368,29 +1510,27 @@ class Tomo(TomoParameters):
self.parameters.tomo_n = tomo_n
self.parameters.exposure_time = expo_time
pcotomo = tomo.PcoTomo(self)
self.active_tomo = pcotomo
self.active_tomo = self.pcotomo
pcotomo.parameters.mode = mode
pcotomo.parameters.user_output = user_output
pcotomo.parameters.start_turn = start_turn
self.pcotomo.parameters.mode = mode
self.pcotomo.parameters.user_output = user_output
self.pcotomo.parameters.start_turn = start_turn
if mode == "consecutive":
pcotomo.parameters.ntomo = ntomo
pcotomo.parameters.nloop = 1
pcotomo.parameters.noread = 1
pcotomo.parameters.nwait = 0
self.pcotomo.parameters.ntomo = ntomo
self.pcotomo.parameters.nloop = 1
self.pcotomo.parameters.noread = 1
self.pcotomo.parameters.nwait = 0
elif mode == "multiple":
pcotomo.parameters.ntomo = ntomo
pcotomo.parameters.nloop = nloop
pcotomo.parameters.nwait = nwait
pcotomo.parameters.noread = 1
self.pcotomo.parameters.ntomo = ntomo
self.pcotomo.parameters.nloop = nloop
self.pcotomo.parameters.nwait = nwait
self.pcotomo.parameters.noread = 1
elif mode == "endless":
pcotomo.parameters.ntomo = ntomo
pcotomo.parameters.nloop = nloop
pcotomo.parameters.nwait = nwait
pcotomo.parameters.noread = 0
self.pcotomo.parameters.ntomo = ntomo
self.pcotomo.parameters.nloop = nloop
self.pcotomo.parameters.nwait = nwait
self.pcotomo.parameters.noread = 0
else:
raise AttributeError(
f"{mode} is not an available setting, please choose between consecutive, multiple or endless"
......@@ -1429,9 +1569,11 @@ class Tomo(TomoParameters):
if tomo_nb_points != None:
self.parameters.tomo_n = tomo_nb_points
topotomo = tomo.TopoTomo(self, topo_start_pos, topo_end_pos, topo_nb_points)
self.topotomo = tomo.TopoTomo(
self, topo_start_pos, topo_end_pos, topo_nb_points
)
self.active_tomo = topotomo
self.active_tomo = self.topotomo
if dataset_name is not None:
setup_globals.newdataset(dataset_name)
......
......@@ -3,11 +3,12 @@ import gevent
import numpy as np
import time
import os
import glob
import PyTango
import bliss
from bliss import global_map, setup_globals
from bliss import global_map, setup_globals, current_session
from bliss.config.static import get_config
from bliss.common.logtools import log_info, log_debug, log_warning
from bliss.common import session
......@@ -862,3 +863,36 @@ class TomoCcd(TomoParameters):
lima_params["saving_frame_per_file"] = npoints
return lima_params
def estimate_transfer_rate(self, expo_time):
if not os.path.exists(current_session.scan_saving.get_path()):
os.makedirs(current_session.scan_saving.get_path())
depth = self.detector.image.depth
roix = self.detector.image.roi[0]
roiy = self.detector.image.roi[1]
width = self.detector.image.width
height = self.detector.image.height
self.detector.proxy.image_roi = [roix, roiy, width, height]
self.detector.proxy.saving_prefix = "transfer"
self.detector.proxy.acq_nb_frames = 50
self.detector.proxy.acq_expo_time = expo_time
self.detector.proxy.acq_trigger_mode = "INTERNAL_TRIGGER"
self.detector.proxy.saving_mode = "AUTO_FRAME"
self.detector.proxy.saving_frame_per_file = self.detector.saving.frames_per_file
self.detector.proxy.saving_directory = setup_globals.SCAN_SAVING.get_path()
self.detector.prepareAcq()
self.detector.startAcq()
while self.detector.proxy.acq_status == "Running":
print("lima acquisition is running")
time.sleep(0.5)
self.detector.proxy.abortAcq()
files = glob.glob(
self.detector.proxy.saving_directory
+ "/"
+ self.detector.proxy.saving_prefix
+ "*"
+ self.detector.proxy.saving_suffix
)
for f in files:
os.unlink(f)
......@@ -79,6 +79,9 @@ class FastTomo:
tomo.tomo_scan = TomoScan(tomo)
log_info(self, "__init__() leaving")
def scan_info(self):
pass
def calculate_parameters(self):
"""
Calculates fasttomo sequence parameters:
......@@ -634,7 +637,7 @@ class HalfTomo(FastTomo, TomoParameters):
return True
class ZSeries:
class ZSeries(FastTomo):
"""
Class to handle z series tomo acquisition
......@@ -1294,7 +1297,7 @@ class Mtomo(FastTomo):
)
class Progressive:
class Progressive(FastTomo):
"""
Class to handle progressive tomo acquisition
......@@ -1541,9 +1544,108 @@ class PcoTomo(FastTomo, TomoParameters):
self.tomo.rotation_axis,
self.tomo.shutter.sync_shutter_time,
)
self.in_pars = {}
print("Musst channel used: %s" % self.tomo_musst.mot_chan)
log_info(self, "__init__() leaving")
def scan_info(self):
numberofscans = self.in_pars["numberofscans"]
sizeofonescan = self.in_pars["sizeofonescan"]
totalcontinuoustime = self.in_pars["totalcontinuoustime"]
transferrate = self.in_pars["transferrate"]
time = self.in_pars["time"]
frequency = self.in_pars["frequency"]
totaltime = self.in_pars["totaltime"]
unlimitwaitingturns = self.in_pars["unlimitwaitingturns"]
unlimitfrequency = self.in_pars["unlimitfrequency"]
if self.parameters.mode == "consecutive":
print("\n\nConsecutive Scans Without Waiting Turns")
print(f"You can collect a maximum of {numberofscans} scans in the memory")
print(
f"One scan is {round(sizeofonescan * 1024 * 1024 * 1024, 2)} B or {round(sizeofonescan, 2)} GB"
)
print(
f"It means a film of {totalcontinuoustime} s ({round(totalcontinuoustime / 60, 2)} min)\n"
)
print(
f"Time to download film: {round((sizeofonescan * numberofscans) / (transferrate / 1024), 2)} s ({round((sizeofonescan * numberofscans) / (transferrate / 1024) / 60, 2)} min)\n"
)
elif mode == "multiple":
print("\n\nWaiting Turns Between Each Scan")
print(f"You will collect a total of {numberofscans} scans\n")
print(f"You will wait {self.parameters.nwait} turns between each scan")
print(
f"One scan of {time} s every {frequency} s during {totaltime} s ({round(totaltime / 60, 2)} min) \n"
)
print(
f"Time to download film: {round((sizeofonescan * numberofscans) / (transferrate / 1024), 2)} s ({round((sizeofonescan * numberofscans) / (transferrate / 1024) / 60, 2)} min)\n"
)
elif mode == "endless":
print(
f"\n\nYou will wait {unlimitwaitingturns} turns between each scan, during this time, scan is downloaded"
)
print(f"One scan of {time} s every {unlimitfrequency} s FOREVER \n")
print(
f"Time to download one scan: {round(sizeofonescan / (transferrate / 1024), 2)} s ({round(sizeofonescan / (transferrate / 1024) / 60, 2)} min) \n"
)
def calculate_parameters(self):
depth = self.tomo.tomo_ccd.detector.image.depth
width = self.tomo.tomo_ccd.detector.image.width
height = self.tomo.tomo_ccd.detector.image.height
sizeofoneimage = depth * width * height / 1024 / 1024
sizeofonescan = sizeofoneimage * self.tomo.parameters.tomo_n / 1024
self.tomo.tomo_ccd.estimate_transfer_rate(self.tomo.parameters.exposure_time)
numberofscans = int(
self.tomo.tomo_ccd.detector.camera.max_nb_images
/ self.tomo.parameters.tomo_n
)
readout = self.tomo.tomo_ccd.calibrate_ccd_readout_time(
self.tomo.parameters.exposure_time
)
time = (
self.tomo.parameters.exposure_time
+ readout
+ self.tomo.parameters.latency_time
)
totalcontinuoustime = numberofscans * time
waitingtime = (
(360 / self.parameters.trange) * self.parameters.nwait
+ int(180 / self.parameters.trange)
) * time
frequency = waitingtime + time
totaltime = frequency * numberofscans
transferrate = round(
self.tomo.tomo_ccd.detector.proxy.saving_statistics[-1] / 1024 / 1024, 2
)
unlimitwaitingturns = (
int(
((sizeofonescan / (transferrate / 1024)) / time)
/ (360 / self.parameters.trange)
)
+ 2
)
unlimitwaitingtime = (
(360 / self.parameters.trange) * unlimitwaitingturns
+ int(180 / self.parameters.trange)
) * time
unlimitfrequency = unlimitwaitingtime + time
self.in_pars["numberofscans"] = numberofscans
self.in_pars["sizeofonescan"] = sizeofonescan
self.in_pars["totalcontinuoustime"] = totalcontinuoustime
self.in_pars["transferrate"] = transferrate
self.in_pars["totaltime"] = totaltime
self.in_pars["frequency"] = frequency
self.in_pars["time"] = time
self.in_pars["unlimitfrequency"] = unlimitfrequency
self.in_pars["unlimitwaitingturns"] = unlimitwaitingturns
def estimate_scan_time(self, motor, start_pos, end_pos, nb_points):
"""
Estimates scan duration
......
......@@ -267,43 +267,6 @@ class PcoTomo(Tomo):
self.setup_info()
def estimate_transfer_rate(self):
if not os.path.exists(current_session.scan_saving.get_path()):
os.makedirs(current_session.scan_saving.get_path())
depth = self.tomo_ccd.detector.image.depth
roix = self.tomo_ccd.detector.image.roi[0]
roiy = self.tomo_ccd.detector.image.roi[1]
width = self.tomo_ccd.detector.image.width
height = self.tomo_ccd.detector.image.height
self.tomo_ccd.detector.proxy.image_roi = [roix, roiy, width, height]
self.tomo_ccd.detector.proxy.saving_prefix = "transfer"
self.tomo_ccd.detector.proxy.acq_nb_frames = 50
self.tomo_ccd.detector.proxy.acq_expo_time = self.calibrate_detector()
self.tomo_ccd.detector.proxy.acq_trigger_mode = "INTERNAL_TRIGGER"
self.tomo_ccd.detector.proxy.saving_mode = "AUTO_FRAME"
self.tomo_ccd.detector.proxy.saving_frame_per_file = (
self.tomo_ccd.detector.saving.frames_per_file
)
self.tomo_ccd.detector.proxy.saving_directory = (
setup_globals.SCAN_SAVING.get_path()
)
self.tomo_ccd.detector.prepareAcq()
self.tomo_ccd.detector.startAcq()
while self.tomo_ccd.detector.proxy.acq_status == "Running":
print("lima acquisition is running")
time.sleep(0.5)
self.tomo_ccd.detector.proxy.abortAcq()
files = glob.glob(
self.tomo_ccd.detector.proxy.saving_directory
+ "/"
+ self.tomo_ccd.detector.proxy.saving_prefix
+ "*"
+ self.tomo_ccd.detector.proxy.saving_suffix
)
for f in files:
os.unlink(f)
def setup_info(self, mode=None):
depth = self.tomo_ccd.detector.image.depth
......@@ -311,7 +274,7 @@ class PcoTomo(Tomo):
height = self.tomo_ccd.detector.image.height
sizeofoneimage = depth * width * height / 1024 / 1024
sizeofonescan = sizeofoneimage * self.parameters.tomo_n / 1024
self.estimate_transfer_rate()
self.tomo_ccd.estimate_transfer_rate(self.parameters.exposure_time)
numberofscans = int(
self.tomo_ccd.detector.camera.max_nb_images / self.parameters.tomo_n
)
......
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