Skip to content

Commit 3506b7f

Browse files
committed
azel*radec: test, functionalize Vallado non-Astropy
1 parent e5dc895 commit 3506b7f

File tree

6 files changed

+62
-18
lines changed

6 files changed

+62
-18
lines changed

src/pymap3d/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Fortran: [Maptran3D](https://github.com/geospace-code/maptran3d)
3030
"""
3131

32-
__version__ = "3.1.0"
32+
__version__ = "3.1.1"
3333

3434
from .aer import aer2ecef, aer2geodetic, ecef2aer, geodetic2aer
3535
from .ecef import (

src/pymap3d/azelradec.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,24 @@ def azel2radec(
5252
"""
5353

5454
try:
55-
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
55+
return azel2radec_astropy(az_deg, el_deg, lat_deg, lon_deg, time)
56+
except NameError:
57+
return vazel2radec(az_deg, el_deg, lat_deg, lon_deg, time)
5658

57-
direc = AltAz(
58-
location=obs, obstime=Time(str2dt(time)), az=az_deg * u.deg, alt=el_deg * u.deg
59-
)
6059

61-
sky = SkyCoord(direc.transform_to(ICRS()))
60+
def azel2radec_astropy(
61+
az_deg: float, el_deg: float, lat_deg: float, lon_deg: float, time: datetime
62+
) -> tuple[float, float]:
63+
"""azel2radec using Astropy
64+
see azel2radec() for description
65+
"""
66+
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
6267

63-
return sky.ra.deg, sky.dec.deg
64-
except NameError:
65-
return vazel2radec(az_deg, el_deg, lat_deg, lon_deg, time)
68+
direc = AltAz(location=obs, obstime=Time(str2dt(time)), az=az_deg * u.deg, alt=el_deg * u.deg)
69+
70+
sky = SkyCoord(direc.transform_to(ICRS()))
71+
72+
return sky.ra.deg, sky.dec.deg
6673

6774

6875
def radec2azel(
@@ -97,10 +104,27 @@ def radec2azel(
97104
"""
98105

99106
try:
100-
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
101-
points = SkyCoord(Angle(ra_deg, unit=u.deg), Angle(dec_deg, unit=u.deg), equinox="J2000.0")
102-
altaz = points.transform_to(AltAz(location=obs, obstime=Time(str2dt(time))))
103-
104-
return altaz.az.degree, altaz.alt.degree
107+
return radec2azel_astropy(ra_deg, dec_deg, lat_deg, lon_deg, time)
105108
except NameError:
106109
return vradec2azel(ra_deg, dec_deg, lat_deg, lon_deg, time)
110+
111+
112+
def radec2azel_astropy(
113+
ra_deg: float,
114+
dec_deg: float,
115+
lat_deg: float,
116+
lon_deg: float,
117+
time: datetime,
118+
) -> tuple[float, float]:
119+
"""
120+
rade2azel using Astropy
121+
see radec2azel() for description
122+
"""
123+
124+
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
125+
126+
points = SkyCoord(Angle(ra_deg, unit=u.deg), Angle(dec_deg, unit=u.deg), equinox="J2000.0")
127+
128+
altaz = points.transform_to(AltAz(location=obs, obstime=Time(str2dt(time))))
129+
130+
return altaz.az.degree, altaz.alt.degree

src/pymap3d/sidereal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def datetime2sidereal(time: datetime, lon_radians: float) -> float:
4444

4545

4646
def datetime2sidereal_astropy(t: datetime, lon_radians: float) -> float:
47-
""" datetime to sidereal time using astropy
47+
"""datetime to sidereal time using astropy
4848
see datetime2sidereal() for description
4949
"""
5050

@@ -54,7 +54,7 @@ def datetime2sidereal_astropy(t: datetime, lon_radians: float) -> float:
5454

5555

5656
def datetime2sidereal_vallado(t: datetime, lon_radians: float) -> float:
57-
""" datetime to sidereal time using Vallado methods
57+
"""datetime to sidereal time using Vallado methods
5858
see datetime2sidereal() for description
5959
"""
6060

src/pymap3d/tests/test_sidereal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ def test_sidereal(time):
2323

2424

2525
def test_sidereal_astropy():
26+
pytest.importorskip("astropy")
2627
tsr = pmd.datetime2sidereal_astropy(t0, radians(lon))
2728
assert tsr == approx(sra, rel=1e-5)
2829
assert isinstance(tsr, float)
2930

3031

31-
def test_sidereal_valado():
32+
def test_sidereal_vallado():
3233
tsr = pmd.datetime2sidereal_vallado(t0, radians(lon))
3334
assert tsr == approx(sra, rel=1e-5)
3435
assert isinstance(tsr, float)

src/pymap3d/tests/test_sky.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22

33
import pymap3d as pm
4+
import pymap3d.vallado as pv
45
import pytest
56
from pytest import approx
67

@@ -14,6 +15,15 @@
1415
def test_azel2radec():
1516
radec1 = pm.azel2radec(*azel, lat, lon, t0)
1617
assert radec1 == approx(radec, rel=0.01)
18+
assert isinstance(radec1[0], float)
19+
assert isinstance(radec1[1], float)
20+
21+
22+
def test_azel2radec_vallado():
23+
radec1 = pv.azel2radec(*azel, lat, lon, t0)
24+
assert radec1 == approx(radec, rel=0.01)
25+
assert isinstance(radec1[0], float)
26+
assert isinstance(radec1[1], float)
1727

1828

1929
def test_numpy_azel2radec():
@@ -25,6 +35,15 @@ def test_numpy_azel2radec():
2535
def test_radec2azel():
2636
azel1 = pm.radec2azel(*radec, lat, lon, t0)
2737
assert azel1 == approx(azel, rel=0.01)
38+
assert isinstance(azel1[0], float)
39+
assert isinstance(azel1[1], float)
40+
41+
42+
def test_radec2azel_vallado():
43+
azel1 = pv.radec2azel(*radec, lat, lon, t0)
44+
assert azel1 == approx(azel, rel=0.01)
45+
assert isinstance(azel1[0], float)
46+
assert isinstance(azel1[1], float)
2847

2948

3049
def test_numpy_radec2azel():

src/pymap3d/vallado.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
converts right ascension, declination to azimuth, elevation and vice versa.
33
Normally do this via AstroPy.
4-
These functions are fallbacks for those wihtout AstroPy.
4+
These functions are fallbacks for those without AstroPy.
55
66
Michael Hirsch implementation of algorithms from D. Vallado
77
"""

0 commit comments

Comments
 (0)