spacr.qt.widgets.organize_for_measure¶
Make Masks’ “Organize for Measure…” popup: images and masks into merged/.
One popup puts images and their masks into the layout Measure reads – Yokogawa-named channel folders, the masks,
and merged/*.npy – through spacr.channel_sorting and
spacr.folder_consolidation, which hold every decision:
a SOURCE folder (typed, browsed or dropped), optionally consolidated first (its subfolders’ images copied into one folder, named after their folders);
the REGEX box: Mask generation’s own
metadata_typefield – the same grouped convention menu, example and “Test on my folder” – with itscustom_regex, plus “Sort by regex”, “Auto regex” and “Detect sets”;the DIMENSIONS: which columns are image channels and which are masks, each mask with its role (cell, nucleus, pathogen) and the channel whose images it outlines;
a TABLE with one column per channel and per mask and one row per field. Every column takes files and folders dropped from the file manager (a folder brings its images, recursively) and cells dragged from another column. Dropped files sort themselves by name and are matched across the columns the way Detect sets pairs images – file-name tokens, then order, never two images of different size (
spacr.channel_sorting. _match_columns()). A cell nothing matched stays empty and flagged.
Mode 1: fill the source, choose or test the regex, press “Sort by regex”,
Apply. Mode 2: fill the columns by dropping, Apply. Mode 3, “Teach me…”:
answer “Which channel is this?” for one image at a time while spaCR learns
a regex from the answers (spacr.channel_sorting._teach_step()), until
every image is placed. Each works without the others. A folder made by
folder consolidation is read under its files’ ORIGINAL names, from its
rename_manifest.csv, because the copies’ names may have lost what told
the channels apart. If any image cannot be copied during consolidation, the
popup reports the failed-file count and the manifest path and stops there:
the source folder, the consolidation choice and the table stay as they were,
so the problem can be fixed and the step retried. Apply builds a spacr.channel_sorting.SortPlan; incomplete
rows block it (the regex box is where to fix them), RGB images and z-stacks
are offered for conversion, and detected sets are shown three at a time
before they are used. Nothing moves before Apply; the screen applies the
plan off the GUI thread and every move is written to the manifest.
Classes¶
Put images and masks into channel folders and |
Module Contents¶
- class spacr.qt.widgets.organize_for_measure.OrganizeForMeasureDialog(source: str = '', parent=None, channel_folders: Sequence[str] | None = None, masks_dir: str | None = None)[source]¶
Bases:
PySide6.QtWidgets.QDialogPut images and masks into channel folders and
merged/for Measure.- Variables:
plan – the confirmed
spacr.channel_sorting.SortPlanonce the dialog is accepted, else None.columns – the table’s columns, in order.
rows – one list per field, one path or None per column.
Build the popup, prefilled from a drop when there was one.
- Parameters:
source – the source folder, if known.
parent – the Qt parent.
channel_folders – folders to put in the table, one channel column each (their masks from each folder’s
masks/) – the Make Masks drop of several folders or of channel-like subfolders.masks_dir – the source’s masks folder, when not its
masks/.
The layout puts the fields on aligned rows at the top, every action button on one line below them, then the view controls over the table.
- add_column(kind: str, role: str = '', of_channel: int | None = None) int[source]¶
Add a channel or mask column at the end.
- Parameters:
kind –
"channel"or"mask".role – a mask’s role; default the first role no mask has.
of_channel – a mask’s channel; default the first channel with no mask column, else 1.
- Returns:
the new column’s index.
- add_files(column: int, paths: Iterable[str], rematch: bool = True) List[str][source]¶
Put dropped files and folders into a column, and match the rows.
A folder brings its images, recursively, not its
masks/. Images dropped into a channel column bring the masks Make Masks saved for them (<their folder>/masks/<stem>.tif) into that channel’s mask column, which is made when there is none. A file already in the table moves to this column. Nothing on disk changes.- Parameters:
column – the column index.
paths – files and folders.
rematch – match the rows afterwards (off while prefilling).
- Returns:
the image files added.
- auto_regex() str | None[source]¶
Propose a regex, put it in custom_regex, and sort by it.
- Returns:
the regex, or None when none was found.
- detect_sets() bool[source]¶
Match the columns’ files by name, order and size, and check three.
With an empty table and a source folder, the source is sorted by the regex first, for its channels. The sets are shown three at a time (
spacr.qt.widgets.channel_sort_dialog.ExampleSetsDialog) and kept only when the user says they are right.- Returns:
whether the detected sets were kept.
- prepare_plan(convert: bool = False) spacr.channel_sorting.SortPlan | None[source]¶
Build the plan from the table, or None while rows are incomplete.
- Parameters:
convert – convert RGB images and z-stacks to one plane.
- Returns:
the plan, which may still carry problems.
- remove_column(index: int) None[source]¶
Remove a column and its files from the table.
- Parameters:
index – the column.
- sort_by_regex(pattern: str | None = None, chan_map: Dict[str, object] | None = None) spacr.channel_sorting.SetReport | None[source]¶
Fill the table from the regex: chanID is the column, the rest the row.
With a source folder its images are read (consolidated first when asked), and their masks found where Make Masks saves them; with none, the files already in the channel columns are re-sorted, keeping the column each is in. Masks go into a mask column per channel. A mask two images share (two files with one stem) is left out and named.
- Parameters:
pattern – the regex; default what the regex box stands for.
chan_map –
{chanID value: label}learned by “Teach me”, a label being("channel", n)or("mask", n, role); by default the regex’s chanID values are channels in natural order.
- Returns:
the set report, or None when there was nothing to read.
- teach() str | None[source]¶
“Teach me”: ask what images are until a regex places all of them.
One image is shown at a time with “Which channel is this?” (
ask_label). From the answersspacr.channel_sorting._teach_step()learns what in the names marks each channel or mask and writes a regex; each new marker is confirmed withask_marker(a channel, a mask, or only part of the field’s name). The table fills as it goes, and the regex is put in custom_regex, where it can be edited. It ends when every image is placed, or when the user says stop.- Returns:
the learned regex, or None when none was learned.