Skip to content

Instantly share code, notes, and snippets.

@astropenguin
Last active February 13, 2023 05:31
Show Gist options
  • Save astropenguin/fff873494031fce71072493134973579 to your computer and use it in GitHub Desktop.
Save astropenguin/fff873494031fce71072493134973579 to your computer and use it in GitHub Desktop.
nqm2ms: Convert NEWSTAR data (*.nqm) to CASA MS
#!/usr/bin/env python
"""nqm2ms: Convert NEWSTAR data (*.nqm) to CASA MS.
Usage: /path/to/casa -c nqm2ms [<nqm> [<nqm> ...]]
Note: This script only works with CASA <= 5.0.0.
"""
import asap
import sys
NQM_EXT = ".nqm"
MS2_EXT = ".ms"
MS2_FMT = "MS2"
def convert(path_nqm, path_ms=None):
# type: (str, str | None) -> str
"""Convert a NEWSTAR data (*.nqm) to a CASA MS."""
st = asap.scantable(path_nqm)
if path_ms is None:
path_ms = path_nqm[:-len(NQM_EXT)] + MS2_EXT
st.save(path_ms, MS2_FMT)
return path_ms
def main():
# type: () -> None
"""Main function of the command line interface."""
nqms = [arg for arg in sys.argv if arg.endswith(NQM_EXT)]
if not nqms:
print(__doc__)
for nqm in nqms:
print("Converting {0}".format(nqm))
convert(nqm)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment