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
4 changes: 3 additions & 1 deletion openhcs/core/projected_image_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ def contextualize(
"Contextual object-label output strategy requires "
f"ObjectLabelValue, got {type(output_value).__name__}."
)
return output_value.with_source_image_context(source_payload)
return output_value.with_source_image_context(
source_payload
).with_parent_image_context(source_payload)


class DenseArrayObjectLabelOutputValueContextStrategy(
Expand Down
25 changes: 18 additions & 7 deletions openhcs/core/steps/function_artifact_materialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,13 +1122,24 @@ def from_record(
source_identity = (
ArtifactStreamSourceMetadataAuthority.payload_source_identity(data)
)
record_source = AnalysisOutputDescriptorAuthority.record_source_descriptor(
context,
plan,
record,
spec,
output_plan=output_plan,
)
try:
record_source = AnalysisOutputDescriptorAuthority.record_source_descriptor(
context,
plan,
record,
spec,
output_plan=output_plan,
)
except IncompleteFunctionOutputFilenameIdentityError as exc:
if not AnalysisOutputDescriptorAuthority.missing_component_is_aggregated(
exc.component_name,
record.key.scope,
tuple(plan.variable_components or ()),
):
raise
# A projected stack has no single coordinate on its stacked axis.
# The writer names each occurrence from its complete plane identity.
record_source = None
filename_source_identity = (
None if record_source is None
else AnalysisOutputDescriptorAuthority.source_identity_for_path(
Expand Down
58 changes: 28 additions & 30 deletions openhcs/core/steps/function_output_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,12 @@ class StepOutputManifestStore:
field(default_factory=dict)
)
records_revision: int = 0
selected_records_by_plan: dict[
tuple[int, int],
selected_records_by_source: dict[
tuple[
int, StepOutputManifestKey | None, frozenset[tuple[str, str, str | None]]
],
tuple[ProducedOutputSemantics, ...] | None,
] = field(default_factory=dict)
filtered_paths_by_plan: dict[
tuple[int, int, tuple[str, ...], int],
tuple[str, ...],
] = field(default_factory=dict)

def begin_step(
self,
Expand Down Expand Up @@ -324,8 +322,7 @@ def record_outputs(

def _invalidate_record_selection_caches(self) -> None:
self.records_revision += 1
self.selected_records_by_plan.clear()
self.filtered_paths_by_plan.clear()
self.selected_records_by_source.clear()

def producer_records_for(
self,
Expand Down Expand Up @@ -455,43 +452,45 @@ def filter_to_producer_paths(
paths: Sequence[str],
parser: FilenameParser,
) -> list[str]:
cache_key = (
self.records_revision,
id(plan),
tuple(str(path) for path in paths),
id(parser),
)
cached = self.filtered_paths_by_plan.get(cache_key)
if cached is not None:
return list(cached)

index = self.producer_record_index_for(plan, parser)
if index is None:
return list(paths)
selected = [path for path in paths if index.contains(path)]
if selected:
self.filtered_paths_by_plan[cache_key] = tuple(selected)
return selected
if paths:
raise NoStepOutputManifestMatch
self.filtered_paths_by_plan[cache_key] = ()
return []

def _producer_selection_key(
self,
plan: CompiledStepPlan,
) -> tuple[
int, StepOutputManifestKey | None, frozenset[tuple[str, str, str | None]]
]:
"""Select by current producer declarations, never a temporary plan address."""
return (
self.records_revision,
self._main_input_producer_key(plan),
self._requested_producer_outputs(plan),
)

def _selected_unique_producer_records_for(
self,
plan: CompiledStepPlan,
) -> tuple[ProducedOutputSemantics, ...] | None:
cache_key = (self.records_revision, id(plan))
if cache_key in self.selected_records_by_plan:
return self.selected_records_by_plan[cache_key]
cache_key = self._producer_selection_key(plan)
if cache_key in self.selected_records_by_source:
return self.selected_records_by_source[cache_key]

producer_records = self.producer_records_for(plan)
if producer_records is None:
self.selected_records_by_plan[cache_key] = None
producer_key, requested = cache_key[1:]
if producer_key is None:
self.selected_records_by_source[cache_key] = None
return None
selected = self._select_requested_producer_records(plan, producer_records)
producer_records = self.records_for_key(producer_key)
selected = self._select_requested_producer_records(requested, producer_records)
selected = self._unique_output_path_records(selected)
self.selected_records_by_plan[cache_key] = selected
self.selected_records_by_source[cache_key] = selected
return selected

@staticmethod
Expand All @@ -511,10 +510,9 @@ def _unique_output_path_records(

def _select_requested_producer_records(
self,
plan: CompiledStepPlan,
requested: frozenset[tuple[str, str, str | None]],
producer_records: Sequence[ProducedOutputSemantics],
) -> tuple[ProducedOutputSemantics, ...]:
requested = self._requested_producer_outputs(plan)
if not requested:
return tuple(producer_records)
selected = tuple(
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_cellprofiler_module_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
MeasureObjectSizeShapeModule,
ShapeObjectMeasurementRows,
_surface_area,
_surface_areas_3d_from_labels,
measure_object_size_shape_feature_arrays,
measure_object_size_shape,
)
from openhcs.processing.backends.cellprofiler.structuring_elements import (
Expand Down Expand Up @@ -18212,8 +18212,12 @@ def test_measure_object_size_shape_surface_areas_match_marching_cubes_oracle() -
)
expected.append(_surface_area(labels[bounds] == label_id))

features, measured_labels = measure_object_size_shape_feature_arrays(
labels, calculate_advanced=False, calculate_zernikes=False,
)
np.testing.assert_array_equal(measured_labels, label_ids)
np.testing.assert_allclose(
_surface_areas_3d_from_labels(labels, label_ids),
features[MeasureObjectSizeShapeModule.MeasurementFeature.SURFACE_AREA.value],
np.asarray(expected, dtype=np.float64),
rtol=1e-6,
atol=1e-5,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_function_runtime_source_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5630,8 +5630,12 @@ def test_producer_admission_rederives_live_storage_aliases_each_epoch(
record = replace(records[0], filename_component_values=storage_components)
store.record_outputs(producer, (record,))
old_index = store.producer_record_index_for(consumer, parser)
old_alias = record.without_filename_qualifier().filename(parser)
assert store.filter_to_producer_paths(consumer, (old_alias,), parser) == [old_alias]
storage_components["channel"] = 9
new_alias = record.without_filename_qualifier().filename(parser)
with pytest.raises(NoStepOutputManifestMatch):
store.filter_to_producer_paths(consumer, (old_alias,), parser)

assert old_index.matching_records(new_alias) == ()
current_index = store.producer_record_index_for(consumer, parser)
Expand Down
Loading