-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_astrometryd
executable file
·77 lines (62 loc) · 2.69 KB
/
pipeline_astrometryd
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
#!/usr/bin/env python3
#
# This file is part of the Robotic Observatory Control Kit (rockit)
#
# rockit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rockit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rockit. If not, see <http://www.gnu.org/licenses/>.
"""Frame astrometry daemon"""
import argparse
import base64
import os
import subprocess
import tempfile
import Pyro4
from astropy.io import fits
from rockit.common import daemons
def header_to_dict(header):
ret = {}
for card in header.cards:
if card.is_blank or not card.keyword or card.keyword in ['COMMENT', 'HISTORY']:
continue
ret[card.keyword] = card.value
return ret
class PipelineAstrometryDaemon:
@Pyro4.expose
def solve(self, args):
with tempfile.TemporaryDirectory() as tmp_dir:
wcs_path = os.path.join(tmp_dir, 'scratch.wcs')
table_path = os.path.join(tmp_dir, 'scratch.xyls')
with open(table_path, 'wb') as f:
f.write(base64.b64decode(args['objects']))
wcs_args = [
'/usr/bin/solve-field',
'--overwrite', '--no-plots',
'--axy', 'none', '--rdls', 'none', '--match', 'none',
'--corr', 'none', '--solved', 'none',
'--scale-units', 'arcsecperpix', '--scale-high', str(args['scale_high']),
'--scale-low', str(args['scale_low']), '--width', str(args['width']), '--height', str(args['height'])]
if 'ra' in args and 'dec' in args and 'radius' in args:
wcs_args.extend([
'--ra', str(args['ra']),
'--dec', str(args['dec']),
'--radius', str(args['radius'])
])
wcs_args.append(table_path)
subprocess.check_call(wcs_args, timeout=args['timeout'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
return header_to_dict(fits.Header.fromfile(wcs_path))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Data pipeline worker daemon')
parser.add_argument('daemon_name', help='Daemon name')
getattr(daemons, parser.parse_args().daemon_name).launch(PipelineAstrometryDaemon())