-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathgalactic.py
executable file
·76 lines (58 loc) · 2.31 KB
/
galactic.py
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
#!/usr/bin/env python3
#
# galactic.py - by Don Cross - 2021-06-14
#
# Example Python program for Astronomy Engine:
# https://github.com/cosinekitty/astronomy
#
# Demo of converting galactic coordinates to horizontal coordinates.
#
import sys
from astronomy import *
from typing import Tuple
UsageText = r'''
USAGE: galactic olat olon glat glon [yyyy-mm-ddThh:mm:ssZ]
where
olat = observer's latitude on the Earth
olon = observer's longitude on the Earth
glat = IAU 1958 galatic latitude of the target
glon = IAU 1958 galatic longitude of the target
yyyy-mm-ddThh:mm:ssZ = optional UTC date/time
Given the galactic coordinates of a point source in the sky,
this program calculates horizontal aiming coordinates for an
observer on or near the Earth's surface.
If the date/time is given on the command line, it is used.
Otherwise, the computer's current date/time is used.
'''
def GalacticToHorizontal(time: Time, observer: Observer, glat: float, glon: float) -> Tuple[float, float]:
# Calculate a matrix that converts galactic coordinates
# to J2000 equatorial coordinates.
rot = Rotation_GAL_EQJ()
# Adjust the rotation matrix to convert galactic to horizontal.
adjust_rot = Rotation_EQJ_HOR(time, observer)
rot = CombineRotation(rot, adjust_rot)
# Convert the galactic coordinates from angles to a unit vector.
gsphere = Spherical(glat, glon, 1.0)
gvec = VectorFromSphere(gsphere, time)
# Use the rotation matrix to convert the galactic vector to a horizontal vector.
hvec = RotateVector(rot, gvec)
# Convert the horizontal vector back to angular coordinates.
# Assume this is a radio source (not optical), do not correct for refraction.
hsphere = HorizonFromVector(hvec, Refraction.Airless)
return hsphere.lat, hsphere.lon
if __name__ == '__main__':
if len(sys.argv) not in [5, 6]:
print(UsageText)
sys.exit(1)
olat = float(sys.argv[1])
olon = float(sys.argv[2])
observer = Observer(olat, olon)
glat = float(sys.argv[3])
glon = float(sys.argv[4])
if len(sys.argv) > 5:
time = Time.Parse(sys.argv[5])
else:
time = Time.Now()
altitude, azimuth = GalacticToHorizontal(time, observer, glat, glon)
print('altitude = {:10.3f}, azimuth = {:10.3f}'.format(altitude, azimuth))
sys.exit(0)