From 764a5e94c5147a459afaded172c5dc094190cbb8 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 08:10:32 +0000 Subject: [PATCH 1/2] Read pulserver's [Protocol] listing, so its sequences show their parameters and FOV pulserver delimits its protocol blocks with [Protocol]; the console read only [NimPulseqGUI Protocol], so every plugin listed no parameters and a scan sent no field of view. Both delimiters are read and [Protocol] is written. A boolean edited in a parameter tab travels as its value, not its text's truth. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01Afq4fxyjbebF7KbvaNC1uh --- marge/seq/pulserver_console.py | 14 +++++++++----- tests/test_pulserver_console.py | 22 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/marge/seq/pulserver_console.py b/marge/seq/pulserver_console.py index 2f68310..779477b 100644 --- a/marge/seq/pulserver_console.py +++ b/marge/seq/pulserver_console.py @@ -32,8 +32,10 @@ #: WebSocket address of ``pulserver console``; the console mode is off without it. GATEWAY = os.environ.get("MARGE_PULSERVER", "") -PROTOCOL_BEGIN = "[NimPulseqGUI Protocol]" -PROTOCOL_END = "[NimPulseqGUI Protocol End]" +PROTOCOL_BEGIN = "[Protocol]" +PROTOCOL_END = "[Protocol End]" +#: The delimiters of a console that predates pulserver's ``[Protocol]`` block, also read. +_FORMER = ("[NimPulseqGUI Protocol]", "[NimPulseqGUI Protocol End]") FOV_OFFSET = ("fov_offset_x", "fov_offset_y", "fov_offset_z") FOV_ROTATION = tuple(f"fov_rotation_{i}{j}" for i in (1, 2, 3) for j in (1, 2, 3)) PRESCRIPTION = FOV_OFFSET + FOV_ROTATION @@ -79,10 +81,10 @@ def parse_listing(reply: str) -> dict[str, dict[str, Any]]: inside = False for line in reply.splitlines(): text = line.strip() - if text == PROTOCOL_BEGIN: + if text in (PROTOCOL_BEGIN, _FORMER[0]): inside = True continue - if text == PROTOCOL_END: + if text in (PROTOCOL_END, _FORMER[1]): break if not inside or text.startswith("#") or ": " not in text: continue @@ -150,7 +152,9 @@ def format_values( if entry["kind"] not in _EDITABLE or name in PRESCRIPTION: continue if entry["kind"] == "bool": - text = "true" if value else "false" + # MaRGE's parameter tabs hand an edited boolean back as its text. + on = value.strip().lower() == "true" if isinstance(value, str) else bool(value) + text = "true" if on else "false" elif entry["kind"] == "stringlist": text = str(entry["options"].index(value)) elif entry["kind"] == "int": diff --git a/tests/test_pulserver_console.py b/tests/test_pulserver_console.py index f4805c9..2ac7ab1 100644 --- a/tests/test_pulserver_console.py +++ b/tests/test_pulserver_console.py @@ -18,7 +18,7 @@ #: pulserver's listing of its gre2d test plugin, with a boolean, a string list #: and a description added. LISTING = """PROTOCOL -[NimPulseqGUI Protocol] +[Protocol] TE: int|dropdown|8000|1000|80000|10|us|-2|5000|8000 bandwidth: float|typein|250000.0|1000.0|1000000.0|1.0|Hz nx: int|typein|128|32|512|2| @@ -29,7 +29,7 @@ note: description|two\\nlines fov_offset_x: float|off|0.0|-1000.0|1000.0|0.1|mm fov_rotation_11: float|off|1.0|-1.0|1.0|1e-06| -[NimPulseqGUI Protocol End] +[Protocol End] """ @@ -56,6 +56,24 @@ def test_a_listing_reads_as_the_interpreter_reads_it(): assert entries["note"]["value"] == "two\nlines" +def test_a_boolean_edited_as_text_in_marges_tabs_travels_as_its_value(): + entries = console.parse_listing(LISTING) + rotation = console.ORIENTATIONS["axial"] + + for text, sent in (("False", "false"), ("True", "true")): + block = console.format_values({"fatsat": text}, entries, rotation, (0.0, 0.0, 0.0)) + assert block.splitlines()[1] == f"fatsat: {sent}" + + +def test_a_listing_of_an_older_console_reads_the_same(): + former = LISTING.replace("[Protocol]", "[NimPulseqGUI Protocol]").replace( + "[Protocol End]", "[NimPulseqGUI Protocol End]" + ) + + assert console.parse_listing(former) == console.parse_listing(LISTING) + assert console.parse_listing(LISTING) + + def test_the_console_shows_the_editable_entries_outside_the_prescription(): entries = console.parse_listing(LISTING) From f5a28fad78b0a00ab91056d2e3f94305bf7e3a83 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 08:13:02 +0000 Subject: [PATCH 2/2] Read the Image tab's orientation whatever its case, and name the choices otherwise Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01Afq4fxyjbebF7KbvaNC1uh --- marge/seq/pulserver_console.py | 5 ++++- tests/test_pulserver_console.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/marge/seq/pulserver_console.py b/marge/seq/pulserver_console.py index 779477b..61fae53 100644 --- a/marge/seq/pulserver_console.py +++ b/marge/seq/pulserver_console.py @@ -187,7 +187,10 @@ def prescription( cross = np.array([[0.0, -k[2], k[1]], [k[2], 0.0, -k[0]], [-k[1], k[0], 0.0]]) theta = math.radians(angle_deg) turn = np.eye(3) + math.sin(theta) * cross + (1 - math.cos(theta)) * cross @ cross - rotation = turn @ ORIENTATIONS[orientation] + name = orientation.strip().lower() + if name not in ORIENTATIONS: + raise ValueError(f"orientation is one of {', '.join(ORIENTATIONS)}, not {orientation!r}") + rotation = turn @ ORIENTATIONS[name] return rotation, rotation.T @ np.asarray(dfov_mm, dtype=float) diff --git a/tests/test_pulserver_console.py b/tests/test_pulserver_console.py index 2ac7ab1..c0f6b9c 100644 --- a/tests/test_pulserver_console.py +++ b/tests/test_pulserver_console.py @@ -65,6 +65,14 @@ def test_a_boolean_edited_as_text_in_marges_tabs_travels_as_its_value(): assert block.splitlines()[1] == f"fatsat: {sent}" +def test_an_orientation_typed_in_marges_image_tab_is_read_whatever_its_case(): + rotation, _ = console.prescription(" Coronal", 0.0, (1.0, 0.0, 0.0), (0.0, 0.0, 0.0)) + + np.testing.assert_array_equal(rotation, console.ORIENTATIONS["coronal"]) + with pytest.raises(ValueError, match="axial, coronal, sagittal"): + console.prescription("oblique", 0.0, (1.0, 0.0, 0.0), (0.0, 0.0, 0.0)) + + def test_a_listing_of_an_older_console_reads_the_same(): former = LISTING.replace("[Protocol]", "[NimPulseqGUI Protocol]").replace( "[Protocol End]", "[NimPulseqGUI Protocol End]"