diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py index 76776dd..a518630 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py @@ -562,8 +562,8 @@ class LamNI(LamNIOpticsMixin, LamniGuiTools): for scan_nr in range(start_scan_number, end_scan_number): self._write_tomo_scan_number(scan_nr, angle, subtomo_number) - #todo here bl chk - successful = True + #todo here bl chk, if ok then successfull true + successful = True def _golden(self, ii, howmany_sorted, maxangle=360, reverse=False): diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py index 24b7b27..060e1a8 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py @@ -15,7 +15,11 @@ from csaxs_bec.bec_ipython_client.plugins.cSAXS import cSAXSBeamlineChecks from csaxs_bec.bec_ipython_client.plugins.flomni.flomni_optics_mixin import FlomniOpticsMixin from csaxs_bec.bec_ipython_client.plugins.flomni.x_ray_eye_align import XrayEyeAlign from csaxs_bec.bec_ipython_client.plugins.flomni.gui_tools import flomniGuiTools -from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import OMNYTools +from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import ( + OMNYTools, + PtychoReconstructor, + TomoIDManager, +) logger = bec_logger.logger @@ -65,9 +69,6 @@ class FlomniError(Exception): # print("Please expicitely confirm y or n.") - - - class FlomniInitStagesMixin: def flomni_init_stages(self): @@ -1172,18 +1173,12 @@ class Flomni( super().__init__() self.client = client self.device_manager = client.device_manager - self.check_shutter = False - self.check_light_available = False - self.check_fofb = False - self._check_msgs = [] self.tomo_id = -1 self.special_angles = [] self.special_angle_repeats = 20 self.special_angle_tolerance = 20 self._current_special_angles = [] self._beam_is_okay = True - self._stop_beam_check_event = None - self.beam_check_thread = None self.corr_pos_y = [] self.corr_angle_y = [] self.corr_pos_y_2 = [] @@ -1197,6 +1192,8 @@ class Flomni( self.progress["angle"] = 0 self.progress["tomo_type"] = 0 self.OMNYTools = OMNYTools(self.client) + self.reconstructor = PtychoReconstructor(self.ptycho_reconstruct_foldername) + self.tomo_id_manager = TomoIDManager() self.align = XrayEyeAlign(self.client, self) self.set_client(client) @@ -1228,27 +1225,6 @@ class Flomni( def axis_id_to_numeric(self, axis_id) -> int: return ord(axis_id.lower()) - 97 - def get_beamline_checks_enabled(self): - print( - f"Shutter: {self.check_shutter}\nFOFB: {self.check_fofb}\nLight available:" - f" {self.check_light_available}" - ) - - @property - def beamline_checks_enabled(self): - return { - "shutter": self.check_shutter, - "fofb": self.check_fofb, - "light available": self.check_light_available, - } - - @beamline_checks_enabled.setter - def beamline_checks_enabled(self, val: bool): - self.check_shutter = val - self.check_light_available = val - self.check_fofb = val - self.get_beamline_checks_enabled() - def set_special_angles(self, angles: list, repeats: int = 20, tolerance: float = 0.5): """Set the special angles for a tomo @@ -1392,6 +1368,7 @@ class Flomni( @ptycho_reconstruct_foldername.setter def ptycho_reconstruct_foldername(self, val: str): self.client.set_global_var("ptycho_reconstruct_foldername", val) + self.reconstructor.folder_name = val # keep reconstructor in sync @property def tomo_angle_stepsize(self): @@ -1499,7 +1476,6 @@ class Flomni( if 0 <= angle < 180.05: print(f"Starting flOMNI scan for angle {angle}") while not successful: - self._start_beam_check() try: start_scan_number = bec.queue.next_scan_number self.tomo_scan_projection(angle) @@ -1512,11 +1488,9 @@ class Flomni( error_caught = True else: raise exc - - if self._was_beam_okay() and not error_caught: - successful = True - else: - self._wait_for_beamline_checks() + #todo here was if blchk success, then setting to success true + successful = True + end_scan_number = bec.queue.next_scan_number for scan_nr in range(start_scan_number, end_scan_number): self._write_tomo_scan_number(scan_nr, angle, 0) @@ -1605,7 +1579,7 @@ class Flomni( print(f"Starting flOMNI scan for angle {angle} in subtomo {subtomo_number}") self._print_progress() while not successful: - self._start_beam_check() + self.bl_chk._bl_chk_start() if not self.special_angles: self._current_special_angles = [] if self._current_special_angles: @@ -1628,10 +1602,10 @@ class Flomni( else: raise exc - if self._was_beam_okay() and not error_caught: + if self.bl_chk._bl_chk_stop() and not error_caught: successful = True else: - self._wait_for_beamline_checks() + self.bl_chk._bl_chk_wait_until_recovered() end_scan_number = bec.queue.next_scan_number for scan_nr in range(start_scan_number, end_scan_number): self._write_tomo_scan_number(scan_nr, angle, subtomo_number) @@ -1783,13 +1757,15 @@ class Flomni( self, samplename, date, eaccount, scan_number, setup, sample_additional_info, user ): """Add a sample to the omny sample database. This also retrieves the tomo id.""" - subprocess.run( - f"wget --user=omny --password=samples -q -O /tmp/currsamplesnr.txt 'https://omny.web.psi.ch/samples/newmeasurement.php?sample={samplename}&date={date}&eaccount={eaccount}&scannr={scan_number}&setup={setup}&additional={sample_additional_info}&user={user}'", - shell=True, + return self.tomo_id_manager.register( + sample_name=samplename, + date=date, + eaccount=eaccount, + scan_number=scan_number, + setup=setup, + additional_info=sample_additional_info, + user=user, ) - with open("/tmp/currsamplesnr.txt") as tomo_number_file: - tomo_number = int(tomo_number_file.read()) - return tomo_number def _at_each_angle(self, angle: float) -> None: if "flomni_at_each_angle" in builtins.__dict__: @@ -1851,19 +1827,11 @@ class Flomni( def tomo_reconstruct(self, base_path="~/Data10/specES1"): """write the tomo reconstruct file for the reconstruction queue""" bec = builtins.__dict__.get("bec") - base_path = os.path.expanduser(base_path) - ptycho_queue_path = Path(os.path.join(base_path, self.ptycho_reconstruct_foldername)) - ptycho_queue_path.mkdir(parents=True, exist_ok=True) - - # pylint: disable=undefined-variable - last_scan_number = bec.queue.next_scan_number - 1 - ptycho_queue_file = os.path.abspath( - os.path.join(ptycho_queue_path, f"scan_{last_scan_number:05d}.dat") + self.reconstructor.write( + scan_list=self._current_scan_list, + next_scan_number=bec.queue.next_scan_number, + base_path=base_path, ) - with open(ptycho_queue_file, "w") as queue_file: - scans = " ".join([str(scan) for scan in self._current_scan_list]) - queue_file.write(f"p.scan_number {scans}\n") - queue_file.write("p.check_nextscan_started 1\n") def _write_tomo_scan_number(self, scan_number: int, angle: float, subtomo_number: int) -> None: tomo_scan_numbers_file = os.path.expanduser( @@ -2114,4 +2082,4 @@ if __name__ == "__main__": builtins.__dict__["bec"] = bec builtins.__dict__["umv"] = umv flomni = Flomni(bec) - flomni.start_x_ray_eye_alignment() + flomni.start_x_ray_eye_alignment() \ No newline at end of file