Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/xradio/image/_util/_casacore/xds_to_casacore.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ def _coord_dict_from_xds(xds: xr.Dataset) -> dict:
coord["worldmap2"] = np.array([3], dtype=np.int32)
# this probbably needs some verification
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

Typo in comment: "probbably" should be "probably".

Suggested change
# this probbably needs some verification
# this probably needs some verification

Copilot uses AI. Check for mistakes.
coord["worldreplace0"] = [0.0, 0.0]
coord["worldreplace1"] = np.array(coord["stokes1"]["crval"])
coord["worldreplace2"] = np.array(coord["spectral2"]["wcs"]["crval"])
coord["worldreplace1"] = np.atleast_1d(coord["stokes1"]["crval"])
coord["worldreplace2"] = np.atleast_1d(coord["spectral2"]["wcs"]["crval"])
Copy link
Copy Markdown
Collaborator Author

@r-xue r-xue Mar 26, 2026

Choose a reason for hiding this comment

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

The coord["spectral2"]["wcs"]["crval"] value is stored as a Python float. Before the changes, calling np.array(coord["spectral2"]["wcs"]["crval"]) actually created a 0-dimensional numpy array (e.g., array(1415000000.0)).

casatools doesn't seem to like serializing 0-D arrays into the table keyword structure. By failing silently on serialization, it then later substituted the value with an empty 1-D array (array([], dtype=float64)) when fetching, therefore leading to the mismatch. python-casacore, on the other hand, might be more tolerant of this... even though I believe this should be a 1D array in the first place.

I have wrapped both coord["stokes1"]["crval"] and coord["spectral2"]["wcs"]["crval"] here with np.atleast_1d, even though it's likely unnecessary for the former.

Since we have figured out the root cause now, the earlier worldreplace2 workaround in test_image.py also got cleaned up.


return coord


Expand Down
5 changes: 0 additions & 5 deletions tests/unit/image/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,6 @@ def test_metadata(self):
# by casacore on the fly, so we cannot easily compare them,
# and really comes down to comparing the values of c used in
# the computations (eg, if c is in m/s or km/s)
# it appears that 'worldreplace2' is not correctly recorded or retrieved
# by casatools, with empty np.array returned instead.
c2["coordinates"]["worldreplace2"] = np.array(
[c2["coordinates"]["spectral2"]["wcs"]["crval"]]
)
assert_attrs_dicts_equal(
c2,
c1,
Expand Down
Loading