Skip to content

Commit

Permalink
azel*radec: test, functionalize Vallado non-Astropy
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jan 8, 2025
1 parent e5dc895 commit 3506b7f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/pymap3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Fortran: [Maptran3D](https://github.com/geospace-code/maptran3d)
"""

__version__ = "3.1.0"
__version__ = "3.1.1"

from .aer import aer2ecef, aer2geodetic, ecef2aer, geodetic2aer
from .ecef import (
Expand Down
50 changes: 37 additions & 13 deletions src/pymap3d/azelradec.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,24 @@ def azel2radec(
"""

try:
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
return azel2radec_astropy(az_deg, el_deg, lat_deg, lon_deg, time)
except NameError:
return vazel2radec(az_deg, el_deg, lat_deg, lon_deg, time)

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

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

return sky.ra.deg, sky.dec.deg
except NameError:
return vazel2radec(az_deg, el_deg, lat_deg, lon_deg, time)
direc = AltAz(location=obs, obstime=Time(str2dt(time)), az=az_deg * u.deg, alt=el_deg * u.deg)

sky = SkyCoord(direc.transform_to(ICRS()))

return sky.ra.deg, sky.dec.deg


def radec2azel(
Expand Down Expand Up @@ -97,10 +104,27 @@ def radec2azel(
"""

try:
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
points = SkyCoord(Angle(ra_deg, unit=u.deg), Angle(dec_deg, unit=u.deg), equinox="J2000.0")
altaz = points.transform_to(AltAz(location=obs, obstime=Time(str2dt(time))))

return altaz.az.degree, altaz.alt.degree
return radec2azel_astropy(ra_deg, dec_deg, lat_deg, lon_deg, time)
except NameError:
return vradec2azel(ra_deg, dec_deg, lat_deg, lon_deg, time)


def radec2azel_astropy(
ra_deg: float,
dec_deg: float,
lat_deg: float,
lon_deg: float,
time: datetime,
) -> tuple[float, float]:
"""
rade2azel using Astropy
see radec2azel() for description
"""

obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)

points = SkyCoord(Angle(ra_deg, unit=u.deg), Angle(dec_deg, unit=u.deg), equinox="J2000.0")

altaz = points.transform_to(AltAz(location=obs, obstime=Time(str2dt(time))))

return altaz.az.degree, altaz.alt.degree
4 changes: 2 additions & 2 deletions src/pymap3d/sidereal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def datetime2sidereal(time: datetime, lon_radians: float) -> float:


def datetime2sidereal_astropy(t: datetime, lon_radians: float) -> float:
""" datetime to sidereal time using astropy
"""datetime to sidereal time using astropy
see datetime2sidereal() for description
"""

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


def datetime2sidereal_vallado(t: datetime, lon_radians: float) -> float:
""" datetime to sidereal time using Vallado methods
"""datetime to sidereal time using Vallado methods
see datetime2sidereal() for description
"""

Expand Down
3 changes: 2 additions & 1 deletion src/pymap3d/tests/test_sidereal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ def test_sidereal(time):


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


def test_sidereal_valado():
def test_sidereal_vallado():
tsr = pmd.datetime2sidereal_vallado(t0, radians(lon))
assert tsr == approx(sra, rel=1e-5)
assert isinstance(tsr, float)
Expand Down
19 changes: 19 additions & 0 deletions src/pymap3d/tests/test_sky.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime

import pymap3d as pm
import pymap3d.vallado as pv
import pytest
from pytest import approx

Expand All @@ -14,6 +15,15 @@
def test_azel2radec():
radec1 = pm.azel2radec(*azel, lat, lon, t0)
assert radec1 == approx(radec, rel=0.01)
assert isinstance(radec1[0], float)
assert isinstance(radec1[1], float)


def test_azel2radec_vallado():
radec1 = pv.azel2radec(*azel, lat, lon, t0)
assert radec1 == approx(radec, rel=0.01)
assert isinstance(radec1[0], float)
assert isinstance(radec1[1], float)


def test_numpy_azel2radec():
Expand All @@ -25,6 +35,15 @@ def test_numpy_azel2radec():
def test_radec2azel():
azel1 = pm.radec2azel(*radec, lat, lon, t0)
assert azel1 == approx(azel, rel=0.01)
assert isinstance(azel1[0], float)
assert isinstance(azel1[1], float)


def test_radec2azel_vallado():
azel1 = pv.radec2azel(*radec, lat, lon, t0)
assert azel1 == approx(azel, rel=0.01)
assert isinstance(azel1[0], float)
assert isinstance(azel1[1], float)


def test_numpy_radec2azel():
Expand Down
2 changes: 1 addition & 1 deletion src/pymap3d/vallado.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
converts right ascension, declination to azimuth, elevation and vice versa.
Normally do this via AstroPy.
These functions are fallbacks for those wihtout AstroPy.
These functions are fallbacks for those without AstroPy.
Michael Hirsch implementation of algorithms from D. Vallado
"""
Expand Down

0 comments on commit 3506b7f

Please sign in to comment.