-
Notifications
You must be signed in to change notification settings - Fork 21
/
hadec2altaz.jl
99 lines (75 loc) · 2.91 KB
/
hadec2altaz.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.
function _hadec2altaz{T<:AbstractFloat}(ha::T, dec::T, lat::T, ws::Bool)
sh = sind(ha)
ch = cosd(ha)
sd = sind(dec)
cd = cosd(dec)
sl = sind(lat)
cl = cosd(lat)
x = -ch*cd*sl + sd*cl
y = -sh*cd
z = ch*cd*cl + sd*sl
r = hypot(x, y)
# Now get altitude, azimuth
az = mod(rad2deg(atan2(y, x)), 360)
alt = rad2deg(atan2(z, r))
# Convert azimuth to West from South, if desired
if ws
az = mod(az + 180, 360)
end
return alt, az
end
"""
hadec2altaz(ha, dec, lat[, ws=true]) -> alt, az
### Purpose ###
Convert Hour Angle and Declination to Horizon (Alt-Az) coordinates.
### Explanation ###
Can deal with the NCP singularity. Intended mainly to be used by program
`eq2hor`.
### Arguments ###
Input coordinates may be either a scalar or an array, of the same dimension.
* `ha`: the local apparent hour angle, in degrees. The hour angle is the time
that right ascension of 0 hours crosses the local meridian. It is
unambiguously defined.
* `dec`: the local apparent declination, in degrees.
* `lat`: the local geodetic latitude, in degrees, scalar or array.
* `ws` (optional boolean keyword): if true, the output azimuth is measured West
from South. The default is to measure azimuth East from North.
`ha` and `dec` can be given as a 2-tuple `(ha, dec)`.
### Output ###
2-tuple `(alt, az)`
* `alt`: local apparent altitude, in degrees.
* `az`: the local apparent azimuth, in degrees.
The output coordinates are always floating points and have the same type (scalar
or array) as the input coordinates.
### Example ###
Arcturus is observed at an apparent hour angle of 336.6829 and a declination of
19.1825 while at the latitude of +43° 4' 42''. What are the local altitude and
azimuth of this object?
``` julia
alt, az = hadec2altaz(336.6829, 19.1825, ten(43, 4, 42))
# => (59.08617155005683,133.3080693440254)
```
### Notes ###
`altaz2hadec` converts Horizon (Alt-Az) coordinates to Hour Angle and
Declination.
Code of this function is based on IDL Astronomy User's Library.
"""
hadec2altaz(ha::Real, dec::Real, lat::Real; ws::Bool=false) =
_hadec2altaz(promote(float(ha), float(dec), float(lat))..., ws)
hadec2altaz(hadec::Tuple{Real, Real}, lat::Real; ws::Bool=false) =
hadec2altaz(hadec..., lat, ws=ws)
function hadec2altaz{R1<:Real, R2<:Real, R3<:Real}(ha::AbstractArray{R1},
dec::AbstractArray{R2},
lat::AbstractArray{R3};
ws::Bool=false)
@assert length(ha) == length(dec) == length(lat)
typeha = typeof(float(one(R1)))
alt = similar(ha, typeha)
az = similar(ha, typeha)
for i in eachindex(ha)
alt[i], az[i] = hadec2altaz(ha[i], dec[i], lat[i], ws=ws)
end
return alt, az
end