Skip to content

prediction_status

Status and updates generated by the prediction worker.

PredictionState #

Bases: IntEnum

Prediction state.

Source code in src/careamics_napari/signals/prediction_status.py
class PredictionState(IntEnum):
    """Prediction state."""

    IDLE = 0
    """Prediction is idle."""

    PREDICTING = 1
    """Prediction is ongoing."""

    DONE = 2
    """Prediction is done."""

    STOPPED = 3
    """Prediction was stopped."""

    CRASHED = 4
    """Prediction crashed."""

CRASHED = 4 class-attribute instance-attribute #

Prediction crashed.

DONE = 2 class-attribute instance-attribute #

Prediction is done.

IDLE = 0 class-attribute instance-attribute #

Prediction is idle.

PREDICTING = 1 class-attribute instance-attribute #

Prediction is ongoing.

STOPPED = 3 class-attribute instance-attribute #

Prediction was stopped.

PredictionStatus dataclass #

Status of the prediction thread.

This dataclass is used to update the prediction UI with the current status and progress of the prediction. Listeners can be registered to the events attribute to be notified of changes in the value of the attributes (see psygnal documentation for more details).

Source code in src/careamics_napari/signals/prediction_status.py
@evented
@dataclass
class PredictionStatus:
    """Status of the prediction thread.

    This dataclass is used to update the prediction UI with the current status and
    progress of the prediction. Listeners can be registered to the `events` attribute to
    be notified of changes in the value of the attributes (see `psygnal` documentation
    for more details).
    """

    if TYPE_CHECKING:
        events: PredictionStatusSignalGroup
        """Attribute allowing the registration of parameter-specific listeners."""

    max_samples: int = -1
    """Number of samples."""

    sample_idx: int = -1
    """Index of the current sample being predicted."""

    state: PredictionState = PredictionState.IDLE
    """Current state of the prediction process."""

    def update(self, new_update: PredictionUpdate) -> None:
        """Update the status with the new values.

        Exceptions, debugging messages and samples are ignored.

        Parameters
        ----------
        new_update : PredictionUpdate
            New update to apply.
        """
        if (
            new_update.type != PredictionUpdateType.EXCEPTION
            and new_update.type != PredictionUpdateType.DEBUG
            and new_update.type != PredictionUpdateType.SAMPLE
        ):
            setattr(self, new_update.type.value, new_update.value)

events instance-attribute #

Attribute allowing the registration of parameter-specific listeners.

max_samples = -1 class-attribute instance-attribute #

Number of samples.

sample_idx = -1 class-attribute instance-attribute #

Index of the current sample being predicted.

state = PredictionState.IDLE class-attribute instance-attribute #

Current state of the prediction process.

update(new_update) #

Update the status with the new values.

Exceptions, debugging messages and samples are ignored.

Parameters:

Name Type Description Default
new_update PredictionUpdate

New update to apply.

required
Source code in src/careamics_napari/signals/prediction_status.py
def update(self, new_update: PredictionUpdate) -> None:
    """Update the status with the new values.

    Exceptions, debugging messages and samples are ignored.

    Parameters
    ----------
    new_update : PredictionUpdate
        New update to apply.
    """
    if (
        new_update.type != PredictionUpdateType.EXCEPTION
        and new_update.type != PredictionUpdateType.DEBUG
        and new_update.type != PredictionUpdateType.SAMPLE
    ):
        setattr(self, new_update.type.value, new_update.value)

PredictionStatusSignalGroup #

Bases: SignalGroup

Signal group for the prediction status dataclass.

Source code in src/careamics_napari/signals/prediction_status.py
class PredictionStatusSignalGroup(SignalGroup):
    """Signal group for the prediction status dataclass."""

    max_samples: SignalInstance
    """Number of samples."""

    sample_idx: SignalInstance
    """Index of the current sample being predicted."""

    state: SignalInstance
    """Current state of the prediction process."""

max_samples instance-attribute #

Number of samples.

sample_idx instance-attribute #

Index of the current sample being predicted.

state instance-attribute #

Current state of the prediction process.

PredictionUpdate dataclass #

Update from the prediction worker.

Source code in src/careamics_napari/signals/prediction_status.py
@dataclass
class PredictionUpdate:
    """Update from the prediction worker."""

    type: PredictionUpdateType
    """Type of the update."""

    value: Optional[Union[int, float, str, NDArray, PredictionState, Exception]] = None
    """Content of the update."""

type instance-attribute #

Type of the update.

value = None class-attribute instance-attribute #

Content of the update.

PredictionUpdateType #

Bases: str, Enum

Type of prediction update.

Source code in src/careamics_napari/signals/prediction_status.py
class PredictionUpdateType(str, Enum):
    """Type of prediction update."""

    MAX_SAMPLES = "max_samples"
    """Number of samples."""

    SAMPLE_IDX = "sample_idx"
    """Index of the current sample being predicted."""

    SAMPLE = "sample"
    """Prediction result."""

    STATE = "state"
    """Current state of the prediction process."""

    DEBUG = "debug message"
    """Debug message."""

    EXCEPTION = "exception"
    """Exception raised during the prediction process."""

DEBUG = 'debug message' class-attribute instance-attribute #

Debug message.

EXCEPTION = 'exception' class-attribute instance-attribute #

Exception raised during the prediction process.

MAX_SAMPLES = 'max_samples' class-attribute instance-attribute #

Number of samples.

SAMPLE = 'sample' class-attribute instance-attribute #

Prediction result.

SAMPLE_IDX = 'sample_idx' class-attribute instance-attribute #

Index of the current sample being predicted.

STATE = 'state' class-attribute instance-attribute #

Current state of the prediction process.