-
Notifications
You must be signed in to change notification settings - Fork 15
#554 load_image fix for sumwt images #555
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,10 +50,15 @@ | |
| def _squeeze_if_needed(ary: da, image_type: str) -> da: | ||
| if image_type.upper() == "VISIBILITY_NORMALIZATION": | ||
| shape = ary.shape | ||
| if len(shape) != 5: | ||
| raise ValueError( | ||
| "VISIBILITY_NORMALIZATION casa image must be 5D before squeezing. " | ||
| f"Found shape {shape}" | ||
| ) | ||
| if shape[3] != 1 or shape[4] != 1: | ||
| raise ValueError( | ||
| "VISIBILITY_NORMALIZATION casa image must have l and m of length 1. Found " | ||
| + [shape[3], shape[4]] | ||
| "VISIBILITY_NORMALIZATION casa image must have l and m of length 1. " | ||
| f"Found {(shape[3], shape[4])}" | ||
| ) | ||
| ary = ary.squeeze(axis=(3, 4)) | ||
| return ary | ||
|
|
@@ -99,7 +104,7 @@ def _load_casa_image_block( | |
| starts, shapes, slices = _get_starts_shapes_slices(block_des, coords, cshape) | ||
| transpose_list, new_axes = _get_transpose_list(coords) | ||
| block = _get_persistent_block( | ||
| image_full_path, shapes, starts, dimorder, transpose_list, new_axes | ||
| image_full_path, shapes, starts, transpose_list, new_axes | ||
| ) | ||
| block = _squeeze_if_needed(block, image_type) | ||
| xds = _add_sky_or_aperture( | ||
|
|
@@ -109,8 +114,9 @@ def _load_casa_image_block( | |
| for m in mymasks: | ||
| full_path = os.sep.join([image_full_path, m]) | ||
| block = _get_persistent_block( | ||
| full_path, shapes, starts, dimorder, transpose_list, new_axes | ||
| full_path, shapes, starts, transpose_list, new_axes | ||
| ) | ||
| block = _squeeze_if_needed(block, image_type) | ||
| # data vars are all caps by convention | ||
|
Comment on lines
116
to
120
|
||
| mask_name = re.sub(r"\bMASK(\d+)\b", r"MASK_\1", m.upper()) | ||
| xds = _add_mask(xds, mask_name, block, dimorder) | ||
|
|
||
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.
The newly added
_squeeze_if_needed(...)call can trigger an exception path where_squeeze_if_neededattempts to build the ValueError message via string concatenation with a Python list ("... Found " + [shape[3], shape[4]]), which will raise aTypeErrorand mask the intended validation error. Please format the shape values as a string (e.g., tuple/list via f-string/str(...)) so the correctValueErroris raised when l/m are not length 1 (and consider guarding against unexpected dimensionality before indexing shape[3]/shape[4]).