diff --git a/README.md b/README.md index 8f97c97..ea90f76 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ASKAP utilities for updating MeasurementSets for external imagers. ASKAP MSs are produced in a way that breaks compatibility with most other imagers (e.g. CASA, WSclean). Here we provide two modules (with CLI hooks) that perform the fixes that need to be applied in order to produce astronomically correct imagers with non-YandaSoft imagers: -1. `fix_ms_dir` : ASKAP MeasurementSets are phased towards the centre of field, but not the centre of its given beam. This utility reads the appropriate offsets to the beam centre from the `BEAM_OFFSET` and updates the `FIELD` table, as well as the phase and delay reference columns. An option is also available to restore the `FIELD` table directions to the original directions if `fix_ms_dir` has already been run. +1. `fix_ms_dir` : ASKAP MeasurementSets are phased towards the centre of field, but not the centre of its given beam. This utility reads the appropriate offsets to the beam centre from the `BEAM_OFFSET` and updates the `FIELD` table, as well as the phase and delay reference columns. An option is also available to restore the `FIELD` table directions to the original directions if `fix_ms_dir` has already been run. `BEAM_OFFSET` is also restored with this option. 2. `fix_ms_corrs` : ASKAP MeasurementSets, as calibrated by the obervatory, provide correlations in the instrument frame. ASKAP has a unique 'roll' axis which means, in principle, the instrument frame can be at any arbitrary rotation on the sky. This utility applies the appropriate rotation matrix to the visibilities such the 'X' is aligned North-South and 'Y' is aligned East-West (IAU convention). Further, ASKAPsoft defines Stokes I as $I=XX+YY$, whereas most other telescopes use $I=\frac{1}{2}(XX+YY)$ (note this also applies to all other Stokes paramters). This factor is also corrected for here at the same time as the rotation. If you have calibrated with non-ASKAPsoft tools, you may need to use the `--no-fix-stokes-factor` option, which will disable the factor of two correction and just do a rotation. diff --git a/fixms/fix_ms_dir.py b/fixms/fix_ms_dir.py index 94f5ae4..963481d 100644 --- a/fixms/fix_ms_dir.py +++ b/fixms/fix_ms_dir.py @@ -232,24 +232,40 @@ 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), 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") - tp.putcol("PHASE_DIR", field_dir) - tp.putcol("DELAY_DIR", field_dir) - tp.putcol("REFERENCE_DIR", field_dir) - tp.flush() - tp.close() + logger.info("Restoring FIELD directions in %s" % (ms)) + with table("%s/FIELD" % (ms), readonly=False, ack=False) as tp, table( + "%s/FIELD_OLD" % (ms), readonly=True, ack=False + ) as fp: + + field_dir = fp.getcol("PHASE_DIR") + tp.putcol("PHASE_DIR", field_dir) + tp.putcol("DELAY_DIR", field_dir) + tp.putcol("REFERENCE_DIR", field_dir) + + else: + logger.warning( + "No `FIELD_OLD` table in %s - cannot restore directions if direction has not changed." + % (ms) + ) + + if tableexists("%s/FEED_OLD" % (ms)): + + logger.info("Restoring BEAM_OFFSET in %s" % (ms)) + with table("%s/FEED" % (ms), readonly=False, ack=False) as tp, table( + "%s/FEED_OLD" % (ms), readonly=True, ack=False + ) as fp: + + offset = fp.getcol("BEAM_OFFSET") + tp.putcol("BEAM_OFFSET", offset) + else: logger.warning( - "No `FIELD_OLD` table in %s - cannot restore direction if direction has not changed." - % (ms), - ms=ms, + "No `FEED_OLD` table in %s - cannot restore beam offsets if they have not been changed." + % (ms) ) -def fix_ms_dir(ms): +def fix_ms_dir(ms, backup_beam_offsets=True): logger.info("Fixing FEED directions in %s" % (ms), ms=ms) # Check that the observation wasn't in pol_fixed mode with table("%s/ANTENNA" % (ms), readonly=True, ack=False) as ta: @@ -282,6 +298,7 @@ def fix_ms_dir(ms): # Open up the MS FEED table so we can work out what the offset is for the beam. with table("%s/FEED" % (ms), readonly=False, ack=False) as tf: + offset = tf.getcol("BEAM_OFFSET") offset = offset - offset offset = tf.putcol("BEAM_OFFSET", offset) diff --git a/pyproject.toml b/pyproject.toml index af1f8d2..a135226 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fixms" -version = "0.2.0" +version = "0.2.1" description = "" authors = ["Alec Thomson (S&A, Kensington WA) "] readme = "README.md"