Coverage for python/lsst/sims/utils/approxCoordTransforms.py : 16%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import numpy as np
2from lsst.sims.utils import calcLmstLast
4__all__ = ['_approx_altAz2RaDec', '_approx_RaDec2AltAz', 'approx_altAz2RaDec', 'approx_RaDec2AltAz']
7def approx_altAz2RaDec(alt, az, lat, lon, mjd, lmst=None):
8 """
9 Convert alt, az to RA, Dec without taking into account aberration, precession, diffraction, etc.
11 Parameters
12 ----------
13 alt : numpy.array
14 Altitude, same length as `ra` and `dec`. Degrees.
15 az : numpy.array
16 Azimuth, same length as `ra` and `dec`. Must be same length as `alt`. Degrees.
17 lat : float
18 Latitude of the observatory in degrees.
19 lon : float
20 Longitude of the observatory in degrees.
21 mjd : float
22 Modified Julian Date.
23 lmst : float (None)
24 The local mean sidereal time (computed if not given). (hours)
26 Returns
27 -------
28 ra : array_like
29 RA, in degrees.
30 dec : array_like
31 Dec, in degrees.
32 """
33 ra, dec = _approx_altAz2RaDec(np.radians(alt), np.radians(az), np.radians(lat),
34 np.radians(lon), mjd, lmst=lmst)
35 return np.degrees(ra), np.degrees(dec)
38def _approx_altAz2RaDec(alt, az, lat, lon, mjd, lmst=None):
39 """
40 Convert alt, az to RA, Dec without taking into account aberration, precession, diffraction, etc.
42 Parameters
43 ----------
44 alt : numpy.array
45 Altitude, same length as `ra` and `dec`. Radians.
46 az : numpy.array
47 Azimuth, same length as `ra` and `dec`. Must be same length as `alt`. Radians.
48 lat : float
49 Latitude of the observatory in radians.
50 lon : float
51 Longitude of the observatory in radians.
52 mjd : float
53 Modified Julian Date.
54 lmst : float (None)
55 The local mean sidereal time (computed if not given). (hours)
57 Returns
58 -------
59 ra : array_like
60 RA, in radians.
61 dec : array_like
62 Dec, in radians.
63 """
64 if lmst is None:
65 lmst, last = calcLmstLast(mjd, lon)
66 lmst = lmst/12.*np.pi # convert to rad
67 sindec = np.sin(lat)*np.sin(alt) + np.cos(lat)*np.cos(alt)*np.cos(az)
68 sindec = np.clip(sindec, -1, 1)
69 dec = np.arcsin(sindec)
70 ha = np.arctan2(-np.sin(az)*np.cos(alt), -np.cos(az)*np.sin(lat)*np.cos(alt)+np.sin(alt)*np.cos(lat))
71 ra = (lmst-ha)
72 raneg = np.where(ra < 0)
73 ra[raneg] = ra[raneg] + 2.*np.pi
74 raover = np.where(ra > 2.*np.pi)
75 ra[raover] -= 2.*np.pi
76 return ra, dec
79def approx_RaDec2AltAz(ra, dec, lat, lon, mjd, lmst=None):
80 """
81 Convert Ra,Dec to Altitude and Azimuth.
83 Coordinate transformation is killing performance. Just use simple equations to speed it up
84 and ignore aberration, precession, nutation, nutrition, etc.
86 Parameters
87 ----------
88 ra : array_like
89 RA, in degrees.
90 dec : array_like
91 Dec, in degrees. Must be same length as `ra`.
92 lat : float
93 Latitude of the observatory in degrees.
94 lon : float
95 Longitude of the observatory in degrees.
96 mjd : float
97 Modified Julian Date.
98 lmst : float (None)
99 The local mean sidereal time (computed if not given). (hours)
101 Returns
102 -------
103 alt : numpy.array
104 Altitude, same length as `ra` and `dec`. degrees.
105 az : numpy.array
106 Azimuth, same length as `ra` and `dec`. degrees.
107 """
108 alt, az = _approx_RaDec2AltAz(np.radians(ra), np.radians(dec), np.radians(lat),
109 np.radians(lon), mjd, lmst=lmst)
110 return np.degrees(alt), np.degrees(az)
113def _approx_RaDec2AltAz(ra, dec, lat, lon, mjd, lmst=None):
114 """
115 Convert Ra,Dec to Altitude and Azimuth.
117 Coordinate transformation is killing performance. Just use simple equations to speed it up
118 and ignore aberration, precession, nutation, nutrition, etc.
120 Parameters
121 ----------
122 ra : array_like
123 RA, in radians.
124 dec : array_like
125 Dec, in radians. Must be same length as `ra`.
126 lat : float
127 Latitude of the observatory in radians.
128 lon : float
129 Longitude of the observatory in radians.
130 mjd : float
131 Modified Julian Date.
132 lmst : float (None)
133 The local mean sidereal time (computed if not given). (hours)
135 Returns
136 -------
137 alt : numpy.array
138 Altitude, same length as `ra` and `dec`. Radians.
139 az : numpy.array
140 Azimuth, same length as `ra` and `dec`. Radians.
141 """
142 if lmst is None:
143 lmst, last = calcLmstLast(mjd, lon)
144 lmst = lmst/12.*np.pi # convert to rad
145 ha = lmst-ra
146 sindec = np.sin(dec)
147 sinlat = np.sin(lat)
148 coslat = np.cos(lat)
149 sinalt = sindec*sinlat+np.cos(dec)*coslat*np.cos(ha)
150 sinalt = np.clip(sinalt, -1, 1)
151 alt = np.arcsin(sinalt)
152 cosaz = (sindec-np.sin(alt)*sinlat)/(np.cos(alt)*coslat)
153 cosaz = np.clip(cosaz, -1, 1)
154 az = np.arccos(cosaz)
155 signflip = np.where(np.sin(ha) > 0)
156 az[signflip] = 2.*np.pi-az[signflip]
157 return alt, az