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
7 changes: 6 additions & 1 deletion src/morphobricks_preprocessing/run_inputs_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,12 @@ def unchecked_refusal(mask_id: str, unchecked: Iterable[str], total: int) -> Ref


def rgb_refusal(capabilities: Capabilities, rgb_images: Iterable[str]) -> Refusal | None:
"""Return ``A_RGB_NOT_SUPPORTED`` when ``rgb`` units are requested without the capability."""
"""Return ``A_RGB_NOT_SUPPORTED`` when ``rgb`` units are requested without the capability.

``rgb_images`` are the images of ``rgb`` units whose channels the request names (experiment-v1
§8: the refusal applies to a request that includes an RGB unit's channels); a mask-only request
names none, so it is never refused for RGB.
"""
images = tuple(sorted(rgb_images))
if not images or capabilities.rgb_support:
return None
Expand Down
4 changes: 3 additions & 1 deletion src/morphobricks_preprocessing/run_inputs_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ def resolve_request(self, request: Request) -> ResolvedRequest:
found, more = self._mask(mask, description, fovs, repeats, masks_table)
refusals.extend(found)
covered.extend(more)
rgb = [f.relative_path for f in fovs if f.image_type == RGB]
# A mask-only request names no channel: never refused for RGB (§8 A_RGB_NOT_SUPPORTED).
asked = set(request.channel_ids)
rgb = [f.relative_path for f in fovs if f.image_type == RGB and asked & set(f.channel_ids)]
refusals.extend(_some(rgb_refusal(request.capabilities, rgb)))
refusals.extend(_some(volume_refusal(request)))
selections = () if refusals else self._selections(request, description, fovs)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_spec_resolve_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,20 @@ def test_v28_rgb_units_are_refused_unless_the_consumer_declares_rgb_support(tmp_
assert accepted.selections[0].channel_indices == (0, 1, 2)


@pytest.mark.parametrize("channels", [(), ("G",)])
def test_v28_only_a_request_naming_rgb_channels_needs_rgb_support(tmp_path, channels):
"""experiment-v1 §8: A_RGB_NOT_SUPPORTED is for a request naming an RGB unit's channels.

A mask-only request (no channel) is accepted for any consumer; naming one of R, G, B is not.
"""
inputs, _ = _open(tmp_path, "v28")
resolved = inputs.resolve_request(Request(channels))
if channels:
assert _codes(resolved) == [("A_RGB_NOT_SUPPORTED", "rgb")]
else:
assert not resolved.refused and len(resolved.selections) == 32


def test_v01_channel_units_are_channels_and_need_no_capability(tmp_path):
inputs, _ = _open(tmp_path, "v01")
resolved = inputs.resolve_request(Request(("DNA",)))
Expand Down
Loading