linumpy.io.slice_config#
Shared helpers for reading, writing and stamping slice_config.csv.
slice_config.csv is the single per-slice trace file threaded through
the reconstruction pipeline. Each stage that makes a per-slice decision
(quality assessment, rehoming correction, auto-exclusion, missing-slice
interpolation, …) stamps its flag columns via this module and hands
the enriched file to the next stage.
Only pipeline-decision columns live here; raw metrics belong in the pipeline report and per-stage diagnostics JSON.
Concurrency model#
This module does not implement any file locking. Safe concurrent use depends on the upstream Nextflow pipeline’s channel discipline:
Every process receives
slice_config.csvas an immutable input staged into its own work directory. Nothing reads and writes the same file at the same time.Per-slice stages (interpolation, pairwise registration, …) emit per-slice fragment files (
slice_z{NN}_manifest.csv). Those fragments are collected and merged sequentially in a single downstream process (finalise_interpolation), so the CSV writer always runs on a single worker.Stamping helpers (
stamp()/merge_fragments()) always produce a new CSV atslice_config_outrather than updating in place, so a reader on the old version is never in a torn state.
If you ever need to call these helpers outside of Nextflow (e.g. ad-hoc scripts running in parallel), make sure each writer targets a distinct output path; otherwise the last writer wins.
Attributes#
Functions#
|
Return |
|
Read |
|
Return the header row of |
|
Atomically write |
|
Stamp a single slice: read |
|
Stamp multiple slices at once. |
|
Merge per-slice CSV fragments into |
|
Return the set of slice IDs whose |
|
Return a boolean flag from a config row (default when absent/empty). |
|
Return True if |
|
Return slice IDs that stacking should treat as motor-only (force-skip their pairwise transforms). |
Module Contents#
- linumpy.io.slice_config.CANONICAL_COLUMNS: list[str] = ['slice_id', 'use', 'exclude_reason', 'quality_score', 'galvo_confidence', 'galvo_fix', 'notes',...[source]#
- linumpy.io.slice_config.normalize_slice_id(slice_id)[source]#
Return
slice_idas a two-digit zero-padded string ("01","17").Accepts int / str / float (“1.0”) inputs. Falls back to
str(slice_id).strip()for non-numeric ids.
- linumpy.io.slice_config.read(path)[source]#
Read
slice_config.csv; returnslice_id -> rowwith normalized ids.Raises
FileNotFoundErrorif the file does not exist. Row values are kept as strings (CSV native); useget_flag()for bool coercion.- Parameters:
path (pathlib.Path)
- Return type:
- linumpy.io.slice_config.read_header(path)[source]#
Return the header row of
path(empty list if file has no header).- Parameters:
path (pathlib.Path)
- Return type:
- linumpy.io.slice_config.write(path, rows, extra_columns=())[source]#
Atomically write
rowstopath.The header always starts with
CANONICAL_COLUMNS(in that order); any extra columns come after. Missing canonical columns are emitted empty.Rows are sorted by
slice_id.slice_idis normalised to a 2-digit string.
- Parameters:
path (pathlib.Path)
rows (collections.abc.Iterable[collections.abc.Mapping[str, object]])
extra_columns (collections.abc.Iterable[str])
- Return type:
None
- linumpy.io.slice_config.stamp(path_in, path_out, slice_id, **flags)[source]#
Stamp a single slice: read
path_in, updateslice_idwithflags, write topath_out.New slice rows are appended with
use=falsewhen the row is absent.- Parameters:
path_in (pathlib.Path)
path_out (pathlib.Path)
slice_id (object)
flags (object)
- Return type:
None
- linumpy.io.slice_config.stamp_many(path_in, path_out, updates)[source]#
Stamp multiple slices at once.
updatesmapsslice_id -> {column: value}. Unknown slices are appended withuse=falseunless the caller supplies ausekey.- Parameters:
path_in (pathlib.Path)
path_out (pathlib.Path)
updates (collections.abc.Mapping[str, collections.abc.Mapping[str, object]])
- Return type:
None
- linumpy.io.slice_config.merge_fragments(path_in, fragment_paths, path_out, column_map=None)[source]#
Merge per-slice CSV fragments into
path_inand write topath_out.Each fragment is a small CSV with at least a
slice_idcolumn. Columns from the fragment are stamped onto the matching slice row, renamed viacolumn_mapif provided ({fragment_col: target_col}).Fragments that reference slices absent from the base config add new rows (
use=false).- Parameters:
path_in (pathlib.Path)
fragment_paths (collections.abc.Iterable[pathlib.Path])
path_out (pathlib.Path)
column_map (collections.abc.Mapping[str, str] | None)
- Return type:
None
- linumpy.io.slice_config.filter_slices_to_use(path)[source]#
Return the set of slice IDs whose
usecolumn is truthy.When
slice_config.csvis missing this raisesFileNotFoundError– callers should guard onpath.exists()or pass an optional path themselves.- Parameters:
path (pathlib.Path)
- Return type:
- linumpy.io.slice_config.get_flag(row, column, default=False)[source]#
Return a boolean flag from a config row (default when absent/empty).
- linumpy.io.slice_config.is_interpolated(path, slice_id)[source]#
Return True if
slice_idis flagged as interpolated inpath.- Parameters:
path (pathlib.Path)
slice_id (object)
- Return type:
- linumpy.io.slice_config.force_skip_slices(path)[source]#
Return slice IDs that stacking should treat as motor-only (force-skip their pairwise transforms).
A slice is force-skipped when it is explicitly excluded (
use=false) or was flagged by auto-exclude (auto_excluded=true).- Parameters:
path (pathlib.Path)
- Return type: