Skip to content

Reading and rewriting a CASA caltable changes calibration result #1654

@rlbyrne

Description

@rlbyrne

I have a CASA-generated caltable. Applying the calibration table to a *.ms file in CASA gives a different result than reading the caltable with pyuvdata, rewriting it, and then applying the rewritten caltable to the same *.ms file.

As a minimum working example, I read a data file, selected one antenna, one frequency channel, and one polarization and wrote to two separate *.ms files:

uv_orig = pyuvdata.UVData()
uv_orig.read(
    "data_orig.ms",
    data_column="DATA",
)
uv_orig.select(
    antenna_names=["LWA269"],
    polarizations=[-5],
    frequencies=[37324218.75],
)
uv_orig.write_ms("data_single_chan_cal1.ms")
uv_orig.write_ms("data_single_chan_cal2.ms")

I then applied to caltable to the first file in CASA, using the command applycal("data_single_chan_cal1.ms", gaintable="calibration_2026-01-12_05h.B.flagged", flagbackup=False)

Next I read and rewrote the caltable with pyuvdata:

cal = pyuvdata.UVCal()
cal.read_ms_cal("calibration_2026-01-12_05h.B.flagged")
cal.write_ms_cal("caltable_rewritten.B")

Then I applied the new caltable to the second file: applycal("data_single_chan_cal2.ms", gaintable="caltable_rewritten.B", flagbackup=False)

Finally I read the calibrated data from each file and compared.

uv1 = pyuvdata.UVData()
uv1.read(
    "data_single_chan_cal1.ms",
    data_column="CORRECTED_DATA",
    ignore_single_chan=False,
)
uv2 = pyuvdata.UVData()
uv2.read(
    "data_single_chan_cal2.ms",
    data_column="CORRECTED_DATA",
    ignore_single_chan=False,
)
print(uv1.data_array.flatten())
print(uv2.data_array.flatten())

Output is:

[68898648.+0.j 69056976.+0.j 69133112.+0.j 69129080.+0.j 69201160.+0.j
 68972824.+0.j 69310408.+0.j 69140696.+0.j 68981088.+0.j 69416584.+0.j
 69405520.+0.j 69430992.+0.j]
[15.081883-0.j 15.116542-0.j 15.133208-0.j 15.132325-0.j 15.148104-0.j
 15.098121-0.j 15.172017-0.j 15.134867-0.j 15.099929-0.j 15.195258-0.j
 15.192838-0.j 15.198413-0.j]

The caltable is available here: https://drive.google.com/file/d/1a7MtpdjAlbxbHTy23P8z-K1kHEKm7rCj/view?usp=sharing

Datafiles are:
data_single_chan_cal1.ms.zip
data_single_chan_cal2.ms.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions