-
Notifications
You must be signed in to change notification settings - Fork 3
/
coordinates_manager.py
73 lines (62 loc) · 2.78 KB
/
coordinates_manager.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
#https://keflavich-astropy.readthedocs.io/en/latest/coordinates/observing-example.html
#https://docs.astropy.org/en/stable/coordinates/
import astropy as ast
from astropy.coordinates import SkyCoord, EarthLocation, AltAz, get_body, ICRS
import datetime
from ICRS_coordinates import ICRS_coordinates
class coordinates_manager():
def __init__(self):
self.lat = 0.0
self.lon = 0.0
self.height = 0.0
self.utcoffset = 0.0
self.loc = None
self.target = None
self.az = 0.0
self.alt = 0.0
def setLocation(self, lat, lon, height, utc_offset):
self.lat = lat
self.lon = lon
self.height = height
self.utcoffset = utc_offset * ast.units.hour
self.loc = EarthLocation(lat=lat, lon=lon, height=200)
ast.utils.iers.conf.auto_download = False
return True
def setTarget(self, s, target_type):
if target_type == 0: #NGC or Messier Object
a = ICRS_coordinates()
if a.setObject(s) == True:
objCoor = a.getICRSCoord()
self.target = SkyCoord(frame=ICRS,ra=objCoor[0]*ast.units.deg, dec=objCoor[1]*ast.units.deg)
else:
return False
elif target_type == 1: #solar system object
self.target = get_body(s, time=ast.time.Time(datetime.datetime.now())-self.utcoffset) #Remember to take into account UTC offset!
elif target_type == 2: #other
self.target = SkyCoord.from_name(s)
return True
def getCoordinate(self):
ctime = datetime.datetime.now() #current time (according to this computer)
#https://docs.astropy.org/en/stable/api/astropy.time.Time.html#astropy.time.Time
#Convert to astropy Time object
t = ast.time.Time(ctime)
#Account for offset to UTC
t -= self.utcoffset
#https://docs.astropy.org/en/stable/coordinates/transforming.html
#https://docs.astropy.org/en/stable/api/astropy.coordinates.AltAz.html
#Transform target to a SkyCoord object with Altitude/Azimuth coordinate system
target_altaz = self.target.transform_to(AltAz(obstime=t,location=self.loc))
#https://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html#astropy.coordinates.SkyCoord.to_string
return target_altaz.to_string('decimal')
def updateCoordinate(self):
s = self.getCoordinate()
space_pos = 0
for i in range(0,len(s),1):
if s[i] == " ":
space_pos = i
break
az_new = float(s[0:space_pos])
alt_new = float(s[space_pos+1:len(s)])
self.az = az_new
self.alt = alt_new
return True