spacr.qt.make_masks_demo

Make Masks’ test data: ten Toxoplasma vacuole fields, one button away.

Ten images of the Toxoplasma PV training set are published on Hugging Face as a small test dataset for Make Masks, with a button that loads the dataset and opens its first image in Make Masks.

WHAT IS PUBLISHED. MAKE_MASKS_EXAMPLE_REPO holds ten of the lab’s own acquisitions – no figure harvested from a paper, no held-out field – at the top level, their curated label masks under ground_truth_masks/, a manifest.csv carrying each image’s row from the in-house manifest, and one archive of all of it. The images open UNSEGMENTED: Make Masks reads drafts from masks/, never from ground_truth_masks/, so the editor starts on raw fields and the truth sits beside them.

THE SAME PATTERN AS EVERY OTHER EXAMPLE SET. One uncompressed .tar per repository, streamed to a .part file on a worker thread behind the shared progress dialog, unpacked through the tar data filter (spacr.qt.hf_download._TarExampleWorker does all of that), and cached: is_present() is asked first, so a second press opens the folder without a request.

ITS OWN FOLDER, NOT THE SHARED PLATE. The Measure and Annotate sets unpack into example_plate_folder() because they compose into one plate. These ten fields are not part of that plate, and the Mask demo decides it is present by finding *.tif there, so unpacking them into it would make that demo think it had been downloaded.

WHY THIS IS A MODULE AND NOT A METHOD. The screen gets one call in its navigation row. Everything else lives here, so make_masks.py – which several items edit at once – carries a two-line hook.

Functions

download_make_masks_example(→ None)

Fetch the Make Masks test data behind the shared progress dialog.

install_test_data_button(→ PySide6.QtWidgets.QPushButton)

Build Make Masks' "Load test data…" button, wired to screen.

is_present(→ bool)

Whether a complete copy of the test data is unpacked in folder.

listed_files(→ List[str])

Every file the dataset's manifest.csv says a complete copy holds.

load_the_test_data(→ bool)

Open the test data in Make Masks, downloading it first when needed.

make_masks_example_folder(→ pathlib.Path)

Where the test data is unpacked and cached.

open_the_test_data(→ bool)

Open an unpacked copy of the test data on its first image by name.

Module Contents

spacr.qt.make_masks_demo.download_make_masks_example(parent, dest, on_done: Callable[[spacr.qt.hf_download.DownloadResult | None, str], None]) → None[source]

Fetch the Make Masks test data behind the shared progress dialog.

Parameters:
  • parent – the widget the progress dialog belongs to.

  • dest – the folder the archive unpacks into.

  • on_done – called on the GUI thread as on_done(result, error). result is None on failure or cancellation, and error then says why.

spacr.qt.make_masks_demo.install_test_data_button(screen) → PySide6.QtWidgets.QPushButton[source]

Build Make Masks’ “Load test data…” button, wired to screen.

Parameters:

screen – the Make Masks screen the data opens in. The button is kept on it as _btn_test_data, so a load can disable it while the download runs.

Returns:

the button, for the caller to place.

spacr.qt.make_masks_demo.is_present(folder) → bool[source]

Whether a complete copy of the test data is unpacked in folder.

Parameters:

folder – where the dataset is expected.

Returns:

True only when the manifest exists and every image and mask it lists is a file. A half-unpacked set reads as absent, which is the answer that gets it downloaded again.

spacr.qt.make_masks_demo.listed_files(folder) → List[str][source]

Every file the dataset’s manifest.csv says a complete copy holds.

Parameters:

folder – where the dataset was unpacked.

Returns:

paths relative to folder, each image followed by its ground-truth mask, in manifest order. Empty when there is no readable manifest, or when any row names no image, so that an incomplete or unrecognised folder is never mistaken for the dataset.

spacr.qt.make_masks_demo.load_the_test_data(screen, *, ask=None, folder=None) → bool[source]

Open the test data in Make Masks, downloading it first when needed.

A cached copy opens at once. Otherwise the button is disabled, the status line says a download is running, and the download runs on a worker thread behind a progress dialog. When it finishes, the folder opens on its first image by name. A failure is reported with the reason the downloader gave, on the status line and, when there is a display to show one, in a warning.

Parameters:
Returns:

whether this call opened the data. False while a download is still running, and after a failure.

spacr.qt.make_masks_demo.make_masks_example_folder() → pathlib.Path[source]

Where the test data is unpacked and cached.

~/.cache/spacr/example_data/make_masks_toxo_pv, beside the shared example plate rather than inside it. See the module docstring for why.

Returns:

the folder. It is not created here.

spacr.qt.make_masks_demo.open_the_test_data(screen, folder) → bool[source]

Open an unpacked copy of the test data on its first image by name.

Parameters:
  • screen – the Make Masks screen.

  • folder – where the data was unpacked.

Returns:

whether the screen is now on it. An incomplete copy is reported rather than opened, because half the fields would pass for the whole set.

Nested helpers

load_the_test_data._done(result, error)

Put the button back, then open the data or say why it did not.

spacr/qt/make_masks_demo.py:215