Skip to content

Remove image downsampling from IMAT endpoint#344

Closed
Dagonite wants to merge 6 commits intomainfrom
remove-imat-logic
Closed

Remove image downsampling from IMAT endpoint#344
Dagonite wants to merge 6 commits intomainfrom
remove-imat-logic

Conversation

@Dagonite
Copy link
Copy Markdown
Collaborator

@Dagonite Dagonite commented Apr 1, 2026

Closes #296.

Description

Removes unused downsampling support from the IMAT latest-image flow and aligns the frontend with the simplified API contract.

  • Simplified GET /imat/latest-image so it no longer accepts downsample_factor.
  • Removed unused latest-image response metadata (originalWidth, originalHeight, sampledWidth, sampledHeight, downsampleFactor) and now return only data and shape.
  • Updated the frontend IMAT Latest Image viewer to request /imat/latest-image without downsample_factor and derive sizing from shape.
  • Updated plotting-service tests to cover the new latest-image behavior.

Testing

  • Passed: pytest test/test_plotting_api.py -q -k "convert_image_to_rgb_array or latest_imat_image" -p no:cacheprovider

Stop downsampling IMAT images and simplify image conversion plumbing. The GET /imat/latest-image endpoint no longer accepts or uses a downsample_factor and now returns full-resolution RGB bytes with shape [height, width, 3]. The image_service.convert_image_to_rgb_array signature was simplified to return (data, width, height) and all resizing logic was removed. Router imports and payload fields related to original/sampled dimensions and downsampleFactor were removed, and tests were updated to match the new full-resolution behavior (including removal of the downsampling unit test).
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes downsampling support from the plotting-service IMAT “latest image” flow and updates tests to reflect the simplified response contract.

Changes:

  • Simplifies GET /imat/latest-image to remove downsample_factor and return only data and shape.
  • Refactors convert_image_to_rgb_array to always return full-resolution RGB data plus dimensions.
  • Updates plotting-service tests to validate the new helper signature and endpoint payload.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
plotting-service/plotting_service/routers/imat.py Removes the downsample query param and trims response payload to data + shape.
plotting-service/plotting_service/services/image_service.py Simplifies image conversion helper to full-resolution output and updates return signature.
plotting-service/test/test_plotting_api.py Updates/cleans tests for new helper signature and latest-image response shape.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plotting-service/test/test_plotting_api.py Outdated
Comment thread plotting_service/services/image_service.py
Comment on lines 58 to 68
# Convert the image to RGB array
try:
data, original_width, original_height, sampled_width, sampled_height = convert_image_to_rgb_array(
latest_path, downsample_factor
)
data, width, height = convert_image_to_rgb_array(latest_path)
except Exception as exc:
logger.error("Failed to convert IMAT image at %s", latest_path, exc_info=exc)
raise HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, "Unable to convert IMAT image") from exc

# Calculate effective downsample factor
effective_downsample = original_width / sampled_width if sampled_width else 1

payload = {
"data": data,
"shape": [sampled_height, sampled_width, 3],
"originalWidth": original_width,
"originalHeight": original_height,
"sampledWidth": sampled_width,
"sampledHeight": sampled_height,
"downsampleFactor": effective_downsample,
"shape": [height, width, 3],
}
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/imat/latest-image now always returns full-resolution pixel data as a JSON list of ints. Compared to the previous default downsample (8x), this can increase response size and server memory/CPU significantly for typical IMAT images; consider adding a hard cap/alternative encoding (e.g., base64 bytes) or explicitly documenting/guarding the maximum supported image dimensions.

Copilot uses AI. Check for mistakes.
Dagonite and others added 2 commits April 9, 2026 10:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI changed the title Remove image downsampling from IMAT endpoint Fix docstring for convert_image_to_rgb_array and test naming Apr 9, 2026
@Dagonite Dagonite changed the title Fix docstring for convert_image_to_rgb_array and test naming Remove image downsampling from IMAT endpoint Apr 10, 2026
@Dagonite Dagonite requested a review from Pasarus April 14, 2026 07:44
@Dagonite
Copy link
Copy Markdown
Collaborator Author

Closing for now as IMAT Stack Viewer still uses this logic.

@Dagonite Dagonite closed this Apr 14, 2026
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.

Remove excess imat-viewer endpoint logic

4 participants