pad_device.py
38 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
# -*- coding: utf-8 -*-
# pip install
import numpy as np
import os
import sys
import time
import traceback
import functools
paths = ["../../src"]
paths.append("../../../guitastro_device_ascomcam/src")
paths.append("../../../guitastro_device_dfm/src")
for path in paths:
if path not in sys.path:
sys.path.insert(0,path)
import guitastro
from guitastro_device_ascomcam import Device_Ascomcam
from guitastro_device_dfm import Device_DFM
import tkinter as tk
from tkinter import ttk
import tkinter.font as tkFont
import tkinter.messagebox as messageBox
import os, sys
import time
import pickle
import yaml
import math
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
# #####################################################################
# #####################################################################
# #####################################################################
# Class Devicepad
# #####################################################################
# #####################################################################
# This class provides a pad
# #####################################################################
class Devicepad():
"""
Pad to drive a device.
"""
def __init__(self, device):
self._device = device
self.tkroot = None
self._command_history = []
self._command_history.append('self._main')
self._command_history_index = 0
# === GUI
self.pad_cbk_compute_things_repeated_stop = True
self.after_id = None
self.pad_gui_create() # gui will block the code here
# ==========================================
# ==========================================
# === pad method repeated regularly to fill infos
# ==========================================
# ==========================================
def pad_cbk_compute_things_repeated(self):
"""
Compute in one time all the informations to refresh in the pad
"""
try:
# self.pad_var_motion_axis_polar.set(texte)
pass
except:
msg = "{}".format(sys.exc_info())
print(msg)
if self.pad_cbk_compute_things_repeated_stop == False:
self.after_id = self.tkroot.after(100,self.pad_cbk_compute_things_repeated)
# ==========================================
# ==========================================
# === pad Ra,Dec GOTO
# ==========================================
# ==========================================
# ==========================================
# ==========================================
# === pad Calibrations Console
# ==========================================
# ==========================================
def pad_cbk_console(self, event):
command =self.pad_var_console.get()
res = ""
try:
exec(f"""locals()['temp'] = {command}""")
res = locals()['temp']
#exec(f"""globals()['temp'] = {command}""")
#res = globals()['temp']
#self.log.print("res={}".format(res))
except Exception as err:
res = err
#self.log.print("type(res)={}".format(type(res)))
#self.log.print("(2) res={}".format(res))
self.text_console.insert(tk.END,command+"\n","command")
self.text_console.yview_moveto(1.0)
res = "# "+str(res)+"\n"
self.text_console.insert(tk.END,res,"result")
self.text_console.yview_moveto(1.0)
self._command_history.append(command)
self._command_history_index = len(self._command_history)
command =self.pad_var_console.set("")
def pad_cbk_command_prev(self, event):
k = self._command_history_index
k -= 1
if k>=0:
self._command_history_index = k
command = self._command_history[k]
self.pad_var_console.set(command)
self.entry_console.icursor(tk.END)
def pad_cbk_command_next(self, event):
n = len(self._command_history)
k = self._command_history_index
k += 1
if k<n:
self._command_history_index = k
command = self._command_history[k]
self.pad_var_console.set(command)
self.entry_console.icursor(tk.END)
# ==========================================
# ==========================================
# === pad Camera
# ==========================================
# ==========================================
def pad_cbk_camstart(self):
ima1 = self._main.camera_ima
exp = self.pad_var_camera_exp.get()
binning = self.pad_var_camera_bin.get()
camusedark = self.pad_var_camusedark.get()
camdark = self.pad_var_camdark.get()
self.log.print(f"== pad_cbk_camstart 1: camusedark={camusedark} camdark={camdark}")
if camusedark == 1 and camdark != "":
fitsdark = camdark
else:
fitsdark = None
# --- special processings
cam_infos = self._main.camera_cam.properties()
if self._visumethod == "matplotlib":
visu_first = (self.tkroot, self.fig1, self.ax1)
else:
visu_first = self._visu1
process_stripes = False
if cam_infos["Name"].startswith("ZWO ASI174M"):
process_stripes = True
visu_first = None
# --- Acquisition itself
self.log.print(f"== pad_cbk_camstart 2: fitsdark={fitsdark}")
self._main.camera_acq(exp, binning, fitsdark, visu_first)
# --- special processings
if process_stripes == True:
self.log.print("Corrections stripes")
ima1.save('tmp')
ima1.sortx(50)
stats = ima1.stat()
mean = stats["mean"]
ima1.save('mask')
ima1.load('tmp')
ima1.sub('mask')
ima1.offset(mean)
self.pad_imavisu()
ima1.save('tmp')
def pad_cbk_camload(self):
ima1 = self._main.camera_ima
fitsname = ima1.load()
if fitsname!="":
self.pad_imavisu()
def pad_cbk_camsave(self):
ima1 = self._main.camera_ima
fitsname = ima1.save()
if fitsname!="":
self. pad_imavisu()
def pad_cbk_camheader(self):
ima1 = self._main.camera_ima
kwds = ima1.getkwds()
for kwd in kwds:
card = ima1.getkwd(kwd)
self.log.print(f"{kwd:8s} = {card}")
def pad_cbk_camdark_choice(self):
ima1 = self._main.camera_ima
fitsname = ima1.load()
self.pad_imavisu()
self.pad_var_camdark.set(fitsname)
self.pad_var_camusedark.set(1)
def pad_cbk_camsuperdark(self):
cam1 = self._main.camera_cam
ima1 = self._main.camera_ima
exp = self.pad_var_camera_exp.get()
binning = self.pad_var_camera_bin.get()
cam1.exptime(exp)
cam1.bin(binning, binning)
fgeneric = f"dark_exp{exp:.0f}_bin{binning}"
nf = 5
# --- acquisition
for kimg in range(1,nf+1):
filename = fgeneric + "-" + str(kimg)
self.log.print(f"Acquisition dark {filename}")
cam1.acqwait()
time.sleep(1.0)
self.pad_imavisu()
ima1.save(filename)
# --- mean
for kimg in range(1,nf+1):
filename = fgeneric + "-" + str(kimg)
if kimg==1:
ima1.load(filename)
else:
ima1.add(filename)
ima1.mult(1./nf)
ima1.save(fgeneric)
self.log.print(f"Mean dark is {fgeneric}")
self.pad_imavisu()
ima1.save("dark")
self.pad_var_camdark.set(fgeneric)
self.pad_var_camusedark.set(1)
def pad_cbk_dispheader(self):
self.text_fitsheader_res.delete("0.0",tk.END)
ima1 = self._main.camera_ima
if isinstance(ima1._hdu,type(None)) == True:
return
for kwd in ima1.getkwds():
val = ima1.getkwd(kwd)
texte = f"{kwd:8s} "
self.text_fitsheader_res.insert(tk.END, texte,"red")
texte = str(val)
self.text_fitsheader_res.insert(tk.END, texte+"\n","blue")
self.text_calibwcs_res.yview_moveto(1.0)
def pad_cbk_camwcs(self):
valid = False
try:
method = "astap"
ima1 = self._main.camera_ima
ima1.calibwcs(method)
except guitastro.ima.ImaException as msg:
self.log.print(f"{msg}")
valid = False
else:
self.log.print(f"WCS calibration succeed using method {method}.")
valid = True
if valid == True:
supertext = "WCS calibration succeed"
self.text_calibwcs_res.insert(tk.END,supertext+"\n","green")
self.text_calibwcs_res.yview_moveto(1.0)
supertext = ""
ra = float(ima1.getkwd("RA"))
crval1 = float(ima1.getkwd("CRVAL1"))
dra = crval1 - ra
dra_min = dra/15.0*60
texte = f"Mount must be offset by {abs(dra_min):.2f} hmin "
if dra_min>=0:
texte += "toward west (increase HA)"
else:
texte += "toward east (decrease HA)"
self.log.print(texte)
supertext += texte + "\n"
dec = float(ima1.getkwd("DEC"))
crval2 = float(ima1.getkwd("CRVAL2"))
ddec = crval2 - dec
ddec_arcmin = ddec*60.0
texte = f"Mount must be offset by {abs(ddec_arcmin):.1f} arcmin "
if ddec_arcmin<0:
texte += "toward north (decrease Dec)"
else:
texte += "towoard south (increase Dec)"
self.log.print(texte)
supertext += texte
self.text_calibwcs_res.insert(tk.END,supertext+"\n","blue")
texte = f"Centre RA,Dec = {guitastro.Angle(crval1).sexagesimal('H:0.2')} {guitastro.Angle(crval2).sexagesimal('d:+090.1')}"
self.log.print(texte)
self.text_calibwcs_res.insert(tk.END,texte+"\n","black")
x, y = ima1.radec2xy(ra, dec)
texte = f"Target ra,dec = {ra:.5f}, {dec:.5f}\n"
texte = f"Target x,y = {x:.2f}, {y:.2f}\n"
print(texte)
if self._visumethod == "guitastro_visu":
if self._wcstag != None:
self._visu1.clear_marks(self._wcstag)
self._wcstag = self._visu1.add_mark("circle",x, y, 7, color='#00FF00')
# ---
supertext = ""
cdelt1 = ima1.getkwd("CDELT1")
cdelt2 = ima1.getkwd("CDELT2")
naxis1 = ima1.getkwd("NAXIS1")
naxis2 = ima1.getkwd("NAXIS2")
sampling_base = cdelt1*3600
sampling_pole = cdelt2*3600
fov_base_arcmin = abs(sampling_base*naxis1/60.0)
fov_pole_arcmin = abs(sampling_pole*naxis2/60.0)
texte = f"Spatial sampling = {abs(sampling_base):.2f} arcsec/pix"
supertext += texte + "\n"
texte = f"Field of view = {fov_base_arcmin:.2f} x {fov_pole_arcmin:.2f} arcmin"
supertext += texte
self.text_calibwcs_res.insert(tk.END,supertext+"\n","blue")
self.text_calibwcs_res.yview_moveto(1.0)
# ---
date = guitastro.Date(ima1.getkwd("DATE-OBS"))
jd = date.jd()
params = {}
params["EQUINOX"] = "J2000"
ha_target = 0
dec_target = 90
ra_equinox, dec_equinox = self._main.radec_app2cat(jd, ha_target, dec_target, params)
x, y = ima1.radec2xy(0, 90)
texte = f"Pole x,y = {x:.2f}, {y:.2f}\n"
self.text_calibwcs_res.insert(tk.END,texte+"\n","black")
try:
if self._visumethod == "matplotlib":
self.ax1.scatter([x], [y], c = 'yellow', marker = 'o', s=200)
# update the plot
plt.tight_layout()
self.tkroot.update()
self.fig1.canvas.draw()
else:
self._visu1.add_mark("circle",x, y, 5, 'yellow')
except:
pass
else:
supertext_intro = "WCS calibration failed\n"
self.text_calibwcs_res.insert(tk.END,supertext_intro+"\n","red")
self.text_calibwcs_res.yview_moveto(1.0)
return valid
def pad_cbk_camtemperature(self):
cam_infos = self._main.camera_cam.properties()
texte = ""
CCDTemperature= cam_infos["CCDTemperature"]
texte += f"{CCDTemperature:.1f} degC"
CanSetCCDTemperature = cam_infos["CanSetCCDTemperature"]
CanGetCoolerPower = cam_infos["CanGetCoolerPower"]
if CanSetCCDTemperature==True:
SetCCDTemperature = cam_infos["SetCCDTemperature"]
CoolerOn = cam_infos["CoolerOn"]
texte += f" / {SetCCDTemperature:.1f} degC"
if CoolerOn==True:
texte += " (cooler on)"
else:
texte += " (cooler off)"
else:
SetCCDTemperature = None
CoolerOn = None
if CanGetCoolerPower==True:
CoolerPower = cam_infos["CoolerPower"]
texte += f" power {CoolerPower:.0f} percent"
else:
CoolerPower = None
self.pad_var_camtemp.set(texte)
def pad_cbk_cammodelregu(self):
self._cammodel(1)
def pad_cbk_cammodelflip(self):
self._cammodel(-1)
def pad_cbk_cammodel_compute_images(self):
if self._visumethod == "matplotlib":
self._main.camera_wcs_modpoi("images",(self.tkroot, self.fig1, self.ax1))
else:
self._main.camera_wcs_modpoi("images", self._visu1)
def pad_cbk_cammodel_compute_pointings(self):
if self._visumethod == "matplotlib":
self._main.camera_wcs_modpoi("pointings",(self.tkroot, self.fig1, self.ax1))
else:
self._main.camera_wcs_modpoi("pointings", self._visu1)
def _cammodel(self, side):
exp = self.pad_var_camera_exp.get()
binning = self.pad_var_camera_bin.get()
camdark = self.pad_var_camdark.get()
camusedark = self.pad_var_camusedark.get()
if camusedark == 1 and camdark != "":
fitsdark = camdark
else:
fitsdark = None
if self._visumethod == "matplotlib":
self._main.camera_acq_modpoi(exp, binning, side, fitsdark, (self.tkroot, self.fig1, self.ax1))
else:
self._main.camera_acq_modpoi(exp, binning, side, fitsdark, self._visu1)
def pad_cbk_button_pushed(self, key):
print(f"Select command {key=}")
device = self._device
res = device.commandstring(key)
self.pad_var_component[component_name].set(res)
# ==========================================
# ==========================================
# === pad GUI
# ==========================================
# ==========================================
def pad_cbk_quit(self):
# --- We can destroy the windows of the gui
"""
self.pad_cbk_compute_things_repeated_stop = True
self.tkroot.after_idle(self.pad_cbk_compute_things_repeated)
if self.after_id != None:
self.tkroot.after_cancel(self.after_id)
"""
self.tkroot.quit()
self.tkroot.destroy()
print("Pad Quit terminated")
def pad_gui_create(self):
device = self._device
self.tkroot = tk.Tk()
screen_width = self.tkroot.winfo_screenwidth()
screen_height = self.tkroot.winfo_screenheight()
max_height = 700
if screen_height>max_height:
screen_height = max_height
self.tkroot.geometry(str(screen_width)+"x"+str(screen_height)+"+0+0")
self.tkroot.title("Device pad for "+ device.param['NAME'])
self.tkroot.protocol('WM_DELETE_WINDOW', self.pad_cbk_quit)
# Check components
msg = ""
for component_name in device.component_names:
component = device.component(component_name)
name = component.name
p = component.prop()
a = p['actions']
msg += f"\n--- Component {name} actions: {a}\n"
for keya in a:
if keya in p.keys():
o = p[keya]
for keyo, val in o.items():
if isinstance(val, dict):
so = val
for keyso, val in so.items():
msg += f" * Operation {keya} {keyo} {keyso} = {val}\n"
else:
msg += f" * Operation {keya} {keyo} = {val}\n"
#print(f"{msg=}")
fontStyle_1 = tkFont.Font(family="Arial", size=14, weight="bold")
fontStyle_2 = tkFont.Font(family="Arial", size=12, weight="bold")
fontStyle_3 = tkFont.Font(family="Arial", size=10, weight="bold")
fontStyle_c3 = tkFont.Font(family="courier", size=10, weight="bold")
# =====================================================
# === All the tabs are in a X scrollable frame
# =====================================================
superframe = ttk.Frame(self.tkroot)
supercanvas = tk.Canvas(superframe)
superscrollbar = ttk.Scrollbar(superframe, orient="horizontal", command=supercanvas.xview)
superscrollable_frame = ttk.Frame(supercanvas)
superscrollable_frame.bind("<Configure>", lambda e: supercanvas.configure(scrollregion=supercanvas.bbox("all")))
supercanvas.create_window((0, 0), window=superscrollable_frame, anchor="nw")
supercanvas.configure(xscrollcommand=superscrollbar.set)
# =====================================================
# =====================================================
# (100) Frame Pilot
# =====================================================
# =====================================================
frame_pilot = tk.Frame(superscrollable_frame)
notebook = ttk.Notebook(frame_pilot)
tabs = {}
kcomps = []
for kcomp in range(101, 101+len(device.component_names), 1):
kcomps.append(kcomp)
# =====================================================
# Tab 1xx
# =====================================================
frame = {}
button = {}
label = {}
entry = {}
self.pad_var_component = {}
for kcomp, component_name in zip(kcomps, device.component_names):
tabs[kcomp] = ttk.Frame(notebook)
component = device.component(component_name)
# ---
frame[kcomp] = tk.Frame(tabs[kcomp])
# ---
name = component.name
p = component.prop()
a = p['actions']
for keya in a:
if keya in p.keys():
o = p[keya]
for keyo, val in o.items():
if isinstance(val, dict):
so = val
for keyso, val in so.items():
msg = f"{val}"
key = f"{keya}_{keyo}_{keyso}"
cmd = f"{component_name} {keya} {keyo} {keyso}"
lab_comp_key = str(kcomp) + "_" + key
frame_tmp = tk.Frame(frame[kcomp])
button[lab_comp_key] = tk.Button(frame_tmp, text = key, command=functools.partial(self.pad_cbk_button_pushed, cmd), font=fontStyle_3)
button[lab_comp_key].pack(side = tk.LEFT)
label[lab_comp_key] = tk.Label(frame_tmp, text = msg, font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
else:
msg = f"{val}"
key = f"{keya}_{keyo}"
cmd = f"{component_name} {keya} {keyo}"
lab_comp_key = str(kcomp) + "_" + key
frame_tmp = tk.Frame(frame[kcomp])
button[lab_comp_key] = tk.Button(frame_tmp, text = key, command=functools.partial(self.pad_cbk_button_pushed, cmd), font=fontStyle_3)
button[lab_comp_key].pack(side = tk.LEFT)
label[lab_comp_key] = tk.Label(frame_tmp, text = msg, font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
self.pad_var_component[component_name] = tk.StringVar()
self.pad_var_component[component_name].set("")
lab_comp_key = component_name
frame_tmp = tk.Frame(frame[kcomp])
label[lab_comp_key] = tk.Label(frame_tmp, text = "Result", font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_component[component_name], font=fontStyle_3)
entry[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
if component.category == 'SensorDetector':
# ---
val = component.command("GET", "exptime")
lab_comp_key = str(kcomp) + "_exptime"
self.pad_var_exptime = tk.DoubleVar()
self.pad_var_exptime.set(1.2)
frame_tmp = tk.Frame(frame[kcomp])
label[lab_comp_key] = tk.Label(frame_tmp, text = "Exptime", font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_exptime, font=fontStyle_3)
entry[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
# ---
val = component.command("GET", "binning")
lab_comp_key = str(kcomp) + "_binning"
self.pad_var_binning = tk.StringVar()
self.pad_var_binning.set([1, 1])
frame_tmp = tk.Frame(frame[kcomp])
label[lab_comp_key] = tk.Label(frame_tmp, text = "Binning", font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_binning, font=fontStyle_3)
entry[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
if component.category == 'MountPointing':
# ---
val = component.command("GET", "target")
lab_comp_key = str(kcomp) + "_target"
self.pad_var_target = tk.StringVar()
self.pad_var_target.set("RADEC 6h 30d")
frame_tmp = tk.Frame(frame[kcomp])
label[lab_comp_key] = tk.Label(frame_tmp, text = "Target", font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_target, font=fontStyle_3)
entry[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
if component.category == 'DetectorFocuser':
# ---
val = component.command("GET", "target")
lab_comp_key = str(kcomp) + "_target"
self.pad_var_detectorfocuser_target = tk.DoubleVar()
self.pad_var_detectorfocuser_target.set("1000")
frame_tmp = tk.Frame(frame[kcomp])
label[lab_comp_key] = tk.Label(frame_tmp, text = "Target", font=fontStyle_3)
label[lab_comp_key].pack(side = tk.LEFT)
entry[lab_comp_key] = tk.Entry(frame_tmp, textvariable = self.pad_var_detectorfocuser_target, font=fontStyle_3)
entry[lab_comp_key].pack(side = tk.LEFT)
frame_tmp.pack(side = tk.TOP, anchor = tk.W)
frame[kcomp].pack(side = tk.TOP, pady=5)
# =====================================================
# Pack frame pilot
# =====================================================
for kcomp, component_name in zip(kcomps, device.component_names):
component = device.component(component_name)
notebook.add(tabs[kcomp], text=component_name)
notebook.pack(fill = tk.BOTH)
frame_pilot.pack(fill = tk.Y, side = tk.LEFT, anchor=tk.NW)
# =====================================================
# =====================================================
# (200) Frame camera
# =====================================================
# =====================================================
if False:
frame_camera = tk.Frame(superscrollable_frame, width = 500)
notebook = ttk.Notebook(frame_camera)
tab201 = ttk.Frame(notebook)
# =====================================================
# Tab 201 == Load and save FITS images
# =====================================================
# === Title
frame_tabload_title = tk.Frame(tab201)
label_tabload_title = tk.Label(frame_tabload_title, text="Load / save FITS images", font=fontStyle_1)
label_tabload_title.pack(side = tk.TOP)
frame_tabload_title.pack(side = tk.TOP, pady=5)
frame_camload = tk.Frame(tab201)
button_camload = tk.Button(frame_camload, text="Load", command=self.pad_cbk_camload, font=fontStyle_3)
button_camload.pack(side = tk.LEFT, padx=5)
button_camheader = tk.Button(frame_camload, text="Header", command=self.pad_cbk_camheader, font=fontStyle_3)
button_camheader.pack(side = tk.LEFT, padx=5)
button_camsave = tk.Button(frame_camload, text="Save", command=self.pad_cbk_camsave, font=fontStyle_3)
button_camsave.pack(side = tk.LEFT, padx=5)
frame_camload.pack(side = tk.TOP, pady=5)
tab201.pack()
# =====================================================
# Pack notebook camera
# =====================================================
notebook.add(tab201, text="Load/Save")
notebook.pack(fill = tk.BOTH)
# =====================================================
# Pack frame visu
# =====================================================
# === Frame of camera visu
frame_camvisu = tk.Frame(frame_camera)
# ---
if True:
self._visu1 = guitastro.Visu(frame_camvisu)
else:
self.tkrootvisu = tk.Toplevel(self.tkroot)
screen_width = self.tkrootvisu.winfo_screenwidth()
screen_height = self.tkrootvisu.winfo_screenheight()
cam_infos = self._main.camera_cam.properties()
nbcellx = cam_infos["CameraXSize"]
nbcelly = cam_infos["CameraYSize"]
framex = 30
framey = 100
ratiox = (screen_width-framex) / nbcellx
ratioy = (screen_height-framey) / nbcelly
ratiomini = ratioy
if ratiox < ratiomini:
ratiomini = ratiox
if ratiox > 1 and ratioy > 1:
width = nbcellx + framex
height = nbcelly + framey
else:
width = nbcellx*ratiox + framex
height = nbcelly*ratioy + framey
height = int(height)
width = int(width)
self.tkrootvisu.geometry(str(width)+"x"+str(height)+"+600+200")
self.tkrootvisu.title("Visu tool for Mount pad")
self.tkrootvisu.protocol('WM_DELETE_WINDOW', self.pad_cbk_quit)
self._visu1 = guitastro.Visu(self.tkrootvisu)
# ---
frame_camvisu.pack(side=tk.BOTTOM, pady=0, expand=tk.YES, fill=tk.BOTH)
frame_camera.pack(side=tk.LEFT, anchor=tk.NW, expand=tk.YES, fill=tk.BOTH)
frame_camera.pack_propagate(0)
# =====================================================
# =====================================================
# (300) Frame processing
# =====================================================
# =====================================================
frame_processing = tk.Frame(superscrollable_frame) # self.tkroot
notebook = ttk.Notebook(frame_processing)
tab301 = ttk.Frame(notebook)
tab302 = ttk.Frame(notebook)
tab303 = ttk.Frame(notebook)
tab304 = ttk.Frame(notebook)
# =====================================================
# Tab 301 == Processing Header FITS
# =====================================================
# === Title
frame_fitsheader_title = tk.Frame(tab301)
label_fitsheader_title = tk.Label(frame_fitsheader_title, text="FITS Header", font=fontStyle_1)
label_fitsheader_title.pack(side = tk.TOP)
frame_fitsheader_title.pack(side = tk.TOP, pady=5)
frame_fitsheader_go = tk.Frame(tab301)
button_camwcs = tk.Button(frame_fitsheader_go, text="Display FITS header", command=self.pad_cbk_dispheader, font=fontStyle_3)
button_camwcs.pack(side = tk.LEFT, padx=5)
frame_fitsheader_go.pack(side = tk.TOP, pady=5)
frame_fitsheader_disp = tk.Frame(tab301)
self.text_fitsheader_res = tk.Text(frame_fitsheader_disp, height=32, wrap="word", font=fontStyle_c3)
self.text_fitsheader_res.pack(side = tk.TOP, padx=5, pady=1)
self.text_fitsheader_res.tag_config('red', foreground="red")
self.text_fitsheader_res.tag_config('blue', foreground="blue")
self.text_fitsheader_res.tag_config('black', foreground="black")
self.text_fitsheader_res.tag_config('green', foreground="green")
frame_fitsheader_disp.pack(side = tk.TOP, pady=5)
tab301.pack()
# =====================================================
# Tab 302 == Processing WCS calibration
# =====================================================
# === Title
frame_calibwcs_title = tk.Frame(tab302)
label_calibwcs_title = tk.Label(frame_calibwcs_title, text="WCS calibration", font=fontStyle_1)
label_calibwcs_title.pack(side = tk.TOP)
frame_calibwcs_title.pack(side = tk.TOP, pady=5)
frame_calibwcs_go = tk.Frame(tab302)
button_camwcs = tk.Button(frame_calibwcs_go, text="Solve WCS", command=self.pad_cbk_camwcs, font=fontStyle_3)
button_camwcs.pack(side = tk.LEFT, padx=5)
frame_calibwcs_go.pack(side = tk.TOP, pady=5)
frame_calibwcs_disp = tk.Frame(tab302)
self.text_calibwcs_res = tk.Text(frame_calibwcs_disp, height=32, wrap="word", font=fontStyle_3)
self.text_calibwcs_res.pack(side = tk.TOP, padx=5, pady=1)
self.text_calibwcs_res.tag_config('red', foreground="red")
self.text_calibwcs_res.tag_config('blue', foreground="blue")
self.text_calibwcs_res.tag_config('black', foreground="black")
self.text_calibwcs_res.tag_config('green', foreground="green")
frame_calibwcs_disp.pack(side = tk.TOP, pady=5)
tab302.pack()
# =====================================================
# Tab 303 == Processing Python console
# =====================================================
# === Title
frame_pyconsole_title = tk.Frame(tab303)
label_pyconsole_title = tk.Label(frame_pyconsole_title, text="Python console", font=fontStyle_1)
label_pyconsole_title.pack(side = tk.TOP)
frame_pyconsole_title.pack(side = tk.TOP, pady=5)
# === Frames of console
frame_console = tk.Frame(tab303)
self.pad_var_console = tk.StringVar()
self.text_console = tk.Text(frame_console, height=35, wrap="word", font=fontStyle_3)
self.text_console.pack(side = tk.TOP, padx=5, pady=1)
self.text_console.tag_config('command', foreground="red")
self.text_console.tag_config('result', foreground="blue")
self.entry_console = tk.Entry(frame_console, textvariable=self.pad_var_console, font=fontStyle_3)
self.entry_console.pack(side = tk.TOP, padx=5, pady=1, fill="both")
self.entry_console.bind("<Return>", self.pad_cbk_console)
self.entry_console.bind("<Up>", self.pad_cbk_command_prev)
self.entry_console.bind("<Down>", self.pad_cbk_command_next)
frame_console.pack(side = tk.BOTTOM, pady=5)
tab302.pack()
# =====================================================
# Tab 304 == Processing Pointing model
# =====================================================
# === Title
frame_modpoi_title = tk.Frame(tab304)
label_modpoi_title = tk.Label(frame_modpoi_title, text="Pointing model computations", font=fontStyle_1)
label_modpoi_title.pack(side = tk.TOP)
frame_modpoi_title.pack(side = tk.TOP, pady=5)
# === Frame of acq modpoi buttons
frame_pmcpt = tk.Frame(tab304)
label_pmcpt_title = tk.Label(frame_pmcpt, text="Compute pointing model", font=fontStyle_2)
label_pmcpt_title.pack(side = tk.LEFT)
button_pmcpt1 = tk.Button(frame_pmcpt, text="from FITS images", command=self.pad_cbk_cammodel_compute_images, font=fontStyle_3)
button_pmcpt1.pack(side = tk.LEFT, padx=5)
button_pmcpt2 = tk.Button(frame_pmcpt, text="from pointing file", command=self.pad_cbk_cammodel_compute_pointings, font=fontStyle_3)
button_pmcpt2.pack(side = tk.LEFT, padx=5)
frame_pmcpt.pack(side = tk.TOP, pady=5)
tab304.pack()
# =====================================================
# Pack frame processing
# =====================================================
notebook.add(tab301, text="Header")
notebook.add(tab302, text="WCS")
notebook.add(tab303, text="Python")
notebook.add(tab304, text="Compute model")
notebook.pack(fill = tk.Y)
frame_processing.pack(side=tk.LEFT, anchor="nw")
# =====================================================
# =====================================================
# Event loop
# =====================================================
# =====================================================
superframe.pack(fill=tk.BOTH, expand=True)
supercanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
superscrollbar.pack(side=tk.BOTTOM, fill=tk.X)
self.tkroot.attributes("-topmost", True)
self.tkroot.update()
self.tkroot.attributes("-topmost", False)
#self.pad_cbk_compute_things_repeated_stop = False
#self.pad_cbk_compute_things_repeated()
self.tkroot.mainloop()
print("Pad mainloop terminated")
if __name__ == "__main__":
ima = guitastro.Ima()
path_products = ima.copy_data2products()
site = "GPS 2 E 43 137"
# ------------------------
if False:
name = "Camera"
device = "ASCOM.ASICamera2.Camera"
model = "ZWO"
serial_number = "12345"
description = "Test"
dev = Device_Ascomcam("ASCOMCAM", transport="USB", name=name, description=description, model=model, serial_number=serial_number, device=device, site=site)
else:
dev = Device_DFM("ZADKO", transport="TCP", name="Test mount Zadko", serial_number="#0000")
# ------------------------
real = False
dev.open(real)
# ------------------------
for component_name in dev.component_names:
component = dev.component(component_name)
if component.category == 'SensorDetector':
cam = component
# ------------------------
cam.ima.fcontext_create("pad_device", "Pad for Guitastro devices")
cam.ima.fcontext = "pad_device"
cam.ima.extension = ".fit"
rootdir0 = cam.ima.rootdir
cam.ima.rootdir = os.path.join(rootdir0, "pad_device")
os.makedirs(cam.ima.rootdir, exist_ok=True)
print(f"{cam.__repr__()}")
# ------------------------
if real == False:
import shutil
fname_in = os.path.join(cam.ima.rootdir, "..", "..", "data", "m57.fit")
fname_out = os.path.join(cam.ima.rootdir, "m57.fit")
shutil.copy(fname_in, fname_out)
# --- try to catch the Ctrl+C interrupt
try:
# --- We launch the pad
print("Create the pad. Tk Event loop activated.")
pad = Devicepad(dev)
print("Pad deleted. Tk Event loop stopped")
except (KeyboardInterrupt, SystemExit):
pass
except:
raise