class AnalyzeTipTiltPerformance(KPFTranslatorFunction):
'''# Description
Generates a plot analyzing tip tilt performance for a single observation.
Can take as input either an L0 file, in which case it will strip out the
guider extension for use, or a guider "cube" file.
# Parameters
None
'''
@classmethod
def pre_condition(cls, args, logger, cfg):
pass
@classmethod
def perform(cls, args, logger, cfg):
viewer_command = find_viewer_command(args)
for file in args.get('files'):
file = Path(file).expanduser()
if file.exists() is False:
log.error(f"Could not find file {args.get('file')}")
plotfile = Path(str(file.name).replace('.fits', '.png'))
plot_tiptilt_stats(file, plotfile=plotfile,
start=args.get('start', None),
end=args.get('end', None),
snr=args.get('snr', None),
minarea=args.get('minarea', None),
deblend_nthresh=args.get('deblend_nthresh', None),
deblend_cont=args.get('deblend_cont', None),
)
if viewer_command is not None:
log.info(f"Opening {plotfile} using {viewer_command}")
proc = subprocess.Popen([viewer_command, f"{plotfile}"])
if args.get('gif') is True:
giffile = Path(str(file.name).replace('.fits', '.gif'))
generate_cube_gif(file, giffile)
if viewer_command is not None:
log.info(f"Opening {giffile} using {viewer_command}")
proc = subprocess.Popen([viewer_command, f"{giffile}"])
@classmethod
def post_condition(cls, args, logger, cfg):
pass
@classmethod
def add_cmdline_args(cls, parser, cfg=None):
parser.add_argument('files', type=str, nargs='*',
help="The FITS files to analyze")
parser.add_argument("-g", "--gif", dest="gif",
default=False, action="store_true",
help="Generate the animated GIF of frames (computationally expensive)")
parser.add_argument("--view", dest="view",
default=False, action="store_true",
help="Open a viewer once the file is generated")
parser.add_argument("--start", dest="start", type=float,
help="Zoom the plot in to this start time (in seconds).")
parser.add_argument("--end", dest="end", type=float,
help="Zoom the plot in to this end time (in seconds).")
parser.add_argument("--snr", dest="snr", type=float,
help="Run source extractor again with this SNR threshold")
parser.add_argument("--minarea", dest="minarea", type=float,
help="Run source extractor again with this minarea parameter")
parser.add_argument("--deblend_nthresh", dest="deblend_nthresh", type=float,
help="Run source extractor again with this deblend_nthresh")
parser.add_argument("--deblend_cont", dest="deblend_cont", type=float,
help="Run source extractor again with this deblend_cont parameter")
return super().add_cmdline_args(parser, cfg)