-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
3142 lines (2766 loc) · 146 KB
/
main.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
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 6 14:54:39 2018
@author: mshem
"""
#Importing Circle to draw circles to images
try:
from matplotlib.patches import Circle
except Exception as e:
print("{}. Mtplotlib is not installed?".format(e))
exit(0)
#Importing PyQt5
try:
from PyQt5 import QtWidgets
from PyQt5 import QtCore
except Exception as e:
print("{}. PyQt5 is not installed?".format(e))
exit(0)
#Importing argv to get arguments from terminal
from sys import argv
from sys import exit as sexit
#Importing myraf's GUI
try:
import gui as g
except Exception as e:
print("{}. Cannot find gui.py".format(e))
exit(0)
try:
from fPlot import FitsPlot
except Exception as e:
print("{}. Cannot find fPlot.py".format(e))
exit(0)
try:
from myraf import Ui_Form
except Exception as e:
print("{}. Cannot find myraf.py".format(e))
exit(0)
#Importing myraf's needed modules
try:
from myraflib import myEnv
from myraflib import myCos
except Exception as e:
print("{}. Cannot find myraflib".format(e))
from myraflib import myAst
class MyForm(QtWidgets.QWidget, Ui_Form):
def __init__(self, verb=True):
super(MyForm, self).__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.verb = verb
self.etc = myEnv.etc(verb=self.verb)
self.cnv = myEnv.converter(verb=self.verb)
self.fop = myEnv.file_op(verb=self.verb)
self.fit = myAst.fits(verb=self.verb)
self.sex = myAst.sextractor(verb=self.verb)
self.pht = myAst.phot(verb=self.verb)
self.clc = myAst.calc(verb=self.verb)
self.cat = myAst.cat(verb=self.verb)
self.cal = myAst.calibration(verb=self.verb)
self.tim = myAst.time(verb=self.verb)
self.etc.log("***MyRAF STARTED***")
for device in ["PHOT", "ALIGN", "ATRACK", "COSMIC"]:
self.empty_display(device)
self.first_thing_first()
lfs = self.fop.get_size(self.etc.log_file) / 1048576
mlfs = self.fop.get_size(self.etc.mini_log_file) / 1048576
if lfs > 5 or mlfs > 5:
self.etc.log("Log file is too big. Ask for deletation.")
answ = g.question(self, "Log files are getting Huge. It'll effect the performance. Would you like to clear them?")
if answ == QtWidgets.QMessageBox.Yes:
self.clear_log()
self.etc.log("Resetting Gui for Log tab")
#set Log tab
self.ui.label_19.setProperty("text",
"Logs are stored in: {} & {}".format(
self.etc.log_file,
self.etc.mini_log_file))
self.etc.log("Resetting Gui for Calibration tab")
#set calibration tab
self.ui.progressBar.setProperty("value", 0)
self.ui.label_3.setProperty("text", "")
self.ui.label_4.setProperty("text", "")
self.ui.label_5.setProperty("text", "")
self.ui.label_6.setProperty("text", "")
self.ui.label.setProperty("text", "")
self.calibration_annotation()
self.etc.log("Creating triggers for Calibration tab")
#add triggers for Calibration
self.ui.pushButton_6.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_6),
self.calibration_annotation()))
self.ui.pushButton_5.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_6),
self.calibration_annotation()))
self.ui.listWidget_6.installEventFilter(self)
self.ui.pushButton_8.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_7),
self.calibration_annotation()))
self.ui.pushButton_7.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_7),
self.calibration_annotation()))
self.ui.pushButton_37.clicked.connect(lambda: (self.zero_combine()))
self.ui.listWidget_7.installEventFilter(self)
self.ui.pushButton_10.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_8),
self.calibration_annotation()))
self.ui.pushButton_9.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_8),
self.calibration_annotation()))
self.ui.pushButton_40.clicked.connect(lambda: (self.dark_combine()))
self.ui.listWidget_8.installEventFilter(self)
self.ui.pushButton_12.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_9),
self.calibration_annotation()))
self.ui.pushButton_11.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_9),
self.calibration_annotation()))
self.ui.pushButton_41.clicked.connect(lambda: (self.flat_combine()))
self.ui.listWidget_9.installEventFilter(self)
self.ui.pushButton.clicked.connect(lambda: (self.do_calibration()))
self.etc.log("Resetting Gui for Align tab")
#set align tab
self.ui.progressBar_2.setProperty("value", 0)
self.ui.label_2.setProperty("text", "")
self.align_annotation()
self.etc.log("Creating triggers for Align tab")
#add triggers for align
self.ui.pushButton_3.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget),
self.align_annotation()))
self.ui.pushButton_4.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget),
self.align_annotation(),
self.empty_display("align")))
self.ui.pushButton_2.clicked.connect(lambda: (self.do_align()))
self.ui.listWidget.clicked.connect(lambda: (self.display_align()))
self.ui.listWidget.installEventFilter(self)
self.etc.log("Resetting Gui for Photometry tab")
#set photometry tab
self.ui.progressBar_4.setProperty("value", 0)
self.ui.label_8.setProperty("text", "")
self.ui.label_54.setProperty("text", "")
self.phot_annotation()
self.etc.log("Creating triggers for Photometry tab")
#add triggers for photometry
self.ui.pushButton_15.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_2),
self.phot_annotation(), self.phot_hex()))
self.ui.pushButton_14.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_2),
self.phot_annotation(), self.phot_hex(),
self.empty_display("PHOT")))
self.ui.pushButton_36.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_14),
self.phot_annotation()))
self.ui.pushButton_35.clicked.connect(lambda: (
self.display_coors_phot()))
self.ui.disp_photometry.canvas.fig.canvas.mpl_connect(
'button_press_event',self.mouseClick)
self.ui.pushButton_51.clicked.connect(lambda: (self.phot_hex()))
self.ui.pushButton_49.clicked.connect(lambda: (self.queue_header()))
self.ui.pushButton_50.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_20)))
self.ui.pushButton_34.clicked.connect(lambda: (self.run_sex()))
self.ui.pushButton_16.clicked.connect(lambda: (self.do_phot()))
self.ui.listWidget_2.clicked.connect(lambda: (self.display_phot()))
self.ui.listWidget_14.installEventFilter(self)
self.ui.listWidget_2.installEventFilter(self)
self.ui.listWidget_20.installEventFilter(self)
self.etc.log("Resetting Gui for A-Track tab")
#set a-track tab
self.ui.progressBar_7.setProperty("value", 0)
self.ui.label_27.setProperty("text", "")
self.atrack_annotation()
self.etc.log("Creating triggers for A-Track tab")
#add triggers for atrack
self.ui.pushButton_33.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_13),
self.atrack_annotation()))
self.ui.pushButton_32.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_13),
self.atrack_annotation(),
self.empty_display("ATRAK")))
self.ui.pushButton_43.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_15)))
self.ui.listWidget_13.clicked.connect(lambda: (self.display_atrack()))
self.ui.pushButton_42.clicked.connect(lambda: (self.a_track()))
self.ui.listWidget_13.installEventFilter(self)
self.ui.listWidget_15.installEventFilter(self)
self.etc.log("Resetting Gui for Hedit tab")
#set header editor tab
self.ui.progressBar_3.setProperty("value", 0)
self.ui.label_10.setProperty("text", "")
self.heditor_annotation()
self.etc.log("Creating triggers for Hedit tab")
#add triggers for header editor
self.ui.pushButton_20.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_3),
self.heditor_annotation()))
self.ui.pushButton_19.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_3),
self.heditor_annotation()))
self.ui.checkBox_5.clicked.connect(lambda: (
self.use_existing_header()))
self.ui.pushButton_39.clicked.connect(lambda: (
self.do_hedit(update_add=True)))
self.ui.pushButton_38.clicked.connect(lambda: (
self.do_hedit(update_add=False)))
self.ui.listWidget_3.clicked.connect(lambda: (self.header_list()))
self.ui.listWidget_4.clicked.connect(lambda: (self.get_the_header()))
self.ui.listWidget_3.installEventFilter(self)
self.ui.listWidget_4.installEventFilter(self)
self.etc.log("Resetting Gui for CosmicC tab")
#set Cosmic Cleaner tab
self.ui.progressBar_5.setProperty("value", 0)
self.ui.label_11.setProperty("text", "")
self.cosmicC_annotation()
self.etc.log("Creating triggers for CosmicC tab")
#add triggers for Cosmic Cleaner
self.ui.pushButton_22.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_5),
self.cosmicC_annotation()))
self.ui.pushButton_21.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_5),
self.cosmicC_annotation(),
self.empty_display("COSMIC")))
self.ui.pushButton_23.clicked.connect(lambda: (self.do_cosmicC()))
self.ui.listWidget_5.clicked.connect(lambda: (self.display_cosmicC()))
self.ui.listWidget_5.installEventFilter(self)
self.etc.log("Resetting Gui for Calculator tab")
#set Caloculator tab
self.ui.progressBar_9.setProperty("value", 0)
self.ui.label_49.setProperty("text", "")
self.calculator_annotation()
self.etc.log("Creating triggers for Calculator")
#add triggers for Calculator
self.ui.groupBox_33.clicked.connect(lambda: (
self.calculator_annotation()))
self.ui.groupBox_34.clicked.connect(lambda: (
self.calculator_annotation()))
self.ui.groupBox_35.clicked.connect(lambda: (
self.calculator_annotation()))
self.ui.groupBox_14.clicked.connect(lambda: (
self.calculator_annotation()))
self.ui.pushButton_47.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_16),
self.calculator_annotation()))
self.ui.pushButton_46.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_16),
self.calculator_annotation()))
self.ui.pushButton_48.clicked.connect(lambda: (self.do_calculator()))
self.ui.listWidget_16.clicked.connect(lambda: (
self.header_list_calculator()))
self.ui.listWidget_16.installEventFilter(self)
self.etc.log("Resetting Gui for WCS tab")
#set WCS Editor tab
self.ui.progressBar_6.setProperty("value", 0)
self.ui.label_17.setProperty("text", "")
self.ui.label_14.setProperty("text", "")
self.wcs_annotation()
self.etc.log("Creating triggers for WCS tab")
#add triggers for WCS Editor
self.ui.pushButton_24.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_11),
self.wcs_annotation()))
self.ui.pushButton_25.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_11),
self.wcs_annotation()))
self.ui.pushButton_26.clicked.connect(lambda: (self.do_wcs()))
self.ui.listWidget_11.installEventFilter(self)
self.etc.log("Creating triggers for Sttings tab")
#add triggers for Settings
self.ui.pushButton_17.clicked.connect(lambda: (self.save_settings()))
self.ui.groupBox_5.clicked.connect(lambda: (
self.astrometrynet_check()))
self.etc.log("Creating triggers for Observatory Editor tab")
#add triggers for Observatory Editor
self.ui.pushButton_30.clicked.connect(lambda: (self.add_obs()))
self.ui.pushButton_29.clicked.connect(lambda: (self.rm_obs()))
self.ui.listWidget_12.clicked.connect(lambda: (
self.get_observat_prop()))
self.ui.listWidget_12.installEventFilter(self)
self.load_observat()
self.etc.log("Creating triggers for Log tab.")
#add triggers for Logs
self.ui.pushButton_28.clicked.connect(lambda: (self.reload_log()))
self.ui.pushButton_18.clicked.connect(lambda: (self.save_log()))
self.ui.pushButton_27.clicked.connect(lambda: (self.clear_log()))
self.reload_log()
self.etc.log("Resetting Gui for Graph tab")
#set Graph Editor
self.ui.label_31.setProperty("text", "")
self.etc.log("Creating triggers for Graph tab")
#set triggers Graph Editor tab
self.ui.pushButton_44.clicked.connect(lambda: (
self.get_graph_file_path()))
self.ui.pushButton_45.clicked.connect(lambda: (
self.plot_graph()))
self.ui.disp_align.canvas.fig.canvas.mpl_connect(
'button_press_event',self.mouseClick)
self.etc.log("Resetting Gui for HExtractor tab")
#set HExtractor Editor
self.ui.label_28.setProperty("text", "")
self.ui.progressBar_10.setProperty("value", 0)
self.hextractor_annotation()
self.ui.pushButton_57.clicked.connect(lambda: (
g.add_files(self, self.ui.listWidget_18),
self.hextractor_annotation()))
self.ui.pushButton_56.clicked.connect(lambda: (
g.rm(self, self.ui.listWidget_18),
self.hextractor_annotation()))
self.ui.listWidget_18.clicked.connect(lambda: (self.hextractor_list()))
self.ui.pushButton_58.clicked.connect(lambda: (self.hextractor()))
self.ui.listWidget_18.installEventFilter(self)
def eventFilter(self, source, event):
if(event.type() == 7 and source is self.ui.listWidget_18):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_18)
self.hextractor_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_12):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_12)
self.load_observat()
return True
if(event.type() == 7 and source is self.ui.listWidget_11):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_11)
self.wcs_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_16):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_16)
self.calculator_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_4):
if event.key() == 16777223:
self.do_hedit(update_add=False)
return True
if(event.type() == 7 and source is self.ui.listWidget_15):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_15)
return True
if(event.type() == 7 and source is self.ui.listWidget_13):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_13)
self.atrack_annotation()
self.empty_display("ATRACK")
return True
if(event.type() == 7 and source is self.ui.listWidget_5):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_5)
self.cosmicC_annotation()
self.empty_display("COSMIC")
return True
if(event.type() == 7 and source is self.ui.listWidget_3):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_3)
self.heditor_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_6):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_6)
self.calibration_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_7):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_7)
self.calibration_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_8):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_8)
self.calibration_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget_9):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_9)
self.calibration_annotation()
return True
if(event.type() == 7 and source is self.ui.listWidget):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget)
self.align_annotation()
self.empty_display("ALIGN")
return True
if(event.type() == 7 and source is self.ui.listWidget_2):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_2)
self.phot_annotation()
self.empty_display("PHOT")
return True
if(event.type() == 7 and source is self.ui.listWidget_20):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_20)
return True
if(event.type() == 7 and source is self.ui.listWidget_14):
if event.key() == 16777223:
g.rm(self, self.ui.listWidget_14)
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_13):
menu = QtWidgets.QMenu()
subMenu = menu.addMenu("Add files from")
subMenu.addAction('Header Editor', lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget_13),
self.phot_annotation()))
subMenu.addAction('Header Calculator', lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget_13),
self.phot_annotation()))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_2):
menu = QtWidgets.QMenu()
subMenu = menu.addMenu("Add files from")
subMenu.addAction('Header Calculator', lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget_2),
self.phot_annotation()))
subMenu.addAction('Cosmic Cleaner', lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget_2),
self.phot_annotation()))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_5):
menu = QtWidgets.QMenu()
menu.addAction('Check for possible over writes', lambda: (
self.check_over_write(self.ui.listWidget_5)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_11):
menu = QtWidgets.QMenu()
menu.addAction('Check for possible over writes', lambda: (
self.check_over_write(self.ui.listWidget_11)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget):
menu = QtWidgets.QMenu()
subMenu = menu.addMenu("Add files from")
subMenu.addAction('Header Editor', lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget),
self.align_annotation()))
subMenu.addAction('Header Calculator', lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget),
self.align_annotation()))
menu.addSeparator()
menu.addAction('Check for possible over writes', lambda: (
self.check_over_write(self.ui.listWidget_6)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_6):
menu = QtWidgets.QMenu()
subMenu = menu.addMenu("Add files from")
subMenu.addAction('Header Editor', lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget_6),
self.calibration_annotation()))
subMenu.addAction('Header Calculator', lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget_6),
self.calibration_annotation()))
menu.addSeparator()
menu.addAction('Check for possible over writes', lambda: (
self.check_over_write(self.ui.listWidget_6)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_7):
menu = QtWidgets.QMenu()
menu.addAction('Get Stats', lambda: (
self.fits_stats(self.ui.listWidget_7)))
menu.addSeparator()
subMenu = menu.addMenu("Add files from")
subMenu.addAction('Header Editor', lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget_7),
self.calibration_annotation()))
subMenu.addAction('Header Calculator', lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget_7),
self.calibration_annotation()))
menu.addSeparator()
menu.addAction("Check for possible duplicates", lambda: (
self.check_over_write(self.ui.listWidget_7, ow=False)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_8):
menu = QtWidgets.QMenu()
menu.addAction('Get Stats', lambda: (
self.fits_stats(self.ui.listWidget_8)))
menu.addSeparator()
subMenu = menu.addMenu("Add files from")
subMenu.addAction("Header Editor", lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget_8),
self.calibration_annotation()))
subMenu.addAction("Header Calculator", lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget_8),
self.calibration_annotation()))
menu.addSeparator()
menu.addAction("Check for possible duplicates", lambda: (
self.check_over_write(self.ui.listWidget_8, ow=False)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_9):
menu = QtWidgets.QMenu()
menu.addAction('Get Stats', lambda: (
self.fits_stats(self.ui.listWidget_9)))
menu.addSeparator()
subMenu = menu.addMenu("Add files from")
subMenu.addAction('Header Editor', lambda: (
self.bring_from(self.ui.listWidget_3,
self.ui.listWidget_9),
self.calibration_annotation()))
subMenu.addAction('Header Calculator', lambda: (
self.bring_from(self.ui.listWidget_16,
self.ui.listWidget_9),
self.calibration_annotation()))
menu.addSeparator()
menu.addAction('Check for possible duplicates', lambda: (
self.check_over_write(self.ui.listWidget_9, ow=False)))
menu.exec_(event.globalPos())
return True
if (event.type() == QtCore.QEvent.ContextMenu and
source is self.ui.listWidget_14):
menu = QtWidgets.QMenu()
menu.addAction('Export', self.export_coordinates)
menu.addAction('Import', self.import_coordinates)
menu.exec_(event.globalPos())
return True
return super(MyForm, self).eventFilter(source, event)
# def fwhm_clc(self, event):
# may_the_file = self.ui.listWidget_2.currentItem()
# if may_the_file is not None:
# the_file = may_the_file.text()
# if self.fit.is_fit(the_file):
# data = self.fit.data(the_file, table=False)
# objects = self.sex.find(data, only_best=False)
# all_sources_x = self.cnv.list2npar(objects['x'])
# all_sources_y = self.cnv.list2npar(objects['y'])
# wanted = self.cnv.list2npar([float(event.globalX()),
# float(event.globalY())])
# close = self.clc.get_closest_index(all_sources_x, all_sources_y, wanted)
# print(objects[close]['x'], objects[close]['y'])
# print(wanted)
# else:
# self.etc.log("The file is not a fit")
#
# else:
# #Log and display an error about not selected file
# self.etc.log("Nothing was selected in list")
# QtWidgets.QMessageBox.critical(
# self, ("MYRaf Error"), ("Please select a file"))
# PyQt5.QtCore.QPoint(941, 410)
def fwhm_clc(self, event):
print(event.globalPos())
def check_over_write(self, list_dev_s, ow=True):
all_lines = g.list_of_list(self, list_dev_s)
is_there = []
rm_list = []
if len(all_lines) > 0:
for it, line in enumerate(all_lines):
path, name = self.fop.get_base_name(line)
if not name in is_there:
is_there.append(name)
else:
rm_list.append(it)
if len(rm_list) > 0:
if ow:
the_ow = "over write"
else:
the_ow = "duplicate"
post_msg = "Do you want to remove the file"
if len(rm_list) == 1:
msg = "There is an {}. {}?".format(the_ow, post_msg)
else:
msg = "There are {} {}s. {}s?".format(len(rm_list),
the_ow, post_msg)
answ = g.question(self, msg)
if answ == QtWidgets.QMessageBox.Yes:
for rm_line in reversed(sorted(rm_list)):
list_dev_s.takeItem(rm_line)
else:
self.etc.log("Nothing is in source list. No overwrite expected.")
def bring_from(self, list_dev_s, list_dev_d):
all_lines = g.list_of_list(self, list_dev_s)
if len(all_lines) > 0:
g.add(self, list_dev_d, all_lines)
else:
#Log and display an error about empty listWidget
self.etc.log("Nothing found in source list")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"), ("Nothing found in source list"))
def export_coordinates(self):
if not g.is_list_empty(self, self.ui.listWidget_14):
coordinates = g.list_of_list(self, self.ui.listWidget_14)
dest = g.save_file_other(self)
#Check if the path is available
if dest:
f2w = open(dest, "w")
for coordinate in coordinates:
f2w.write("{}\n".format(coordinate))
f2w.close()
else:
#Log and display an error about empty listWidget
self.etc.log("Nothing to Export")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"), ("Please add some coordinates"))
#Reload log file to log view
self.reload_log()
def import_coordinates(self):
try:
file_path = g.get_file_path(self)
if self.fop.is_file(file_path):
list_to_add = []
f2r = open(file_path, "r")
for ln in f2r:
line = ln.replace("\n", "")
if ", " in line:
list_to_add.append(line)
g.add(self, self.ui.listWidget_14, list_to_add)
except Exception as e:
self.rtc.log(e)
#Reload log file to log view
self.reload_log()
def queue_header(self):
if len(g.list_of_selected(self, self.ui.listWidget_19)) > 0:
already_there_headers = g.list_of_list(self, self.ui.listWidget_20)
selected_headers = g.list_of_selected(self, self.ui.listWidget_19)
headers_to_add = []
for header in selected_headers:
if not header in already_there_headers:
headers_to_add.append(header)
g.add(self, self.ui.listWidget_20, headers_to_add)
def hextractor(self):
#Check if listWidget is empty
if not g.is_list_empty(self, self.ui.listWidget_18):
if len(g.list_of_selected(self, self.ui.listWidget_17)) > 0 :
self.ui.label.setText("Hextraction started")
dest = g.save_file_other(self)
if dest:
files = g.list_of_list(self, self.ui.listWidget_18)
headers = g.list_of_selected(self, self.ui.listWidget_17)
the_ret = []
out_put_header = ["File Name"]
for header in headers:
key = header.split("=>")[0]
out_put_header.append(key)
for it, file in enumerate(files):
if self.fit.is_fit(file):
line = [file]
for header in headers:
key = header.split("=>")[0]
the_header = self.fit.header(file, key)
if the_header is not None:
ext_header = str(the_header[1])
else:
ext_header = "None"
line.append(ext_header)
the_ret.append(line)
g.proc(self,
self.ui.progressBar_10, (it + 1) / len(files))
out_file = open(dest, "w")
out_file.write("#{}\n".format("\t".join(out_put_header)))
for ln in the_ret:
out_file.write("{}\n".format("\t".join(ln)))
out_file.close()
else:
self.etc.log("No path was given to save")
else:
self.etc.log("No enough input")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"),
("Please select header keys to extract"))
else:
#Log and display an error about empty listWidget
self.etc.log("Nothing to hextract")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"), ("Please add some files"))
#Reload log file to log view
self.reload_log()
#Get whole list of headers of a fits file
def hextractor_list(self):
#Get file's name
img = self.ui.listWidget_18.currentItem().text()
#Check if file does exist
if self.fit.is_fit(img):
try:
#Get all headers of give file
all_header = self.fit.header(img)
#convert [key, value] to "key=>value" format in an array
header_list = []
for i in all_header:
header_list.append("{}=>{}".format(i[0], i[1]))
#Replace whole list with header list
g.replace_list_con(self, self.ui.listWidget_17, header_list)
except Exception as e:
#Log error if any occurs
self.etc.log(e)
else:
#Log and display an error about not existing file
self.etc.log("Bad fits or no such (Header List)file({})".format(
img))
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"), ("Bad fits or no such a file"))
#Reload log file to log view
self.reload_log()
def hextractor_annotation(self):
img = g.list_lenght(self, self.ui.listWidget_18)
self.ui.label_28.setProperty(
"text", "header(s) of {0} files will be extracted".format(img))
#Reload log file to log view
self.reload_log()
#Plot a graph for given file
def plot_graph(self):
#Get file's path
path_to_file = self.ui.label_31.text()
#Check path
if self.fop.is_file(path_to_file):
#Load the file to an array
the_file = self.fop.read_array(path_to_file)
xs = None
ys = None
y2s = None
#Check if file was loaded
if the_file is not None:
#Try to get the wanted column for X axis
try:
xaxis = int(self.ui.comboBox_13.currentText())
xs = the_file[:, xaxis]
except Exception as e:
self.etc.log(e)
#Try to get the wanted column for Y axis
try:
yaxis = int(self.ui.comboBox_14.currentText())
ys = the_file[:, yaxis]
except Exception as e:
self.etc.log(e)
#Checl if second Y (Z) axis wanted
if self.ui.groupBox_29.isChecked():
#Try to get the wanted column for Y2 (Z) axis
try:
y2axis = int(self.ui.comboBox_15.currentText())
y2s = the_file[:, y2axis]
except Exception as e:
self.etc.log(e)
#Check if X and Y axises are valid
if xs is not None or ys is not None:
#Check if second Y (Z) axis wanted
if self.ui.groupBox_29.isChecked():
#Check if secod Y (Z) axis is valid
if y2s is not None:
#Check if it's second Y or Z axis
if self.ui.checkBox_7.isChecked():
self.etc.log("Plotting 3D Graph")
else:
self.etc.log("Plotting 2D Graph with overplot")
else:
self.etc.log("Y2 (Z) of axis is not correct")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"),
("Y2 (Z) of axis is not correct"))
else:
self.etc.log("Plotting 2D Graph")
else:
self.etc.log("X or Y of axis is not correct")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"),
("X or Y of axis is not correct"))
else:
self.etc.log("No such file({})".format(path_to_file))
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"),
("No such file({})".format(path_to_file)))
def fits_stats(self, list_widget):
#Getting list of files selected
selected = g.list_of_selected(self, list_widget)
#Check if any file(s) was selected
if len(selected) > 0:
stt = ""
#Loop for all selected files
for file in selected:
#Check if file exist
if self.fit.is_fit(file):
#Get status for file
the_stats = self.fit.fits_stat(file)
fname = self.fop.get_base_name(file)[1]
#Append file name and status to a string
stt = "{0}, Mean:{1:.2f}, Stdev:{2:.2f}\n{3}".format(
fname, the_stats['Mean'], the_stats['Stdev'], stt)
if not stt == "":
#Display results
QtWidgets.QMessageBox.information(
self, ("MYRaf Information"),
("Stats for files are as below:\n{}".format(stt)))
else:
#Log and display an error about 0 files selected
self.etc.log("Could not get any stats")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"),
("Given file(s) could not be analyed"))
else:
#Log and display an error about 0 files selected
self.etc.log("No file was selected to show stats")
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"),
("Please at least select one file to analyse"))
#Add header values to calculator's dropdown menus
def header_list_calculator(self):
#Get file's name
img = self.ui.listWidget_16.currentItem().text()
#Check if file does exist
if self.fit.is_fit(img):
try:
#Get all headers of give file
all_header = self.fit.header(img)
#convert [key, value] to "key=>value" format in an array
header_list = []
for i in all_header:
header_list.append("{}=>{}".format(i[0], i[1]))
#Replace whole combo with header list
g.c_replace_list_con(self, self.ui.comboBox_16, header_list)
g.c_replace_list_con(self, self.ui.comboBox_18, header_list)
g.c_replace_list_con(self, self.ui.comboBox_17, header_list)
g.c_replace_list_con(self, self.ui.comboBox_19, header_list)
g.c_replace_list_con(self, self.ui.comboBox_20, header_list)
except Exception as e:
#Log error if any occurs
self.etc.log(e)
else:
#Log and display an error about not existing file
self.etc.log("Bad fits or no such (Header List)file({})".format(
img))
QtWidgets.QMessageBox.critical(
self, ("MYRaf Error"), ("Bad fits or no such a file"))
#Reload log file to log view
self.reload_log()
#Calculate wanted values adn add them to header
def do_calculator(self):
#Check if listWidget is empty
if not g.is_list_empty(self, self.ui.listWidget_16):
#Check what calculations wanted
do_jd = self.ui.groupBox_33.isChecked()
do_airmass = self.ui.groupBox_34.isChecked()
do_imexam = self.ui.groupBox_35.isChecked()
do_utc = self.ui.groupBox_14.isChecked()
#Get pref for header keys
pref = self.ui.lineEdit_9.text()
#Check if JD, airmass or imexamine calculation wanted
if do_jd or do_airmass or do_imexam or do_utc: