fix(tomo): type-4 progress GUI + tomo_params window size
CI for csaxs_bec / test (push) Successful in 3m5s
CI for csaxs_bec / test (push) Successful in 3m5s
- flomni GUI progress: guard division by total_projections == 0 (type 4 file without END, endless golden ratio); the error was swallowed and the progress window stayed on the reset defaults for the whole scan. - Fill tomo type/total/subtomo for type 4 right after scan start, so the GUI is meaningful during empty frames and the 0-deg reference shot. - tomo_parameters() window opens at 730x1170. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5CiUfRUwnPyuAkq5Wyptm
This commit is contained in:
1 parent
28929b174c
commit
517b0f7e3a
7 files changed
+89
-6
No files matched your search
@@ -2124,6 +2124,7 @@ class LamNI(
|
||||
self.write_pdf_report()
|
||||
self._reset_progress_for_new_scan()
|
||||
if file_angles is not None:
|
||||
self._init_angle_file_progress(file_angles, projection_number)
|
||||
self._scilog_angle_file_record(file_angles)
|
||||
# Unconditional single 0-degree reference projection at the very
|
||||
# start of a new tomogram, independent of
|
||||
|
||||
@@ -188,6 +188,18 @@ class TomoAngleFileMixin:
|
||||
)
|
||||
return file_angles
|
||||
|
||||
def _init_angle_file_progress(self, file_angles: AngleFileResult, projection_number) -> None:
|
||||
"""Fill the progress fields that are already known from the file, so the
|
||||
GUI shows the real tomo type/total (and sub-tomogram 1) during the
|
||||
preparation steps and the 0-deg reference shot that precede the loop,
|
||||
instead of the blank reset defaults (tomo type 0, projection 0)."""
|
||||
self.progress["tomo_type"] = "Angles from file"
|
||||
self.progress["total_projections"] = (
|
||||
len(file_angles.angles) if file_angles.is_complete else 0
|
||||
)
|
||||
if projection_number is None:
|
||||
self.progress["subtomo"] = 1
|
||||
|
||||
def _scilog_angle_file_record(self, file_angles: AngleFileResult) -> None:
|
||||
"""Record of the angles known at scan start -- the file itself may be
|
||||
edited, deleted, or grow further after this point."""
|
||||
|
||||
@@ -218,6 +218,9 @@ class TomoQueueMixin:
|
||||
_TOMO_PARAMS_WINDOW_NAME: str = ""
|
||||
_TOMO_PARAMS_ERROR: type[Exception] = RuntimeError
|
||||
_TOMO_PARAMS_GUI_TIMEOUT = 20
|
||||
# (pos_x, pos_y, width, height) of the tomo parameter window when it is
|
||||
# created: tall and narrow, so the whole parameter column fits on screen.
|
||||
_TOMO_PARAMS_WINDOW_GEOMETRY = (50, 50, 730, 1170)
|
||||
|
||||
# Name of a registered at_each_angle hook (see register_at_each_angle_hook()),
|
||||
# or None for the default per-projection behaviour.
|
||||
@@ -272,7 +275,7 @@ class TomoQueueMixin:
|
||||
print("The tomo parameter window is already open.")
|
||||
return
|
||||
else:
|
||||
gui.new(name, timeout=timeout)
|
||||
gui.new(name, geometry=self._TOMO_PARAMS_WINDOW_GEOMETRY, timeout=timeout)
|
||||
time.sleep(1)
|
||||
window = getattr(gui, name)
|
||||
window.new("OMNY_TomoParams", object_name="tomo_params", timeout=timeout)
|
||||
|
||||
@@ -2852,6 +2852,8 @@ class Flomni(
|
||||
# self.progress.reset() above, before the gates -- only the actual
|
||||
# start time is set here, once the scan is genuinely committed to.
|
||||
self.progress["tomo_start_time"] = datetime.datetime.now().isoformat()
|
||||
if file_angles is not None:
|
||||
self._init_angle_file_progress(file_angles, projection_number)
|
||||
self.collect_empty_frames()
|
||||
# Unconditional single 0-degree reference projection at the very
|
||||
# start of a new tomogram, independent of
|
||||
|
||||
@@ -265,6 +265,17 @@ class flomniGuiTools:
|
||||
except Exception as e:
|
||||
logger.warning(f"Error in flomnigui_show_progress: {e}")
|
||||
|
||||
@staticmethod
|
||||
def _percent(numerator, denominator) -> float:
|
||||
"""numerator/denominator in percent; 0 when the denominator is not
|
||||
positive -- e.g. the total of a tomo_type 4 scan whose angle file has
|
||||
no 'END' marker yet, or an endless golden-ratio scan (0 = unknown).
|
||||
Without this the division raised, the error was swallowed, and the
|
||||
GUI stayed frozen on the reset defaults for the whole scan."""
|
||||
if not denominator or denominator <= 0:
|
||||
return 0.0
|
||||
return numerator / denominator * 100
|
||||
|
||||
def _flomnigui_update_progress(self):
|
||||
"""Update the progress ring bar and center label from the current progress state.
|
||||
|
||||
@@ -281,11 +292,9 @@ class flomniGuiTools:
|
||||
|
||||
main_progress_ring = self.progressbar.rings[0]
|
||||
subtomo_progress_ring = self.progressbar.rings[1]
|
||||
progress = self.progress["projection"] / self.progress["total_projections"] * 100
|
||||
subtomo_progress = (
|
||||
self.progress["subtomo_projection"]
|
||||
/ self.progress["subtomo_total_projections"]
|
||||
* 100
|
||||
progress = self._percent(self.progress["projection"], self.progress["total_projections"])
|
||||
subtomo_progress = self._percent(
|
||||
self.progress["subtomo_projection"], self.progress["subtomo_total_projections"]
|
||||
)
|
||||
main_progress_ring.set_value(progress)
|
||||
subtomo_progress_ring.set_value(subtomo_progress)
|
||||
|
||||
@@ -718,3 +718,47 @@ def test_resume_does_not_reset_progress(monkeypatch, tmp_path):
|
||||
|
||||
assert reset_calls == []
|
||||
assert flomni.progress["estimated_remaining_time"] == 42.0
|
||||
|
||||
|
||||
def test_angle_file_progress_shows_type_and_total_before_the_zero_deg_shot(monkeypatch, tmp_path):
|
||||
flomni = make_flomni_for_angle_file(monkeypatch, tmp_path, "10\n20\nEND\n")
|
||||
seen = []
|
||||
flomni._tomo_scan_at_angle = lambda angle, subtomo, **kw: seen.append(
|
||||
(angle, flomni.progress["tomo_type"], flomni.progress["total_projections"])
|
||||
)
|
||||
|
||||
flomni.tomo_scan()
|
||||
|
||||
assert seen[0] == (0, "Angles from file", 2) # the initial 0-deg shot
|
||||
|
||||
|
||||
def test_flomni_gui_progress_survives_zero_total(monkeypatch):
|
||||
"""total_projections == 0 (type 4 file without 'END' yet, or endless
|
||||
golden ratio) must not make the GUI update raise (it was swallowed,
|
||||
leaving the progress window frozen on the reset defaults)."""
|
||||
from csaxs_bec.bec_ipython_client.plugins.flomni.gui_tools import flomniGuiTools
|
||||
|
||||
labels, ring_values = [], []
|
||||
ring = types.SimpleNamespace(set_value=ring_values.append)
|
||||
gui = object.__new__(flomniGuiTools)
|
||||
gui.progressbar = types.SimpleNamespace(
|
||||
rings=[ring, ring], set_center_label=labels.append
|
||||
)
|
||||
gui.progress = {
|
||||
"projection": 3,
|
||||
"total_projections": 0,
|
||||
"subtomo_projection": 1,
|
||||
"subtomo_total_projections": 2,
|
||||
"tomo_type": "Angles from file",
|
||||
"angle": 10.0,
|
||||
"subtomo": 1,
|
||||
"tomo_start_time": None,
|
||||
"estimated_remaining_time": None,
|
||||
"estimated_finish_time": None,
|
||||
}
|
||||
gui._describe_active_hook = lambda: None
|
||||
|
||||
gui._flomnigui_update_progress()
|
||||
|
||||
assert ring_values == [0.0, 50.0]
|
||||
assert "Angles from file" in labels[0]
|
||||
@@ -258,3 +258,15 @@ def test_queue_job_line_shows_angle_file_for_type_4():
|
||||
assert "angles=angles.txt" in line
|
||||
line = obj._describe_tomo_job_line({"params": {"tomo_type": 1}})
|
||||
assert "angles=" not in line
|
||||
|
||||
|
||||
def test_progress_shows_type_and_total_before_the_zero_deg_shot(monkeypatch, tmp_path):
|
||||
lamni = make_lamni_for_angle_file(monkeypatch, tmp_path, "10\n20\nEND\n")
|
||||
seen = []
|
||||
lamni._tomo_scan_at_angle = lambda angle, subtomo: seen.append(
|
||||
(angle, lamni.progress["tomo_type"], lamni.progress["total_projections"])
|
||||
)
|
||||
|
||||
lamni.tomo_scan(force=True)
|
||||
|
||||
assert seen[0] == (0, "Angles from file", 2) # the initial 0-deg shot
|
||||
Reference in new issue
Block a user