Merge pull request #25 from cbassa/auto_astrometry

Basic implementation of automatic astrometry with solve-field
pull/26/head
Cees Bassa 2019-07-28 13:40:21 +02:00 committed by GitHub
commit 4fac038f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View File

@ -6,6 +6,7 @@ from stvid.stio import fourframe
from stvid.stars import generate_star_catalog
from stvid.astrometry import calibrate_from_reference
from stvid.astrometry import is_calibrated
from stvid.astrometry import generate_reference_with_anet
from stvid.satellite import generate_satellite_predictions
from stvid.satellite import find_hough3d_lines
from stvid.extract import extract_tracks
@ -103,9 +104,21 @@ if __name__ == "__main__":
# Generate star catalog
pix_catalog = generate_star_catalog(fname)
# Create reference calibration file
if not os.path.exists("test.fits"):
solved = generate_reference_with_anet(fname, "")
# Calibrate astrometry
calibrate_from_reference(fname, "test.fits", pix_catalog)
# Redo refence if astrometry failed
if not is_calibrated(fourframe(fname)) and pix_catalog.nstars>10:
print(colored("Recomputing astrometric calibration for %s" % fname, "yellow"))
solved = generate_reference_with_anet(fname, "")
# Calibrate astrometry
calibrate_from_reference(fname, "test.fits", pix_catalog)
# Generate satellite predictions
generate_satellite_predictions(fname)
@ -114,7 +127,7 @@ if __name__ == "__main__":
# Get properties
ff = fourframe(fname)
# Extract tracks
if is_calibrated(ff):
extract_tracks(fname, trkrmin, drdtmin, trksig, ntrkmin, root_dir, results_dir)

View File

@ -1,7 +1,10 @@
#!/usr/bin/env python3
from __future__ import print_function
import os
import glob
import numpy as np
import subprocess
import shutil
import astropy.units as u
from astropy.io import fits
from astropy import wcs
@ -216,3 +219,30 @@ def is_calibrated(ff):
return False
else:
return True
def generate_reference_with_anet(fname, cmd_args, reffname="test.fits", tempfroot="cal"):
# Copy file to generic name
shutil.copy2(fname, tempfroot + ".fits")
# Generate command
command = "solve-field %s -O -T -N %s %s.fits" % (cmd_args, reffname, tempfroot)
# Run command
try:
subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
# Did the astrometry succeed?
solved = os.path.exists("%s.solved" % tempfroot)
except:
solved = False
# Remove temporary files
for fname in glob.glob("%s*" % tempfroot):
try:
os.remove(fname)
except:
pass
return solved

View File

@ -29,7 +29,6 @@ class pixel_catalog:
self.flag = None
self.nstars = 0
def generate_star_catalog(fname):
# Skip if file already exists
if not os.path.exists(os.path.join(fname, ".cat")):