-
Notifications
You must be signed in to change notification settings - Fork 3
/
Func_gui.py
executable file
·2499 lines (2085 loc) · 107 KB
/
Func_gui.py
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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import webbrowser
import os
import time
import logging
import pickle
from Func_cal import *
from Func_db import DbEditor
import matplotlib as mpl
mpl.use("TkAgg")
from matplotlib.figure import Figure
import matplotlib.pylab as pl
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
import matplotlib.cm as cm
import matplotlib.gridspec as gridspec
import queue
from tkinter import ttk
import numpy as np
from tkinter import scrolledtext
import multiprocessing
from multiprocessing import Process
from threading import Thread
import load_conf as lc
import model_effect as me
import utility as ut
from Func_uv import FuncUv
from Func_img import FuncImg
from Func_obs import FuncObs
from Func_radplot import FuncRadPlot
# from Func_sched import FuncSched
__version__ = '1.0'
__author__ = 'Zhen Zhao'
_github_page_ = "https://github.com/ZhenZHAO/VNSIM"
__about_text__ = """
VNSIM, AN INTEGRATED VLBI SIMULATOR FOR EAST ASIA VLBI NETWORK
ZHEN ZHAO
(Shanghai Astronomical Observatory)
VNSIM, an integrated VLBI simulator for East Asia VLBI Network(EAVN), aims to assist radio astronomers to design, evaluate and simulate the VLBI experiments in a more friendly, flexible, and convenient fashion. It not only integrates the functionality of plotting (u, v) coverage, scheduling the observation, and displaying the dirty and CLEAN images, but also further extends to add new features such as the sensitivity calculation of a certain network. To facilitate the use for new astronomers, VNSIM provides flexible interactions on both command line and graphical user interface and offers friendly support for log report and database management.
"""
__feedback_text__ = """
This software is still under developing by SKA group at Shanghai Astronomical Observatory. You are very welcome to leave your comments to us.
Would you like to visit our group page?
"""
__help_text__ = """
VNSIM is an integrated VLBI simulator for East Asia VLBI Network. You can config your specific simulation on the left configure panel, where we support space VLBI and various constraints.
You can choose different kinds of functions you like to explore on the left pane. There are three functional cluster, and you can switch them by clicking the corresponding label. In addition, there are two additional functions, parameter evaluation and database configuration, which can be accessible on the menu bar (Tool).
You can add your self-defined VLBI stations or satellites by inserting new data into the database on the database page, and new data will be loaded into the GUI automatically.
You can save your configurations and your newly edited database, as well as various types of images. For All images, you can easily zoom in/out, move, adjust gamma, etc.
Enjoy it!
"""
COPY_RIGHT_INFO = 'VNSIM \N{COPYRIGHT SIGN} 2018, %s' % __author__
TITLE = 'VNSIM - Shanghai Astronomical Observatory - version %s' % __version__
# colors normalization
norm = mpl.colors.Normalize(vmin=0, vmax=0.6)
# addtional functions
POP_OUT_PARA_CAL = 'para'
POP_OUY_DB_EDIT = 'database'
# multiple choice type
MULTI_CHOICE_TYPE_SRC = 'source'
MULTI_CHOICE_TYPE_VLBA = 'vlba'
MULTI_CHOICE_TYPE_EAVN = 'eavn'
MULTI_CHOICE_TYPE_EVN = 'evn'
MULTI_CHOICE_TYPE_LBA = 'lba'
MULTI_CHOICE_TYPE_OTHER = 'other'
MULTI_CHOICE_TYPE_SAT = 'satellite'
MULTI_CHOICE_TYPE_TELE = 'telemetry'
# trigger to update (set multiple by addition)
UPDATE_TYPE_UV = 1
UPDATE_TYPE_OBS = 2
UPDATE_TYPE_IMG = 4
UPDATE_TYPE_RAD = 8
UPDATE_TYPE_UO = 1 + 2
UPDATE_TYPE_UI = 1 + 4
UPDATE_TYPE_UOI = 1 + 2 + 4
# multiprocess type
PROCESS_TYPE_UV_SINGLE = 0
PROCESS_TYPE_UV_SKY = 1
PROCESS_TYPE_UV_TIME = 2
PROCESS_TYPE_UV_SRC = 3
PROCESS_TYPE_OBS_AZ_EL = 4
PROCESS_TYPE_OBS_SURVEY = 5
PROCESS_TYPE_IMG = 6
PROCESS_TYPE_RAD = 7
# pop out uv window
UV_SHOW_POP_TYPE_YEAR = 'All Year Coverage'
UV_SHOW_POP_TYPE_SRC = 'Multi Source Coverage'
MY_IMG_FONT = {'family': 'Arial',
'color': 'darkred',
'weight': 'normal',
'size': 10,
}
def process_finish_call_back(args):
# logger = logging.getLogger()
# logger.info(time.asctime() + ": {0} updating - done !".format(str(args)))
logging.info(time.asctime() + ": {0} updating - done !".format(str(args)))
print(time.asctime() + ": {0} updating - done !".format(str(args)))
class AppData(object):
def __init__(self, parent=None):
# super().__init__()
self.parent = parent
# 1. initial parameters of calculating class
self.init_true_cal_para_globally()
self.update_time()
# 2. calculating class
self.myFuncUv = None
self.myFuncObs = None
self.myFuncImg = None
self.myFuncRad = None
# 3. all simulation result
self.result_uv_single_u = []
self.result_uv_single_v = []
self.result_uv_single_max = 0.0
self.result_uv_sky_u = []
self.result_uv_sky_v = []
self.result_uv_sky_max = 0.0
self.result_uv_time_u = []
self.result_uv_time_v = []
self.result_uv_time_max = 0.0
self.result_uv_src_name = []
self.result_uv_src_u = []
self.result_uv_src_v = []
self.result_uv_src_max = 0.0
self.result_obs_az = []
self.result_obs_el = []
self.result_obs_hour = []
self.result_obs_survey_sun = []
self.result_obs_survey_moon = []
self.result_obs_survey_array = []
self.result_img_model = []
self.result_img_beam = []
self.result_img_dirty = []
self.result_img_clean = []
self.result_img_x_max = 0.0
self.result_rad_u = []
self.result_rad_v = []
self.result_rad_bl = []
self.result_rad_vis = []
def clear_result(self):
self.result_uv_single_u = []
self.result_uv_single_v = []
self.result_uv_single_max = 0.0
self.result_uv_sky_u = []
self.result_uv_sky_v = []
self.result_uv_sky_max = 0.0
self.result_uv_time_u = []
self.result_uv_time_v = []
self.result_uv_time_max = 0.0
self.result_uv_src_name = []
self.result_uv_src_u = []
self.result_uv_src_v = []
self.result_uv_src_max = 0.0
self.result_obs_az = []
self.result_obs_el = []
self.result_obs_hour = []
self.result_obs_survey_sun = []
self.result_obs_survey_moon = []
self.result_obs_survey_array = []
self.result_img_model = []
self.result_img_beam = []
self.result_img_dirty = []
self.result_img_clean = []
self.result_img_x_max = 0.0
self.result_rad_u = []
self.result_rad_v = []
self.result_rad_bl = []
self.result_rad_vis = []
def update_time(self):
self.var_start_time = ut.time_2_mjd(self.var_start_year, self.var_start_month,
self.var_start_day, self.var_start_hour,
self.var_start_minute, self.var_start_second, 0)
self.var_stop_time = ut.time_2_mjd(self.var_stop_year, self.var_stop_month,
self.var_stop_day, self.var_stop_hour,
self.var_stop_minute, self.var_stop_second, 0)
self.var_time_step = ut.time_2_day(0, self.var_step_hour, self.var_step_minute,
self.var_step_second)
def update_calculation_class(self):
self.myFuncUv = FuncUv(self.var_start_time, self.var_stop_time, self.var_time_step,
self.var_main_src, self.var_src_lst,
self.var_sat_lst, self.var_vlbi_lst, self.var_telem_lst,
self.var_freq, self.var_baseline_type, self.var_unit,
self.var_cutoff_mode_dict, self.var_procession)
self.myFuncObs = FuncObs(self.var_start_time, self.var_stop_time, self.var_time_step,
self.var_main_src, self.var_vlbi_lst,
self.var_sat_lst, self.var_telem_lst,
self.var_baseline_type, self.var_cutoff_mode_dict, self.var_procession)
self.myFuncImg = FuncImg(self.var_model_name, self.var_pix_size,
self.result_uv_single_u, self.result_uv_single_v, self.result_uv_single_max,
self.var_freq, True, self.var_clean_gain,
self.var_clean_thresh, self.var_clean_niter, self.var_unit)
self.myFuncRad = FuncRadPlot(self.var_rad_plot_file)
def init_true_cal_para_globally(self):
# time
self.var_start_year = lc.StartTimeGlobalYear
self.var_start_month = lc.StartTimeGlobalMonth
self.var_start_day = lc.StartTimeGlobalDay
self.var_start_hour = lc.StartTimeGlobalHour
self.var_start_minute = lc.StartTimeGlobalMinute
self.var_start_second = lc.StartTimeGlobalSecond
self.var_stop_year = lc.StopTimeGlobalYear
self.var_stop_month = lc.StopTimeGlobalMonth
self.var_stop_day = lc.StopTimeGlobalDay
self.var_stop_hour = lc.StopTimeGlobalHour
self.var_stop_minute = lc.StopTimeGlobalMinute
self.var_stop_second = lc.StopTimeGlobalSecond
self.var_step_hour = lc.TimeStepGlobalHour
self.var_step_minute = lc.TimeStepGlobalMinute
self.var_step_second = lc.TimeStepGlobalSecond
# source
self.var_main_src = lc.pos_mat_src[0]
self.var_src_lst = lc.pos_mat_src
# vlbi
self.var_vlbi_lst = lc.pos_mat_vlbi
# satellite
self.var_sat_lst = lc.pos_mat_sat
self.var_telem_lst = lc.pos_mat_telemetry
# parameters
self.var_freq = lc.obs_freq
self.var_unit = lc.unit_flag
self.var_baseline_type = lc.baseline_type
self.var_procession = lc.precession_mode
self.var_cutoff_mode_dict = lc.cutoff_mode
# imaging
self.var_model_name = lc.source_model
self.var_pix_size = lc.n_pix
self.var_clean_gain = lc.clean_gain
self.var_clean_thresh = lc.clean_threshold
self.var_clean_niter = lc.clean_niter
self.var_color_map_name = lc.color_map_name
# rad plot
self.var_rad_plot_file = lc.rad_plot_file
def __call__(self, p_type, d_key, d_data):
# print("call run!")
if p_type == PROCESS_TYPE_UV_SINGLE:
print('begin to update single uv')
d_data[d_key] = self.update_data_uv_single()
self.parent.set_after_call('Main UV Coverage - data')
# process_finish_call_back('Main UV Coverage - data')
elif p_type == PROCESS_TYPE_UV_SKY:
print('begin to update all sky uv')
d_data[d_key] = self.update_data_uv_sky()
process_finish_call_back('SKY Coverage - data')
elif p_type == PROCESS_TYPE_UV_TIME:
print('begin to update all year uv')
d_data[d_key] = self.update_data_uv_time()
process_finish_call_back('AllYear Coverage - data')
elif p_type == PROCESS_TYPE_UV_SRC:
print('begin to update multi source uv')
d_data[d_key] = self.update_data_uv_src()
process_finish_call_back('MultiSrc Coverage - data')
elif p_type == PROCESS_TYPE_OBS_AZ_EL:
print('begin to update Az-EL')
d_data[d_key] = self.update_data_obs_az_el()
process_finish_call_back('AZ-EL - data')
elif p_type == PROCESS_TYPE_OBS_SURVEY:
print('begin to update Az-EL')
d_data[d_key] = self.update_data_obs_survey()
process_finish_call_back('SKY SURVEY - data')
elif p_type == PROCESS_TYPE_IMG:
print('begin to update img')
d_data[d_key] = self.update_data_img()
process_finish_call_back('ALL Imaging - data')
elif p_type == PROCESS_TYPE_RAD:
print('begin to update radplot')
d_data[d_key] = self.update_data_rad()
process_finish_call_back('Rad Plot - data')
else:
pass
def _update_uv_with_multiprocess(self):
# 1. update para
self.update_data_uv_para()
# 2. set up the passing arguments
mng = multiprocessing.Manager()
arg1 = [PROCESS_TYPE_UV_SINGLE, PROCESS_TYPE_UV_SKY, PROCESS_TYPE_UV_TIME, PROCESS_TYPE_UV_SRC]
arg2 = ['single_uv', 'sky_uv', 'time_uv', 'src_uv']
data_dict = mng.dict()
# 3. run multiprocess
jobs = [Process(target=self, args=(arg1[i], arg2[i], data_dict)) for i in range(len(arg1))]
for j in jobs:
j.start()
for j in jobs:
j.join()
# 4. parse the result
for each in arg2:
if each == 'single_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_single_u = value[0]
self.result_uv_single_v = value[1]
self.result_uv_single_max = value[2]
elif each == 'sky_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_sky_u = value[0]
self.result_uv_sky_v = value[1]
self.result_uv_sky_max = value[2]
elif each == 'time_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_time_u = value[0]
self.result_uv_time_v = value[1]
self.result_uv_time_max = value[2]
elif each == 'src_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_src_name = value[0]
self.result_uv_src_u = value[1]
self.result_uv_src_v = value[2]
self.result_uv_src_max = value[3]
def _update_obs_with_multiprocess(self):
self.update_data_obs_para()
mng = multiprocessing.Manager()
arg1 = [PROCESS_TYPE_OBS_AZ_EL, PROCESS_TYPE_OBS_SURVEY]
arg2 = ['az_el', 'survey']
data_dict = mng.dict()
jobs = [Process(target=self, args=(arg1[i], arg2[i], data_dict)) for i in range(len(arg1))]
for j in jobs:
j.start()
for j in jobs:
j.join()
for each in arg2:
if each == 'az_el':
value = data_dict.get(each, None)
if value is not None:
self.result_obs_az = value[0]
self.result_obs_el = value[1]
self.result_obs_hour = value[2]
elif each == 'survey':
value = data_dict.get(each, None)
if value is not None:
self.result_obs_survey_sun = value[0]
self.result_obs_survey_moon = value[1]
self.result_obs_survey_array = value[2]
def _update_uv_obs_with_multiprocess(self):
# 1. update para
self.update_data_uv_para()
self.update_data_obs_para()
# 2. set up the passing arguments
mng = multiprocessing.Manager()
arg1 = [PROCESS_TYPE_UV_SINGLE, PROCESS_TYPE_UV_SKY, PROCESS_TYPE_UV_TIME,
PROCESS_TYPE_UV_SRC, PROCESS_TYPE_OBS_AZ_EL, PROCESS_TYPE_OBS_SURVEY]
arg2 = ['single_uv', 'sky_uv', 'time_uv', 'src_uv', 'az_el', 'survey']
data_dict = mng.dict()
# 3. run multiprocess
jobs = [Process(target=self, args=(arg1[i], arg2[i], data_dict)) for i in range(len(arg1))]
for j in jobs:
j.start()
for j in jobs:
j.join()
# 4. parse the result
for each in arg2:
if each == 'single_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_single_u = value[0]
self.result_uv_single_v = value[1]
self.result_uv_single_max = value[2]
elif each == 'sky_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_sky_u = value[0]
self.result_uv_sky_v = value[1]
self.result_uv_sky_max = value[2]
elif each == 'time_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_time_u = value[0]
self.result_uv_time_v = value[1]
self.result_uv_time_max = value[2]
elif each == 'src_uv':
value = data_dict.get(each, None)
if value is not None:
self.result_uv_src_name = value[0]
self.result_uv_src_u = value[1]
self.result_uv_src_v = value[2]
self.result_uv_src_max = value[3]
elif each == 'az_el':
value = data_dict.get(each, None)
if value is not None:
self.result_obs_az = value[0]
self.result_obs_el = value[1]
self.result_obs_hour = value[2]
elif each == 'survey':
value = data_dict.get(each, None)
if value is not None:
self.result_obs_survey_sun = value[0]
self.result_obs_survey_moon = value[1]
self.result_obs_survey_array = value[2]
def _update_all_first_update_with_accelerate(self):
# update all uv
self._update_uv_with_multiprocess()
# update obs, img, radplot
self.update_data_obs_para()
self.update_data_img_para()
self.update_data_rad_para()
mng = multiprocessing.Manager()
arg1 = [PROCESS_TYPE_OBS_AZ_EL, PROCESS_TYPE_OBS_SURVEY, PROCESS_TYPE_IMG, PROCESS_TYPE_RAD]
arg2 = ['az_el', 'survey', 'imaging', 'radplot']
data_dict = mng.dict()
jobs = [Process(target=self, args=(arg1[i], arg2[i], data_dict)) for i in range(len(arg1))]
for j in jobs:
j.start()
for j in jobs:
j.join()
for each in arg2:
if each == arg2[0]:
value = data_dict.get(each, None)
if value is not None:
self.result_obs_az = value[0]
self.result_obs_el = value[1]
self.result_obs_hour = value[2]
elif each == arg2[1]:
value = data_dict.get(each, None)
if value is not None:
self.result_obs_survey_sun = value[0]
self.result_obs_survey_moon = value[1]
self.result_obs_survey_array = value[2]
elif each == arg2[2]:
value = data_dict.get(each, None)
if value is not None:
self.result_img_model = value[0]
self.result_img_beam = value[1]
self.result_img_dirty = value[2]
self.result_img_clean = value[3]
self.result_img_x_max = value[4]
elif each == arg2[3]:
value = data_dict.get(each, None)
if value is not None:
self.result_rad_u = value[0]
self.result_rad_v = value[1]
self.result_rad_bl = value[2]
self.result_rad_vis = value[3]
def update_all_with_flag(self, update_flag_first_run, update_flag_uv,
update_flag_obs, update_flag_img,
update_flag_rad):
# Process(target=self.parent.gress_bar.start(), args=(arg1[i], arg2[i], data_dict))
# self.parent.gress_bar.quit()
if update_flag_first_run:
self._update_all_first_update_with_accelerate()
return
# update time
if update_flag_uv or update_flag_obs:
self.update_time()
# update uv, obs with multiprocessing
if update_flag_uv and not update_flag_obs:
self._update_uv_with_multiprocess()
elif update_flag_obs and not update_flag_uv:
self._update_obs_with_multiprocess()
elif update_flag_obs and update_flag_uv:
self._update_uv_obs_with_multiprocess()
# update img
if update_flag_img:
print('begin to update img')
self.update_data_img_para()
tmp = self.update_data_img()
if tmp is not None:
self.result_img_model = tmp[0]
self.result_img_beam = tmp[1]
self.result_img_dirty = tmp[2]
self.result_img_clean = tmp[3]
self.result_img_x_max = tmp[4]
process_finish_call_back('ALL Imaging - data')
# update radplot
if update_flag_rad:
print('begin to update radplot')
self.update_data_rad_para()
tmp = self.update_data_rad()
if tmp is not None:
self.result_rad_u = tmp[0]
self.result_rad_v = tmp[1]
self.result_rad_bl = tmp[2]
self.result_rad_vis = tmp[3]
process_finish_call_back('Rad Plot - data')
# self.parent.notify_queue.put((1,))
def update_all_with_flag_wo_speed(self, update_flag_first_run, update_flag_uv,
update_flag_obs, update_flag_img,
update_flag_rad):
if update_flag_first_run or update_flag_uv:
print('begin to update uv')
self.update_data_uv_para()
tmp1 = self.update_data_uv_single()
tmp2 = self.update_data_uv_sky()
tmp3 = self.update_data_uv_time()
tmp4 = self.update_data_uv_src()
if tmp1 is not None:
self.result_uv_single_u = tmp1[0]
self.result_uv_single_v = tmp1[1]
self.result_uv_single_max = tmp1[2]
if tmp2 is not None:
self.result_uv_sky_u = tmp2[0]
self.result_uv_sky_v = tmp2[1]
self.result_uv_sky_max = tmp2[2]
if tmp3 is not None:
self.result_uv_time_u = tmp3[0]
self.result_uv_time_v = tmp3[1]
self.result_uv_time_max = tmp3[2]
if tmp4 is not None:
self.result_uv_src_name = tmp4[0]
self.result_uv_src_u = tmp4[1]
self.result_uv_src_v = tmp4[2]
self.result_uv_src_max = tmp4[3]
process_finish_call_back('UV Coverage - data')
if update_flag_first_run or update_flag_obs:
print('begin to update obs')
self.update_data_obs_para()
tmp1 = self.update_data_obs_az_el()
if tmp1 is not None:
self.result_obs_az = tmp1[0]
self.result_obs_el = tmp1[1]
self.result_obs_hour = tmp1[2]
tmp2 = self.update_data_obs_survey()
if tmp2 is not None:
self.result_obs_survey_sun = tmp2[0]
self.result_obs_survey_moon = tmp2[1]
self.result_obs_survey_array = tmp2[2]
process_finish_call_back('Observation - data')
if update_flag_first_run or update_flag_img:
print('begin to update img')
self.update_data_img_para()
tmp = self.update_data_img()
if tmp is not None:
self.result_img_model = tmp[0]
self.result_img_beam = tmp[1]
self.result_img_dirty = tmp[2]
self.result_img_clean = tmp[3]
self.result_img_x_max = tmp[4]
process_finish_call_back('ALL Imaging - data')
if update_flag_first_run or update_flag_rad:
print('begin to update radplot')
self.update_data_rad_para()
tmp = self.update_data_rad()
if tmp is not None:
self.result_rad_u = tmp[0]
self.result_rad_v = tmp[1]
self.result_rad_bl = tmp[2]
self.result_rad_vis = tmp[3]
process_finish_call_back('Rad Plot - data')
# update data
def update_data_uv_para(self):
self.myFuncUv = FuncUv(self.var_start_time, self.var_stop_time, self.var_time_step,
self.var_main_src, self.var_src_lst,
self.var_sat_lst, self.var_vlbi_lst, self.var_telem_lst,
self.var_freq, self.var_baseline_type, self.var_unit,
self.var_cutoff_mode_dict, self.var_procession)
def update_data_uv_single(self):
return self.myFuncUv.get_result_single_uv_with_update()
def update_data_uv_sky(self):
return self.myFuncUv.get_result_sky_uv_with_update()
def update_data_uv_time(self):
return self.myFuncUv.get_result_year_uv_with_update()
def update_data_uv_src(self):
return self.myFuncUv.get_result_multi_src_with_update()
def update_data_obs_para(self):
self.myFuncObs = FuncObs(self.var_start_time, self.var_stop_time, self.var_time_step,
self.var_main_src, self.var_vlbi_lst,
self.var_sat_lst, self.var_telem_lst,
self.var_baseline_type, self.var_cutoff_mode_dict, self.var_procession)
def update_data_obs_az_el(self):
return self.myFuncObs.get_result_az_el_with_update()
def update_data_obs_survey(self):
return self.myFuncObs.get_result_sky_survey_with_update()
def update_data_img_para(self):
self.myFuncImg = FuncImg(self.var_model_name, self.var_pix_size,
self.result_uv_single_u, self.result_uv_single_v, self.result_uv_single_max,
self.var_freq, True, self.var_clean_gain,
self.var_clean_thresh, self.var_clean_niter, self.var_unit)
def update_data_img(self):
if len(self.result_uv_single_u) > 0 and len(self.result_uv_single_v) > 0 and self.var_model_name != '':
# 2. update results
tmp_model, tmp_x_max = self.myFuncImg.get_result_src_model_with_update()
tmp_beam = self.myFuncImg.get_result_dirty_beam_with_update()
tmp_dirty = self.myFuncImg.get_result_dirty_map_with_update()
tmp_clean, tmp_res, show_src, show_cln_beam = self.myFuncImg.get_result_clean_map_with_update()
return tmp_model, tmp_beam, tmp_dirty, tmp_clean, tmp_x_max
else:
return None
def update_data_rad_para(self):
self.myFuncRad = FuncRadPlot(self.var_rad_plot_file)
def update_data_rad(self):
if self.myFuncRad.get_data_state():
tmp_u, tmp_v = self.myFuncRad.get_result_uv_data()
tmp_bl, tmp_vis = self.myFuncRad.get_result_rad_data()
return tmp_u, tmp_v, tmp_bl, tmp_vis
else:
return None
# getters - uv
def get_data_uv_single(self):
return self.result_uv_single_u, self.result_uv_single_v, self.result_uv_single_max
def get_data_uv_sky(self):
return self.result_uv_sky_u, self.result_uv_sky_v, self.result_uv_sky_max
def get_data_uv_time(self):
return self.result_uv_time_u, self.result_uv_time_v, self.result_uv_time_max
def get_data_uv_src(self):
return self.result_uv_src_name, self.result_uv_src_u, self.result_uv_src_v, self.result_uv_src_max
# getters - obs
def get_data_obs_az_el(self):
return self.result_obs_az, self.result_obs_el, self.result_obs_hour
def get_data_obs_survey(self):
return self.result_obs_survey_sun, self.result_obs_survey_moon, self.result_obs_survey_array
# getters - img
def get_data_img_model(self):
return self.result_img_model, self.result_img_x_max
def get_data_img_beam(self):
return self.result_img_beam, self.result_img_x_max
def get_data_img_dirty(self):
return self.result_img_dirty, self.result_img_x_max
def get_data_img_clean(self):
return self.result_img_clean, self.result_img_x_max
# getters - rad
def get_data_rad_uv(self):
return self.result_rad_u, self.result_rad_v
def get_data_rad_vis(self):
return self.result_rad_bl, self.result_rad_vis
class AppGUI(object):
def __init__(self, master=None, db_file='', pkl_file=''):
self.notify_queue = queue.Queue()
self.window = master
self.window.protocol("WM_DELETE_WINDOW", self.quit)
self.db_name = db_file
self.pkl_name = pkl_file
self.pkl_path = os.path.join(os.path.join(os.getcwd(), 'DATABASE'), self.pkl_name)
# 0. real-time input checking
self.test_float = self.window.register(self.test_input_float)
# 1. initialize pop out windows
self.PopOutParaCal = None
self.is_pop_out_para = False
self.PopOutDbEditor = None
self.is_pop_out_db = False
# 2. init cal class/parameters
self.myData = AppData(self)
# 3. load database (db->ui_choice_para->ui_cal_para->true_cal_para)
self._pickle_load_database()
# 4. init ui parameters
self._init_ui_cal_para()
self._init_ui_choice_para()
self._load_cal_para_to_ui_para()
# 5. whether need to update the calculation
self.if_update_first_time = True
self.if_update_uv = False
self.if_update_img = False
self.if_update_obs = False
self.if_update_rad = False
# 6. show info on uv plane
self.tab_uv_ui_var_info = tk.StringVar('')
# 7. color bar on obs plane
self.obs_panel_color_bar = None
# 8. gui after call
self.gress_bar = GressBar()
self.is_start_process_msg = False
# self.process_msg()
# self.after_call_new = False
# self.after_call_str = ''
# self.gui_after_call()
# 9. init gui
self.gui_var_status = tk.StringVar() # status
self._gui_int()
def start_process_msg(self):
self.is_start_process_msg = True
self.process_msg()
def stop_process_msg(self):
self.is_start_process_msg = False
def process_msg(self):
if not self.is_start_process_msg:
return
self.window.after(400, self.process_msg)
# print("heloo")
# if self.gress_bar.master is not None:
# print("heloo")
# if self.gress_bar.master is not None:
# self.gress_bar.master.overrideredirect(True)
# print("=-="*20)
while not self.notify_queue.empty():
try:
msg = self.notify_queue.get()
if msg[0] == 1:
time.sleep(0.5)
self.gress_bar.quit()
self.stop_process_msg()
except queue.Empty:
pass
def reset_all(self):
self.myData.init_true_cal_para_globally()
self._load_cal_para_to_ui_para()
self.logger.info(time.asctime() + ": reset all gui para - done!")
self.gui_var_status.set("Ready")
self.reset_panel_uv()
logging.info(time.asctime() + ": reset panel-coverage - done!")
self.reset_panel_obs()
logging.info(time.asctime() + ": reset panel-observe - done!")
self.reset_panel_img()
logging.info(time.asctime() + ": reset panel-imaging - done!")
self.reset_panel_radplot()
logging.info(time.asctime() + ": reset panel-radplot - done!")
self.if_update_first_time = True
def set_after_call(self, info):
self.after_call_new = True
self.after_call_str = info
def gui_after_call(self):
self.window.after(200, self.gui_after_call)
if self.after_call_new:
print('hell0')
process_finish_call_back(self.after_call_str)
self.after_call_new = False
def apply_all_with_multiprocess(self):
self._load_ui_para_to_cal_para()
self.logger.info(time.asctime() + ": reading gui para - done!")
self.gui_var_status.set('Running')
self.start_time = time.time()
self.myData.update_all_with_flag(self.if_update_first_time,
self.if_update_uv,
self.if_update_obs,
self.if_update_img,
self.if_update_rad)
self.update_all_panel()
def apply_all(self):
self._load_ui_para_to_cal_para()
self.logger.info(time.asctime() + ": reading gui para - done!")
self.gui_var_status.set('Running')
self.start_time = time.time()
self.start_process_msg()
def cal_para_normal(_queue):
self.update_all_data()
self.update_all_panel()
_queue.put((1,))
th1 = Thread(target=cal_para_normal, args=(self.notify_queue,))
th1.start()
self.gress_bar.start()
th1.join()
def update_all_data(self):
self.myData.update_all_with_flag_wo_speed(self.if_update_first_time,
self.if_update_uv,
self.if_update_obs,
self.if_update_img,
self.if_update_rad)
def update_all_panel(self):
# update uv coverage functions
if self.if_update_first_time or self.if_update_uv:
self.update_panel_uv()
process_finish_call_back("UV - panel")
self.if_update_uv = False
# update uv observation functions
if self.if_update_first_time or self.if_update_obs:
self.update_panel_obs()
process_finish_call_back("OBS - panel")
self.if_update_obs = False
# update uv imaging functions
if self.if_update_first_time or self.if_update_img:
self.update_panel_img()
process_finish_call_back("IMG - panel")
self.if_update_img = False
# update uv radplot functions
if self.if_update_first_time or self.if_update_rad:
self.update_panel_radplot()
process_finish_call_back("RAD - panel")
self.if_update_rad = False
self.if_update_first_time = False
self.gui_var_status.set('Done')
print("RUNING TIME IS %s" % (time.time() - self.start_time))
def trigger_panel_update(self, t_type):
self.if_update_uv = (t_type & 1 != 0)
self.if_update_obs = (t_type & 2 != 0)
self.if_update_img = (t_type & 4 != 0)
self.if_update_rad = (t_type & 8 != 0)
# print(t_type, self.if_update_uv, self.if_update_obs, self.if_update_img, self.if_update_rad)
def trigger_update_event(self, event, t_type):
self.if_update_uv = (t_type & 1 != 0)
self.if_update_obs = (t_type & 2 != 0)
self.if_update_img = (t_type & 4 != 0)
self.if_update_rad = (t_type & 8 != 0)
def refresh_ui_config_with_db(self):
self._pickle_load_database()
self._init_ui_choice_para()
# 多选框 是不需要单独更新的,因为每次弹出都会读取新的 choice_lst
# 需要更新与数据库相关的单选box - 只有一个,ui_main_src 处
self.selec_single_src.config(values=self.ui_choice_src)
def _pickle_load_database(self):
with open(self.pkl_path, 'rb') as fr:
self.db_src_dict = pickle.load(fr)
self.db_sat_dict = pickle.load(fr)
self.db_telem_dict = pickle.load(fr)
self.db_vlbi_vlba_dict = pickle.load(fr)
self.db_vlbi_evn_dict = pickle.load(fr)
self.db_vlbi_eavn_dict = pickle.load(fr)
self.db_vlbi_lba_dict = pickle.load(fr)
self.db_vlbi_other_dict = pickle.load(fr)
def _init_ui_cal_para(self):
# time
self.ui_start_year = tk.StringVar('')
self.ui_start_month = tk.StringVar('')
self.ui_start_day = tk.StringVar('')
self.ui_start_hour = tk.StringVar('')
self.ui_start_minute = tk.StringVar('')
self.ui_start_second = tk.StringVar('')
self.ui_stop_year = tk.StringVar('')
self.ui_stop_month = tk.StringVar('')
self.ui_stop_day = tk.StringVar('')
self.ui_stop_hour = tk.StringVar('')
self.ui_stop_minute = tk.StringVar('')
self.ui_stop_second = tk.StringVar('')
self.ui_step_hour = tk.StringVar('')
self.ui_step_minute = tk.StringVar('')
self.ui_step_second = tk.StringVar('')
# source
self.ui_main_src = tk.StringVar('')
self.ui_src_lst = []
# vlbi
self.ui_vlbi_vlba_lst = []
self.ui_vlbi_evn_lst = []
self.ui_vlbi_eavn_lst = []
self.ui_vlbi_lba_lst = []
self.ui_vlbi_othter_lst = []
# satellite
self.ui_sat_lst = []
self.ui_telem_lst = []
# parameters
self.ui_freq = tk.StringVar('')
self.ui_unit = tk.StringVar("")
self.ui_cutoff_angle = tk.StringVar('')
self.ui_procession = tk.StringVar('')
self.ui_baseline_gg = tk.IntVar()
self.ui_baseline_gs = tk.IntVar()
self.ui_baseline_ss = tk.IntVar()
# imaging
self.ui_model_name = tk.StringVar('')
self.ui_pix_size = tk.StringVar('')
self.ui_clean_gain = tk.StringVar('')
self.ui_clean_thresh = tk.StringVar('')
self.ui_clean_niter = tk.StringVar('')
self.ui_color_map = tk.StringVar('')
# radplot