spacr.object_settings_table

Convert per-object settings between flat keys and a table with one row per question.

Per-object settings repeat questions for each object type – cell_diameter, nucleus_diameter, pathogen_diameter and organelle_diameter, for example. The table puts each question in one row and each object type in one column.

The organelle count is variable, up to spacr.organelle_types.MAX_ORGANELLES. Each added slot repeats the primary organelle’s settings. In the table an additional organelle adds a column while the question rows stay the same.

This module is only the model: it reads a flat settings dict into a table and writes a table back out, losslessly. It draws nothing. A GUI renders to_table() and calls from_table() on edit, and the headless path never has to know the table exists – the stored keys are unchanged, so no settings file, notebook or tutorial migrates.

Storing a nested {question: {object: value}} structure instead would be a file-format change, and every saved settings file, every published tutorial, and the headless spacr-run path would have to change with it. Only the presentation changes.

Functions

column_label(→ str)

Return the column header text for obj.

families(→ Dict[str, List[str]])

{question: [objects that ask it]}, objects in display order.

from_table(→ Dict[str, object])

Flatten a table back to settings keys, over base if given.

questions(→ List[str])

The distinct questions in keys, in first-seen order.

to_table(→ Dict[str, Dict[str, object]])

Read a flat settings dict as {question: {object: value}}.

widen(→ Dict[str, Dict[str, object]])

Return a copy of table with a column for obj, copying like's answers where it has them.

Module Contents

spacr.object_settings_table.column_label(obj: str) → str[source]

Return the column header text for obj.

organelleb is a storage spelling, not a thing a user recognises. The letter suffixes exist because object types are embedded in underscore-separated object keys and organelle2 is ambiguous with label 2 – an implementation constraint that has no business appearing in a column header.

Parameters:

obj – an object name from OBJECT_ORDER, e.g. "cell" or "organelleb". Organelle slots get their numbered label; any other name has underscores turned into spaces and is capitalised.

spacr.object_settings_table.families(keys: Iterable[str]) → Dict[str, List[str]][source]

{question: [objects that ask it]}, objects in display order.

Parameters:

keys – flat settings names such as "cell_min_area", "remove_background_cell", "remove_background_organelle_2" and "adjust_cells". Unsupported names are skipped.

spacr.object_settings_table.from_table(table: Mapping[str, Mapping[str, object]], base: Mapping[str, object] | None = None) → Dict[str, object][source]

Flatten a table back to settings keys, over base if given.

The inverse of to_table(), without loss: the table is the settings file rearranged, not transformed, so it can be used as an editing surface. A test round-trips every default settings dict.

Parameters:
  • table – {question: {object: value}}.

  • base – the settings the table came from. Keys the table does not cover are carried through unchanged, so a caller can edit the per-object half without holding the rest.

spacr.object_settings_table.questions(keys: Iterable[str]) → List[str][source]

The distinct questions in keys, in first-seen order.

One entry per question, however many objects ask it: cell_diameter and nucleus_diameter are one question, diameter.

Parameters:

keys – flat settings names such as "cell_diameter", "remove_background_cell", "remove_background_organelle_2" and "adjust_cells". Unsupported names are skipped.

spacr.object_settings_table.to_table(settings: Mapping[str, object]) → Dict[str, Dict[str, object]][source]

Read a flat settings dict as {question: {object: value}}.

Only the keys that ARE per-object questions are taken. Everything else – src, verbose, n_jobs – is not a table row and is left where it is; a caller wanting the whole settings dict back uses from_table() with the original.

A question a given object does not ask is ABSENT from its row rather than present as None. cytoplasm has no channel, no diameter and no detection method because it is derived rather than found in a channel, and a blank cell says that where a None would read as “not set yet”.

Parameters:

settings – a flat settings dict, e.g. Mask’s settings; it is only read.

spacr.object_settings_table.widen(table: Mapping[str, Mapping[str, object]], obj: str, *, like: str | None = None) → Dict[str, Dict[str, object]][source]

Return a copy of table with a column for obj, copying like’s answers where it has them.

Adding an organelle is one call that adds one column; in the flat vocabulary it is twenty new settings that every consumer, tooltip table and translation catalog has to include.

Parameters:
  • obj – the object to add, e.g. 'organellec'.

  • like – an existing object whose answers to copy as the starting point. Defaults to the first organelle when obj is one, because a second mitochondrion should start where the first one is rather than at a global default nobody chose.

Nested helpers

_filter_text._num(value)

One bound as compact text; blank for an unset bound.

spacr/object_settings_table.py:178

_parse_filter_text._side(value)

One side of the range as a number; None when left blank.

spacr/object_settings_table.py:218