6
6
from astropy .utils import iers
7
7
import sys , subprocess
8
8
9
- def polarcalc (mylat , mylong , myelev , time , p1RA , p1DEC , p2RA , p2DEC , p3RA , p3DEC ):
10
- #iers.conf.auto_download = False
11
- #iers.conf.auto_max_age = None
12
-
13
- #Create time object based on given time
14
- observing_time = Time ('2020-08-10 3:00:05' )
15
-
16
- #Create location object based on lat/long/elev
17
- observing_location = EarthLocation (lat = mylat * u .deg , lon = mylong * u .deg , height = 177 * u .m )
18
-
19
- #Create coordinate objects for each point
20
- p1 = SkyCoord (p1RA , p1DEC , unit = 'deg' )
21
- p2 = SkyCoord (p2RA , p2DEC , unit = 'deg' )
22
- p3 = SkyCoord (p3RA , p3DEC , unit = 'deg' )
23
- p1X = (90 - p1 .dec .degree ) * math .cos (p1 .ra .radian )
24
- p1Y = (90 - p1 .dec .degree ) * math .sin (p1 .ra .radian )
25
- p2X = (90 - p2 .dec .degree ) * math .cos (p2 .ra .radian )
26
- p2Y = (90 - p2 .dec .degree ) * math .sin (p2 .ra .radian )
27
- p3X = (90 - p3 .dec .degree ) * math .cos (p3 .ra .radian )
28
- p3Y = (90 - p3 .dec .degree ) * math .sin (p3 .ra .radian )
29
-
30
- #Calculate center of circle using three points in the complex plane. DEC is treated as unitless for the purposes of the calculation.
31
- x , y , z = complex (p1X ,p1Y ), complex (p2X ,p2Y ), complex (p3X ,p3Y )
32
- w = z - x
33
- w /= y - x
34
- c = (x - y )* (w - abs (w )** 2 )/ 2j / w .imag - x
35
- resultX = - c .real
36
- resultY = c .imag
37
-
38
- #Convert X/Y values of circle into RA/DEC
39
- resultDEC = (90 - math .sqrt (resultX ** 2 + resultY ** 2 ))
40
- resultRA = math .atan2 (resultY , resultX )* 360 / (2 * math .pi )
41
- if resultRA < 0 :
42
- resultRA = (180 - abs (resultRA ))+ 180
43
-
44
- #Create coordinate object for current alignment offset
45
- offset = SkyCoord (resultRA , resultDEC , frame = 'icrs' , unit = 'deg' )
46
- print (f"Current alignment in RA/DEC: { offset .ra .to_string (u .hour , precision = 2 )} /{ offset .dec .to_string (u .deg , precision = 2 )} ." )
47
-
48
- #Create coordinate object for pole
49
- pole = SkyCoord (0 , 90 , frame = 'icrs' , unit = 'deg' )
50
-
51
- #Create coordinate object for pole
52
- poleAzAlt = pole .transform_to (AltAz (obstime = observing_time ,location = observing_location ))
53
- print (f"True polar alignment in Az./Alt.: 0h00m00s/{ Angle (mylat * u .degree ).to_string (u .degree , sep = ('d' , 'm' , 's' ), precision = 2 )} ." )
54
-
55
- #Transform current alignment to Alt/Az coordinate system
56
- #offsetAzAlt = offset.transform_to(AltAz(obstime=observing_time,location=observing_location, temperature=25*u.deg_C, pressure=101325*u.Pa, relative_humidity=0.5))
57
- offsetAzAlt = offset .transform_to (AltAz (obstime = observing_time ,location = observing_location ))
58
- print (f"Current alignment in Az./Alt.: { offsetAzAlt .az .to_string (u .hour , precision = 2 )} /{ offsetAzAlt .alt .to_string (u .deg , precision = 2 )} ." )
59
-
60
- #Calculate offset deltas from pole
61
- if offsetAzAlt .az .deg < 180 :
62
- errorAz = - offsetAzAlt .az .deg * 60
63
- else :
64
- errorAz = (360 - offsetAzAlt .az .deg )* 60
65
- print (f"Azimuth error correction is: { errorAz :.4f} arcminutes." )
66
- errorAlt = (mylat - offsetAzAlt .alt .deg )* 60
67
- print (f"Altitude error correction is: { errorAlt :.4f} arcminutes." )
68
-
69
- return errorAz , errorAlt
9
+ def polarcalc (mylat , mylong , myelev , observing_time , p1RA , p1DEC , p2RA , p2DEC , p3RA , p3DEC ):
10
+ #iers.conf.auto_download = False
11
+ #iers.conf.auto_max_age = None
12
+
13
+ #Create time object based on given time
14
+ observing_time = Time (observing_time )
15
+
16
+ #Create location object based on lat/long/elev
17
+ observing_location = EarthLocation (lat = mylat * u .deg , lon = mylong * u .deg , height = myelev * u .m )
18
+
19
+ #Create coordinate objects for each point
20
+ p1 = SkyCoord (p1RA , p1DEC , unit = 'deg' )
21
+ p2 = SkyCoord (p2RA , p2DEC , unit = 'deg' )
22
+ p3 = SkyCoord (p3RA , p3DEC , unit = 'deg' )
23
+ p1X = (90 - p1 .dec .degree ) * math .cos (p1 .ra .radian )
24
+ p1Y = (90 - p1 .dec .degree ) * math .sin (p1 .ra .radian )
25
+ p2X = (90 - p2 .dec .degree ) * math .cos (p2 .ra .radian )
26
+ p2Y = (90 - p2 .dec .degree ) * math .sin (p2 .ra .radian )
27
+ p3X = (90 - p3 .dec .degree ) * math .cos (p3 .ra .radian )
28
+ p3Y = (90 - p3 .dec .degree ) * math .sin (p3 .ra .radian )
29
+
30
+ #Calculate center of circle using three points in the complex plane. DEC is treated as unitless for the purposes of the calculation.
31
+ x , y , z = complex (p1X ,p1Y ), complex (p2X ,p2Y ), complex (p3X ,p3Y )
32
+ w = z - x
33
+ w /= y - x
34
+ c = (x - y )* (w - abs (w )** 2 )/ 2j / w .imag - x
35
+ resultX = - c .real
36
+ resultY = c .imag
37
+
38
+ #Convert X/Y values of circle into RA/DEC
39
+ resultDEC = (90 - math .sqrt (resultX ** 2 + resultY ** 2 ))
40
+ resultRA = math .atan2 (resultY , resultX )* 360 / (2 * math .pi )
41
+ if resultRA < 0 :
42
+ resultRA = (180 - abs (resultRA ))+ 180
43
+
44
+ #Create coordinate object for current alignment offset
45
+ offset = SkyCoord (resultRA , resultDEC , frame = 'itrs' , unit = 'deg' , representation_type = 'spherical' , obstime = Time (observing_time ))
46
+ print (f"Current alignment in RA/DEC: { Angle (resultRA * u .deg ).to_string (u .hour , precision = 2 )} /{ Angle (resultDEC * u .deg ).to_string (u .degree , precision = 2 )} ." )
47
+
48
+ #Create coordinate object for pole
49
+ pole = SkyCoord (0 , 90 , frame = 'itrs' , unit = 'deg' , representation_type = 'spherical' , obstime = Time (observing_time ))
50
+
51
+ #Create coordinate object for pole
52
+ poleAzAlt = pole .transform_to (AltAz (obstime = Time (observing_time ),location = observing_location ))
53
+ print (f"True polar alignment in Az./Alt.: 0h00m00s/{ poleAzAlt .alt .to_string (u .degree , precision = 2 )} ." )
54
+
55
+ #Transform current alignment to Alt/Az coordinate system
56
+ offsetAzAlt = offset .transform_to (AltAz (obstime = Time (observing_time ),location = observing_location ))
57
+ print (f"Current alignment in Az./Alt.: { offsetAzAlt .az .to_string (u .hour , precision = 2 )} /{ offsetAzAlt .alt .to_string (u .degree , precision = 2 )} ." )
58
+
59
+ #Calculate offset deltas from pole
60
+ #Normalize the azimuth values to between -180 and 180 degrees prior to determining offset.
61
+ errorAz = (((poleAzAlt .az .deg + 180 ) % 360 - 180 )- ((offsetAzAlt .az .deg + 180 ) % 360 - 180 ))* 60
62
+ print (f"Azimuth error correction is: { errorAz :.4f} arcminutes." )
63
+ errorAlt = (poleAzAlt .alt .deg - offsetAzAlt .alt .deg )* 60
64
+ print (f"Altitude error correction is: { errorAlt :.4f} arcminutes." )
65
+
66
+ return errorAz , errorAlt
70
67
71
68
#Latitude in degrees
72
69
mylat = float (sys .argv [1 ])
@@ -75,42 +72,45 @@ def polarcalc(mylat, mylong, myelev, time, p1RA, p1DEC, p2RA, p2DEC, p3RA, p3DEC
75
72
mylong = float (sys .argv [2 ])
76
73
77
74
#Elevation in meters
78
- myelev = sys .argv [3 ]
75
+ myelev = float ( sys .argv [3 ])
79
76
80
77
#YYYY-MM-DD HH:MM:SS format
81
78
time = sys .argv [4 ]
82
79
83
80
#All RA/DEC values must be in compatible format to Astropy.coordinates library.
84
81
#Preferrably degrees, but 00h00m00.0s and 00d00m00.0s should also work
85
- p1RA = sys .argv [5 ]
86
- p1DEC = sys .argv [6 ]
87
- p2RA = sys .argv [7 ]
88
- p2DEC = sys .argv [8 ]
89
- p3RA = sys .argv [9 ]
90
- p3DEC = sys .argv [10 ]
82
+ p1RA = float ( sys .argv [5 ])
83
+ p1DEC = float ( sys .argv [6 ])
84
+ p2RA = float ( sys .argv [7 ])
85
+ p2DEC = float ( sys .argv [8 ])
86
+ p3RA = float ( sys .argv [9 ])
87
+ p3DEC = float ( sys .argv [10 ])
91
88
92
89
#Serial port address for Arduino, typically /dev/ttyACM0 in Astroberry, possibly /dev/ttyACM1
93
- serialport = sys .argv [11 ]
90
+ if len (sys .argv ) <= 11 :
91
+ serialport = "/dev/ttyACM0"
92
+ else :
93
+ serialport = sys .argv [11 ]
94
94
95
95
result = polarcalc (mylat , mylong , myelev , time , p1RA , p1DEC , p2RA , p2DEC , p3RA , p3DEC )
96
96
97
- #Verify error correction values can be handled by AutoPA hardware (assuming it is in home/centered position)
97
+ #Verify error correction can be handled by AutoPA hardware (assuming it is in home/centered position)
98
98
moveAz = "N"
99
99
if abs (result [0 ]) > 120 :
100
- moveAz = input ("Azimuth error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): " )
100
+ moveAz = input ("Azimuth error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): " )
101
101
else :
102
- moveAz = "Y"
102
+ moveAz = "Y"
103
103
if moveAz .upper () == "Y" :
104
- #Call process to move azimuth using elevated privileges to override any existing serial connection
105
- subprocess .call (['sudo' , './altaz.py' , "az" , str (result [0 ]), serialport ])
104
+ #Call process to move azimuth using elevated privileges to override any existing serial connection
105
+ subprocess .call (['sudo' , './altaz.py' , "az" , str (result [0 ]), serialport ])
106
106
107
107
moveAlt = "N"
108
108
if result [1 ] > 168 :
109
- moveAz = input ("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): " )
109
+ moveAz = input ("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): " )
110
110
elif result [1 ] > 432 :
111
- moveAz = input ("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): " )
111
+ moveAz = input ("Altitude error may be out of bounds of hardware capabilities if not in home position. Continue? (Y/N): " )
112
112
else :
113
- moveAlt = "Y"
113
+ moveAlt = "Y"
114
114
if moveAlt .upper () == "Y" :
115
- #Call process to move altitude using elevated privileges to override any existing serial connection
116
- subprocess .call (['sudo' , './altaz.py' , "alt" , str (result [1 ]), serialport ])
115
+ #Call process to move altitude using elevated privileges to override any existing serial connection
116
+ subprocess .call (['sudo' , './altaz.py' , "alt" , str (result [1 ]), serialport ])
0 commit comments