Repository navigation
Add DANDI API key selection and a Slack notification toggle #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nmarkowitz
wants to merge
70
commits into
lincbrain:master
Choose a base branch
from
nmarkowitz:feat/config-api-keys
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
8b1c780
ammend configs to select dandi api key
933d283
update pytests
nmarkowitz 70aded7
debugging updates
nmarkowitz 92cf9d5
add github testing
nmarkowitz a77aa8d
fix pytest integration test isolation
nmarkowitz 916920d
update configs
jcborn93 1bf800f
enable toggle slack notifications
jcborn93 41a147a
dandi upload now working
nmarkowitz 8f30ada
matlab processing working
nmarkowitz 9c717a8
matlab tile batch flow workings
nmarkowitz bbee959
fixes and updates
nmarkowitz d2e2760
dispersion takes multiple channels
nmarkowitz fad9aea
update PSOCTScanConfig blocks
nmarkowitz 5836ca4
port linc-convert tiling
nmarkowitz ce418a6
enface previewing
nmarkowitz 7901d7e
add 3d tile saving as option
nmarkowitz 8cdd128
add opts for calibrated files
nmarkowitz a090b65
update docker yaml
nmarkowitz e8ace46
update docker file
nmarkowitz 7745173
change fiji path
nmarkowitz 0031422
Merge remote-tracking branch 'origin/feat/phase-calibration-volume-ou…
nmarkowitz 8d8770f
Merge remote-tracking branch 'origin/fix/psoct-processing' into fix/p…
nmarkowitz d6583b1
update toml file
nmarkowitz cc52a58
fixes
nmarkowitz 4979043
bug fixing
nmarkowitz 6edb255
more updates
nmarkowitz ddbad5d
many updates
nmarkowitz 46dc0cb
Follow continuous tile numbering across mosaics and slices in oct watch
nmarkowitz 981ebf1
save complex files
nmarkowitz ae4ba27
enface acquisition previews working
nmarkowitz e8944f6
default and processing updates
nmarkowitz 80ee338
add grid-size-y-tilt
nmarkowitz ac10136
archiving done without matlab needed
nmarkowitz 341e6ad
filename pattern changes
nmarkowitz bb3aad6
update block cli
nmarkowitz 878e2be
Merge branch 'fix/psoct-processing' of https://github.com/nmarkowitz/…
nmarkowitz 3ce5db4
change hardcoded file size minimums
nmarkowitz 66be1e8
add --no-batches flag for state show
nmarkowitz 7e515bc
change x and y descriptors
nmarkowitz 8f3de12
some adjustments
nmarkowitz 3d00cf2
Merge branch 'fix/psoct-processing' of https://github.com/nmarkowitz/…
nmarkowitz cc82108
many updates
nmarkowitz f65b3af
bids sidecar files added
nmarkowitz e9f6890
BIDS sidecar uploads
nmarkowitz a866e19
BIDS sidecar updates
nmarkowitz 8fed012
update default refractive index
nmarkowitz c0cb52e
Describe grid_size_x as columns and grid_size_y as rows
nmarkowitz 83fd6ac
Add tile location to BIDS sidecar AcquisitionParameters
nmarkowitz ebe09a2
Default dandi_api_key to the dandi-api-key Secret block
nmarkowitz 0fd71ee
Add --body-part-details to ops oct setup
nmarkowitz 0f51a68
Never read the acquisition software's filenames.csv
nmarkowitz a1800f5
Use snake-by-rows, left-down tile traversal
nmarkowitz aaeb799
small bids edit
nmarkowitz 23dd5b2
Delete a slice's spectral files once previews and archives finish
nmarkowitz 2b9b1fb
Bump linc-convert to 835823d
nmarkowitz e645568
Write acquisition previews as mosaic2d JPEGs only
nmarkowitz 377bbef
Separate X and Y tile overlaps for normal and tilted mosaics
nmarkowitz 7cc4c64
Add `ops oct preview` to stitch a small test mosaic quickly
nmarkowitz d148aaf
Delete spectral files only as a slice's last operation
nmarkowitz 2612705
Remove stale ops oct deploy commands
nmarkowitz 31d746f
Add BATCH_DANDI_UPLOADED and fix MOSAIC_ENFACE_STITCHED value
nmarkowitz f51db3f
Test PollingStableWatcher companions
nmarkowitz 00cbc8d
Remove MATLAB processing; drive the PS-OCT chain from en-face maps
nmarkowitz 5c94fde
Drop psoct-toolbox and the bundled MATLAB overlay
nmarkowitz 33daf80
Document the PS-OCT chain without MATLAB
nmarkowitz ef2c128
Delete the MATLAB docs
nmarkowitz d86c657
Merge feat/phase-calibration-volume-output into feat/no-matlab
nmarkowitz 81e57da
Add opt-in two-view 3D optic-axis flow on SLICE_READY
nmarkowitz 0e5dee4
Update customization: trial.agent.md
nmarkowitz 6374737
all tests pass
nmarkowitz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| name: trial | ||
| description: Describe what this custom agent does and when to use it. | ||
| tools: Read, Grep, Glob, Bash # specify the tools this agent can use. If not set, all enabled tools are allowed. | ||
| --- | ||
|
|
||
| <!-- Tip: Use /create-agent in chat to generate content with agent assistance --> | ||
|
|
||
| Define what this custom agent does, including its behavior, capabilities, and any specific instructions for its operation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| HOST_IP=172.20.126.96 | ||
| HOST_IP=172.20.126.209 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
| name: Unit tests | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install uv | ||
| uv sync --extra dev --frozen | ||
|
|
||
| - name: Run unit tests | ||
| run: uv run pytest -ra | ||
|
|
||
| integration-tests: | ||
| name: Prefect integration tests | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| steps: | ||
| - name: Check out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install uv | ||
| uv sync --extra dev --frozen | ||
|
|
||
| - name: Start Prefect and PostgreSQL | ||
| run: docker compose --profile server up -d | ||
|
|
||
| - name: Wait for Prefect | ||
| run: | | ||
| for attempt in {1..60}; do | ||
| if curl --fail --silent http://127.0.0.1:4200/api/health > /dev/null; then | ||
| exit 0 | ||
| fi | ||
| sleep 2 | ||
| done | ||
| docker compose --profile server logs --no-color | ||
| exit 1 | ||
|
|
||
| - name: Configure Prefect client | ||
| run: uv run prefect config set PREFECT_API_URL=http://127.0.0.1:4200/api | ||
|
|
||
| - name: Run integration tests | ||
| run: uv run pytest -o addopts= -m integration -ra | ||
|
|
||
| - name: Show service logs after a failure | ||
| if: failure() | ||
| run: docker compose --profile server logs --no-color | ||
|
|
||
| - name: Stop services | ||
| if: always() | ||
| run: docker compose --profile server down |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,6 @@ | |
| *.pyc | ||
| *.nii | ||
| .vscode/ | ||
| /db/ | ||
| .DS_Store | ||
| .venv | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Overview | ||
|
|
||
| OpticStream is a set of Prefect 3 workflows for processing large microscopy datasets. It runs two pipelines: **LSM** (light-sheet strips → channels → volumes) and **PS-OCT** (tile batches → mosaics → slices). The CLI is `opticstream`, also available as `ops` (Cyclopts, `opticstream/cli`). | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| uv sync --extra dev # install (Python >=3.11; git-pinned deps: linc-convert, nifti-zarr) | ||
| uv run pytest -ra # unit tests (integration tests are excluded by default via addopts) | ||
| uv run pytest tests/test_state_guards.py::TestName::test_name # single test | ||
| uv run pytest -o addopts= -m integration -ra # integration tests; need a Prefect server + Postgres: | ||
| docker compose --profile server up -d # Prefect at :4200, then: prefect config set PREFECT_API_URL=http://127.0.0.1:4200/api | ||
| uv run ruff check opticstream # lint (ruff is in dev extras; no project-specific ruff config) | ||
| mkdocs serve # docs (mkdocs.yml, docs/) | ||
| ``` | ||
|
|
||
|
|
||
| ## Architecture | ||
|
|
||
| **Event-driven flow graph.** Flows do not call downstream flows directly. Each stage emits a Prefect event named `linc.opticstream.{pipeline}.{hierarchy}.{state}` (constants live in `opticstream/events/{lsm,psoct}_events.py`, and emitters in `*_event_emitters.py`). Deployments subscribe to those events through `get_event_trigger` / `create_event_deployment` (`opticstream/utils/deployment_utils.py`), and Jinja templates map the event payload into flow parameters. For example, PS-OCT runs `batch.ready → archive → batch.archived → DANDI upload → batch.dandi_uploaded`, and `mosaic.ready → en-face stitch + Slack QC → mosaic.enface_stitched → slice.ready → 3D optic axis (opt-in)` (details below). Uploads always run as separate event-triggered flows, so they never block compute. Deployments are served through `ops lsm serve` / `ops oct serve all` (`ops oct run` serves and watches together), and watchers (`ops lsm|oct watch`, `opticstream/utils/directory_watch.py`, `polling_watcher.py`) watch acquisition directories and emit the first events. | ||
|
|
||
| **Payload conventions.** Event payloads carry typed identifiers such as `mosaic_ident` and `strip_ident`, which parse into `OCTMosaicId`, `LSMStripId`, and so on. Most processing parameters come from the project's scan-config **Prefect Block**: `PSOCTScanConfig` saved as `"{project_name}-psoct-config"`, or `LSMScanConfig` saved as `"{project_name}-lsm-config"`, both in `opticstream/config/`. Fields removed from a config model must be added to its legacy-key drop list (`REMOVED_FIELDS` in `psoct_scan_config.py`) so saved blocks still load. `force_rerun` in a payload bypasses the skip guards. | ||
|
|
||
| **Project state (PostgreSQL).** `opticstream/state/` stores per-project state as JSONB rows keyed by `(project_type, project_name)` and accessed through a Prefect `SqlAlchemyConnector` block (`project_state_postgres.py`). Every mutation takes a project-scoped Prefect global concurrency lock (limit 1), then loads, mutates, and saves. The services are `OCT_STATE_SERVICE` and `LSM_STATE_SERVICE`, and they expose three kinds of access: | ||
| - `open_*`: locked context manager that yields a **mutable** model and saves on exit. | ||
| - `read_*`: locked read that returns a frozen **View** model. | ||
| - `peek_*`: unlocked, best-effort read. | ||
|
|
||
| Mutable models only exist inside `open_*` scopes; use `to_view()` to take a snapshot. See `docs/developer/prefect_state_design.md`. | ||
|
|
||
| **Idempotency / milestones.** Flows call `state_guards.should_skip_run` / `enter_flow_stage` to skip work that is already done or to restart it. Milestone decorators (`state/milestone_wrappers_{psoct,lsm}.py`, built on `milestone_runtime.guarded_milestone`) set a boolean field through `set_<field>()` on success and optionally emit the next event. When you add a milestone field, the state model needs matching `set_<field>` and `reset_<field>` methods. Flow hooks in `opticstream/hooks/` (such as `check_mosaic_ready_hook` and `check_slice_ready_hook`) check whether a parent level is complete and emit its `ready` event. Other hooks handle Slack notifications and publishing artifacts. | ||
|
|
||
| **PS-OCT chain.** There is no tile reconstruction in the pipeline: the MATLAB processing (psoct-toolbox), Fiji stitching, volume stitching and slice registration were removed, and replacement processing will subscribe to the events later (all event constants are kept, some unemitted). The steps are: | ||
|
|
||
| 1. `ops oct watch` (one watcher, `cli/oct/watch.py`) counts a tile once it has its raw spectral file **and** the acquisition's en-face maps (aip/mip/ori/ret, plus surf when mapped in `acquisition.filename_modality_map`). It emits `BATCH_READY` for each complete, stable batch and records the batch. When it records a mosaic's last batch, it emits `MOSAIC_READY` with `input_dir`, `acquisition` and `image_offset`. | ||
| 2. `BATCH_READY` → `tile_batch_archive_flow` → `BATCH_ARCHIVED` → `tile_batch_upload_flow` (milestone `dandi_uploaded`, event `BATCH_DANDI_UPLOADED`). | ||
| 3. `MOSAIC_READY` → `acquisition_preview_flow.preview_enface_mosaic`. It stitches the maps into JPEGs with linc-convert `mosaic2d`, posts them to Slack, and only then sets `enface_stitched` and emits `MOSAIC_ENFACE_STITCHED`. | ||
| 4. Its `check_slice_ready_hook` emits `SLICE_READY` once all `mosaics_per_slice` mosaics are stitched. | ||
| `SLICE_READY` → `optic_axis_3d_flow.fit_optic_axis_3d_slice` (opt-in via the block's `optic_axis_3d.enabled`). It lists the slice's en-face tiles as the previews found them, runs `data_processing/optic_axis_3d/run_3daxis.jl` with Julia/PSOCTRec, then sets the slice milestone `optic_axis_3d` and emits `SLICE_OPTIC_AXIS_3D`. | ||
| 5. `spectral_cleanup_flow` deletes a slice's spectral files last; every state milestone needs a `MILESTONE_RULES` entry there. | ||
|
|
||
| `data_processing/psoct_recon` (numpy ports) and `data_processing/stitch` are kept as building blocks but are unused by the flows. | ||
|
|
||
| **Uploads.** `tasks/dandi_upload.py` handles DANDI and LINC uploads, and `tasks/archive_file.py` handles archiving. | ||
|
|
||
| ## Notes | ||
|
|
||
| - Dependencies are pinned to specific git commits in `pyproject.toml`. Local editable overrides go in `[tool.uv.sources]` (commented out by default). Don't commit machine-specific `path =` entries. | ||
| - Deeper design docs are in `docs/developer/`: `oct_*.md`, `watcher_design_lsm_oct.md`, and `prefect_state_design.md`. Concept docs are in `docs/concepts/`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| # Acquisition en-face stitch and Slack QC | ||
|
|
||
| When every batch of a mosaic is ready, `ops oct watch` emits `MOSAIC_READY`. The | ||
| `preview-enface-mosaic` deployment (served by `ops oct serve all` / `ops oct run`) then: | ||
|
|
||
| 1. stitches the mosaic's AIP, MIP, orientation (`ori`) and retardance (`ret`) tiles, plus | ||
| surface-finding (`surf`) maps when the project maps them, into JPEGs with linc-convert | ||
| `mosaic2d()`; | ||
| 2. posts the JPEGs to Slack for QC; | ||
| 3. sets the mosaic's `enface_stitched` milestone and emits `MOSAIC_ENFACE_STITCHED`. | ||
|
|
||
| Its completion hook emits `SLICE_READY` once every mosaic of the slice is stitched. | ||
|
|
||
| The maps are the ones the acquisition software writes. mosaic2d writes only the JPEGs (no | ||
| NIfTI). Orientation is coloured by angle, with a colour wheel. The JPEGs are not uploaded to | ||
| DANDI. | ||
|
|
||
| There is no separate preview watcher: the one watcher waits for each tile's spectral file | ||
| *and* its maps before it counts a batch as ready (see | ||
| [OCT events and state](developer/oct_events_and_state.md)), so `MOSAIC_READY` means the maps | ||
| are all there. | ||
|
|
||
| ## Configure and run | ||
|
|
||
| The maps are found with the project's input naming (see oct_input_naming.md): | ||
|
|
||
| - `acquisition.filename_pattern` must contain `{modality}`. | ||
| - `acquisition.filename_modality_map` maps each filename label to a type: | ||
| - the labels mapped to `aip`, `mip`, `ori` and `ret` are the en-face maps (all four | ||
| required); | ||
| - a label mapped to `surf` adds a surface-finding map, which then becomes required too. | ||
|
|
||
| `ops oct watch` refuses to start when the naming cannot find the maps. | ||
|
|
||
| For example, a folder holding | ||
|
|
||
| ``` | ||
| sub-test_tile-0011_acq-normal0deg_spectral.nii | ||
| sub-test_tile-0011_acq-normal0deg_processed_aip.nii | ||
| sub-test_tile-0011_acq-normal0deg_processed_mip.nii | ||
| sub-test_tile-0011_acq-normal0deg_processed_orientation.nii | ||
| sub-test_tile-0011_acq-normal0deg_processed_retardance.nii | ||
| sub-test_tile-0011_acq-normal0deg_processed_surface_finding.nii | ||
| ``` | ||
|
|
||
| uses | ||
|
|
||
| ```json | ||
| { | ||
| "filename_pattern": "sub-test_tile-{image}_acq-{acq}_{modality}", | ||
| "filename_modality_map": { | ||
| "spectral": "spectral", | ||
| "processed_aip": "aip", | ||
| "processed_mip": "mip", | ||
| "processed_orientation": "ori", | ||
| "processed_retardance": "ret", | ||
| "processed_surface_finding": "surf" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Matching rules:** | ||
| - The pattern may leave out the extension; it then matches `.nii`, `.nii.gz`, `.mat` or | ||
| `.raw` (see oct_input_naming.md). | ||
| - Labels missing from the map (e.g. `processed`, the intensity volume) are ignored. | ||
| - `{image}` matches any zero padding. Two files for the same modality and image (e.g. | ||
| `..._0001_...` and `..._1_...`) are an error. | ||
|
|
||
| **Supported maps:** | ||
| - NIfTI (`.nii`/`.nii.gz`) and the other formats the QC loader reads are accepted. | ||
| - Only 2D maps, or maps with singleton trailing dimensions, are supported. | ||
| - Orientation maps are read in degrees. Set `acquisition.orientation_units` to `radians` if | ||
| the acquisition writes radians (default `degrees`); mosaic2d then converts them to degrees | ||
| before blending and colouring. | ||
|
|
||
| From Miniforge Prompt, with the project's venv activated and the Prefect API configured: | ||
|
|
||
| ```cmd | ||
| opticstream oct run human-10um D:\data\acquisition | ||
| ``` | ||
|
|
||
| **Continuous numbering.** With continuously numbered files (a `filename_pattern` without | ||
| `{slice}` or `{acq}`), each mosaic's maps are the images in its range; for example, mosaic 2 | ||
| of a 22 x 16 grid starts at image 353. The watcher passes that offset (`image_offset`) and the | ||
| mosaic's `acquisition_mosaic_map` label in the `MOSAIC_READY` payload. | ||
|
|
||
| **Rerunning.** To redo one mosaic, run the manual `preview-enface-mosaic` deployment with the | ||
| mosaic's ident, the acquisition folder, its label, its `image_offset` and `force_rerun`. | ||
|
|
||
| `ops oct preview` still stitches a quick M x N test mosaic outside the pipeline (no project | ||
| state, no events). | ||
|
|
||
| ## Geometry | ||
|
|
||
| Tiles are numbered consecutively within the mosaic, starting at image 1 (with continuous | ||
| numbering, at the mosaic's first image). Batch 1 holds the first `grid_size_y` tiles, batch 2 | ||
| the next set, and so on. The mosaic has `grid_size_x` * `grid_size_y` tiles. | ||
|
|
||
| Tilted mosaics use `grid_size_y_tilted` in place of `grid_size_y` when it is set. For example, | ||
| a scanner with 22 strips of 18 (normal) and 25 (tilted) tiles uses: | ||
| - `grid_size_x_normal=22`, `grid_size_x_tilted=22`; | ||
| - `grid_size_y=18`, `grid_size_y_tilted=25`. | ||
|
|
||
| The grid traversal is fixed (`GRID_TYPE`/`GRID_ORDER` in | ||
| `opticstream/flows/psoct/acquisition_preview_flow.py`): linc-convert `snake-by-rows` / | ||
| `left-down`. Individual images are not flipped. | ||
|
|
||
| Coordinates use the actual image dimensions and the mosaic's overlaps, in percent (X is | ||
| between batches, Y within a batch): | ||
| - normal mosaics: `acquisition.tile_overlap_x_normal` / `tile_overlap_y_normal`; | ||
| - tilted mosaics: `tile_overlap_x_tilted` / `tile_overlap_y_tilted`. | ||
|
|
||
| These are nominal-grid QC mosaics, not image-registered ones. Inspect alignment against a | ||
| known acquisition before relying on the geometry. | ||
|
|
||
| **Blending.** Orientation uses circular blending; AIP, MIP and retardance use ordinary | ||
| blending. Acquisition originals are never changed. Only non-NIfTI tiles are copied, to a | ||
| temporary NIfTI, before stitching. | ||
|
|
||
| **Stability.** Readiness is a heuristic, not a producer completion handshake: the watcher | ||
| waits until a batch's files have kept their sizes and modification times for | ||
| `--stability-seconds` (15 by default). Increase it if acquisition pauses during writes. A | ||
| missing, corrupt or inconsistent tile fails the stitch rather than producing a partial mosaic. | ||
|
|
||
| ## Outputs, Slack and retries | ||
|
|
||
| All JPEGs for a slice go in one folder, `project_base_path/slice-NN/acquisition_previews/`, | ||
| with the mosaic in the file name: `mosaic_001_aip.jpg`, ..., `mosaic_001_surf.jpg` and the | ||
| checkpoint `mosaic_001_progress.json`. Per-batch files from earlier versions | ||
| (`mosaic_001_batch_0003_*`) are left in place and can be deleted. | ||
|
|
||
| **The checkpoint.** | ||
| - `progress.json` records which modalities are stitched and posted, so a rerun skips | ||
| completed work. | ||
| - It also records where the mosaic's tiles are; spectral cleanup reads that. | ||
| - Changes to the inputs' paths, sizes or mtimes, or to the `acquisition` settings, invalidate | ||
| it, so the mosaic may be restitched and posted again after editing them. | ||
| - Changing only file content, without changing size or mtime, is not detected. | ||
|
|
||
| **Slack.** | ||
| - The existing Slack bot credentials and channel, and the `slack-notifications-enabled` | ||
| variable, are reused. | ||
| - When Slack is disabled, stitching still runs and the mosaic is marked stitched. | ||
| - Successful uploads are checkpointed per modality. If any upload fails, the flow fails | ||
| without emitting `MOSAIC_ENFACE_STITCHED`, and a rerun posts only the missing ones. | ||
| - Slack delivery is not exactly-once: a crash after Slack accepts an upload but before the | ||
| checkpoint is saved can duplicate it. | ||
|
|
||
| ## Deleting raw spectral files (always last) | ||
|
|
||
| With the block's `delete_spectral_after_previews` set to true (default false), a slice's | ||
| spectral files are deleted as the slice's **last** operation. `sweep-spectral-cleanup` checks | ||
| every 5 minutes. `ops oct serve all <project>` (and `ops oct run`) serve it; with `all` | ||
| instead of a project, only the manual flow is served. It deletes a slice's files only when all | ||
| of these hold: | ||
|
|
||
| 1. **En-face stitch.** The stitch has finished for every mosaic of the slice (its | ||
| `progress.json` is complete). | ||
| 2. **Archive.** When `archive_path` is set, every tile of the slice has: | ||
| - its archive copy, named by `archive_tile_name_format`; | ||
| - the archive's `.sha256`, which is written once the gzip is complete. | ||
|
|
||
| Tiles are counted rather than batches, so slices batched under an earlier grid setting | ||
| still qualify. | ||
| 3. **State milestones.** Every milestone of the slice, its mosaics and its batches that the | ||
| block enables is done, every batch and mosaic is completed, and nothing in the slice's | ||
| state is running or failed: | ||
|
|
||
| | Enabled by | Milestones | | ||
| |---|---| | ||
| | always | mosaic `enface_stitched` | | ||
| | `archive_path` | batch `archived`, raw-tile DANDI upload (`dandi_uploaded`) | | ||
|
|
||
| 4. **No activity.** No Prefect flow run whose parameters refer to the slice is scheduled, | ||
| pending, running, paused or cancelling, or ended in the last 2 minutes: | ||
| - parameters refer to the slice when they hold an ident or payload with its `project_name` | ||
| and `slice_id`; | ||
| - the 2 minutes give events emitted at the end of a run time to create the runs they | ||
| trigger. | ||
|
|
||
| Two rules keep deletion last as the pipeline grows: | ||
|
|
||
| - **New state milestones block until given a rule.** Every boolean milestone field of the | ||
| batch, mosaic and slice state needs an entry in `MILESTONE_RULES` | ||
| (`flows/psoct/spectral_cleanup_flow.py`) saying which settings produce it. A field without | ||
| one blocks deletion, and `test_every_state_milestone_has_a_rule` fails. | ||
| - **New flows are covered by the activity check.** Any flow taking the slice's identifiers | ||
| holds deletion off until it finishes, with or without a milestone. | ||
|
|
||
| A DANDI upload switched off with the `dandi-uploads-enabled` Prefect Variable never sets its | ||
| milestone, so the slice's spectral files are kept until uploads are turned back on and finish. | ||
|
|
||
| **What is deleted.** Only the files `filename_modality_map` maps to `spectral`, in the image | ||
| ranges recorded in `mosaic_NNN_progress.json`. En-face maps and every other file are kept. | ||
|
|
||
| **Afterwards.** `slice-NN/acquisition_previews/spectral_deleted.json` records the deletion, and | ||
| the sweep skips that slice from then on. Each sweep logs why it is keeping each slice's files. | ||
|
|
||
| **By hand.** To delete one slice, run `delete-slice-spectral` with the project's config and | ||
| the slice id. It makes the same checks, ignores the switch, and is safe to run again. | ||
|
|
||
| Restart the watcher after editing block fields. A project-state reset does not erase the | ||
| stitch checkpoints. To deliberately resend, delete or move the mosaic's `*_progress.json`. | ||
| Deleting only its `.jpg` files restitches without resending. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest adding this to the
.gitignoreso that it is not tracked.