Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 29, 2024
1 parent 2ec5f19 commit d1f179f
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 367 deletions.
1 change: 1 addition & 0 deletions pyuvdata/docstrings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for dealing with merging docstrings."""

import copy
import typing as tp
from collections import ChainMap
Expand Down
1 change: 1 addition & 0 deletions pyuvdata/tests/test_docstrings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests of the docstrings module."""

from docstring_parser import DocstringReturns, DocstringStyle

from pyuvdata.docstrings import combine_docstrings
Expand Down
217 changes: 55 additions & 162 deletions pyuvdata/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@ def astrometry_args():
)

if hasmoon:
(
default_args["moon_app_ra"],
default_args["moon_app_dec"],
) = uvutils.transform_icrs_to_app(
default_args["time_array"],
default_args["icrs_ra"],
default_args["icrs_dec"],
default_args["moon_telescope_loc"],
telescope_frame="mcmf",
(default_args["moon_app_ra"], default_args["moon_app_dec"]) = (
uvutils.transform_icrs_to_app(
default_args["time_array"],
default_args["icrs_ra"],
default_args["icrs_dec"],
default_args["moon_telescope_loc"],
telescope_frame="mcmf",
)
)

default_args["moon_app_coord"] = SkyCoord(
Expand Down Expand Up @@ -403,40 +402,18 @@ def enu_mcmf_info():

def test_xyz_from_latlonalt(enu_ecef_info):
"""Test calculating xyz from lat lot alt."""
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)
assert np.allclose(np.stack((x, y, z), axis=1), xyz, atol=1e-3)


def test_enu_from_ecef(enu_ecef_info):
"""Test calculating ENU from ECEF coordinates."""
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)

enu = uvutils.ENU_from_ECEF(xyz, center_lat, center_lon, center_alt)
Expand All @@ -445,20 +422,9 @@ def test_enu_from_ecef(enu_ecef_info):

@pytest.mark.skipif(not hasmoon, reason="lunarsky not installed")
def test_enu_from_mcmf(enu_mcmf_info):
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_mcmf_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_mcmf_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts, frame="mcmf")
enu = uvutils.ENU_from_ECEF(xyz, center_lat, center_lon, center_alt, frame="mcmf")
assert np.allclose(np.stack((east, north, up), axis=1), enu, atol=1e-3)
Expand All @@ -479,20 +445,9 @@ def test_invalid_frame():
@pytest.mark.parametrize("shape_type", ["transpose", "Nblts,2", "Nblts,1"])
def test_enu_from_ecef_shape_errors(enu_ecef_info, shape_type):
"""Test ENU_from_ECEF input shape errors."""
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)
if shape_type == "transpose":
xyz = xyz.T.copy()
Expand All @@ -511,20 +466,9 @@ def test_enu_from_ecef_shape_errors(enu_ecef_info, shape_type):

def test_enu_from_ecef_magnitude_error(enu_ecef_info):
"""Test ENU_from_ECEF input magnitude errors."""
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)
# error checking
with pytest.raises(ValueError) as cm:
Expand Down Expand Up @@ -554,20 +498,9 @@ def test_ecef_from_enu_roundtrip(enu_ecef_info, enu_mcmf_info, frame):

@pytest.mark.parametrize("shape_type", ["transpose", "Nblts,2", "Nblts,1"])
def test_ecef_from_enu_shape_errors(enu_ecef_info, shape_type):
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)
enu = uvutils.ENU_from_ECEF(xyz, center_lat, center_lon, center_alt)
if shape_type == "transpose":
Expand All @@ -585,20 +518,9 @@ def test_ecef_from_enu_shape_errors(enu_ecef_info, shape_type):

def test_ecef_from_enu_single(enu_ecef_info):
"""Test single coordinate transform."""
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)
# check passing a single value
enu_single = uvutils.ENU_from_ECEF(xyz[0, :], center_lat, center_lon, center_alt)
Expand All @@ -608,20 +530,9 @@ def test_ecef_from_enu_single(enu_ecef_info):

def test_ecef_from_enu_single_roundtrip(enu_ecef_info):
"""Test single coordinate roundtrip."""
(
center_lat,
center_lon,
center_alt,
lats,
lons,
alts,
x,
y,
z,
east,
north,
up,
) = enu_ecef_info
(center_lat, center_lon, center_alt, lats, lons, alts, x, y, z, east, north, up) = (
enu_ecef_info
)
xyz = uvutils.XYZ_from_LatLonAlt(lats, lons, alts)
# check passing a single value
enu = uvutils.ENU_from_ECEF(xyz, center_lat, center_lon, center_alt)
Expand Down Expand Up @@ -1571,13 +1482,9 @@ def test_jphl_lookup():

# If we can't connect to JPL-Horizons, then skip this test and don't outright fail.
try:
[
ephem_times,
ephem_ra,
ephem_dec,
ephem_dist,
ephem_vel,
] = uvutils.lookup_jplhorizons("Sun", 2456789.0)
[ephem_times, ephem_ra, ephem_dec, ephem_dist, ephem_vel] = (
uvutils.lookup_jplhorizons("Sun", 2456789.0)
)
except (SSLError, RequestException) as err:
pytest.skip("SSL/Connection error w/ JPL Horizons: " + str(err))

Expand Down Expand Up @@ -2581,12 +2488,10 @@ def test_redundancy_finder():
bl_positions_new = uvd.uvw_array
bl_positions_new[bi] += sh

(
baseline_groups_new,
vec_bin_centers,
lens,
) = uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions_new, tol=hightol
(baseline_groups_new, vec_bin_centers, lens) = (
uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions_new, tol=hightol
)
)

for gi, gp in enumerate(baseline_groups_new):
Expand Down Expand Up @@ -2617,24 +2522,18 @@ def test_redundancy_finder():
# Check with conjugated baseline redundancies returned
# Ensure at least one baseline has u==0 and v!=0 (for coverage of this case)
bl_positions[16, 0] = 0
(
baseline_groups,
vec_bin_centers,
lens,
conjugates,
) = uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
(baseline_groups, vec_bin_centers, lens, conjugates) = (
uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
)
)

# restore baseline (16,0) and repeat to get correct groups
bl_positions = bl_pos_backup
(
baseline_groups,
vec_bin_centers,
lens,
conjugates,
) = uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
(baseline_groups, vec_bin_centers, lens, conjugates) = (
uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
)
)

# Apply flips to compare with get_antenna_redundancies().
Expand Down Expand Up @@ -2677,13 +2576,10 @@ def test_high_tolerance_redundancy_error():
tol = 20.05 # meters

with pytest.raises(ValueError) as cm:
(
baseline_groups,
vec_bin_centers,
lens,
conjugates,
) = uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
(baseline_groups, vec_bin_centers, lens, conjugates) = (
uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
)
)
assert "Some baselines are falling into" in str(cm.value)

Expand Down Expand Up @@ -2734,13 +2630,10 @@ def test_redundancy_finder_fully_redundant_array():
tol = 1 # meters
bl_positions = uvd.uvw_array

(
baseline_groups,
vec_bin_centers,
lens,
conjugates,
) = uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
(baseline_groups, vec_bin_centers, lens, conjugates) = (
uvutils.get_baseline_redundancies(
uvd.baseline_array, bl_positions, tol=tol, include_conjugates=True
)
)

# Only 1 set of redundant baselines
Expand Down
Loading

0 comments on commit d1f179f

Please sign in to comment.