91 lines
2.1 KiB
Python
Executable File
91 lines
2.1 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
#
|
|
# Get sequence of focussing images and
|
|
# compute the best focus value
|
|
#
|
|
# This variant of the script uses Eddy Emelianov's
|
|
# 'fli_control' executable
|
|
#
|
|
|
|
|
|
from OBSUTILS import focussing_app
|
|
import sys
|
|
import argparse as ap
|
|
import subprocess as sp
|
|
import numpy as np
|
|
import pathlib as pl
|
|
|
|
|
|
# --- FLI-hardware related (ROBOTEL variant)
|
|
|
|
|
|
def init_seq(seq_kwds):
|
|
# replace extension since Eddy's 'fli_control' adds hardcoded '.fit'
|
|
pt = pl.Path(seq_kwds["root_filename"]).with_suffix(".fit")
|
|
seq_kwds["root_filename"] = str(pt)
|
|
|
|
#
|
|
#
|
|
|
|
foc_files = list(
|
|
pt.absolute().parent.glob("{}_[0-9][0-9][0-9][0-9].fit".format(pt.stem))
|
|
)
|
|
|
|
seq_kwds["start_idx"] = 1
|
|
N = len(foc_files)
|
|
if N > 0:
|
|
max = 0
|
|
for fname in foc_files:
|
|
inum = int(fname.stem.split("_")[1])
|
|
if inum > max:
|
|
max = inum
|
|
|
|
seq_kwds["start_idx"] = max + 1
|
|
|
|
return 0
|
|
|
|
|
|
def set_focus(foc_val):
|
|
if foc_val < 0:
|
|
print("INVALID FLI-FOCUSER VALUE! IT MUST BE NON-NEGATIVE VALUE!")
|
|
return -1
|
|
|
|
cmd = ["fli_control", "-g", str(int(foc_val))]
|
|
ret = sp.run(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
|
return ret.returncode
|
|
|
|
|
|
def get_image(filename, exp_time):
|
|
#
|
|
# Eddy's 'fli_control' related stub:
|
|
# filename is expected in form 'rootname_DDDD.ext'
|
|
# convert it to 'rootname'
|
|
#
|
|
|
|
fname = str(filename).split("_")
|
|
fname = fname[0]
|
|
|
|
cmd = [
|
|
"fli_control",
|
|
"-r",
|
|
"/tmp/10micron.fitsheader",
|
|
"-x",
|
|
"{:d}".format(np.round(exp_time * 1000)), # to microseconds
|
|
fname,
|
|
]
|
|
|
|
ret = sp.run(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
|
return ret.returncode
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = ap.ArgumentParser(
|
|
prog="{}".format(pl.Path(sys.argv[0]).name),
|
|
description="FLI CCD and focuser hardware: focussing sequence implementation. It is assumed that 'fli_control' software is installed in the OS.",
|
|
)
|
|
|
|
ret = focussing_app(parser, init_seq, set_focus, get_image)
|
|
|
|
sys.exit(ret)
|