2018-05-01 01:35:34 -06:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
import glob
|
|
|
|
import numpy as np
|
2018-05-06 08:45:51 -06:00
|
|
|
from stvid.stio import fourframe
|
|
|
|
from stvid.stars import generate_star_catalog
|
|
|
|
from stvid.astrometry import calibrate_from_reference
|
2018-05-01 01:35:34 -06:00
|
|
|
import astropy.units as u
|
|
|
|
from astropy.utils.exceptions import AstropyWarning
|
2018-05-06 08:45:51 -06:00
|
|
|
from astropy.coordinates import EarthLocation
|
2018-05-01 01:35:34 -06:00
|
|
|
import warnings
|
2018-05-06 08:45:51 -06:00
|
|
|
import configparser
|
|
|
|
import argparse
|
2018-05-07 08:24:01 -06:00
|
|
|
import os
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-05-06 08:45:51 -06:00
|
|
|
|
|
|
|
# Read commandline options
|
|
|
|
conf_parser = argparse.ArgumentParser(description='Process captured' +
|
|
|
|
' video frames.')
|
|
|
|
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')
|
|
|
|
|
2018-05-01 01:35:34 -06:00
|
|
|
# Set warnings
|
|
|
|
warnings.filterwarnings("ignore", category=UserWarning, append=True)
|
|
|
|
warnings.simplefilter("ignore", AstropyWarning)
|
|
|
|
|
|
|
|
# Set location
|
2018-05-06 08:45:51 -06:00
|
|
|
loc = EarthLocation(lat=cfg.getfloat('Common', 'observer_lat')*u.deg,
|
|
|
|
lon=cfg.getfloat('Common', 'observer_lon')*u.deg,
|
|
|
|
height=cfg.getfloat('Common', 'observer_el')*u.m)
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
# Get files
|
2018-05-07 08:24:01 -06:00
|
|
|
files = sorted(glob.glob(os.path.join(args.file_dir, "2*.fits")))
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
# Statistics file
|
2018-05-07 08:24:01 -06:00
|
|
|
fstat = open(os.path.join(args.file_dir, "imgstat.csv"), "w")
|
2018-05-01 01:35:34 -06:00
|
|
|
fstat.write("fname,mjd,ra,de,rmsx,rmsy,mean,std,nstars,nused\n")
|
2018-05-06 08:45:51 -06:00
|
|
|
|
2018-05-01 01:35:34 -06:00
|
|
|
# Loop over files
|
|
|
|
for fname in files:
|
|
|
|
# Generate star catalog
|
2018-05-06 08:45:51 -06:00
|
|
|
pix_catalog = generate_star_catalog(fname)
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
# Calibrate astrometry
|
2018-05-07 08:24:01 -06:00
|
|
|
calibrate_from_reference(fname,
|
|
|
|
os.path.join(args.file_dir, "test.fits"),
|
|
|
|
pix_catalog)
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
# Stars available and used
|
2018-05-06 08:45:51 -06:00
|
|
|
nused = np.sum(pix_catalog.flag == 1)
|
|
|
|
nstars = pix_catalog.nstars
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
# Get properties
|
2018-05-06 08:45:51 -06:00
|
|
|
ff = fourframe(fname)
|
2018-05-01 01:35:34 -06:00
|
|
|
|
2018-05-06 08:45:51 -06:00
|
|
|
print(("%s,%.8lf,%.6f,%.6f,%.3f,%.3f," +
|
|
|
|
"%.3f,%.3f,%d,%d") % (ff.fname, ff.mjd, ff.crval[0],
|
|
|
|
ff.crval[1], 3600*ff.crres[0],
|
|
|
|
3600*ff.crres[1], np.mean(ff.zavg),
|
|
|
|
np.std(ff.zavg), nstars, nused))
|
|
|
|
fstat.write(("%s,%.8lf,%.6f,%.6f,%.3f,%.3f,%.3f," +
|
|
|
|
"%.3f,%d,%d\n") % (ff.fname, ff.mjd, ff.crval[0],
|
|
|
|
ff.crval[1], 3600*ff.crres[0],
|
|
|
|
3600*ff.crres[1], np.mean(ff.zavg),
|
|
|
|
np.std(ff.zavg), nstars, nused))
|
2018-05-01 01:35:34 -06:00
|
|
|
|
|
|
|
fstat.close()
|