diff --git a/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/angle_file.py b/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/angle_file.py index 2b30e7bc..6737c9f6 100644 --- a/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/angle_file.py +++ b/csaxs_bec/bec_ipython_client/plugins/OMNY_shared/angle_file.py @@ -6,7 +6,9 @@ tomo_parameters(), the tomo queue) and the TomoParams widget's live preview, so both validate a file identically. File format: plain text, one projection per line. - - column 1: angle in degrees, 0 <= angle <= 360 + - column 1: angle in degrees, -2 <= angle <= 362 -- matches the physical + overtravel range of the rotation stage, not just the nominal 0-360 + sweep - column 2 (optional): sub-tomogram number, integer >= 1 (default 1) - further, optional 'key=value' tokens overriding acquisition parameters for this projection and (sticky) every one after it -- see below @@ -55,8 +57,11 @@ import os import re from dataclasses import dataclass -ANGLE_MIN = 0.0 -ANGLE_MAX = 360.0 +# Matches the physical overtravel range of the fsamroy rotation stage, not +# just the nominal 0-360 sweep (see Flomni._min_scan_angle()/_max_scan_angle() +# in flomni.py, which gate tomo_scan()'s actual acquisition to the same range). +ANGLE_MIN = -2.0 +ANGLE_MAX = 362.0 # Two angles closer than this (mod 180) are reported as a 180-degree-opposite # pair: in the parallel-beam approximation they carry the same information. diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py index fcd3341a..02cf2e23 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py @@ -2271,12 +2271,23 @@ class Flomni( "overrides in the angle file are ignored (the hook owns the whole acquisition)." ) + def _min_scan_angle(self) -> float: + """Lower angle limit (inclusive) accepted by _tomo_scan_at_angle(). + tomo_type 4 files may contain any angle in [-2, 362] -- the physical + overtravel range of the fsamroy rotation stage, not just the + nominal 0-360 sweep -- independent of tomo_angle_range (which only + configures tomo_type 1).""" + if self.tomo_type == 4: + return -2 + return 0 + def _max_scan_angle(self) -> float: """Upper angle limit (inclusive) accepted by _tomo_scan_at_angle(). - tomo_type 4 files may contain any angle in [0, 360], independent of - tomo_angle_range (which only configures tomo_type 1).""" + tomo_type 4 files may contain any angle in [-2, 362] -- see + _min_scan_angle() -- independent of tomo_angle_range (which only + configures tomo_type 1).""" if self.tomo_type == 4: - return 360 + return 362 return self.tomo_angle_range @property @@ -2685,7 +2696,7 @@ class Flomni( def _tomo_scan_at_angle(self, angle, subtomo_number, *, step=None, exp_time=None, frames_per_trigger=None): - if 0 <= angle < self._max_scan_angle() + 0.05: + if self._min_scan_angle() <= angle < self._max_scan_angle() + 0.05: now = datetime.datetime.now() prev_heartbeat_str = self.progress.get("heartbeat") if prev_heartbeat_str is not None: @@ -4337,7 +4348,7 @@ class Flomni( if self.tomo_type == 4: print( - "Angle file: one angle (0-360 deg) per line, optional 2nd column =" + "Angle file: one angle (-2 to 362 deg) per line, optional 2nd column =" " sub-tomogram number, '#' comments. Read at scan start, and again" " while the scan runs -- without a final 'END' line the scan waits" " for more angles to be appended rather than stopping." diff --git a/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py b/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py index 8e3a99b0..4b960505 100644 --- a/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py +++ b/csaxs_bec/bec_widgets/widgets/tomo_params/tomo_params.py @@ -760,7 +760,7 @@ class OMNY_TomoParams(BECWidget, QWidget): self._pw["tomo_angle_file"].setEnabled(False) self._pw["tomo_angle_file"].setPlaceholderText("path to angle file") self._pw["tomo_angle_file"].setToolTip( - "Plain text, one angle (0-360 deg) per line, optional 2nd column = " + "Plain text, one angle (-2 to 362 deg) per line, optional 2nd column = " "sub-tomogram number (default 1), '#' starts a comment. Acquired in " "file order. Only the path is stored: the file is re-read at every " "scan start, resume, and when a queued job runs." @@ -792,21 +792,39 @@ class OMNY_TomoParams(BECWidget, QWidget): if path: self._pw["tomo_angle_file"].setText(path) + def _set_angle_file_summary(self, text: str, stylesheet: str) -> None: + """Set _lbl_angle_file_summary's text/style, and recompute its + minimum height from heightForWidth() at its current width. + + QFormLayout sizes a row from the field widget's sizeHint() at + construction time (when the label still holds its short initial + placeholder); it doesn't reliably recompute that row's height later + when setText() swaps in longer, word-wrapped content -- a known Qt + quirk. Without this, multi-line content (e.g. a summary with a + 180-deg-pair or missing-END warning) gets visually clipped instead + of wrapping into a taller row.""" + self._lbl_angle_file_summary.setText(text) + self._lbl_angle_file_summary.setStyleSheet(stylesheet) + w = self._lbl_angle_file_summary.width() + if w > 0: + self._lbl_angle_file_summary.setMinimumHeight( + self._lbl_angle_file_summary.heightForWidth(w) + ) + def _update_angle_file_preview(self) -> None: if self._sec_type4 is None: return path = self._pw["tomo_angle_file"].text().strip() if not path: - self._lbl_angle_file_summary.setText("(no file set)") - self._lbl_angle_file_summary.setStyleSheet("color: orange;") + self._set_angle_file_summary("(no file set)", "color: orange;") return summary, error = _angle_file_status(path) if error: - self._lbl_angle_file_summary.setText(error) - self._lbl_angle_file_summary.setStyleSheet("color: red;") + self._set_angle_file_summary(error, "color: red;") else: - self._lbl_angle_file_summary.setText(summary) - self._lbl_angle_file_summary.setStyleSheet("color: orange;" if "⚠" in summary else "") + self._set_angle_file_summary( + summary, "color: orange;" if "⚠" in summary else "" + ) def _build_edit_buttons(self) -> QHBoxLayout: layout = QHBoxLayout() diff --git a/docs/user/ptychography/flomni.md b/docs/user/ptychography/flomni.md index 2b524ec5..6b047a0c 100644 --- a/docs/user/ptychography/flomni.md +++ b/docs/user/ptychography/flomni.md @@ -395,12 +395,12 @@ With `tomo_type` 4 the projection angles are not computed but read from a plain- **File requirements** - Plain text, one projection per line. -- Column 1: the angle in degrees, `0 <= angle <= 360`. Angles above 180 are allowed; `tomo_angle_range` is not applied. +- Column 1: the angle in degrees, `-2 <= angle <= 362` -- the physical overtravel range of the rotation stage, not just the nominal 0-360 sweep. Angles above 180 are allowed; `tomo_angle_range` is not applied. - Column 2 (optional): the sub-tomogram number, an integer `>= 1`. If omitted, it is 1. It is only a label used for progress display and the saved metadata; it does not change the acquisition. - Columns are separated by whitespace and/or commas. Everything after `#` is a comment; blank lines are ignored. - Projections are acquired in file order, so the order in the file is the order of the measurement. - Further, optional `key=value` tokens after the angle/subtomo may override acquisition parameters for that projection -- see [Per-line acquisition overrides](user.ptychography.flomni.angle_file.overrides) below. -- At least one angle is required. Any malformed line (not a number, angle outside 0-360, sub-tomogram number below 1, an unrecognized or malformed `key=value` token) makes the whole file invalid and names the offending line. +- At least one angle is required. Any malformed line (not a number, angle outside -2 to 362, sub-tomogram number below 1, an unrecognized or malformed `key=value` token) makes the whole file invalid and names the offending line. - A line that is `END` (case-insensitive, nothing but whitespace/comment around it) marks the file as **complete** -- no more angles will ever be appended. A commented-out `# END` does not count, so the marker can be staged ahead of time and uncommented when the file is truly finished. Anything other than a comment or blank line after `END` is an error. Example: diff --git a/tests/tests_bec_ipython_client/test_angle_file.py b/tests/tests_bec_ipython_client/test_angle_file.py index a2f340db..c7ddcf88 100644 --- a/tests/tests_bec_ipython_client/test_angle_file.py +++ b/tests/tests_bec_ipython_client/test_angle_file.py @@ -49,6 +49,19 @@ def test_tilde_expansion(tmp_path, monkeypatch): assert read_angle_file("~/angles.txt").angles == [_e(12.0)] +def test_angle_range_matches_rotation_stage_overtravel(tmp_path): + """-2 and 362 (the stage's physical overtravel limits) must parse, not + just the nominal 0-360 sweep.""" + path = _write(tmp_path, "-2\n-0.1\n0\n360.01\n362\n") + assert read_angle_file(path).angles == [ + _e(-2.0), + _e(-0.1), + _e(0.0), + _e(360.01), + _e(362.0), + ] + + def test_end_marks_complete(tmp_path): path = _write(tmp_path, "0\n10\nEND\n") result = read_angle_file(path) @@ -95,8 +108,8 @@ def test_blank_and_comment_after_end_allowed(tmp_path): @pytest.mark.parametrize( "text, match", [ - ("-0.1\n", "outside"), - ("360.01\n", "outside"), + ("-2.1\n", "outside"), + ("362.01\n", "outside"), ("abc\n", "invalid angle"), ("10 x\n", "invalid sub-tomogram"), ("10 0\n", ">= 1"), diff --git a/tests/tests_bec_ipython_client/test_flomni_tomo_angles.py b/tests/tests_bec_ipython_client/test_flomni_tomo_angles.py index d4a637b0..8dc92714 100644 --- a/tests/tests_bec_ipython_client/test_flomni_tomo_angles.py +++ b/tests/tests_bec_ipython_client/test_flomni_tomo_angles.py @@ -385,16 +385,43 @@ def test_angle_file_ignores_golden_zero_deg_damage_flag(monkeypatch, tmp_path): assert recorded == [(0, 1), (10.0, 1), (20.0, 2), (30.0, 3), (40.0, 5)] -def test_max_scan_angle_is_360_only_for_type_4(): +def test_max_scan_angle_is_362_only_for_type_4(): flomni = object.__new__(Flomni) flomni.client = _FakeClient() flomni.tomo_angle_range = 180 flomni.tomo_type = 4 - assert flomni._max_scan_angle() == 360 + assert flomni._max_scan_angle() == 362 flomni.tomo_type = 1 assert flomni._max_scan_angle() == 180 +def test_min_scan_angle_is_minus_2_only_for_type_4(): + flomni = object.__new__(Flomni) + flomni.client = _FakeClient() + flomni.tomo_type = 4 + assert flomni._min_scan_angle() == -2 + flomni.tomo_type = 1 + assert flomni._min_scan_angle() == 0 + + +def test_angle_file_accepts_physical_overtravel_range(monkeypatch, tmp_path): + """Angles down to -2 and up to 362 (the rotation stage's physical + overtravel range) must actually reach acquisition for tomo_type 4, not + just pass angle-file parsing -- _tomo_scan_at_angle()'s own gate has to + be widened to match, or they'd parse fine but then be silently skipped + with no acquisition and no error.""" + flomni = make_flomni_for_angle_file(monkeypatch, tmp_path, "-2\n-0.1\n361\n362\nEND\n") + flomni._write_tomo_scan_number = lambda *a, **k: None + flomni._log_projection_timing = lambda **k: None + recorded = [] + flomni._at_each_angle = lambda angle, **overrides: recorded.append(angle) + + flomni.tomo_scan() # exercises the real _tomo_scan_at_angle(), not a stub + + # 0: unconditional 0-deg reference shot at the start of a new tomogram + assert recorded == [0, -2.0, -0.1, 361.0, 362.0] + + # ── tomo_type 4: live append -- wait at EOF without 'END', poll, pick up ──── diff --git a/tests/tests_bec_widgets/test_tomo_params_angle_file.py b/tests/tests_bec_widgets/test_tomo_params_angle_file.py index 293adf8c..7101c853 100644 --- a/tests/tests_bec_widgets/test_tomo_params_angle_file.py +++ b/tests/tests_bec_widgets/test_tomo_params_angle_file.py @@ -90,6 +90,7 @@ class _StubTomoParams: _build_type4_section = OMNY_TomoParams._build_type4_section _update_angle_file_preview = OMNY_TomoParams._update_angle_file_preview + _set_angle_file_summary = OMNY_TomoParams._set_angle_file_summary _browse_angle_file = OMNY_TomoParams._browse_angle_file def __init__(self): @@ -117,6 +118,26 @@ def test_type4_section_preview_tracks_file_content(qapp, tmp_path): assert "red" in stub._lbl_angle_file_summary.styleSheet() +def test_type4_section_preview_grows_minimum_height_for_wrapped_content(qapp, tmp_path): + """QFormLayout sizes the Content row from the label's sizeHint() at + construction time (still holding the short '---' placeholder) and + doesn't reliably recompute it later when setText() swaps in longer, + word-wrapped text -- a known Qt quirk. _set_angle_file_summary() must + grow the label's minimum height to compensate, or multi-line content + (e.g. a 180-deg-pair or missing-END warning) gets visually clipped.""" + stub = _StubTomoParams() + initial_height = stub._lbl_angle_file_summary.minimumHeight() + + angle_file = tmp_path / "angles.txt" + angle_file.write_text("10\n190\n") # triggers the 180-deg-pair warning line + stub._pw["tomo_angle_file"].setText(str(angle_file)) + + assert stub._lbl_angle_file_summary.minimumHeight() > initial_height + assert stub._lbl_angle_file_summary.minimumHeight() >= ( + stub._lbl_angle_file_summary.heightForWidth(stub._lbl_angle_file_summary.width()) + ) + + def test_type4_section_preview_flags_missing_end_marker(qapp, tmp_path): stub = _StubTomoParams()