erlab.interactive.imagetool.provenanceΒΆ

Public ImageTool provenance API.

Functions

compose_display_provenance(parent, ...[, ...])

Compose streamlined display provenance from a live source spec.

compose_full_provenance(parent, local)

Compose canonical full provenance from parent and local provenance.

decode_provenance_value(value)

Decode values produced by encode_provenance_value().

direct_replay_input_name(value)

Return a direct input expression for simple replay seeds.

encode_provenance_value(value)

Encode non-JSON provenance values into a JSON-safe representation.

file_load(*, start_label, seed_code, ...[, ...])

Build structured file-backed provenance for runtime reload.

full_data(*operations)

Build a spec that starts from the parent's full current data.

mark_promoted_1d_source(data)

Return data tagged as originating from a promoted 1D source.

operation_from_console_call(call)

Return the structured operation represented by a console call, if known.

operations_expression_code(operations, ...)

Return chained expression code for structured operations.

parse_tool_provenance_operation(value)

Parse one serialized operation payload.

parse_tool_provenance_spec(value)

Parse a serialized provenance payload into a validated spec instance.

public_data(*operations)

Build a spec that starts from the parent's restored public data.

rebase_default_replay_input(code, input_name)

Replace the generic data replay input in generated code.

rebase_script_input_node_uids(value, uid_map)

Return value with script input node UIDs remapped recursively.

replay_file_provenance(spec, *[, cache])

Replay structured file provenance without executing generated Python.

replay_input_name(value)

replay_script_provenance(spec, inputs)

Execute script provenance from already resolved input arrays.

require_live_source_spec(value)

script(*operations, start_label[, ...])

Build script provenance from code, structured steps, and named inputs.

script_input_dependency_refs(value)

Return all live manager dependency references stored in script inputs.

script_provenance_replayable(spec)

Return whether script provenance is self-contained enough to execute.

selection(*operations)

Build a spec that starts from the parent's public selection model.

to_replay_provenance_spec(value)

Parse value and normalize it into canonical replay provenance.

uses_default_replay_input(code)

Return whether generated replay code refers to the generic data input.

Classes

AffineCoordOperation(**data)

AssignAttrsOperation(**data)

AssignCoord1DOperation(**data)

AssignCoordsOperation(**data)

AssignScalarCoordOperation(**data)

AverageOperation(**data)

CoarsenOperation(**data)

ConsoleCall(*[, func, dataarray_method, ...])

Normalized runtime call observed by the ImageTool manager console.

ConsoleOperationPattern(*[, target, ...])

Declarative matcher for direct console-to-operation mappings.

CorrectWithEdgeOperation(**data)

DerivationEntry(label, code[, copyable])

One user-visible step in a provenance derivation listing.

DivideByCoordOperation(**data)

FileDataSelection(**data)

Serializable selection of one displayable array from a loaded file object.

FileLoadSource(**data)

Serializable file origin used by saved file-backed provenance.

FileReplayCall(**data)

Serializable call information used to reload file-backed provenance.

GaussianFilterOperation(**data)

ImageToolSelectionSourceBinding(**data)

ImageTool selection state stored for manager child refreshes.

InterpolationOperation(**data)

IselOperation(**data)

LeadingEdgeOperation(**data)

MaskWithPolygonOperation(**data)

NormalizeOperation(**data)

QSelAggregationOperation(**data)

QSelOperation(**data)

RenameDimsCoordsOperation(**data)

RenameOperation(**data)

ReplayStage(**data)

Structured transformation stage replayed against one parent data array.

RestoreNonuniformDimsOperation(**data)

RotateOperation(**data)

ScriptCodeOperation(**data)

ScriptInput(**data)

Named input captured by script or multi-tool provenance.

ScriptInputDependencyRef(name, label, node_uid)

Live manager dependency captured by a script input.

SelOperation(**data)

SelectCoordOperation(**data)

SliceAlongPathOperation(**data)

SortCoordOrderOperation(**data)

SqueezeOperation(**data)

SwapDimsOperation(**data)

