spacr.qt.synthetic
==================

.. py:module:: spacr.qt.synthetic

.. autoapi-nested-parse::

   Synthetic datasets + saved settings for exercising every pipeline app.

   The goal: give a developer (or a bug reporter) a one-line way to
   generate a demo folder that flows cleanly through every spacr
   pipeline — mask, measure, crop, classify, timelapse — plus a matching
   settings CSV that plugs into the "Import settings…" button on each
   app screen.

   Everything is reverse-engineered from what the pipelines actually
   consume:

   * Filenames match the cellvoyager regex in
     `spacr.utils._get_regex('.tif', 'cellvoyager')`:
         <plateID>_<wellID>_T<timeID>F<fieldID>L<laserID>A<AID>Z<sliceID>C<chanID>.tif
   * Channels are laid out in the order every mask default expects:
         C0 = nucleus, C1 = cell, C2 = pathogen, C3 = organelle
   * Images are 16-bit uint16 with realistic-looking Gaussian blobs so
     the segmentation apps don't just see noise.
   * Settings CSVs are written in the two-column "Key,Value" format that
     `spacr.utils.load_settings` reads. Loading via the AppScreen's
     "Import settings…" button restores every value into the form.

   Public API:
       generate_mask_demo(dst, ...) -> DemoLayout
       generate_measure_demo(dst, ...) -> DemoLayout
       generate_crop_demo(dst, ...) -> DemoLayout
       generate_classify_demo(dst, ...) -> DemoLayout
       generate_timelapse_demo(dst, ...) -> DemoLayout
       save_settings_csv(dst, settings) -> Path
       demo_settings(app_key, src) -> Dict[str, Any]

   CLI:
       python -m spacr.qt.synthetic mask /tmp/demo
       python -m spacr.qt.synthetic all  /tmp/demo









Module Contents
---------------

.. py:data:: LOG

.. py:class:: DemoLayout

   What a demo generator produced. Absolute paths only.


   .. py:attribute:: src
      :type:  pathlib.Path


   .. py:attribute:: image_dir
      :type:  pathlib.Path


   .. py:attribute:: image_files
      :type:  List[pathlib.Path]
      :value: []



   .. py:attribute:: mask_files
      :type:  List[pathlib.Path]
      :value: []



   .. py:attribute:: db_path
      :type:  Optional[pathlib.Path]
      :value: None



   .. py:attribute:: settings_csv
      :type:  Optional[pathlib.Path]
      :value: None



   .. py:attribute:: notes
      :type:  Dict[str, Any]


.. py:function:: cellvoyager_filename(plate: str = 'plate1', well: str = 'A01', time: int = 1, field: int = 1, laser: int = 1, a: int = 1, slice_: int = 1, chan: int = 1, ext: str = 'tif') -> str

   Return a filename matching:
   <plateID>_<wellID>_T<timeID>F<fieldID>L<laserID>A<AID>Z<sliceID>C<chanID>.<ext>


.. py:data:: CHANNEL_LAYOUT

.. py:function:: generate_mask_demo(dst: pathlib.Path, plate: str = 'plate1', wells: Iterable[str] = ('A01', 'A02'), fields: int = 2, channels: Iterable[int] = (0, 1, 2, 3)) -> DemoLayout

   Populate `dst` with a folder that runs cleanly through the Mask
   app. Layout:
       dst/
         <plateID>_<wellID>_T01F<field>L01A01Z01C<chan>.tif
         settings_mask.csv


.. py:function:: generate_measure_demo(dst: pathlib.Path, **kw) -> DemoLayout

   Measure consumes what mask produces: images + `masks/`
   subfolder + a `measurements/measurements.db` scaffold. We
   pre-build the masks so a user can jump straight into Measure.


.. py:function:: generate_crop_demo(dst: pathlib.Path, **kw) -> DemoLayout

   Same as measure — Crop reads images + masks and writes PNG
   crops into `data/` alongside the DB.


.. py:function:: generate_classify_demo(dst: pathlib.Path, n_crops: int = 16) -> DemoLayout

   Classify wants PNG single-object crops + a `measurements.db`
   with a `png_list` table + an `annotate` column carrying class
   labels for training/testing.


.. py:function:: generate_timelapse_demo(dst: pathlib.Path, plate: str = 'plate1', wells: Iterable[str] = ('A01', ), fields: int = 1, times: int = 8, channels: Iterable[int] = (0, 1)) -> DemoLayout

   Timelapse needs multi-T frames per (well, field) so tracking
   has something to lock onto. Same cellvoyager naming, just with
   T01..T<N>.


.. py:function:: demo_settings(app_key: str, src: str) -> Dict[str, Any]

   Return a spacr settings dict tailored for the demo dataset
   generated by `generate_<app>_demo`.

   Values are the minimum needed to make the pipeline flow — real
   users will tweak thresholds + channel numbers to fit their data.


.. py:function:: save_settings_csv(path: pathlib.Path, settings: Dict[str, Any]) -> pathlib.Path

   Write `settings` in the two-column Key,Value format that
   `spacr.utils.load_settings` reads.


.. py:function:: main(argv: Optional[list[str]] = None) -> int

   Generate one (or every) demo dataset via the ``python -m`` CLI.

   :param argv: optional argv list; defaults to ``sys.argv[1:]``.
   :returns: process exit code (0 on success).


