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
3 changes: 2 additions & 1 deletion openhcs/core/equivalence/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
normalize_runtime_source_name,
runtime_source_name_tokens,
)
from openhcs.core.measurements.runtime_measurements import MeasurementScope, MeasurementStatistic, ObjectCoreMeasurementFeature
from openhcs.core.measurements.measurement_declarations import MeasurementStatistic
from openhcs.core.measurements.runtime_measurements import MeasurementScope, ObjectCoreMeasurementFeature
from openhcs.core.equivalence.policy import RuntimeEquivalencePolicy


Expand Down
2 changes: 1 addition & 1 deletion openhcs/core/equivalence/measurement_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
EnumKeyedStrategyMixin,
MostDerivedContextStrategyMixin,
)
from openhcs.core.measurements.measurement_declarations import MeasurementStatistic
from openhcs.core.measurements.runtime_measurements import (
MeasurementScope,
MeasurementStatistic,
ObjectCoreMeasurementFeature,
object_location_features,
ObjectShapeDescriptorFeatureMarker,
Expand Down
2 changes: 1 addition & 1 deletion openhcs/core/equivalence/relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from openhcs.core.equivalence.keys import RuntimeAggregateFeatureIdentity
from openhcs.core.payload.runtime_identifier import normalize_runtime_identifier
from metaclass_registry.strategies import MostDerivedContextStrategyMixin
from openhcs.core.measurements.runtime_measurements import MeasurementStatistic
from openhcs.core.measurements.measurement_declarations import MeasurementStatistic
from openhcs.core.equivalence.keys import RuntimeMeasurementFeatureKey
from openhcs.core.measurements.measurement_dialect import MeasurementDialect

Expand Down
35 changes: 35 additions & 0 deletions openhcs/core/measurements/measurement_declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collections.abc import Iterable
from dataclasses import dataclass
from enum import Enum
from functools import lru_cache
from typing import ClassVar

from openhcs.core.axes.alias_property import AliasProperty
Expand Down Expand Up @@ -234,6 +235,14 @@ def requires_sparse_boundary_object_count_stability(cls) -> bool:
_DEFAULT_OBJECT_IDENTITY_OUTPUT_FIELD: str = "object_label"


class MeasurementStatistic(str, Enum):
"""Canonical runtime measurement statistic labels."""

VALUE = "value"
COUNT = "count"
MEAN = "mean"


@dataclass(frozen=True)
class RuntimeMeasurementRowIdentityContract:
"""Declare row identity precedence, sample numbering and the object-ID field.
Expand Down Expand Up @@ -304,3 +313,29 @@ def selected_sample_identity_fields(
if primary_fields:
return primary_fields
return normalized_present_fields & self.fallback_sample_fields

@lru_cache(maxsize=32768)
def is_sample_number_reference(self, field_name: str) -> bool:
"""Return whether ``field_name`` names the sample number of another row."""
normalized = normalize_runtime_identifier(field_name)
if normalized in self.sample_identity_fields:
return False
parts = tuple(part for part in normalized.split("_") if part)
number_parts = tuple(self.sample_number_field.split("_"))
width = len(number_parts)
return any(
parts[index : index + width] == number_parts
for index in range(len(parts) - width + 1)
)

@lru_cache(maxsize=32768)
def is_aggregate_sample_number_reference(self, field_name: str) -> bool:
"""Return whether ``field_name`` is a mean over sample-number references."""
parts = tuple(
part for part in normalize_runtime_identifier(field_name).split("_") if part
)
return (
bool(parts)
and parts[0] == MeasurementStatistic.MEAN.value
and self.is_sample_number_reference(field_name)
)
41 changes: 0 additions & 41 deletions openhcs/core/measurements/runtime_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from collections.abc import Iterable
from functools import lru_cache
from dataclasses import dataclass, field

from openhcs.core.artifacts.payloads import NamedArtifactPayload
Expand Down Expand Up @@ -619,14 +618,6 @@ def indexed_descriptor_declarations(
return self._indexed_descriptor_declaration_types


class MeasurementStatistic(str, Enum):
"""Canonical runtime measurement statistic labels."""

VALUE = "value"
COUNT = "count"
MEAN = "mean"


LOCATION_SPATIAL_DOMAIN = VolumeSourceSpatialDomain
"""The spatial domain object locations are reported in (its axis names)."""

Expand Down Expand Up @@ -795,38 +786,6 @@ def normalized_feature_name_field_names(cls) -> frozenset[str]:
)


@lru_cache(maxsize=32768)
def _is_sample_number_reference(
contract: RuntimeMeasurementRowIdentityContract,
field_name: str,
) -> bool:
normalized = normalize_runtime_identifier(field_name)
if normalized in contract.sample_identity_fields:
return False
parts = tuple(part for part in normalized.split("_") if part)
number_parts = tuple(contract.sample_number_field.split("_"))
width = len(number_parts)
return any(
parts[index : index + width] == number_parts
for index in range(len(parts) - width + 1)
)


@lru_cache(maxsize=32768)
def _is_aggregate_sample_number_reference(
contract: RuntimeMeasurementRowIdentityContract,
field_name: str,
) -> bool:
parts = tuple(
part for part in normalize_runtime_identifier(field_name).split("_") if part
)
return (
bool(parts)
and parts[0] == MeasurementStatistic.MEAN.value
and _is_sample_number_reference(contract, field_name)
)


class MeasurementRowValueField(str, Enum):
"""Canonical scalar value fields for long/tall measurement rows."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
TypeVar,
)
from openhcs.core.payload.runtime_identifier import normalize_runtime_identifier
from openhcs.core.measurements.measurement_declarations import MeasurementStatistic
from openhcs.core.measurements.runtime_measurements import (
MeasurementScope,
MeasurementStatistic,
ObjectShapeDescriptorFeatureMarker,
RuntimeMeasurementFeature,
RuntimeMeasurementFeatureOwner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def apply(self, request: FeatureEnhancementRequest) -> np.ndarray:
footprint = _structuring_element(request.radius)
masked = request.mask_context.masked_original
if request.speckle_accuracy is SpeckleAccuracy.FAST and request.radius > 3:
from openhcs.processing.backends.cellprofiler.morphology import MorphologyBackendStrategy
from openhcs.processing.backends.cellprofiler.morphology_family.morphology import MorphologyBackendStrategy

opened = MorphologyBackendStrategy.for_callable(
enhance_or_suppress_features,
Expand Down
2 changes: 1 addition & 1 deletion openhcs/processing/backends/cellprofiler/relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
runtime_callable_defaults,
)
from openhcs.core.payload.runtime_identifier import normalize_runtime_identifier
from openhcs.core.measurements.measurement_declarations import MeasurementStatistic
from openhcs.core.measurements.runtime_measurements import (
MeasurementStatistic,
RuntimeMeasurementFeatureDeclaration,
RuntimeMeasurementFeatureSemanticMarker,
)
Expand Down
Loading
Loading