Metadata-Version: 2.4
Name: yellow-belt-imaging
Version: 0.1.3
Summary: A textual TUI for driving the full_containerized meerkat-pipeline image under apptainer/singularity (the APPTAINER.md flow)
Author-email: Tim Molteno <tim@elec.ac.nz>
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: textual>=1.0
Requires-Dist: textual-fspicker>=1.0

# yellow_belt_imaging

A terminal interface for the **yellow-belt MeerKAT imaging pipeline**: one
command runs the whole reduction — RFI flagging and averaging, 1GC calibration,
target flagging, 2GC, and the direction-dependent (3GC) calibration with
DDFacet imaging and a killMS solve — for one measurement set.  Everything runs
in containers ([apptainer](https://apptainer.org) or singularity); this tool
checks the environment, collects and validates the configuration, builds the
pipeline image, runs the pipeline with its output streaming into a log pane,
and cancels cleanly.

Built with [textual](https://textual.textualize.io/).

## Install

```bash
pip install yellow-belt-imaging
yellow_belt_imaging        # or: python -m yellow_belt_imaging
```

Works on Linux (amd64 and arm64) and macOS (to drive a remote pipeline host —
the pipeline itself runs under apptainer/singularity on Linux).

## What you need

* **apptainer** (preferred) or **singularity** — no root, no special flags;
  user namespaces must be enabled (the default on most Linux systems).  The
  interface checks for this at launch and tells you if neither is installed.
* **The raw measurement set** (a `*.ms` directory) in a **writable** directory:
  the first stage writes the averaged MS and flag versions next to it.
* Disk space: a few GB for the pipeline image and cab images, plus the
  products (tens of GB for a real run).
* RAM — the amount you declare as `RAM_GB` becomes the compute budget the
  pipeline plans against (see the resolution note below).

## The walkthrough

1. **Launch** — the status line shows the detected runtime and version, and
   whether the SIF (the pipeline image file) is already built.  Run/Build stay
   disabled until apptainer or singularity is found.
2. **Fill the form** — every directory field has a **Browse…** picker
   (navigate into the directory, press Select):
   * `MS_PATH` — the raw measurement set;
   * `OUT_PATH` — where the run works and the products land (relative paths
     are fine);
   * `BEAMS_DIR` / `BEAM_CUBE_DIR` — optional; see the beam note below;
   * `RAM_GB` — the compute budget (see the resolution note below); `NCPU`
     (empty = all cores); `BAND` (L / UHF);
   * the image tag (default `latest`) and the SIF path (default
     `~/meerkat-pipeline.sif`).
3. **Build SIF** (once) — builds
   `docker://ghcr.io/tmolteno/meerkat-pipeline:<tag>` into the SIF path with
   `--force` (a switch: on by default, so a stale SIF can be refreshed).  The
   first build downloads a multi-GB image — the status line counts the elapsed
   time and the output streams as it converts.  `Check` validates the form
   before anything runs.
4. **Run pipeline** — refuses to start on an invalid configuration (bad paths,
   an unwritable MS parent, a stale SIF: the SIF's version is compared against
   the selected tag on the registry, so you can never accidentally run old
   pipeline code).  While it runs, the output streams into the log pane, the
   status line ticks, and **Cancel** stops everything (SIGTERM, then SIGKILL).
5. **Copy output** (`ctrl+o` or the button) — the whole log pane onto the
   terminal clipboard.  For mouse selection, hold **shift** and drag — most
   terminals pass that through to their own selection even while a TUI claims
   the mouse.
6. Products land in `$OUT_PATH/out_<ms-name>/` (images, models, the plan
   reports, stimela logs under `logs/`); the averaged MS is written next to
   your raw MS.

## RAM_GB sets the resolution

The uv cut — and with it the image resolution — is whatever `RAM_GB` affords,
up to the longest baseline: on the bundled mergA_tim example, 112 GB gives
~3980 m / ~10.9″ (NPix ~5265); give it less and the resolution drops (with
severe shortage, time averaging is added) rather than the run failing;
`RAM_GB=0` plans against what is free at the moment each stage starts.  Set
`UVMAX_USE_PROFILE_CAP` to pin the run to the observation's profile resolution
instead (uv ≤ `MS_UVMAX`, 2500 m / ~17.4″ for mergA_tim).

## Beam cubes are generated on demand

Stage 4 reads a scalar FITS beam cube derived from a full-Jones source cube.
If you don't supply one (`BEAMS_DIR`, or a pre-derived
`primary_beam_mbeams_m012_*` in `BEAM_CUBE_DIR`), the pipeline generates what
is missing: it downloads the band's holography dataset (~420 MB, cached under
`beam-cubes/mbeams-cache/`, ~5.4 GB, reused across runs) and renders the
cubes.  Hand a pre-rendered source cube to the run via `BEAMS_DIR` to skip the
download.

## Your parameters are remembered

Every Run or Build launch saves the full configuration to
`.yellow_belt_imaging_param` in the working directory; the next launch
pre-populates the form from it (a missing or corrupt file falls back to the
defaults).  The file is gitignored in the source repository.

## The headless equivalent

Everything the interface does — environment checks, the configuration
variables, the build and run commands — is documented headless in
[full_containerized/APPTAINER.md](https://github.com/tmolteno/meerkat_imaging/blob/main/full_containerized/APPTAINER.md)
of the [source repository](https://github.com/tmolteno/meerkat_imaging), where
the docker and compose variants live too.

## Development

Source: `full_containerized/yellow_belt_imaging_tui/` in
[tmolteno/meerkat_imaging](https://github.com/tmolteno/meerkat_imaging).
Releases go to PyPI with Trusted Publishing: the
`yellow-belt-imaging.yml` GitHub workflow builds, smoke-tests and uploads on a
`yellow-belt-imaging-vX.Y.Z` tag that matches the pyproject version.

> **Install it into its own venv**: this package needs `rich >= 14.2` (via
> textual), while stimela 2.1.4 pins `rich < 14` — the two cannot share an
> environment, and pip will happily break one while installing the other.
