Skip to content
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

Update FEED table #17

Merged
merged 2 commits into from
Feb 16, 2024
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
42 changes: 42 additions & 0 deletions fixms/fix_ms_corrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@
logger.setLevel(logging.INFO)


def set_pol_axis(ms: Path, pol_ang: u.Quantity, feed_idx: Optional[int] = None) -> None:
with table((ms / "FEED").as_posix(), readonly=True, ack=False) as tf:
ms_feed = tf.getcol("RECEPTOR_ANGLE") * u.rad
# PAF is at 45deg to feeds
# 45 - feed_angle = pol_angle
pol_axes = -(ms_feed - 45.0 * u.deg)

if feed_idx is None:
assert (ms_feed[:, 0] == ms_feed[0, 0]).all() & (
ms_feed[:, 1] == ms_feed[0, 1]
).all(), "The RECEPTOR_ANGLE changes with time, please check the MS"

old_pol_ang = pol_axes[0, 0].to(u.deg)
else:
logger.debug(f"Extracting the third-axis orientation for {feed_idx=}")
old_pol_ang = pol_axes[feed_idx, 0].to(u.deg)

assert old_pol_ang == pol_ang, "Updated pol angle does not match the original!"

pol_axes_cor = pol_axes - pol_ang
# PAF is at 45deg to feeds
# 45 - feed_angle = pol_angle
# -> feed_angle = 45 - pol_angle
new_ms_feed = -(pol_axes_cor - 45.0 * u.deg)
with table((ms / "FEED").as_posix(), readonly=False, ack=False) as tf:
tf.putcol("RECEPTOR_ANGLE", new_ms_feed.to(u.rad).value)
tf.flush()


def get_pol_axis(ms: Path, feed_idx: Optional[int] = None) -> u.Quantity:
"""Get the polarization axis from the ASKAP MS. Checks are performed
to ensure this polarisation axis angle is constant throughout the observation.
Expand Down Expand Up @@ -398,6 +427,19 @@ def fix_ms_corrs(
ms=ms,
app_params=_function_args,
)
logger.info(
f"Updating the FEED table by a rotation of {pol_axis}",
ms=ms,
app_params=_function_args,
)
set_pol_axis(ms, pol_axis, feed_idx=feed_idx)
logger.info(
f"Updated the RECEPTOR_ANGLE column with a rotation of {pol_axis}",
ms=ms.as_posix(),
app_params=_function_args,
)

logger.info("Done!")


def cli():
Expand Down
5 changes: 3 additions & 2 deletions fixms/fix_ms_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def restore_ms_dir(ms):
"""Restore the direction to the ASKAPsoft standard."""

if tableexists("%s/FIELD_OLD" % (ms)):
logger.info("Restoring FIELD directions in %s" % (ms))
logger.info("Restoring FIELD directions in %s" % (ms), ms=ms)
tp = table("{}/FIELD".format(ms), readonly=False, ack=False)
fp = table("%s/FIELD_OLD" % (ms), readonly=True, ack=False)
field_dir = fp.getcol("PHASE_DIR")
Expand All @@ -244,7 +244,8 @@ def restore_ms_dir(ms):
else:
logger.warning(
"No `FIELD_OLD` table in %s - cannot restore direction if direction has not changed."
% (ms)
% (ms),
ms=ms,
)


Expand Down
Loading