Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Registration artifacts and restart behavior

Cy-ExM treats a registration output as a committed cache entry only when the artifact and its own completion JSON are both present, readable, and consistent with the current request. Filename existence by itself never proves completion.

The exact inventories below describe standalone direct-Python ImageRegistration and ChunkedImageRegistration artifacts written inside their dedicated save directory. The YAML workflow layout nests a moving round’s equivalent registration artifacts under rounds/round-002/registration/, manages reference and transformed channels in per-round channels/ directories, and names the shared reference crop reference_crop_indices.json. See Outputs, restart, and recovery for that dataset-level layout, ordinary resume, force, status, and recovery.

Use a dedicated output directory for each fixed/moving registration request. The transform and registered-image names include {round}, while the fixed reference and metric filenames do not; mixing different round requests in one directory therefore produces a deliberate cache-request mismatch instead of silent reuse.

Standalone whole-image artifact inventory

For imaging round {round}, direct ImageRegistration may create:

ArtifactPurposeCompletion record
fixed_reference.tifuint16 fixed reference used for inspectionfixed_reference.tif.complete.json
image_metrics_pre-registration.txtsimilarity before registrationimage_metrics_pre-registration.txt.complete.json
linear_transform_{round}.matforward affine transformlinear_transform_{round}.mat.complete.json
image_metrics_linearly-registered.txtsimilarity after affine applicationimage_metrics_linearly-registered.txt.complete.json
nonlinear_warp_{round}.nii.gzfull-round forward displacement fieldnonlinear_warp_{round}.nii.gz.complete.json
image_metrics_nonlinear-registered.txtsimilarity after nonlinear applicationimage_metrics_nonlinear-registered.txt.complete.json
nonlinear_registered_{round}.tiffinal uint16 registered intensity imagenonlinear_registered_{round}.tif.complete.json

When XY rotation or similarity initialization is enabled, three artifacts are committed before the affine stage:

Conditional artifactPurposeCompletion record
initial_alignment_{round}.jsonangle, optional uniform XY scale, translation, geometry, source/crop identities, scores, and confidenceinitial_alignment_{round}.json.complete.json
initial_alignment_{round}.matexact seed supplied to the configured 3-D linear stageinitial_alignment_{round}.mat.complete.json
initial_alignment_qc_{round}.pngfixed/moving/initialized montage and score plotinitial_alignment_qc_{round}.png.complete.json

When crop=True, two additional conditional artifacts are committed before registration:

Conditional artifactPurposeCompletion record
fixed_crop_indices_{round}.jsonexclusive fixed ZYX crop boundsfixed_crop_indices_{round}.json.complete.json
moving_crop_indices_{round}.jsonexclusive moving ZYX crop boundsmoving_crop_indices_{round}.json.complete.json

Standalone serial chunk artifact inventory

Direct ChunkedImageRegistration creates the whole-image artifacts above plus local nonlinear evidence under round_{round}_chunks/:

ArtifactPurposeCompletion record
chunk_{chunk:04d}_warp.nii.gzone readable local forward displacement fieldchunk_{chunk:04d}_warp.nii.gz.complete.json
chunk_{chunk:04d}_registered_core.npyfloat32 registered scalar core shared by coarse and fine assemblychunk_{chunk:04d}_registered_core.npy.complete.json
manifest.jsoncanonical ordered grid and identities of every local warpmanifest.json.complete.json

The round-level nonlinear_warp_{round}.nii.gz remains a separate artifact. It is the full displacement field stitched from all local chunk cores; it is not an alias for a local warp. Scalar cores are shared coarse/fine serial-chunk artifacts; prepared arrays are fine-only. The shared chunk stage commits both each local warp and its registered scalar core in either execution mode, so a later coarse or fine assembly can resume without repeating successful reconstruction.

Fine-grained internal artifacts

Fine preparation commits four internal float32 arrays under round_{round}_prepared/. Preprocessing-disabled bundles retain the exact strict format-version-2 manifest. Feature-enabled bundles use strict format version 3 and add the canonical preprocessing policy plus measured fixed and moving robust scales. Feature-masked bundles use strict format version 4 and additionally bind the physical morphology policy and realized fixed/moving foreground evidence:

Initial-alignment-enabled raw, feature, and feature-mask bundles use strict format versions 5, 6, and 7 and additionally bind all initialization evidence identities.

ArtifactInternal role
fixed_scalar.npyfixed scalar on the exact reference grid
moving_linear_scalar.npyaffine-resampled moving scalar on that grid
fixed_mask.npyfixed registration metric mask: raw greater-than-zero support or optional feature support
moving_linear_mask.npycorresponding nearest-neighbor affine mask, thresholded on that grid
manifest.jsonidentities, geometry, policies, native threads, and exact ANTs pixel types

