52 lines
2.0 KiB
Python
Executable File
52 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
from __future__ import print_function
|
|
import os
|
|
import configparser
|
|
import argparse
|
|
import subprocess
|
|
|
|
if __name__ == '__main__':
|
|
# Read commandline options
|
|
conf_parser = argparse.ArgumentParser(description='Plate solve FITS file' +
|
|
' and add WCS on header')
|
|
conf_parser.add_argument("-c", "--conf_file",
|
|
help="Specify configuration file. If no file" +
|
|
" is specified 'configuration.ini' is used.",
|
|
metavar="FILE")
|
|
conf_parser.add_argument("-d", "--directory",
|
|
help="Specify directory of observations. If no" +
|
|
" directory is specified parent will be used.",
|
|
metavar='DIR', dest='file_dir', default=".")
|
|
|
|
args = conf_parser.parse_args()
|
|
|
|
# Process commandline options and parse configuration
|
|
cfg = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
|
|
if args.conf_file:
|
|
cfg.read([args.conf_file])
|
|
else:
|
|
cfg.read('configuration.ini')
|
|
|
|
path = args.file_dir
|
|
extension = 'fits'
|
|
files = sorted((f for f in os.listdir(path) if f.endswith('.' + extension)),
|
|
key=lambda x: os.path.getctime(os.path.join(path, x)))
|
|
|
|
if files:
|
|
file_for_astrometry = os.path.join(path, files[0])
|
|
print("Found " + file_for_astrometry + " for astrometric solving.")
|
|
|
|
sex_config = cfg.get('Astrometry', 'sex_config')
|
|
|
|
# Format command
|
|
command = "solve-field -O -y -u app -L 37 -H 40 --use-sextractor " + \
|
|
"--sextractor-config %s --downsample 2 --x-column X_IMAGE " % sex_config + \
|
|
"--y-column Y_IMAGE --sort-column MAG_AUTO --sort-ascending " + \
|
|
"%s" % file_for_astrometry
|
|
|
|
# Run sextractor
|
|
subprocess.run(command, shell=True, stderr=subprocess.STDOUT)
|
|
|
|
else:
|
|
print("No fits file found for astrometric solving.")
|