SymmetrizeNfoldOperation(**data)

SymmetrizeOperation(**data)

ThinOperation(**data)

ToolProvenanceOperation(**data)

Base class for typed operations stored in ToolProvenanceSpec.

ToolProvenanceSpec(**data)

Saved provenance recipe for ImageTool data.

TransposeOperation(**data)

class erlab.interactive.imagetool.provenance.AffineCoordOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['affine_coord']ΒΆ
coord_name: strΒΆ
scale: floatΒΆ
offset: floatΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.AssignAttrsOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['assign_attrs']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
attrs: ProvenanceMappingΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.AssignCoord1DOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['assign_coord_1d']ΒΆ
coord_name: ProvenanceHashableΒΆ
dim: ProvenanceHashableΒΆ
values: typing.AnyΒΆ
classmethod from_console_call(call)[source]ΒΆ
property decoded_values: ndarrayΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.AssignCoordsOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['assign_coords']ΒΆ
coord_name: strΒΆ
values: typing.AnyΒΆ
classmethod from_console_call(call)[source]ΒΆ
property decoded_values: ndarrayΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.AssignScalarCoordOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['assign_scalar_coord']ΒΆ
coord_name: ProvenanceHashableΒΆ
value: typing.AnyΒΆ
classmethod from_console_call(call)[source]ΒΆ
property decoded_value: AnyΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.AverageOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['average']ΒΆ
dims: ProvenanceHashableTupleΒΆ
classmethod from_console_call(call)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.CoarsenOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['coarsen']ΒΆ
dim: ProvenanceIntMappingΒΆ
boundary: strΒΆ
side: strΒΆ
coord_func: strΒΆ
reducer: strΒΆ
classmethod from_console_call(call)[source]ΒΆ
property coarsen_kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ConsoleCall(*, func=None, dataarray_method=None, accessor_path=(), args=(), kwargs=None, display_code, has_extra_tracked_inputs, receiver_data=None)[source]ΒΆ

Bases: object

Normalized runtime call observed by the ImageTool manager console.

Console proxies create this descriptor after unwrapping provenance-aware tool handles to raw xarray.DataArray arguments. Operation classes inspect the invoked callable, DataArray method/accessor context, and raw arguments to decide whether the call can be represented as structured provenance.

accessor_pathΒΆ
argsΒΆ
dataarray_methodΒΆ
display_codeΒΆ
funcΒΆ
has_extra_tracked_inputsΒΆ
kwargsΒΆ
receiver_dataΒΆ
class erlab.interactive.imagetool.provenance.ConsoleOperationPattern(*, target=None, dataarray_method=None, accessor_path=(), fields=(), field_aliases=None, kwargs_field=None, mapping_kwarg=None, defaults=None, ignored_defaults=None)[source]ΒΆ

Bases: object

Declarative matcher for direct console-to-operation mappings.

Use this for calls where public arguments map directly onto operation model fields. Store module-function targets as strings so importing this module does not resolve lazy ERLab analysis modules; the matcher compares those strings with the callable that the console actually invoked. More complex calls should implement ToolProvenanceOperation.from_console_call().

accessor_pathΒΆ
dataarray_methodΒΆ
defaultsΒΆ
field_aliasesΒΆ
fieldsΒΆ
ignored_defaultsΒΆ
kwargs_fieldΒΆ
mapping_kwargsΒΆ
targetsΒΆ
match(call)[source]ΒΆ
class erlab.interactive.imagetool.provenance.CorrectWithEdgeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['correct_with_edge']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
edge_fit: typing.AnyΒΆ
shift_coords: boolΒΆ
property decoded_edge_fit: DatasetΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.DerivationEntry(label, code, copyable=False)[source]ΒΆ

Bases: object

One user-visible step in a provenance derivation listing.

copyable: bool = FalseΒΆ
label: strΒΆ
code: str | NoneΒΆ
class erlab.interactive.imagetool.provenance.DivideByCoordOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['divide_by_coord']ΒΆ
coord_name: ProvenanceHashableΒΆ
divisor_code(data_name)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.FileDataSelection(**data)[source]ΒΆ