These arrays are uncompressed C-contiguous float32 files. Chunk workers validate the manifest and completion records, memory-map the arrays read-only, and copy only one extended region. Unequal native source shapes along Z, Y, and X are supported because affine application is the first exact fixed-grid boundary, matching current Cy-ExM/ANTs geometry behavior.

Each serial chunk commits both its local warp and scalar core. Fine scheduling can run those shared chunk stages independently; coarse scheduling invokes the same stage serially. Assembly ignores worker completion order: it processes canonical chunks in ascending numeric ID and, in expected overlapping legacy output slices, later IDs overwrite earlier values. Every fixed-grid voxel must be covered at least once.

Prepared arrays, scalar cores, and local warps are internal progress. They do not make a workflow round complete. Public completion still requires the affine, full warp, diagnostic TIFF, metrics, and every declared transformed channel to pass ordinary artifact/completion-record validation. The internal .npy files remain retained for restart. Fine mode can add four full float32 prepared volumes, while either serial-chunk mode retains scalar cores; these files do not change the public TIFF export policy.

Scalar reconstruction is an explicit, versioned part of the request:

Histogram matching depends on the reference intensity distribution, so matching each local distribution and then stitching is not generally equivalent to stitching the warped volume and matching once globally. Preserving this ordering is therefore a scientific requirement, not merely an output-format choice. In both modes, the nonlinear mask is independently reconstructed from the committed full warp with nearest-neighbor interpolation and thresholding at 0.5.

The feature algorithm identifier, ZYX voxel sigma, and actual fixed/moving robust scales are part of affine and nonlinear descendant request identities. Format 4 also records the strict-positive threshold, component/dilation policy in physical units, and realized foreground counts and fractions. Changing a sigma or mask policy therefore invalidates prepared feature arrays, affine descendants, local chunk warps and cores, the chunk manifest, full warp, metrics, and registered TIFF. Crop-bound artifacts, fixed_reference.tif, and reference-channel outputs do not include feature parameters and remain reusable when their own inputs and policies still match. Dependent-channel requests are unchanged; they are invalidated transitively when the accepted affine or warp identity changes.

Completion record contents

Every <name>.complete.json uses schema_version: 1 and contains:

Each register() invocation snapshots both input identities before either image is loaded. Every whole-image request, local-chunk request, and manifest request created by that invocation uses the same immutable pair. Cy-ExM verifies the pair after both loads and immediately before and after every artifact reuse or commit. It aborts with a registration-stage error if an input changes or disappears; it never silently reloads changed pixels. If the post-commit check fails, the new completion record is marked stale. A post-reuse failure leaves the previously valid cache record intact.

Input identities are deliberately stat-based: resolved path, st_size, and st_mtime_ns. Cy-ExM does not content-hash source images, so an in-place content change that preserves all three values is outside this check. Keep source files immutable for the duration of registration.

The chunk manifest.json has its own payload schema in addition to its completion record. Payload schema version 2 records axis_convention_version: external-zyx-ants-xyz-v1, round_number, image_shape_zyx, chunk_size_zyx, overlap_fraction, ordered chunk bounds, and each local warp identity.

The effective scalar_postprocessing_policy is recorded in the full nonlinear-warp, nonlinear-registered metrics, and registered-image requests. Every serial local-warp request records the same serial policy. This binds a scalar descendant to the exact distribution scope and operation ordering used to produce it.

request.geometry.shape, chunk shapes, TIFF arrays, and crop bounds use external ZYX order. Origin, spacing, direction, ANTs indexes, and displacement component values remain physical XYZ. The convention version deliberately prevents completion records or manifests produced with the former ambiguous layout from being reused.

Cy-ExM-generated fixed and final TIFFs embed a strict versioned geometry payload containing shape, origin, spacing, and direction. Before atomic promotion, the TIFF writer requires the serialized payload to equal all four source fields exactly. Tolerance is reserved for comparisons after ANTs has rehydrated the serialized geometry. Only TIFFs with no cyexm marker use fallback geometry, and only when the effective layout is explicit ZYX, grayscale QYX, or tifffile’s reconstructed YX view of a declared leading singleton Z axis. YXS, SYX, CYX, and other sample/channel layouts are rejected. Present malformed metadata, including a truncated raw ImageDescription marker that tifffile cannot shape, fails closed.

Validation and reuse

On an identical rerun, Cy-ExM checks the following before reuse:

  1. Neither the artifact nor its completion record is missing.

  2. The completion JSON is readable and has the supported schema.

  3. Every request field exactly matches the current normalized request.

  4. The current artifact identity matches the identity committed in the record.

  5. The artifact-specific reader can reopen the affine, warp, TIFF, metric text, crop bounds, or manifest. Whole-image TIFF readers additionally verify reopened shape, origin, spacing, and direction against the image that produced the request.

