tp_audine_elec.py
6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 11 15:39:17 2021
@author: alain
$ cd ~/guitastro/gui/tp_audine_elec
$ python3 tp_audine_elec.py
"""
import os
import sys
import yaml
import subprocess
import time
from PIL import ImageTk
import tkinter as tk
path = os.path.abspath("../../src")
if path not in sys.path:
sys.path.insert(0,path)
import guitastro
# #####################################################################
# #####################################################################
# #####################################################################
# Main
# #####################################################################
# #####################################################################
# #####################################################################
if __name__ == "__main__":
# --- Get path_images for examples
ima = guitastro.Ima()
path_products = ima.copy_data2products()
fconfig = os.path.join(path_products,"tp_audine_elec.yml")
if not os.path.exists(fconfig):
config = {}
conf = {}
conf["fits_path"] = "/home/user/Documents"
config["visu1"] = conf
else:
with open(fconfig, 'r') as stream:
try:
config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
infos = {}
infos['demarrer_acq'] = "Appuyez sur le bouton Acquisition pour prendre une image"
infos['acq_en_cours'] = "Acquisition en cours. Attendre quelques secondes... Prendre des mesures à l'oscilloscope"
var = {}
def save_config():
global fconfig
with open(fconfig, 'w') as yaml_file:
yaml.dump(config, yaml_file, default_flow_style=False)
def ima1_load():
global widgets
path_cur = config["visu1"]["fits_path"]
ima1.rootdir = path_cur
fullfile = ima1.load()
if fullfile != "":
path_new = os.path.dirname(fullfile)
if path_cur != path_new and path_new != "":
config["visu1"]["fits_path"] = path_new
save_config()
visu1.autocuts()
visu1.disp()
widgets["button_saveima_1"].configure(state= tk.NORMAL)
def ima1_save():
ima1.save()
# Fonction appelée par l'appui du bouton
def acquisition():
global widgets
global infos
global var
widgets["button_loadima_1"].configure(state= tk.DISABLED)
widgets["button_saveima_1"].configure(state= tk.DISABLED)
widgets["button_acq"].configure(state= tk.DISABLED)
var['info'].set(infos['acq_en_cours'])
# ---
expo = var_exp.get()
if expo < 0:
expo = 0
if expo > 30:
expo = 30
var_exp.set(expo)
# ---
binn = var_bin.get()
if binn < 1:
binn = 1
if binn > 100:
binn = 100
var_bin.set(binn)
# ---
tkroot.update()
# ---
argus = []
argus.append("/home/user/iut/tp_ccd/bin/Debug/tp_ccd")
argus.append(f"{expo}")
argus.append(f"{binn}")
# --- Launch the acquisition process
message = f'subprocess.run({argus},capture_output=True)'
print(message)
t0 = time.time()
res = subprocess.run(argus, capture_output=True)
stdo = res.stdout
#lstdos = str(stdo).split("\\n")
dt = time.time() - t0
message = f"Acquisition done in {dt:.3f} sec"
print(message)
print(stdo)
# ---
time.sleep(0.5)
fullfile = ima1.load("/home/user/Documents/image.fit")
path_new = os.path.dirname(fullfile)
config["visu1"]["fits_path"] = path_new
ima1.rootdir = path_new
save_config()
# ---
visu1.autocuts()
visu1.disp()
widgets["button_loadima_1"].configure(state= tk.NORMAL)
widgets["button_saveima_1"].configure(state= tk.NORMAL)
widgets["button_acq"].configure(state= tk.NORMAL)
var['info'].set(infos['demarrer_acq'])
# update the plot
tkroot.update()
# --- load an image from a FITS file
ima1 = guitastro.Ima()
ima1.extension = ".fit"
# --- Create a simple Tk interface
tkroot = tk.Tk()
dimx = 795
dimy = 785
geom = f"{dimx}x{dimy}+120+80"
tkroot.geometry(geom)
tkroot.title("TP CCD Electronique - BUT S5")
tkroot.minsize(height=dimy, width=dimx)
tkroot.maxsize(height=dimy, width=dimx)
# ---
frame1 = tk.Frame(tkroot)
frame1.pack(side = tk.TOP, fill=tk.X, expand=tk.NO)
# ---
widgets = {}
# ---
frame1m = tk.Frame(frame1)
# ---
test = ImageTk.PhotoImage(file='logo_iut_mp.png')
label1 = tk.Label(frame1m, image=test)
label1.image = test
label1.pack(side = tk.LEFT, padx=2)
# ---
var_exp = tk.DoubleVar()
var_exp.set(2.0)
label_exp = tk.Label(frame1m, text="Temps de pose (s)")
label_exp.pack(side = tk.LEFT)
entry_exp = tk.Entry(frame1m, width=4, textvariable=var_exp)
entry_exp.pack(side = tk.LEFT)
# ---
var_bin = tk.IntVar()
var_bin.set(1)
label_bin = tk.Label(frame1m, text="Binning")
label_bin.pack(side = tk.LEFT)
entry_bin = tk.Entry(frame1m, width=4, textvariable=var_bin)
entry_bin.pack(side = tk.LEFT)
# ---
widgets["button_acq"] = tk.Button(frame1m, text="Acquisition", command=acquisition, padx=20, pady=20, font='sans 16 bold')
widgets["button_acq"].pack(side = tk.LEFT, pady=5, padx=5)
# ---
widgets["button_loadima_1"] = tk.Button(frame1m, text="Load FITS", command=ima1_load)
widgets["button_loadima_1"].pack(side=tk.LEFT, padx = 2)
widgets["button_saveima_1"] = tk.Button(frame1m, text="Save FITS", command=ima1_save, state= tk.DISABLED)
widgets["button_saveima_1"].pack(side=tk.LEFT, padx = 2)
frame1m.pack(side = tk.TOP, fill=tk.X, expand=tk.NO)
# ---
frame2 = tk.Frame(tkroot)
# ---
var['info'] = tk.StringVar()
var['info'].set(infos['demarrer_acq'])
widgets["label_info"] = tk.Label(frame2, textvariable=var['info'], padx = 10)
widgets["label_info"].pack(side = tk.LEFT)
frame2.pack(side = tk.TOP, fill=tk.X, expand=tk.NO)
# --- Create and use a visu
try:
frame1i = tk.Frame(tkroot)
visu1 = guitastro.Visu(frame1i)
visu1.ima(ima1)
frame1i.pack(side = tk.TOP, fill=tk.BOTH, expand=tk.YES)
except:
msg = "{}".format(sys.exc_info())
print(msg)
# --- Launch the event loop of the user interface
tkroot.pack_propagate(0)
tkroot.update()
tkroot.mainloop()