From f4ac7805a643bea38632e475a3379267c1ec0d20 Mon Sep 17 00:00:00 2001 From: mcencini Date: Thu, 8 Oct 2026 18:22:14 +0200 Subject: [PATCH] Draw every saturation band the sequence declares pulserver's plugins now declare which explicit bands they play: the mask is a configuration entry, bit n - 1 set for each band n, and the console places the bands rather than turning them on. The views draw the bands of the declared mask. Co-Authored-By: Claude Opus 5.5 --- marge/console/prescribe.py | 10 +++++++--- tests/test_console_prescribe.py | 13 ++++++++++--- tests/test_console_workspace.py | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/marge/console/prescribe.py b/marge/console/prescribe.py index 19c7acf..427d03f 100644 --- a/marge/console/prescribe.py +++ b/marge/console/prescribe.py @@ -25,7 +25,7 @@ "fov", "phase_fov", "slice_thickness", "nslices", "slice_spacing", "imaging_mode" ) GEOMETRY = (READ_FOV, PHASE_FOV, SLICES, THICKNESS, GAP) -#: The explicit saturation bands' mask: bit n - 1 turns band n on. +#: The explicit saturation bands' mask, which the sequence declares: bit n - 1 for band n. BAND_MASK = "exsat_mask" #: The console's own values of the prescription, beside the plugin's entries. @@ -105,10 +105,14 @@ def written( def bands( values: Mapping[str, Any], entries: Mapping[str, Mapping[str, Any]], key: Key = str ) -> list[tuple[int, geometry.Band]]: - """Return each explicit saturation band a sequence's values turn on, by its number, 1 to 6.""" + """Return each explicit saturation band a sequence plays, by its number, 1 to 6. + + The sequence declares which: its mask, a configuration entry, sets bit + ``n - 1`` for each band ``n``. + """ if BAND_MASK not in entries: return [] - mask = int(values[key(BAND_MASK)]) + mask = int(entries[BAND_MASK]["value"]) found = [] for n in range(1, 7): if not mask & (1 << (n - 1)) or f"exsat{n}_loc" not in entries: diff --git a/tests/test_console_prescribe.py b/tests/test_console_prescribe.py index 4e68acb..96d82c4 100644 --- a/tests/test_console_prescribe.py +++ b/tests/test_console_prescribe.py @@ -14,7 +14,7 @@ nslices: int|typein|5|1|64|1| slice_thickness: float|typein|4.0|1.0|20.0|0.5|mm slice_spacing: float|typein|1.0|0.0|20.0|0.5|mm -exsat_mask: int|typein|0|0|3|1| +exsat_mask: config|3 exsat1_normal_x: float|typein|1.0|-1.0|1.0|0.001| exsat1_normal_y: float|typein|0.0|-1.0|1.0|0.001| exsat1_normal_z: float|typein|0.0|-1.0|1.0|0.001| @@ -95,8 +95,15 @@ def test_a_turned_prescription_is_written_as_its_angles_from_the_starting_plane( assert changed == {"tilt_read": 12.0} -def test_a_band_turned_on_is_read_with_its_normal_and_written_back_held(entries, values): - values["exsat_mask"] = 2 +def test_every_band_the_sequence_declares_is_read_with_its_normal(entries, values): + found = prescribe.bands(values, entries) + + assert [n for n, _ in found] == [1, 2] + assert np.allclose(found[0][1].normal, (1, 0, 0)) and found[0][1].position == -60.0 + + +def test_a_band_is_written_back_held_to_its_entries(entries, values): + entries["exsat_mask"]["value"] = 2 ((n, band),) = prescribe.bands(values, entries) turned = geometry.Band(np.array([0.0, 0.6, 0.8]), 72.6, 35.2) diff --git a/tests/test_console_workspace.py b/tests/test_console_workspace.py index 2dbc5a2..4e68eea 100644 --- a/tests/test_console_workspace.py +++ b/tests/test_console_workspace.py @@ -22,7 +22,7 @@ nslices: int|typein|5|1|64|1| slice_thickness: float|typein|4.0|1.0|20.0|0.5|mm slice_spacing: float|typein|1.0|0.0|20.0|0.5|mm -exsat_mask: int|typein|2|0|3|1| +exsat_mask: config|2 exsat1_normal_x: float|typein|1.0|-1.0|1.0|0.001| exsat1_normal_y: float|typein|0.0|-1.0|1.0|0.001| exsat1_normal_z: float|typein|0.0|-1.0|1.0|0.001|