11"""
22Azimuth / elevation <==> Right ascension, declination
33"""
4- from typing import Tuple , Union
4+ from typing import Tuple
55from datetime import datetime
66import numpy as np
7- from .timeconv import str2dt
7+ from .vallado import azel2radec as vazel2radec , radec2azel as vradec2azel
88try :
99 from astropy .time import Time
1010 from astropy import units as u
1111 from astropy .coordinates import Angle , SkyCoord , EarthLocation , AltAz , ICRS
1212except ImportError :
13- from .vallado import vazel2radec , vradec2azel
1413 Time = None
1514
1615
1716def azel2radec (az_deg : float , el_deg : float ,
1817 lat_deg : float , lon_deg : float ,
19- time : Union [str , datetime ]) -> Tuple [float , float ]:
20- """convert astronomical target horizontal azimuth, elevation to
21- ecliptic right ascension, declination (degrees)
18+ time : datetime , usevallado : bool = False ) -> Tuple [float , float ]:
19+ """
20+ viewing angle (az, el) to sky coordinates (ra, dec)
21+
22+ inputs
23+ ------
24+ azimuth: degrees clockwize from North
25+ elevation: degrees above horizon (neglecting aberration)
26+ observer latitude [-90, 90], longitude [-180, 180] (degrees)
27+ time: datetime of observation
28+
29+ Outputs
30+ -------
31+ ecliptic right ascension, declination (degrees)
2232 """
2333
24- if Time is None : # non-AstroPy method, less accurate
34+ if usevallado or Time is None : # non-AstroPy method, less accurate
2535 return vazel2radec (az_deg , el_deg , lat_deg , lon_deg , time )
2636
27- t = str2dt (time )
28-
2937 obs = EarthLocation (lat = lat_deg * u .deg , lon = lon_deg * u .deg )
3038
31- direc = AltAz (location = obs , obstime = Time (t ),
39+ direc = AltAz (location = obs , obstime = Time (time ),
3240 az = az_deg * u .deg , alt = el_deg * u .deg )
3341
3442 sky = SkyCoord (direc .transform_to (ICRS ()))
@@ -38,32 +46,37 @@ def azel2radec(az_deg: float, el_deg: float,
3846
3947def radec2azel (ra_deg : float , dec_deg : float ,
4048 lat_deg : float , lon_deg : float ,
41- time : Union [str , datetime ]) -> Tuple [float , float ]:
42- """convert astronomical target ecliptic right ascension, declination to
43- horizontal azimuth, eelvation (degrees)
49+ time : datetime , usevallado : bool = False ) -> Tuple [float , float ]:
50+ """
51+ sky coordinates (ra, dec) to viewing angle (az, el)
52+
53+ inputs
54+ ------
55+ ecliptic right ascension, declination (degrees)
56+ observer latitude [-90, 90], longitude [-180, 180] (degrees)
57+ time: datetime of observation
58+
59+ Outputs
60+ -------
61+ azimuth: degrees clockwize from North
62+ elevation: degrees above horizon (neglecting aberration)
4463 """
45- if Time is None :
64+
65+ if usevallado or Time is None :
4666 return vradec2azel (ra_deg , dec_deg , lat_deg , lon_deg , time )
4767# %% input trapping
48- t = str2dt (time )
4968 lat = np .atleast_1d (lat_deg )
5069 lon = np .atleast_1d (lon_deg )
5170 ra = np .atleast_1d (ra_deg )
5271 dec = np .atleast_1d (dec_deg )
5372
54- if not (lat .size == 1 & lon .size == 1 ):
55- raise ValueError ('radec2azel is designed for one observer and one or more points (ra,dec).' )
56-
57- if ra .shape != dec .shape :
58- raise ValueError ('ra and dec must be the same shape ndarray' )
59-
6073 obs = EarthLocation (lat = lat * u .deg ,
6174 lon = lon * u .deg )
6275
6376 points = SkyCoord (Angle (ra , unit = u .deg ),
6477 Angle (dec , unit = u .deg ),
6578 equinox = 'J2000.0' )
6679
67- altaz = points .transform_to (AltAz (location = obs , obstime = Time (t )))
80+ altaz = points .transform_to (AltAz (location = obs , obstime = Time (time )))
6881
6982 return altaz .az .degree , altaz .alt .degree
0 commit comments