Skip to content

Commit

Permalink
Fix antpos units when reading/writing miriad files
Browse files Browse the repository at this point in the history
  • Loading branch information
adampbeardsley authored and dannyjacobs committed Aug 31, 2017
1 parent a737ecb commit bcb045e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pyuvdata/miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def read_miriad(self, filepath, correct_lat_lon=True, run_check=True,

nants = uv['nants']
try:
antpos = uv['antpos'].reshape(3, nants).T
# Miriad stores antpos values in units of ns, pyuvdata uses meters.
antpos = uv['antpos'].reshape(3, nants).T * const.c.to('m/ns').value
# Miriad stores antpos values in a rotated ECEF coordinate system
# where the x-axis goes through the local meridan. Need to convert
# these positions back to standard ECEF and subtract off the
Expand Down Expand Up @@ -696,7 +697,8 @@ def write_miriad(self, filepath, run_check=True, check_extra=True,
antpos[np.where(antpos_length == 0), :] = [0, 0, 0]

uv.add_var('antpos', 'd')
uv['antpos'] = antpos.T.flatten()
# Miriad stores antpos values in units of ns, pyuvdata uses meters.
uv['antpos'] = antpos.T.flatten() / const.c.to('m/ns').value

uv.add_var('sfreq', 'd')
uv['sfreq'] = self.freq_array[0, 0] / 1e9 # first spw; in GHz
Expand Down
19 changes: 19 additions & 0 deletions pyuvdata/tests/test_miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import pyuvdata.utils as uvutils
import pyuvdata.tests as uvtest
from pyuvdata.data import DATA_PATH
import aipy.miriad as amiriad
from astropy import constants as const


def test_ReadNRAOWriteMiriadReadMiriad():
Expand Down Expand Up @@ -431,3 +433,20 @@ def test_multi_files():
' pyuvdata.', uv1.history))
uv1.history = uv_full.history
nt.assert_equal(uv1, uv_full)


def test_antpos_units():
"""
Read uvfits, write miriad. Check written antpos are in ns.
"""
uv = UVData()
uvfits_file = os.path.join(DATA_PATH, 'day2_TDEM0003_10s_norx_1src_1spw.uvfits')
testfile = os.path.join(DATA_PATH, 'test/uv_antpos_units')
uvtest.checkWarnings(uv.read_uvfits, [uvfits_file], message='Telescope EVLA is not')
uv.write_miriad(testfile, clobber=True)
auv = amiriad.UV(testfile)
aantpos = auv['antpos'].reshape(3, -1).T * const.c.to('m/ns').value
aantpos = aantpos[uv.antenna_numbers, :]
aantpos = (uvutils.ECEF_from_rotECEF(aantpos, uv.telescope_location_lat_lon_alt[1]) -
uv.telescope_location)
nt.assert_true(np.allclose(aantpos, uv.antenna_positions))
3 changes: 2 additions & 1 deletion pyuvdata/uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def __init__(self):
spoof_val={}, expected_type=dict)

desc = ('Array giving coordinates of antennas relative to '
'telescope_location (ITRF frame), shape (Nants_telescope, 3)')
'telescope_location (ITRF frame), shape (Nants_telescope, 3), '
'units meters')
self._antenna_positions = uvp.AntPositionParameter('antenna_positions',
required=False,
description=desc,
Expand Down

0 comments on commit bcb045e

Please sign in to comment.