Skip to content

Commit

Permalink
Fix a bug where the ellipsoid wasn't passed in lat/lon/alt conversions
Browse files Browse the repository at this point in the history
add a test
  • Loading branch information
bhazelton committed Mar 19, 2024
1 parent 41b0eb6 commit ed5393d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
12 changes: 10 additions & 2 deletions pyuvdata/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,10 @@ def lat_lon_alt(self):
else:
# check defaults to False b/c exposed check kwarg exists in UVData
return utils.LatLonAlt_from_XYZ(
self.value, check_acceptability=False, frame=self.frame
self.value,
check_acceptability=False,
frame=self.frame,
lunar_ellipsoid=self.lunar_ellipsoid,
)

def set_lat_lon_alt(self, lat_lon_alt):
Expand All @@ -953,7 +956,11 @@ def set_lat_lon_alt(self, lat_lon_alt):
self.value = None
else:
self.value = utils.XYZ_from_LatLonAlt(
lat_lon_alt[0], lat_lon_alt[1], lat_lon_alt[2], frame=self.frame
lat_lon_alt[0],
lat_lon_alt[1],
lat_lon_alt[2],
frame=self.frame,
lunar_ellipsoid=self.lunar_ellipsoid,
)

def lat_lon_alt_degrees(self):
Expand Down Expand Up @@ -984,6 +991,7 @@ def set_lat_lon_alt_degrees(self, lat_lon_alt_degree):
longitude * np.pi / 180.0,
altitude,
frame=self.frame,
lunar_ellipsoid=self.lunar_ellipsoid,
)

def check_acceptability(self):
Expand Down
39 changes: 39 additions & 0 deletions pyuvdata/tests/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
from astropy.coordinates import CartesianRepresentation, Latitude, Longitude, SkyCoord

from pyuvdata import parameter as uvp
from pyuvdata.tests.test_utils import (
frame_selenoid,
ref_latlonalt,
ref_latlonalt_moon,
ref_xyz,
ref_xyz_moon,
)
from pyuvdata.uvbase import UVBase


Expand Down Expand Up @@ -397,6 +404,38 @@ def test_location_set_lat_lon_alt_degrees_none():
assert param1.value is None


@pytest.mark.parametrize(["frame", "selenoid"], frame_selenoid)
def test_location_xyz_latlonalt_match(frame, selenoid):
if frame == "itrs":
xyz_val = ref_xyz
latlonalt_val = ref_latlonalt
else:
xyz_val = ref_xyz_moon[selenoid]
latlonalt_val = ref_latlonalt_moon

param1 = uvp.LocationParameter(
name="p1", value=xyz_val, frame=frame, lunar_ellipsoid=selenoid
)
np.testing.assert_allclose(latlonalt_val, param1.lat_lon_alt())

param2 = uvp.LocationParameter(name="p2", frame=frame, lunar_ellipsoid=selenoid)
param2.set_lat_lon_alt(latlonalt_val)

np.testing.assert_allclose(xyz_val, param2.value)

param3 = uvp.LocationParameter(name="p2", frame=frame, lunar_ellipsoid=selenoid)
latlonalt_deg_val = np.array(
[
latlonalt_val[0] * 180 / np.pi,
latlonalt_val[1] * 180 / np.pi,
latlonalt_val[2],
]
)
param3.set_lat_lon_alt_degrees(latlonalt_deg_val)

np.testing.assert_allclose(xyz_val, param3.value)


def test_location_acceptability():
"""Test check_acceptability with LocationParameters"""
val = np.array([0.5, 0.5, 0.5])
Expand Down
6 changes: 1 addition & 5 deletions pyuvdata/uvdata/tests/test_uvfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pyuvdata.utils as uvutils
from pyuvdata import UVData
from pyuvdata.data import DATA_PATH
from pyuvdata.tests.test_utils import frame_selenoid
from pyuvdata.uvdata.uvdata import _future_array_shapes_warning

casa_tutorial_uvfits = os.path.join(
Expand All @@ -24,11 +25,6 @@

paper_uvfits = os.path.join(DATA_PATH, "zen.2456865.60537.xy.uvcRREAAM.uvfits")

selenoids = ["SPHERE", "GSFC", "GRAIL23", "CE-1-LAM-GEO"]
frame_selenoid = [["itrs", "SPHERE"]]
for snd in selenoids:
frame_selenoid.append(["mcmf", snd])


def _fix_uvfits_multi_group_params(vis_hdu):
par_names = vis_hdu.data.parnames
Expand Down
6 changes: 1 addition & 5 deletions pyuvdata/uvdata/tests/test_uvh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import pyuvdata.utils as uvutils
from pyuvdata import UVData
from pyuvdata.data import DATA_PATH
from pyuvdata.tests.test_utils import frame_selenoid
from pyuvdata.uvdata.uvdata import _future_array_shapes_warning

from .. import uvh5
Expand All @@ -33,11 +34,6 @@
pytest.mark.filterwarnings("ignore:Telescope EVLA is not"),
]

selenoids = ["SPHERE", "GSFC", "GRAIL23", "CE-1-LAM-GEO"]
frame_selenoid = [["itrs", "SPHERE"]]
for snd in selenoids:
frame_selenoid.append(["mcmf", snd])


@pytest.fixture(scope="session")
def uv_uvh5_main():
Expand Down

0 comments on commit ed5393d

Please sign in to comment.