spacr.import_examples

Import’s test data: one set of fields, written in every format and naming.

A small set of fields from the toxo_mito example plate, converted into the container formats spaCR reads and renamed into every filename convention Mask’s metadata_type offers, published together with their masks and a measurements database. Importing any variant should give back exactly the wells, fields and channels the fields started as, and the manifest says what those are.

WHAT IS PUBLISHED. IMPORT_EXAMPLE_REPO holds one archive. Inside it, under import_example/:

  • variants/<key>/plate1/ – the SAME twelve planes (wells E01 and E02, fields 9 and 10, three channels, cropped from the toxo_mito plate) written once per variant: once per filename convention, once as Zeiss CZI, once as OME-TIFF and once as an ImageJ TIFF stack;

  • variants/<key>/masks/{cell,nucleus,pathogen}/ – the Mask run’s label images for exactly those fields, named the way that variant names images;

  • variants/<key>/measurements.db – the Measure rows of exactly the cells in those masks, keyed by that variant’s own file names, as a collaborator’s table would be;

  • reference/measurements.db – the same rows as spaCR wrote them;

  • variants/nikon_nd2 and variants/leica_lif – PUBLIC SAMPLE FILES, because no open library writes ND2 or LIF. They are other people’s images under CC BY 4.0, with no masks, and they go through the Format Converter;

  • manifest.csv – one row per image file stating the well, field, channel, z and t it truly is. The LAST member of the archive, so a transfer that died part-way leaves no manifest and reads as absent.

THE REGISTRY IS HERE AND NOT IN THE ARCHIVE. IMPORT_VARIANTS is what the Import screen offers before anything is downloaded, and what tools/build_import_example.py writes. One list for both is what keeps a button from naming a folder the archive does not have.

This module imports nothing from Qt, so the round-trip test and the builder can use it headless.

Classes

ImportVariant

One way the same fields were written, and how Import reads it back.

Functions

import_example_folder(→ pathlib.Path)

Where the unpacked set lives.

import_variant(→ ImportVariant)

The variant called key.

is_present(→ bool)

Whether a complete copy of the set -- or of one variant -- is here.

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

Every row of the set's manifest.csv.

variant_inputs(→ Dict[str, object])

What the chooser fills in for one variant.

Module Contents

class spacr.import_examples.ImportVariant[source]

One way the same fields were written, and how Import reads it back.

Parameters:
  • key – the folder under variants/ and the chooser’s route key.

  • label – the button text.

  • route – 'import' for the Import screen itself (images, masks and a measurement table), 'convert' for the Format Converter (images only).

  • metadata_type – the filename convention to parse by, or 'auto' for folders and tokens.

  • custom_regex – the pattern, for metadata_type='custom'.

  • file_format – what the image files are, in words.

  • example – one image path from the variant, relative to its plate1 folder, so the chooser can show what the names look like before anything is downloaded.

  • note – anything the reader should know about this variant.

property description: str[source]

The paragraph the chooser shows on hover.

spacr.import_examples.import_example_folder(plate_folder: pathlib.Path | None = None) → pathlib.Path[source]

Where the unpacked set lives.

Parameters:

plate_folder – the shared example plate the archive unpacks into; spacr.example_archives.example_plate_folder() when omitted.

Returns:

<plate folder>/import_example. Not created here.

spacr.import_examples.import_variant(key: str) → ImportVariant[source]

The variant called key.

Parameters:

key – a key from IMPORT_VARIANTS.

Raises:

KeyError – naming the keys that exist.

spacr.import_examples.is_present(root, key: str | None = None) → bool[source]

Whether a complete copy of the set – or of one variant – is here.

Parameters:
  • root – the unpacked import_example folder.

  • key – one variant, or every variant when omitted.

Returns:

True only when the manifest exists and every file it lists for the variant(s) is on disk. A half-unpacked set reads as absent, which is the answer that gets it downloaded again.

spacr.import_examples.manifest_rows(root) → List[Dict[str, str]][source]

Every row of the set’s manifest.csv.

Parameters:

root – the unpacked import_example folder.

Returns:

the rows, or [] when there is no readable manifest.

spacr.import_examples.variant_inputs(root, key: str) → Dict[str, object][source]

What the chooser fills in for one variant.

Parameters:
  • root – the unpacked import_example folder.

  • key – the variant.

Returns:

images (the plate1 folder), masks ({object: folder} for the import route, empty for the converter), measurements (the table, or ''), metadata_type and custom_regex.