Bases: BaseModel

Serializable selection of one displayable array from a loaded file object.

New provenance stores stable Dataset variable names and DataTree data paths instead of the positional parsed-array index used by older workspaces.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

kind: typing.Literal['dataarray', 'dataset_variable', 'datatree_path', 'parsed_index']ΒΆ
value: typing.AnyΒΆ
class erlab.interactive.imagetool.provenance.FileLoadSource(**data)[source]ΒΆ

Bases: BaseModel

Serializable file origin used by saved file-backed provenance.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

path: strΒΆ
loader_label: strΒΆ
loader_text: strΒΆ
kwargs_text: strΒΆ
replay_call: FileReplayCall | NoneΒΆ
load_code: str | NoneΒΆ
class erlab.interactive.imagetool.provenance.FileReplayCall(**data)[source]ΒΆ

Bases: BaseModel

Serializable call information used to reload file-backed provenance.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

kind: typing.Literal['erlab_loader', 'callable']ΒΆ
target: strΒΆ
kwargs: dict[str, typing.Any]ΒΆ
selection: FileDataSelectionΒΆ
cast_float64: boolΒΆ
class erlab.interactive.imagetool.provenance.GaussianFilterOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['gaussian_filter']ΒΆ
sigma: ProvenanceFloatMappingΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ImageToolSelectionSourceBinding(**data)[source]ΒΆ

Bases: BaseModel

ImageTool selection state stored for manager child refreshes.

Stores the parent dimension indices selected in an ImageTool plot. When a child refreshes after parent coordinates change, materialize() rebuilds qsel or isel operations from the current parent data so the child follows the same cursor or bin position instead of old coordinate labels.

schema_version: typing.Literal[1]ΒΆ
kind: typing.Literal['imagetool_selection']ΒΆ
selection_mode: typing.Literal['qsel', 'isel']ΒΆ
selection_indexers: ProvenanceMappingΒΆ
selection_binned_dims: ProvenanceHashableTupleΒΆ
crop_sel_indexers: ProvenanceMappingΒΆ
crop_isel_indexers: ProvenanceMappingΒΆ
transpose_dims: NullableProvenanceHashableTupleΒΆ
squeeze: boolΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

materialize(parent_data)[source]ΒΆ

Build a source spec for the current parent data.

