Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions marge/console/prescribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions tests/test_console_prescribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_console_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
Loading