spacr.drop_classification

What was dropped on Make Masks, decided before anything is opened.

Make Masks takes a drop of files, folders or both, and what the user means depends on what they dropped. classify_drop() reads the paths – names, folder layout and, for a few TIFFs, their pixels – and says which of these it is, without a single question or widget:

images

Image files (and possibly folders) to open as one queue, in drop order.

folder

One folder of images, opened as it is (masks in its masks/).

nested

One folder whose images sit in subfolders: when the subfolders look like channels (channel_like), “Organize for Measure” with one channel column per subfolder; otherwise the consolidation question.

folders

Several folders, each holding images: Make Masks opens “Organize for Measure” with one channel column per folder.

images_with_masks

Images dropped together with their masks (a masks folder, files whose name says mask, or integer label TIFFs named after a dropped image): masks pairs them.

spacr_output

A folder spaCR wrote (merged/*.npy, a sorted_channels folder, or a merged folder itself): description says what it is and open_folder is the images folder to open, if any.

nothing

Nothing Make Masks can use.

Whatever the drop held that is none of these – a .npy, a text file, an empty folder, a mask no image claims – is in unrecognised or unpaired_masks, so the screen can list it instead of losing it.

Classes

DropClassification

What a drop on Make Masks is, and everything needed to act on it.

Functions

classify_drop(→ DropClassification)

Say what a drop on Make Masks is, without asking or opening anything.

Module Contents

class spacr.drop_classification.DropClassification[source]

What a drop on Make Masks is, and everything needed to act on it.

Variables:
  • kind – one of images, folder, nested, folders, images_with_masks, spacr_output or nothing.

  • images – image files, absolute, in drop order (images and images_with_masks).

  • folders – the folder dropped (folder, nested), the folders (folders) or the folders dropped with loose images (images).

  • channel_folders – the subfolders of a nested folder that hold images, naturally sorted; for folders, the dropped folders.

  • channel_like – whether channel_folders look like one channel each – names such as DAPI or ch1, or the same fields in every one.

  • masks – {image path: mask path} for images_with_masks.

  • unpaired_masks – masks that no dropped image claims.

  • open_folder – for spacr_output, the image folder to open, or None when there is none.

  • description – one plain sentence saying what a spacr_output drop is.

  • unrecognised – dropped paths used for nothing, each with the reason.

spacr.drop_classification.classify_drop(paths: Iterable) → DropClassification[source]

Say what a drop on Make Masks is, without asking or opening anything.

Parameters:

paths – the dropped files and folders, in drop order.

Returns:

a DropClassification.

spaCR’s own output counts only when it is the whole drop. Files named as masks are masks; beside images, label TIFFs are too, but only when a dropped image claims them by name, since a clean synthetic image can look like labels. Masks dropped alone open the images they belong to, when those are present.

Nested helpers

_spacr_output.npys(path: str) → int

How many .npy files sit directly in path.

Parameters:

path – a folder.

spacr/drop_classification.py:326