forked from ThemosTsikas/PhotoPolarAlign
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPPA-cli.py
More file actions
136 lines (97 loc) · 3.67 KB
/
Copy pathPPA-cli.py
File metadata and controls
136 lines (97 loc) · 3.67 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import argparse
import PPA_lib
from astropy.io import fits
# Parse arguments
argParser = argparse.ArgumentParser(description="A python utility to help align any equotorial telescope by imaging the celestial pole region")
argParser.add_argument("--solver", type=str, nargs="?", default=None, help="Whether to use online \"nova\" or \"local\" solver", required=True)
argParser.add_argument("--horizontal", type=str, nargs="?", metavar="horizontal_file_path", default=None, help="The filepath to the horizontal image", required=True)
argParser.add_argument("--vertical", type=str, nargs="?", metavar="vertical_file_path", default=None, help="The filepath to the vertical image", required=True)
argParser.add_argument("--improved", type=str, nargs="?", metavar="improved_file_path", default=None, help="The filepath to the improved image after adjusting scope mount")
argParser.add_argument("--cache-dir", type=str, nargs="?", help="Filepath to look in for cached .wcs files")
argParser.add_argument("--config", type=str, nargs="?", help="Filepath to config to use")
argParser.add_argument("--more-data", type=bool, nargs="?", default=False, help="Returns more detailed information")
args = argParser.parse_args()
solver_options = ["local", "nova"]
if args.solver not in solver_options:
print("Option '--solver' must be one of " + str(solver_options))
exit(2)
print(args)
config_file_path = args.config
cache_dir = args.cache_dir
return_more_data = args.more_data
solver = args.solver
config = PPA_lib.PPAConfig(config_file_path)
config.cachedir = cache_dir or config.cachedir
def solve_img(imagePath):
PPA_lib.plate_solve(config, imagePath, solver)
# Solve images
hImgPath = args.horizontal
hWcsPath = PPA_lib.get_wcs_file_path(config, hImgPath)
solve_img(hImgPath)
hdulist_h = fits.open(hWcsPath)
vImgPath = args.vertical
vWcsPath = PPA_lib.get_wcs_file_path(config, vImgPath)
solve_img(vImgPath)
hdulist_v = fits.open(vWcsPath)
iImgPath = args.improved
iWcsPath = None
hdulist_i = None
if iImgPath is not None:
iWcsPath = PPA_lib.get_wcs_file_path(config, iImgPath)
solve_img(iImgPath)
hdulist_i = fits.open(iWcsPath)
# Determine axis and error
axis = PPA_lib.find_ra_axis_pix_coords(hdulist_v[0], hdulist_h[0])
# Have the wcs files, just get the error
if hdulist_i is None:
error = PPA_lib.find_error(axis, hdulist_h)
else:
error = PPA_lib.find_error(axis, hdulist_i)
def formatError(err):
print(err)
if err[0] > 0:
inst = 'Right '
else:
inst = 'Left '
decdeg = abs(err[0])
inst = inst + ('%02d:%02d:%02d' % PPA_lib.decdeg2dms(decdeg))
if err[1] > 0:
inst = inst + ' Down '
else:
inst = inst + ' Up '
decdeg = abs(err[1])
inst = inst + ('%02d:%02d:%02d' % PPA_lib.decdeg2dms(decdeg))
return inst
print(formatError(error))
exit(1)
# ppa-cli --horizontal /path/to/horiz/image --verticle /path/horiz/image --[local|nova]
# Returns > left: 6.156705 down: 21.456830
# ppa-cli --horizontal-wcs /path/to/horiz/wcs --verticle-wcs /path/verticle/wcs --improvement /path/improvement/image
# Returns > left: 0.856705 up: 1.456830
# --horizontal will look in cache dir for wcs
# --cache-dir changes cache dir to use
# --config changes path to config to use
# ppa-cli --horizontal /path/to/horiz/wcs --verticle /path/verticle/wcs --improvement /path/improvement/image --config /config.ini
# --more-data will return
"""
{
hemi: 'n',
scale: 1.6
error: { (in degrees)
left: 0.856705,
up: 1.456830,
}
celestial-pole: {
ra: 90,
dec: 0,
alt: x,
az: y
},
axis: {
ra: 90.856705,
dec: -1.456830
alt: x,
az: y
}
}
"""