spacr.metadata_resolution¶
Recover missing spaCR metadata columns without silent identity guesses.
The resolver is UI-independent. A Qt dialog can be supplied as prompt;
headless callers receive one actionable exception instead of blocking on a
window no one is watching. Known aliases are canonicalised before any human
choice is requested.
Exceptions¶
A headless caller must provide an explicit metadata mapping. |
Classes¶
One all-at-once answer returned by a UI or a saved setting. |
|
All unresolved targets and evidence shown to one prompt. |
|
Resolved frame plus the auditable decisions that changed it. |
Functions¶
|
Build the single request a GUI displays for every missing column. |
|
Clear remembered prompt answers (primarily for tests/new runs). |
|
Resolve every required metadata column in one deterministic pass. |
Module Contents¶
- exception spacr.metadata_resolution.MetadataResolutionRequired(missing: Sequence[str], available: Sequence[str])[source]¶
Bases:
ValueErrorA headless caller must provide an explicit metadata mapping.
- Parameters:
missing – canonical metadata columns that could not be resolved.
available – source columns that were available for explicit mapping.
Retain the unresolved and available columns for programmatic repair.
- class spacr.metadata_resolution.MetadataDecision[source]¶
One all-at-once answer returned by a UI or a saved setting.
- Parameters:
column_map – mapping from each canonical target name to an existing source column, applied collision-safely before identity derivation.
well_column – optional source column whose values are parsed strictly as well labels to supply missing
rowIDandcolumnIDvalues.pseudo_source – optional source column whose distinct typed values receive pseudo row and column coordinates when real well metadata is unavailable.
allow_pseudo – explicit permission to synthesize coordinates from
pseudo_source; the source alone never changes the frame.save_path – optional JSON audit destination written after successful resolution with the decision and generated pseudo-well assignments.
remember – whether a prompted decision is cached under a supplied
cache_keyfor the remainder of the current process.
- class spacr.metadata_resolution.MetadataRequest[source]¶
All unresolved targets and evidence shown to one prompt.
- Parameters:
missing – canonical columns that still require a decision.
available – source columns available for mapping.
examples – representative string values for each source column.
guesses – best-effort source-column suggestion for each target.
- class spacr.metadata_resolution.ResolutionResult[source]¶
Resolved frame plus the auditable decisions that changed it.
- Parameters:
frame – normalized frame containing every required metadata column.
column_map – explicit canonical-target to source-column mappings used.
derived_from_well – well column used to derive row and column IDs, if derivation was necessary.
pseudo_map – audited source identities and their generated pseudo well coordinates.
- spacr.metadata_resolution.build_metadata_request(frame: pandas.DataFrame, required: Iterable[str]) MetadataRequest[source]¶
Build the single request a GUI displays for every missing column.
- Parameters:
frame – metadata frame whose current columns and examples are shown.
required – canonical columns that the calling workflow requires.
- spacr.metadata_resolution.clear_run_metadata_decisions() None[source]¶
Clear remembered prompt answers (primarily for tests/new runs).
- spacr.metadata_resolution.resolve_metadata_columns(frame: pandas.DataFrame, required: Iterable[str], *, column_map: Mapping[str, str] | None = None, well_column: str | None = None, pseudo_source: str | None = None, allow_pseudo: bool = False, prompt: Callable[[MetadataRequest], MetadataDecision] | None = None, cache_key: str | None = None, save_path: str | None = None) ResolutionResult[source]¶
Resolve every required metadata column in one deterministic pass.
- Parameters:
frame – source metadata frame to normalize and resolve.
required – canonical columns that must be present in the result.
column_mapis{canonical_target: actual_source}. A prompt, when supplied, is called at most once and receives all unresolved columns. Without one, missing columns raiseMetadataResolutionRequiredwith the non-interactive settings needed to proceed.
Nested helpers¶
- build_metadata_request.comparable(value: str) str¶
Reduce a metadata name to case-insensitive alphanumeric text.
- Parameters:
value – canonical or source column name to compare.
- Returns:
case-folded name with punctuation and whitespace removed.
spacr/metadata_resolution.py:141
- build_metadata_request.guess_score(source: str, target_key: str = target_key, target_root: str = target_root) float¶
Score one available column against the current missing target.
- Parameters:
source – available source-column name to rank.
target_key – normalized current target, bound when the scorer is created so the surrounding loop cannot change it.
target_root – target without an
idorlabelsuffix, likewise bound for this scorer.
- Returns:
sequence similarity plus a root-name bonus when the target without an
idorlabelsuffix occurs in the normalized source name.
spacr/metadata_resolution.py:154