79 lines
1.7 KiB
Python
Executable File
79 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
#
|
|
# Get sequence of focussing images and
|
|
# compute the best focus value
|
|
#
|
|
# This variant uses Fatkhullin's AndorAPI2 library
|
|
# to control Andor IXon Ultra EMCCD camera
|
|
# The script uses TCP-socket Python API to control focus
|
|
# of the SAO RAS Zeiss-1000 telescope
|
|
#
|
|
|
|
|
|
from OBSUTILS import focussing_app
|
|
import sys
|
|
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:
|
|
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):
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
sock.connect(("ztcs.sao.ru", 4444))
|
|
|
|
sock.send("goto={:g}".format(foc_val))
|
|
resp = sock.recv(20)
|
|
|
|
if resp != "OK":
|
|
sock.close()
|
|
return 1
|
|
|
|
sock.close()
|
|
|
|
return 0
|
|
|
|
|
|
#
|
|
# Assumes Andor IXon EMCCD server is listenning UNIX socket on localhost
|
|
#
|
|
def get_image(filename, exp_time):
|
|
cmd = ["ixonultra_cmdclient", "-A", "CCD", "-T", "{:g}".format(exp_time), filename]
|
|
|
|
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="Zeiss-1000 and Andor Ixon EMCCD hardware: focussing sequence implementation.",
|
|
)
|
|
|
|
ret = focussing_app(parser, init_seq, set_focus, get_image)
|
|
|
|
sys.exit(ret)
|