An artifact without its completion record, a record without its artifact, corrupt JSON, changed input metadata, changed geometry, changed registration policy, changed thread settings, or an unreadable artifact raises a focused cache-validation error. Cy-ExM does not guess whether such an entry is safe.

Completion records made before the versioned scalar policy was introduced fail this exact-request check. This intentionally invalidates serial outputs that may have been reconstructed with an extra full-volume histogram match. Rerun with --force (or force_override=True) to migrate those artifacts; do not edit completion JSON to claim the new policy.

The transform_directory.ipynb example applies the same minimum evidence rule before reading crop bounds or applying an existing transform: each supplied affine, nonlinear warp, and optional crop artifact must have a readable completion record, an exact current FileIdentity, the expected stage, and the current axis_convention_version. It then validates the selected records as one provenance chain before reading bounds or loading an image: affine and nonlinear requests must name the same two registration inputs and fixed geometry, the nonlinear upstream must equal the selected affine artifact, and the affine must have no upstream. Round number, crop policy, and XYZ pixel spacing must match the notebook settings on every selected record. Crop use is both fixed and moving records or neither; crop inputs, stages, and fixed/moving roles must belong to the same chain. Finally, the current FIXED_IMAGE identity must equal the recorded fixed input. The original moving registration channel need not remain available because other moving channels are the intended transform targets. Copy each artifact together with its .complete.json record; an artifact file by itself, or individually valid artifacts from unrelated runs, are intentionally unusable in this notebook.

Stale records and force

When an already committed artifact must not be reused, Cy-ExM atomically moves its record from <name>.complete.json to <name>.complete.json.stale. The artifact may remain in place until its replacement is validated and atomically promoted. A stale marker is authorization to recompute; it is never proof that the old artifact is valid. Successful recommit creates a new completion record and removes the stale marker.

For example, replacing an affine stage makes its downstream linear metrics, full warp, nonlinear metrics, and registered TIFF stale. A deterministic local chunk reconstruction failure makes that local warp, the manifest, the full-round warp, and downstream outputs stale together so transitive evidence cannot be reused.

The workflow scripts expose --force, which maps to force_override=True. Use it only when intentionally recomputing the same request. Force skips normal cache reuse, commits replacements atomically, and invalidates dependent records. It does not make an unrelated request compatible with old evidence or weaken artifact validation.

If fine execution evidence is invalid, unauthenticated current-run summaries are omitted from durable rounds; pre-run authenticated reuse remains available through ordinary completion-record validation. This rejection applies to sequential, Local Dask, and SLURM execution. Valid committed scientific artifacts remain restartable, but invalid fine execution evidence never authorizes reuse.

Recovery examples

Recovery normally means rerunning the exact same command with the same inputs and options. Temporary sibling files are removed automatically.

Scheduler topology is not cache identity. In fine SLURM mode, operational evidence schema version 3 records the job cap, processes per job, per-process CPU/memory, shared SLURM job IDs, distinct worker addresses/PIDs, process-group activation, departures, replacements, placement attempts, and cleanup. None of those facts can authorize reuse. A completion record with an exact StageRequest and current artifact identity remains the only authority.

Consequently, a lost process, a lost whole job, or a partial replacement process group can interrupt execution without invalidating already committed scientific artifacts. The executor may keep a healthy sibling active, or revalidate a complete replacement group, but every retried task still enters this document’s ordinary completion-record checks. If the bounded replacement transaction fails, Cy-ExM records the failure stage and closes owned resources; rerunning the same command reuses only independently valid commits.

Affine failure

If affine estimation or validation fails before commit, there is no valid linear_transform_{round}.mat.complete.json. Correct the underlying resource or input problem and rerun. Earlier valid fixed-reference and pre-registration metric artifacts can be reused; the affine stage runs again.

Nonlinear failure

If the affine completed and nonlinear estimation fails, the affine artifact and its completion record remain reusable. Rerun the same command: Cy-ExM reconstructs the affine-aligned moving image from that transform and resumes at nonlinear work. If a new nonlinear warp was committed but a required reconstruction failed, its record is marked stale and that warp is recomputed on the next run.

Chunk failure

If chunk {chunk} fails, earlier chunk_{chunk:04d}_warp.nii.gz entries with valid completion records remain committed. The manifest and full-round warp are not reported complete. Rerun the same serial chunk command: valid earlier local warps are reopened and applied, and work resumes at the first missing or stale chunk. A changed chunk size or overlap is a different request and is rejected unless recomputed intentionally.

If only nonlinear metrics or the final TIFF are stale, serial restart reopens every valid local warp, reconstructs the same locally matched float32 core stitch, reuses the valid full warp, and rebuilds only the stale descendants. It never substitutes a global histogram match during full-warp reuse.