Skip to content

feat: serve motion-corrected micrograph preview image (#308)#312

Merged
vredchenko merged 1 commit into
mainfrom
feat/308-micrograph-image-endpoint
Jul 24, 2026
Merged

feat: serve motion-corrected micrograph preview image (#308)#312
vredchenko merged 1 commit into
mainfrom
feat/308-micrograph-image-endpoint

Conversation

@vredchenko

Copy link
Copy Markdown
Collaborator

Closes #308. Adds the serving half of ADR 0021: the micrograph leaf of the Atlas → Grid Square → Foil Hole → Micrograph hierarchy, which previously had no image endpoint (FoilholeDetail.tsx renders grey placeholders).

Stacked on #311 (#309). Base is feat/309-micrograph-image-ingest because this endpoint reads the two columns that PR adds. The diff here is only the endpoint + tests. Merge #311 first, then retarget this to main.

Endpoint

GET /micrographs/{micrograph_uuid}/micrograph_image resolves in order:

  1. JPEG snapshot (motion_corrected_snapshot_path) — if set and on disk, streamed as-is via FileResponse (image/jpeg), no decode/render. Structurally immune to the atlas-page OOM class.
  2. Motion-corrected MRC (motion_corrected_image_path) — else rendered to PNG through the existing _render_image_png / _cached_image_response helpers, accepting the same optional x,y,w,h crop as atlas_image for future zoom parity.
  3. else 404.

Never reads high_res_path (the raw movie stack). Modeled on the existing atlas_image / gridsquare_image endpoints (same helpers, cache headers, auth).

Verification

  • New test_micrograph_image.py drives the real app via TestClient across all branches: 404 (missing micrograph), 404 (no paths), JPEG snapshot served and preferred over a present MRC path, and a real .mrc rendered to PNG. 54 route/image/consumer tests pass.
  • ruff check/format clean. pyright adds one whereclause false positive — the same SQLModel .where(Model.uuid == value) pattern already flagged 105× across api_server.py (identical to _require_micrograph); matching the established idiom.

Behaviour today

Against the current data every micrograph returns 404 (the ingestion paths from #309 are null until #310's cryoem-services adapter supplies them). Correct behaviour; a release is warranted once this and #311 land.

@vredchenko
vredchenko force-pushed the feat/309-micrograph-image-ingest branch from d8ed79d to 84a65f9 Compare July 24, 2026 12:33
Base automatically changed from feat/309-micrograph-image-ingest to main July 24, 2026 12:37
Add GET /micrographs/{uuid}/micrograph_image, the leaf of the spatial
hierarchy that previously had no image endpoint (ADR 0021). Resolves in
order: the pre-downscaled JPEG snapshot served as-is (zero render), then
the motion-corrected MRC rendered to PNG with an optional x,y,w,h crop for
zoom parity with atlas_image, else 404.

Never reads high_res_path (the raw multi-GB movie stack). Returns 404
against today's data since the ingestion paths (#309) are still null;
behaviour is covered by unit tests over the real routing and render path.
@vredchenko
vredchenko force-pushed the feat/308-micrograph-image-endpoint branch from 8399896 to 424e68e Compare July 24, 2026 12:40
@vredchenko
vredchenko merged commit ad7540a into main Jul 24, 2026
11 checks passed
@vredchenko
vredchenko deleted the feat/308-micrograph-image-endpoint branch July 24, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(api): serve motion-corrected micrograph preview image (ADR 0021)

1 participant