Skip to content

#554 load_image fix for sumwt images#555

Merged
Jan-Willem merged 3 commits intomainfrom
554-open_image-and-load_image-fails-with-twhya-image
Mar 23, 2026
Merged

#554 load_image fix for sumwt images#555
Jan-Willem merged 3 commits intomainfrom
554-open_image-and-load_image-fails-with-twhya-image

Conversation

@dmehring
Copy link
Copy Markdown
Collaborator

No description provided.

@dmehring dmehring linked an issue Mar 20, 2026 that may be closed by this pull request
@dmehring dmehring requested a review from Copilot March 20, 2026 18:25
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/xradio/image/_util/casacore.py 66.66% 1 Missing ⚠️
src/xradio/image/_util/image_factory.py 92.30% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

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

Fixes loading of CASA “sumwt” / VISIBILITY_NORMALIZATION images in load_image by ensuring singleton spatial axes are removed so the resulting xarray variables match the canonical (time, frequency, polarization) dimensionality.

Changes:

  • Add a unit test asserting VISIBILITY_NORMALIZATION block loads squeeze away l/m axes.
  • Apply _squeeze_if_needed to mask blocks as well during CASA block loading.
  • Change _get_persistent_block to return a dask.array.Array (instead of wrapping in an xr.DataArray) to support the squeeze workflow.

Reviewed changes

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

File Description
tests/unit/image/test_image.py Adds coverage for squeezing singleton spatial axes when loading visibility normalization images.
src/xradio/image/_util/casacore.py Ensures mask blocks are also squeezed for VISIBILITY_NORMALIZATION in block-loading path.
src/xradio/image/_util/_casacore/xds_from_casacore.py Adjusts persistent-block helper to return a dask array rather than an xarray wrapper.

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

Comment on lines 111 to 115
block = _get_persistent_block(
full_path, shapes, starts, dimorder, transpose_list, new_axes
)
block = _squeeze_if_needed(block, image_type)
# data vars are all caps by convention
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The newly added _squeeze_if_needed(...) call can trigger an exception path where _squeeze_if_needed attempts to build the ValueError message via string concatenation with a Python list ("... Found " + [shape[3], shape[4]]), which will raise a TypeError and mask the intended validation error. Please format the shape values as a string (e.g., tuple/list via f-string/str(...)) so the correct ValueError is raised when l/m are not length 1 (and consider guarding against unexpected dimensionality before indexing shape[3]/shape[4]).

Copilot uses AI. Check for mistakes.
Comment on lines 111 to 115
block = _get_persistent_block(
full_path, shapes, starts, dimorder, transpose_list, new_axes
)
block = _squeeze_if_needed(block, image_type)
# data vars are all caps by convention
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

This new squeeze step inside the mask loop isn’t covered by the added unit test (the synthetic sumwt image in the test has no mask, so the loop never executes). Consider extending/adding a test that creates a VISIBILITY_NORMALIZATION image with a mask (e.g., MASK_0/default mask) and asserts the returned flag/mask data variable is also squeezed to (time, frequency, polarization) with no l/m dims.

Copilot uses AI. Check for mistakes.
Comment on lines 673 to 684
def _get_persistent_block(
infile: str,
shapes: tuple,
starts: tuple,
dimorder: list,
transpose_list: list,
new_axes: list,
) -> xr.DataArray:
) -> da.Array:
block = _read_image_chunk(infile, shapes, starts)
block = np.expand_dims(block, new_axes)
block = block.transpose(transpose_list)
block = da.from_array(block, chunks=block.shape)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

After changing _get_persistent_block to return a dask.array.Array, the dimorder parameter is no longer used in the function body. To reduce confusion and avoid unused-parameter warnings, consider either removing dimorder from the signature (and updating call sites) or renaming it to _dimorder to make the intentional non-use explicit.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


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

@dmehring dmehring requested a review from Jan-Willem March 20, 2026 19:37
@Jan-Willem Jan-Willem merged commit 5b1d9ce into main Mar 23, 2026
23 of 24 checks passed
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.

open_image and load_image fails with twhya image

3 participants