Commit a9f89392 authored by PERNOT Guillaume's avatar PERNOT Guillaume

fixed stats

better progression reporting
parent 628a69b6
......@@ -7,7 +7,6 @@ import datetime
import socket
import threading
from astropy.io import fits
from astropy.convolution import convolve, Tophat2DKernel
import numpy as np
import re
......@@ -36,8 +35,8 @@ ATIK_PROMPT = 'AtikCtl>'
logging.basicConfig(filename='atsctl.log', level=logging.DEBUG)
def cmd(proc, msg, expect=None, error=None):
if DEVEL:
print(msg)
#if DEVEL:
# print(msg)
output = proc.run_command(msg, timeout=None)
if error is not None and re.match(error, output):
......@@ -58,18 +57,14 @@ def cmd(proc, msg, expect=None, error=None):
def compute_stats(filename):
"""Return flux and max pixel coords"""
tophat_kernel = Tophat2DKernel(4)
with fits.open(filename) as hdul:
img = hdul[0].data
smoothed = convolve(img, tophat_kernel)
data = np.extract(smoothed > np.average(smoothed) + 2*np.std(smoothed),
img - np.average(img))
return np.sum(data), np.unravel_index(np.argmax(img, axis=None), img.shape)
return np.amax(img), np.unravel_index(np.argmax(img, axis=None), img.shape)
def save_stats(destdir, filename, x, y, z, theta, phi, flux, coord):
with open('{}/stats.csv'.format(destdir), 'a') as f:
f.write('{},{},{},{},{},{},{},{},{}\n'.format(filename, x, y, z, theta, phi,
flux, coord[1], coord[0]))
flux, coord[1]+1, coord[0]+1))
def get_position(atsctl):
#float_re : '([+-]?\ *\d+\.?\d*)'
......@@ -129,8 +124,9 @@ def move_and_acquire(atsctl, atik, rel_pos, repeat, _time, destdir):
def scan2d(atsctl, atik, y_inc, z_inc, n_y, n_z, _time, destdir):
cmd(atik, '@time {}'.format(_time), '!TIME', '!ERROR')
for z in range(n_z):
print("scan2d {}/{}".format(z+1, n_z))
print("scan2d {}/{}".format(z+1, n_z), end=' ', flush=True)
for y in range(n_y):
print('.', end='', flush=True)
acquire_and_save(atsctl, atik, destdir)
if y < n_y-1:
cmd(atsctl, 'move_rel_pos_ats 0,{},0,0,0'.format(y_inc), error='ERROR')
......@@ -139,13 +135,15 @@ def scan2d(atsctl, atik, y_inc, z_inc, n_y, n_z, _time, destdir):
cmd(atsctl, 'move_rel_pos_ats 0,0,{},0,0'.format(z_inc), error='ERROR')
cmd(atsctl, 'wait_move', error='ERROR')
y_inc = -y_inc # reverse scan
print()
def scan3d(atsctl, atik, x_inc, y_inc, z_inc, n_x, n_y, n_z, _time, destdir):
cmd(atik, '@time {}'.format(_time), '!TIME', '!ERROR')
for z in range(n_z):
print("scan3d {}/{}".format(z+1, n_z))
print("scan3d {}/{}".format(z+1, n_z), end=' ', flush=True)
for y in range(n_y):
for x in range(n_x):
print('.', end='', flush=True)
acquire_and_save(atsctl, atik, destdir)
if x < n_x-1:
cmd(atsctl, 'move_rel_pos_ats {},0,0,0,0'.format(x_inc), error='ERROR')
......@@ -158,6 +156,7 @@ def scan3d(atsctl, atik, x_inc, y_inc, z_inc, n_x, n_y, n_z, _time, destdir):
cmd(atsctl, 'move_rel_pos_ats 0,0,{},0,0'.format(z_inc), error='ERROR')
cmd(atsctl, 'wait_move', error='ERROR')
y_inc = -y_inc # reverse scan
print(flush=True)
def handle_client_connection(client_socket, atsctl, atik):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment