add init_seq_func to focussingSequence function. Add 'start_idx' key to sequenc control dictionary (see getFocusSequencePars). Rewrite aps
This commit is contained in:
39
focus_app.py
39
focus_app.py
@@ -6,9 +6,10 @@
|
||||
import OBSUTILS as obsutil
|
||||
import sys
|
||||
import numpy as np
|
||||
import pathlib as pl
|
||||
|
||||
|
||||
def focussing_app(parser, set_focus, get_image):
|
||||
def focussing_app(parser, init_seq_func, set_focus_func, get_image_func):
|
||||
"""
|
||||
Focussing sequence standard application skeleton
|
||||
|
||||
@@ -109,13 +110,29 @@ def focussing_app(parser, set_focus, get_image):
|
||||
if args.guess: # rough focus estimation
|
||||
if args.verbose:
|
||||
print("\trough focus estimation ...")
|
||||
|
||||
# add '_rough' suffixes
|
||||
seq_rough_kwds = seq_kwds.copy()
|
||||
if seq_rough_kwds["focus_curve_filename"] is not None:
|
||||
pt = pl.Path(seq_rough_kwds["focus_curve_filename"])
|
||||
seq_rough_kwds["focus_curve_filename"] = str(
|
||||
pt.with_stem(pt.stem + "_rough")
|
||||
)
|
||||
|
||||
if seq_rough_kwds["result_data_filename"] is not None:
|
||||
pt = pl.Path(seq_rough_kwds["result_data_filename"])
|
||||
seq_rough_kwds["result_data_filename"] = str(
|
||||
pt.with_stem(pt.stem + "_rough")
|
||||
)
|
||||
|
||||
result = obsutil.focussingSequence(
|
||||
[focus_start, focus_stop],
|
||||
set_focus,
|
||||
get_image,
|
||||
init_seq_func,
|
||||
set_focus_func,
|
||||
get_image_func,
|
||||
None,
|
||||
sys.stdout,
|
||||
**seq_kwds
|
||||
**seq_rough_kwds
|
||||
)
|
||||
|
||||
if result["ret_code"] != 0:
|
||||
@@ -130,7 +147,7 @@ def focussing_app(parser, set_focus, get_image):
|
||||
|
||||
if args.verbose:
|
||||
print(
|
||||
"\testimate guess focus position in range [{:g},{:g}]".format(
|
||||
"\testimate guess focus position in range of [{:g},{:g}]".format(
|
||||
focus_start, focus_stop
|
||||
)
|
||||
)
|
||||
@@ -138,8 +155,9 @@ def focussing_app(parser, set_focus, get_image):
|
||||
if np.isfinite(args.focus_step):
|
||||
result = obsutil.focussingSequence(
|
||||
[focus_start, focus_stop, focus_step],
|
||||
set_focus,
|
||||
get_image,
|
||||
init_seq_func,
|
||||
set_focus_func,
|
||||
get_image_func,
|
||||
None,
|
||||
sys.stdout,
|
||||
**seq_kwds
|
||||
@@ -147,8 +165,9 @@ def focussing_app(parser, set_focus, get_image):
|
||||
else:
|
||||
result = obsutil.focussingSequence(
|
||||
[focus_start, focus_stop],
|
||||
set_focus,
|
||||
get_image,
|
||||
init_seq_func,
|
||||
set_focus_func,
|
||||
get_image_func,
|
||||
None,
|
||||
sys.stdout,
|
||||
**seq_kwds
|
||||
@@ -160,7 +179,7 @@ def focussing_app(parser, set_focus, get_image):
|
||||
if not args.do_not_set:
|
||||
if args.verbose:
|
||||
print("\n\tSet focus to the best value ...", end="")
|
||||
set_focus(result["focus_value"])
|
||||
set_focus_func(result["focus_value"])
|
||||
print("\tOK")
|
||||
|
||||
if args.verbose:
|
||||
|
||||
@@ -20,6 +20,26 @@ import pathlib as pl
|
||||
# --- FLI-hardware related (ROBOTEL variant)
|
||||
|
||||
|
||||
def init_seq(seq_kwds):
|
||||
# remove extension as Eddy's 'fli_control' add hardcoded '.fit'
|
||||
pt = pl.Path(seq_kwds["root_filename"]).with_suffix("")
|
||||
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:
|
||||
seq_kwds["start_idx"] = N
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def set_focus(foc_val):
|
||||
cmd = ["fli_control", "-g", str(int(foc_val))]
|
||||
ret = sp.run(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
||||
@@ -55,6 +75,6 @@ if __name__ == "__main__":
|
||||
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, set_focus, get_image)
|
||||
ret = focussing_app(parser, init_seq, set_focus, get_image)
|
||||
|
||||
sys.exit(ret)
|
||||
|
||||
@@ -17,6 +17,22 @@ import argparse as ap
|
||||
import subprocess as sp
|
||||
import numpy as np
|
||||
import socket
|
||||
import pathlib as pl
|
||||
|
||||
|
||||
def init_seq(seq_kwds):
|
||||
pt = pl.Path(seq_kwds["root_filename"])
|
||||
|
||||
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:
|
||||
seq_kwds["start_idx"] = N
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def set_focus(foc_val):
|
||||
@@ -51,6 +67,6 @@ if __name__ == "__main__":
|
||||
description="Zeiss-1000 and Andor Ixon EMCCD hardware: focussing sequence implementation.",
|
||||
)
|
||||
|
||||
ret = focussing_app(parser, set_focus, get_image)
|
||||
ret = focussing_app(parser, init_seq, set_focus, get_image)
|
||||
|
||||
sys.exit(ret)
|
||||
|
||||
@@ -84,7 +84,8 @@ def getFocusSequencePars(**user_kwds):
|
||||
"focus_start": None,
|
||||
"focus_stop": None,
|
||||
"focus_step": None,
|
||||
"root_filename": "focus.fit",
|
||||
"root_filename": "focus.fits",
|
||||
"start_idx": 1, # start index of files in sequence
|
||||
"acq_per_value": 1, # number of acquisitions per focus value
|
||||
"exp_time": 10, # exposure time in seconds
|
||||
"set_to_best": True, # set focus to the best value
|
||||
@@ -283,6 +284,7 @@ def computeFocus(
|
||||
|
||||
def focussingSequence(
|
||||
focus_range,
|
||||
init_seq_func,
|
||||
set_focus_func,
|
||||
get_image_func,
|
||||
max_wks=None,
|
||||
@@ -295,6 +297,9 @@ def focussingSequence(
|
||||
|
||||
focus_range: [start, stop] (7 points)
|
||||
or [start, stop, step]
|
||||
init_seq_func: a function with signature:
|
||||
init_seq_func(seq_kwds),
|
||||
where seq_kwds - sequence control dictionary (see getFocusSequencePars function)
|
||||
set_focus_func: a function of signature:
|
||||
set_focus_func(foc_val)
|
||||
get_image_func: a function of signature:
|
||||
@@ -373,6 +378,8 @@ def focussingSequence(
|
||||
|
||||
seq_kwds = getFocusSequencePars(**kwds)
|
||||
|
||||
init_seq_func(seq_kwds)
|
||||
|
||||
if seq_kwds["acq_per_value"] > 1:
|
||||
focus_value = (
|
||||
np.array([focus_value] * seq_kwds["acq_per_value"]).transpose().flatten()
|
||||
@@ -380,18 +387,19 @@ def focussingSequence(
|
||||
|
||||
rname = pt.Path(seq_kwds["root_filename"]).absolute()
|
||||
|
||||
dir = rname.parent
|
||||
fname = rname.stem
|
||||
file_ext = rname.suffix
|
||||
if file_ext == "":
|
||||
file_ext = ".fit"
|
||||
# dir = rname.parent
|
||||
# fname = rname.stem
|
||||
# file_ext = rname.suffix
|
||||
# if file_ext == "":
|
||||
# file_ext = ".fit"
|
||||
|
||||
futures = []
|
||||
flux_rad = []
|
||||
|
||||
executor = ProcessPoolExecutor(max_workers=max_wks)
|
||||
|
||||
i_foc = 1
|
||||
i_foc = seq_kwds["start_idx"]
|
||||
|
||||
ret_code = 0
|
||||
for foc_val in focus_value:
|
||||
print(log_ident, file=log_output, end="")
|
||||
@@ -410,8 +418,10 @@ def focussingSequence(
|
||||
else:
|
||||
print("OK", file=log_output, flush=True)
|
||||
|
||||
filename = "{}_{:04d}{}".format(fname, i_foc, file_ext)
|
||||
full_filename = str(pt.Path.joinpath(dir, pt.Path(filename)))
|
||||
# filename = "{}_{:04d}{}".format(fname, i_foc, file_ext)
|
||||
# full_filename = str(pt.Path.joinpath(dir, pt.Path(filename)))
|
||||
|
||||
full_filename = str(rname.with_stem("{}_{:04d}", rname.stem, i_foc))
|
||||
|
||||
print(log_ident, file=log_output, end="")
|
||||
print(
|
||||
@@ -603,9 +613,9 @@ def getFocussingSequenceCmdlinePars(parser):
|
||||
|
||||
parser.add_argument(
|
||||
"--foc-file",
|
||||
help="Rootname of output focussing images. Default is 'focus.fit'.",
|
||||
help="Rootname of output focussing images. Default is 'focus.fits'.",
|
||||
type=str,
|
||||
default="focus.fit",
|
||||
default="focus.fits",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -725,7 +735,7 @@ def parsFocussingSequenceCmdlinePars(parser_args, parser_msg=[]):
|
||||
parser_msg.append("Invalid '--foc_file' argument! Use of defaul value!")
|
||||
|
||||
kwds["root_filename"] = (
|
||||
parser_args.foc_file if parser_args.foc_file != "" else "focus.fit"
|
||||
parser_args.foc_file if parser_args.foc_file != "" else "focus.fits"
|
||||
)
|
||||
|
||||
if parser_args.repeat <= 0:
|
||||
|
||||
Reference in New Issue
Block a user