class erlab.interactive.imagetool.provenance.InterpolationOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['interpolate']ΒΆ
dim: ProvenanceHashableΒΆ
values: typing.AnyΒΆ
method: typing.Literal['linear', 'nearest']ΒΆ
classmethod from_console_call(call)[source]ΒΆ
property decoded_values: ndarrayΒΆ
apply(data, *, parent_data)[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
derivation_label()[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.IselOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['isel']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
kwargs: ProvenanceMappingΒΆ
property decoded_kwargs: dict[Hashable, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.LeadingEdgeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['leading_edge']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
fraction: floatΒΆ
dim: ProvenanceHashableΒΆ
direction: typing.Literal['positive', 'negative']ΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.MaskWithPolygonOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['mask_with_polygon']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
vertices: typing.AnyΒΆ
dims: ProvenanceHashableTupleΒΆ
invert: boolΒΆ
drop: boolΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.NormalizeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['normalize']ΒΆ
dims: ProvenanceHashableTupleΒΆ
mode: typing.Literal['area', 'minmax', 'min', 'min_area']ΒΆ
denominator_rtol: floatΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.QSelAggregationOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['qsel_aggregate']ΒΆ
dims: ProvenanceHashableTupleΒΆ
func: typing.Literal['mean', 'min', 'max', 'sum']ΒΆ
classmethod from_console_call(call)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.QSelOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['qsel']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
kwargs: ProvenanceMappingΒΆ
property decoded_kwargs: dict[Hashable, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.RenameDimsCoordsOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['rename_dims_coords']ΒΆ
mapping: ProvenanceHashableMappingΒΆ
classmethod from_console_call(call)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.RenameOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['rename']ΒΆ
name: strΒΆ
classmethod from_console_call(call)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ReplayStage(**data)[source]ΒΆ

Bases: BaseModel

Structured transformation stage replayed against one parent data array.

classmethod from_source_spec(source)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

source_kind: typing.Literal['full_data', 'public_data', 'selection']ΒΆ
operations: tuple[pydantic.SerializeAsAny[ToolProvenanceOperation], ...]ΒΆ
class erlab.interactive.imagetool.provenance.RestoreNonuniformDimsOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['restore_nonuniform_dims']ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.RotateOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['rotate']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
angle: floatΒΆ
axes: ProvenanceHashablePairΒΆ
center: tuple[float, float]ΒΆ
reshape: boolΒΆ
order: intΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ScriptCodeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['script_code']ΒΆ
label: strΒΆ
code: str | NoneΒΆ
copyable: boolΒΆ
live_applicable: typing.ClassVar[bool] = FalseΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_entry()[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ScriptInput(**data)[source]ΒΆ

Bases: BaseModel

Named input captured by script or multi-tool provenance.

name is the immutable replay variable, label is the historical display label, node_uid and node_snapshot_token identify the live manager input that was used, and provenance_spec stores the historical replay source used when that live input is unavailable.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parsed_provenance_spec()[source]ΒΆ
name: strΒΆ
label: strΒΆ
node_uid: str | NoneΒΆ
node_snapshot_token: str | NoneΒΆ
provenance_spec: dict[str, typing.Any] | NoneΒΆ
class erlab.interactive.imagetool.provenance.ScriptInputDependencyRef(name, label, node_uid, node_snapshot_token=None)[source]ΒΆ

Bases: object

Live manager dependency captured by a script input.

node_snapshot_token: str | None = NoneΒΆ
name: strΒΆ
label: strΒΆ
node_uid: strΒΆ
class erlab.interactive.imagetool.provenance.SelOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['sel']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
kwargs: ProvenanceMappingΒΆ
property decoded_kwargs: dict[Hashable, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SelectCoordOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['select_coord']ΒΆ
coord_name: ProvenanceHashableΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SliceAlongPathOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['slice_along_path']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
vertices: ProvenanceFloatSequenceMappingΒΆ
step_size: floatΒΆ
dim_name: strΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SortCoordOrderOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['sort_coord_order']ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SqueezeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['squeeze']ΒΆ
classmethod from_console_call(call)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SwapDimsOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['swap_dims']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
mapping: ProvenanceHashableMappingΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SymmetrizeNfoldOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['symmetrize_nfold']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
fold: intΒΆ
axes: ProvenanceHashablePairΒΆ
center: typing.AnyΒΆ
reshape: boolΒΆ
order: intΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.SymmetrizeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['symmetrize']ΒΆ
console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = (<erlab.interactive.imagetool._provenance_framework.ConsoleOperationPattern object>,)ΒΆ
dim: ProvenanceHashableΒΆ
center: floatΒΆ
subtract: boolΒΆ
mode: typing.Literal['full', 'valid']ΒΆ
part: typing.Literal['both', 'below', 'above']ΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ThinOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['thin']ΒΆ
mode: typing.Literal['global', 'per_dim']ΒΆ
factor: int | NoneΒΆ
factors: ProvenanceIntMappingΒΆ
classmethod from_console_call(call)[source]ΒΆ
property kwargs: dict[str, Any]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class erlab.interactive.imagetool.provenance.ToolProvenanceOperation(**data)[source]ΒΆ

Bases: BaseModel

Base class for typed operations stored in ToolProvenanceSpec.

New operations should keep runtime fields in their decoded Python form, prefer the annotated provenance field aliases in this module for lossless JSON serialization, implement apply() to replay the transformation, implement expression_code() to emit the public Python expression for the same transformation, and implement derivation_label() to describe the step in manager UI.

Operation instances store the exact arguments used by live refresh, replay graph execution, copied code, and derivation display. If a public console call maps exactly to an operation, expose it with console_patterns or from_console_call(); ambiguous calls should return None so script provenance records the original code instead.

apply(data, *, parent_data)[source]ΒΆ

Apply this operation to the current derived array.

Subclasses that participate in live refresh or executable provenance replay should reimplement this method. The implementation must be deterministic for the operation’s stored model fields and must not mutate data or parent_data in place.

Parameters:
  • data (DataArray) – Array produced by the preceding replay step.

  • parent_data (DataArray) – Parent ImageTool data for the enclosing provenance spec. Operations may inspect it for coordinates, dimension order, or metadata.

Returns:

xarray.DataArray – Array after this operation has been applied.

Return type:

DataArray

Notes

Operations that only emit generated code should set live_applicable = False and raise from this method.

console_patterns: typing.ClassVar[tuple[ConsoleOperationPattern, ...]] = ()ΒΆ
derivation_entry()[source]ΒΆ

Return the user-visible derivation entry for this operation.

Structured transform subclasses should normally reimplement derivation_label() and expression_code() instead of overriding this method. Override this method only for operations whose display entry cannot be represented as a label plus parameterized operation code, such as stored free-form script code.

Returns:

DerivationEntry – Label, replay code, and copyability flag shown in derivation UI and used by legacy derivation-code paths.

Return type:

DerivationEntry

Notes

The base implementation keeps the legacy derived replay contract while letting concrete operations emit expression code for any input variable.

Use DerivationEntry(..., code=None) instead when the step should remain visible in the derivation list but code generation should stop and return None.

derivation_label()[source]ΒΆ

Return the derivation-list label for this operation.

Subclasses should reimplement this for every structured operation that uses the base derivation_entry() implementation.

Returns:

str – Human-readable operation label for derivation/history UI. Include the operation’s meaningful parameters when they help explain the produced data.

Return type:

str

expression_code(input_name, *, source_name=None)[source]ΒΆ

Return a Python expression applying this operation to an input name.

Subclasses should reimplement this for every structured operation that can be represented as ordinary user-facing Python code. The emitted expression should be complete, public-API-based, and free of assignment to hardcoded temporary names.

Parameters:
  • input_name (str) – Python expression or identifier for the array produced by the previous replay step. Use this exact value as the operation receiver/input instead of assuming a variable name such as derived.

  • source_name (str | None, default: None) – Python expression or identifier for the original public input array for the enclosing replay sequence. Operations that need parent/source context, such as coordinate-order restoration, should use this name for that context. Operations that only transform input_name may ignore it.

Returns:

str – Python expression that evaluates to the transformed DataArray.

Return type:

str

classmethod from_console_call(call)[source]ΒΆ

Build an operation from a normalized manager-console call.

Subclasses should reimplement this when a console call maps cleanly to the operation but cannot be expressed with declarative console_patterns alone. Return None for unsupported, ambiguous, or lossy calls so the original console code remains recorded as script provenance.

Parameters:

call (ConsoleCall) – Normalized descriptor for the function, method, or accessor call observed by the ImageTool manager console, including unwrapped arguments, keyword arguments, display code, and receiver data when available.

Returns:

ToolProvenanceOperation or None – Operation instance when the call is exactly representable by this operation class; otherwise None.

Return type:

ToolProvenanceOperation | None

live_applicable: typing.ClassVar[bool] = TrueΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

replay_code(input_name, *, output_name=None, source_name=None)[source]ΒΆ

Return replay code for this operation with caller-selected names.

This method usually should not be reimplemented by subclasses. Implement expression_code() instead so replay graph emission, dialog copy code, and derivation entries all share the same operation expression.

Parameters:
  • input_name (str) – Python expression or identifier for the array produced by the previous replay step.

  • output_name (str | None, default: None) – Variable name to assign the transformed value to. If None, return only the expression from expression_code().

  • source_name (str | None, default: None) – Python expression or identifier for the original public input array for the enclosing replay sequence. Passed through to expression_code().

Returns:

str – Either an assignment statement when output_name is provided, or a bare expression when it is None.

Return type:

str

class erlab.interactive.imagetool.provenance.ToolProvenanceSpec(**data)[source]ΒΆ

Bases: BaseModel

Saved provenance recipe for ImageTool data.

Live child-tool refresh uses single-parent specs from full_data(), public_data(), or selection(). Durable reload and copied code use file and script specs, including multi-input script_inputs for console or UI actions that combine several ImageTools. Deserialize saved payloads with parse_tool_provenance_spec().

A spec records exact operation arguments for live refresh, runtime replay, copied code, and derivation display. Manager children opened from ImageTool cursor or bin selections should keep ImageToolSelectionSourceBinding as their refresh state; that binding builds a spec before refresh so edited parent coordinates are used.

append_display_operation(operation)[source]ΒΆ

Append a live display operation without making a final name stale.

append_final_rename(name)[source]ΒΆ
append_operations(*operations)[source]ΒΆ

Append operation instances to the spec.

Runtime code should pass operation instances from this module. Saved mappings should be normalized with parse_tool_provenance_spec() before calling this method.

append_replacement_operations(*operations)[source]ΒΆ

Replace a final rename, if present, then append new operation instances.

append_replay_stage(source)[source]ΒΆ

Append one live-source transformation stage to file provenance.

apply(parent_data)[source]ΒΆ
derivation_code()[source]ΒΆ
derivation_entries()[source]ΒΆ
display_code(*, parent_data=None)[source]ΒΆ

Return streamlined replay code for UI and clipboard actions.

The display path preserves exact live-source behavior while omitting user-facing no-op and normalization steps from copied provenance code.

display_entries(*, parent_data=None)[source]ΒΆ

Return streamlined derivation entries for UI and copy-code output.

The display path hides internal ImageTool normalization steps while keeping the recorded replay steps available through derivation_entries().

drop_trailing_rename()[source]ΒΆ
property is_live_source: boolΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to_replay_spec()[source]ΒΆ

Return the durable replay form for this spec.

Replay specs are the canonical, composable form used for derivation metadata, copied code, workspace save/load, and manager dependency status. Structured file provenance remains structured so runtime reloads can replay typed operations without exec. Live ImageTool refresh uses the original single-parent spec via require_live_source_spec().

schema_version: typing.Literal[2]ΒΆ
kind: typing.Literal['full_data', 'public_data', 'selection', 'script', 'file']ΒΆ
start_label: str | NoneΒΆ
seed_code: str | NoneΒΆ
active_name: str | NoneΒΆ
operations: tuple[pydantic.SerializeAsAny[ToolProvenanceOperation], ...]ΒΆ
file_load_source: FileLoadSource | NoneΒΆ
replay_stages: tuple[ReplayStage, ...]ΒΆ
script_inputs: tuple[ScriptInput, ...]ΒΆ
class erlab.interactive.imagetool.provenance.TransposeOperation(**data)[source]ΒΆ

Bases: ToolProvenanceOperation

op: typing.Literal['transpose']ΒΆ
dims: NullableProvenanceHashableTupleΒΆ
classmethod from_console_call(call)[source]ΒΆ
apply(data, *, parent_data)[source]ΒΆ
derivation_label()[source]ΒΆ
expression_code(input_name, *, source_name=None)[source]ΒΆ
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'frozen': True}ΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

erlab.interactive.imagetool.provenance.compose_display_provenance(parent, source_spec, *, parent_data=None)[source]ΒΆ

Compose streamlined display provenance from a live source spec.

erlab.interactive.imagetool.provenance.compose_full_provenance(parent, local)[source]ΒΆ

Compose canonical full provenance from parent and local provenance.

parent represents the replay provenance for the current input data. local represents the additional steps performed by the current node. File-backed parents remain structured when composed with live-source specs so runtime reloads can avoid executing generated Python.

erlab.interactive.imagetool.provenance.decode_provenance_value(value)[source]ΒΆ

Decode values produced by encode_provenance_value().

erlab.interactive.imagetool.provenance.direct_replay_input_name(value)[source]ΒΆ

Return a direct input expression for simple replay seeds.

This only applies to non-default single-line seeds such as watched variables. Generic replay aliases like derived = data continue to use derived so existing non-watched code generation remains stable.

erlab.interactive.imagetool.provenance.encode_provenance_value(value)[source]ΒΆ

Encode non-JSON provenance values into a JSON-safe representation.

erlab.interactive.imagetool.provenance.file_load(*, start_label, seed_code, file_load_source, active_name='derived', replay_stages=())[source]ΒΆ

Build structured file-backed provenance for runtime reload.

erlab.interactive.imagetool.provenance.full_data(*operations)[source]ΒΆ

Build a spec that starts from the parent’s full current data.

erlab.interactive.imagetool.provenance.mark_promoted_1d_source(data)[source]ΒΆ

Return data tagged as originating from a promoted 1D source.

erlab.interactive.imagetool.provenance.operation_from_console_call(call)[source]ΒΆ

Return the structured operation represented by a console call, if known.

erlab.interactive.imagetool.provenance.operations_expression_code(operations, input_name, *, source_name=None)[source]ΒΆ

Return chained expression code for structured operations.

source_name is the public/source array name passed to operations that need context beyond the transformed input, such as coordinate-order restoration.

erlab.interactive.imagetool.provenance.parse_tool_provenance_operation(value)[source]ΒΆ

Parse one serialized operation payload.

This is the deserialize boundary for saved JSON. Runtime call sites should build concrete operation instances directly instead of passing raw mappings around.

erlab.interactive.imagetool.provenance.parse_tool_provenance_spec(value)[source]ΒΆ

Parse a serialized provenance payload into a validated spec instance.

This is the deserialize boundary for saved tool and workspace metadata. Runtime authoring code should pass ToolProvenanceSpec instances directly.

erlab.interactive.imagetool.provenance.public_data(*operations)[source]ΒΆ

Build a spec that starts from the parent’s restored public data.

erlab.interactive.imagetool.provenance.rebase_default_replay_input(code, input_name)[source]ΒΆ

Replace the generic data replay input in generated code.

Manager clipboard actions use this when a concrete source is known, such as a watched variable, a load snippet target, or a user-provided variable name.

erlab.interactive.imagetool.provenance.rebase_script_input_node_uids(value, uid_map)[source]ΒΆ

Return value with script input node UIDs remapped recursively.

erlab.interactive.imagetool.provenance.replay_file_provenance(spec, *, cache=None)[source]ΒΆ

Replay structured file provenance without executing generated Python.

erlab.interactive.imagetool.provenance.replay_input_name(value)[source]ΒΆ
erlab.interactive.imagetool.provenance.replay_script_provenance(spec, inputs)[source]ΒΆ

Execute script provenance from already resolved input arrays.

The caller is responsible for trust and input resolution. This function only validates the provenance shape, compiles it through the replay graph, and returns the replayed xarray.DataArray.

erlab.interactive.imagetool.provenance.require_live_source_spec(value)[source]ΒΆ
erlab.interactive.imagetool.provenance.script(*operations, start_label, seed_code=None, active_name=None, file_load_source=None, script_inputs=())[source]ΒΆ

Build script provenance from code, structured steps, and named inputs.

erlab.interactive.imagetool.provenance.script_input_dependency_refs(value)[source]ΒΆ

Return all live manager dependency references stored in script inputs.

erlab.interactive.imagetool.provenance.script_provenance_replayable(spec)[source]ΒΆ

Return whether script provenance is self-contained enough to execute.

This checks the saved code and structured operations. It does not mean live manager inputs are present; callers still need to resolve script_inputs.

erlab.interactive.imagetool.provenance.selection(*operations)[source]ΒΆ

Build a spec that starts from the parent’s public selection model.

erlab.interactive.imagetool.provenance.to_replay_provenance_spec(value)[source]ΒΆ

Parse value and normalize it into canonical replay provenance.

erlab.interactive.imagetool.provenance.uses_default_replay_input(code)[source]ΒΆ

Return whether generated replay code refers to the generic data input.