Skip to content

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

Open
vredchenko wants to merge 1 commit into
feat/309-micrograph-image-ingestfrom
feat/308-micrograph-image-endpoint
Open

feat: serve motion-corrected micrograph preview image (#308)#312
vredchenko wants to merge 1 commit into
feat/309-micrograph-image-ingestfrom
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.

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.
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.

1 participant