-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtomography_gui.py
executable file
·1905 lines (1448 loc) · 64.2 KB
/
tomography_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
#!/usr/bin/env python
import traceback
import os
import sys
import matplotlib
import matplotlib.pylab as plt
import yaml
import threading
import numpy as np
import glob
from math import factorial
from matplotlib.figure import *
from PyQt4 import QtGui, QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4 import NavigationToolbar2QT as NavigationToolbar
from tardis import run_tardis
import logging
import StringIO
import tardis_log_parser as logparse
import time
import reddening as red
import create_input as cr
import abundances_plots as abplots
import lines_identification as lident
import tardis_gui as gui
import ionization_plot as ions
import tardis_multiple_runner as multirunner
import tardis_kromer_plot as tkp
elements = { 'neut': 0, 'h': 1, 'he': 2, 'li': 3, 'be': 4, 'b': 5, 'c': 6, 'n': 7, 'o': 8, 'f': 9, 'ne': 10, 'na': 11, 'mg': 12, 'al': 13, 'si': 14, 'p': 15, 's': 16, 'cl': 17, 'ar': 18, 'k': 19, 'ca': 20, 'sc': 21, 'ti': 22, 'v': 23, 'cr': 24, 'mn': 25, 'fe': 26, 'co': 27, 'ni': 28, 'cu': 29, 'zn': 30, 'ga': 31, 'ge': 32, 'as': 33, 'se': 34, 'br': 35, 'kr': 36, 'rb': 37, 'sr': 38, 'y': 39, 'zr': 40, 'nb': 41, 'mo': 42, 'tc': 43, 'ru': 44, 'rh': 45, 'pd': 46, 'ag': 47, 'cd': 48}
inv_elements = dict([(v,k) for k, v in elements.items()])
Zmax = 30
Nshellsfinal = 20
logging.basicConfig(filename="tardis_general.log", filemode = "w")
def savitzky_golay(y, window_size, order, deriv=0, rate=1):
r"""Smooth (and optionally differentiate) data with a Savitzky-Golay filter.
The Savitzky-Golay filter removes high frequency noise from data.
It has the advantage of preserving the original shape and
features of the signal better than other types of filtering
approaches, such as moving averages techniques.
Parameters
----------
y : array_like, shape (N,)
the values of the time history of the signal.
window_size : int
the length of the window. Must be an odd integer number.
order : int
the order of the polynomial used in the filtering.
Must be less then `window_size` - 1.
deriv: int
the order of the derivative to compute (default = 0 means only smoothing)
Returns
-------
ys : ndarray, shape (N)
the smoothed signal (or it's n-th derivative).
Notes
-----
The Savitzky-Golay is a type of low-pass filter, particularly
suited for smoothing noisy data. The main idea behind this
approach is to make for each point a least-square fit with a
polynomial of high order over a odd-sized window centered at
the point.
Examples
--------
t = np.linspace(-4, 4, 500)
y = np.exp( -t**2 ) + np.random.normal(0, 0.05, t.shape)
ysg = savitzky_golay(y, window_size=31, order=4)
import matplotlib.pyplot as plt
plt.plot(t, y, label='Noisy signal')
plt.plot(t, np.exp(-t**2), 'k', lw=1.5, label='Original signal')
plt.plot(t, ysg, 'r', label='Filtered signal')
plt.legend()
plt.show()
References
----------
.. [1] A. Savitzky, M. J. E. Golay, Smoothing and Differentiation of
Data by Simplified Least Squares Procedures. Analytical
Chemistry, 1964, 36 (8), pp 1627-1639.
.. [2] Numerical Recipes 3rd Edition: The Art of Scientific Computing
W.H. Press, S.A. Teukolsky, W.T. Vetterling, B.P. Flannery
Cambridge University Press ISBN-13: 9780521880688
"""
try:
window_size = np.abs(np.int(window_size))
order = np.abs(np.int(order))
except ValueError, msg:
raise ValueError("window_size and order have to be of type int")
if window_size % 2 != 1 or window_size < 1:
raise TypeError("window_size size must be a positive odd number")
if window_size < order + 2:
raise TypeError("window_size is too small for the polynomials order")
order_range = range(order+1)
half_window = (window_size -1) // 2
# precompute coefficients
b = np.mat([[k**i for i in order_range] for k in range(-half_window, half_window+1)])
m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv)
# pad the signal at the extremes with
# values taken from the signal itself
firstvals = y[0] - np.abs( y[1:half_window+1][::-1] - y[0] )
lastvals = y[-1] + np.abs(y[-half_window-1:-1][::-1] - y[-1])
y = np.concatenate((firstvals, y, lastvals))
return np.convolve( m[::-1], y, mode='valid')
class inputwriterthread(QtCore.QThread):
starttrigger = QtCore.pyqtSignal(int)
endtrigger = QtCore.pyqtSignal(int)
def __init__(self, parent):
super(inputwriterthread, self).__init__(parent)
self.parent = parent
def run(self):
self.starttrigger.emit(0)
try:
self.parent.read_runid()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print("Warning: could not determine runids")
self.endtrigger.emit(0)
return False
self.parent.save_abundance_file()
self.endtrigger.emit(0)
class tardisthread(QtCore.QThread):
starttrigger = QtCore.pyqtSignal(int)
endtrigger = QtCore.pyqtSignal(int)
def __init__(self, parent):
super(tardisthread, self).__init__(parent)
self.parent = parent
def run(self):
self.starttrigger.emit(0)
try:
self.parent.read_runid()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print("Warning: could not determine runids")
self.endtrigger.emit(1)
return False
try:
self.parent.define_numberOfEpochs()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print("Warning: could not determine the number of epochs")
self.endtrigger.emit(1)
return False
try:
self.parent.define_run_mode()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
self.endtrigger.emit(1)
return False
if self.parent.run_mode is not None:
try:
print self.parent.run_mode
self.Nthreads = 16
multirunner.write_submit(self.Nthreads, self.parent.runid, self.parent.run_mode)
self.files = []
self.t_end = time.time() + 6000
while time.time() < self.t_end:
for file in glob.glob("completed_run_%05d*" % self.parent.runid):
self.files.append(file)
if len(self.files) == len(self.parent.numberOfEpochs):
break
time.sleep(30)
[os.remove(i) for i in self.files]
self.endtrigger.emit(0)
print("Tardis run done")
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print(ex)
print("Warning: Tardis run failed")
self.endtrigger.emit(1)
return False
else:
print("Warning: could not determine in which system to run Tardis." + "\n" + " Please choose between local machine or batch.")
self.endtrigger.emit(1)
class MatplotlibWidget(FigureCanvas):
def __init__(self, parent, fig=None):
self.parent = parent
self.figure = Figure()
self.cid = {}
if fig is None:
self.ax = self.figure.add_subplot(111)
elif fig == "convergence":
self.ax = [self.figure.add_subplot(211), self.figure.add_subplot(212)]
self.cb = None
self.span = None
super(MatplotlibWidget, self).__init__(self.figure)
super(MatplotlibWidget, self).setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
super(MatplotlibWidget, self).updateGeometry()
self.toolbar = NavigationToolbar(self, parent)
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.current_data = None
self.old_data = None
self.obs_spectrum = None
self.current_spectrum = None
self.old_spectrum = None
self.reddening = None
self.distance_modulus = None
self.tardis_config = None
self.tardis_running = 0
self.rescale_model = False
self.save_model = False
self.redden_model = False
self.virtual_model = False
self.runlocalmachine = False
self.runbatch = False
self.show_oldrun = False
self.filter_model = False
self.mdl = None
self.mixed_lines = None
#self.raw_abund_data = None
self.observation_data = None
self.lamax = None
self.lamin = None
self.nepochabundances = None
self.nepochlines = None
self.nepochkromer = None
self.nepochplot = None
self.ion = None
self.nepochion = None
self.addshell_index = 0
self.removeshell_index = 0
self.window = None
self.run_mode = None
self.numberOfEpochs = None
self.krom = None
self.table = QtGui.QTableWidget(5,Zmax+7,self)
self.table.setHorizontalHeaderLabels(["active", "Vmin", "Vmax", "t", "logL/Lsun", "lam min", "lam max"] + [inv_elements[z].capitalize() for z in xrange(1, Zmax+1)])
self.addshell_entry = QtGui.QLineEdit(self)
self.removeshell_entry = QtGui.QLineEdit(self)
self.runid_entry = QtGui.QLineEdit(self)
self.oldrunid_entry = QtGui.QLineEdit(self)
self.runidplot_entry = QtGui.QLineEdit(self)
self.oldrunidplot_entry = QtGui.QLineEdit(self)
self.nepochplot_entry = QtGui.QLineEdit(self)
self.risetime_entry = QtGui.QLineEdit(self)
self.distance_entry = QtGui.QLineEdit(self)
self.reddening_entry = QtGui.QLineEdit(self)
self.window_entry = QtGui.QLineEdit(self)
self.savemodel_cbox = QtGui.QCheckBox("Save Model", self)
self.showoldrun_cbox = QtGui.QCheckBox("Show Previous Run", self)
self.filtermodel_cbox = QtGui.QCheckBox("Apply Savitzky Golay Filter", self)
self.runlocalmachine_cbox = QtGui.QCheckBox("Run at Local Machine", self)
self.runbatch_cbox = QtGui.QCheckBox("Run at Batch System", self)
self.appendshell_button = QtGui.QPushButton("Append Shell")
self.addshell_button = QtGui.QPushButton("Add Shell")
self.removeshell_button = QtGui.QPushButton("Remove Shell")
self.createinput_button = QtGui.QPushButton("Create Input")
self.loadabundances_button = QtGui.QPushButton("Load Abundances")
self.saveabundances_button = QtGui.QPushButton("Save Abundances and Tardis Files")
self.runtardis_button = QtGui.QPushButton("Run Tardis")
self.loadobservation_button = QtGui.QPushButton("Load Observation")
self.updateplots_button = QtGui.QPushButton("Update Plots")
self.showgui_button = QtGui.QPushButton("Tardis Gui")
self.virtualmodel_cbox = QtGui.QCheckBox("Show Virtual Spectrum", self)
self.rescalemodel_cbox = QtGui.QCheckBox("Apply Distance Modulus", self)
self.reddenmodel_cbox = QtGui.QCheckBox("Apply Reddening", self)
self.clearplot_button = QtGui.QPushButton("Clear Figure")
self.bbconvergence_button = QtGui.QPushButton("Show Black-Body Convergence")
self.runidconvergence_entry = QtGui.QLineEdit(self)
self.epochidconvergence_entry = QtGui.QLineEdit(self)
self.abundancesraw_button=QtGui.QPushButton("Raw Abundances")
self.abundancesmix_cbox = QtGui.QCheckBox("Mixed Abundances", self)
self.runidabundances_entry= QtGui.QLineEdit(self)
self.nepochabundances_entry = QtGui.QLineEdit(self)
self.tradsws_button=QtGui.QPushButton("Radiation Temperatures and Dilution Factors")
self.runidtradsws_entry=QtGui.QLineEdit(self)
self.epochidtradsws_entry=QtGui.QLineEdit(self)
self.lineshist_button=QtGui.QPushButton("Last Element Contribution")
self.runidlines_entry=QtGui.QLineEdit(self)
self.lamin_entry=QtGui.QLineEdit(self)
self.lamax_entry=QtGui.QLineEdit(self)
self.nepochlines_entry = QtGui.QLineEdit(self)
self.lineskromer_button=QtGui.QPushButton("Kromer Plot")
self.runidkromer_entry=QtGui.QLineEdit(self)
self.nepochkromer_entry = QtGui.QLineEdit(self)
self.ion_button=QtGui.QPushButton("Ionization Plot")
self.runidion_entry=QtGui.QLineEdit(self)
self.ion_entry=QtGui.QLineEdit(self)
self.nepochion_entry = QtGui.QLineEdit(self)
self.addshell_entry.setText("0")
self.removeshell_entry.setText("0")
self.spectrum_figure = MatplotlibWidget(self)
self.convergence_figure = MatplotlibWidget(self)
self.abundances_figure= MatplotlibWidget(self)
self.tradsws_figure=MatplotlibWidget(self, fig = "convergence")
self.lines_figure=MatplotlibWidget(self)
self.kromer_figure=MatplotlibWidget(self)
self.ion_figure=MatplotlibWidget(self)
table_hbox = QtGui.QHBoxLayout()
table_hbox.addWidget(self.table)
abundance_control_grid = QtGui.QGridLayout()
abundance_control_grid.addWidget(QtGui.QLabel("Rise time:"), 0, 0)
abundance_control_grid.addWidget(self.risetime_entry, 0, 1)
abundance_control_grid.addWidget(QtGui.QLabel("Model: Run ID"), 0, 2)
abundance_control_grid.addWidget(self.runid_entry, 0, 3)
abundance_control_grid.addWidget(QtGui.QLabel("Model: Old run ID"), 0, 4)
abundance_control_grid.addWidget(self.oldrunid_entry, 0, 5)
abundance_control_grid.addWidget(self.loadabundances_button, 1, 0)
abundance_control_grid.addWidget(self.appendshell_button, 2, 0)
abundance_control_grid.addWidget(self.removeshell_button, 2, 1)
abundance_control_grid.addWidget(self.removeshell_entry, 3, 1)
abundance_control_grid.addWidget(self.addshell_button, 2, 3)
abundance_control_grid.addWidget(self.addshell_entry, 3, 3)
abundance_control_grid.addWidget(self.saveabundances_button, 4, 0)
abundance_control_grid.addWidget(self.runlocalmachine_cbox, 4, 1)
abundance_control_grid.addWidget(self.runbatch_cbox, 4, 2)
abundance_control_grid.addWidget(self.runtardis_button, 5, 0)
abundance_control_grid.addWidget(self.savemodel_cbox, 5, 1)
spectrum_control_grid = QtGui.QGridLayout()
spectrum_control_grid.addWidget(QtGui.QLabel("Plotting: Run ID"), 0, 0)
spectrum_control_grid.addWidget(self.runidplot_entry, 0, 1)
spectrum_control_grid.addWidget(QtGui.QLabel("Plotting: Old run ID"), 0, 2)
spectrum_control_grid.addWidget(self.oldrunidplot_entry, 0, 3)
spectrum_control_grid.addWidget(QtGui.QLabel("Epoch"), 0, 4)
spectrum_control_grid.addWidget(self.nepochplot_entry, 0 ,5)
spectrum_control_grid.addWidget(self.loadobservation_button, 1, 0)
spectrum_control_grid.addWidget(self.updateplots_button, 1, 1)
spectrum_control_grid.addWidget(self.clearplot_button, 1, 2)
spectrum_control_grid.addWidget(self.showgui_button, 1, 3)
spectrum_control_grid.addWidget(self.virtualmodel_cbox, 2, 0)
spectrum_control_grid.addWidget(self.showoldrun_cbox, 2, 1)
spectrum_control_grid.addWidget(self.filtermodel_cbox, 2, 2)
spectrum_control_grid.addWidget(self.rescalemodel_cbox, 2, 3)
spectrum_control_grid.addWidget(self.reddenmodel_cbox, 2, 4)
spectrum_control_grid.addWidget(QtGui.QLabel("Distance modulus"), 3, 0)
spectrum_control_grid.addWidget(self.distance_entry, 3, 1)
spectrum_control_grid.addWidget(QtGui.QLabel("Reddening E(B-V)"), 3, 2)
spectrum_control_grid.addWidget(self.reddening_entry, 3, 3)
spectrum_control_grid.addWidget(QtGui.QLabel("Filter (Window Size)"), 3, 4)
spectrum_control_grid.addWidget(self.window_entry, 3, 5)
convergence_control_grid = QtGui.QGridLayout()
convergence_control_grid.addWidget(QtGui.QLabel("Run ID: "), 0, 0)
convergence_control_grid.addWidget(self.runidconvergence_entry, 0, 1)
convergence_control_grid.addWidget(QtGui.QLabel("Epoch: "), 0, 2)
convergence_control_grid.addWidget(self.epochidconvergence_entry, 0, 3)
convergence_control_grid.addWidget(self.bbconvergence_button, 1, 0)
abundances_control_grid= QtGui.QGridLayout()
abundances_control_grid.addWidget(QtGui.QLabel("Run ID: "), 0, 0)
abundances_control_grid.addWidget(self.runidabundances_entry, 0, 1)
abundances_control_grid.addWidget(QtGui.QLabel("Epoch: "), 0, 2)
abundances_control_grid.addWidget(self.nepochabundances_entry, 0, 3)
abundances_control_grid.addWidget(self.abundancesraw_button, 1, 0)
abundances_control_grid.addWidget(self.abundancesmix_cbox, 1, 1)
tradsws_control_grid= QtGui.QGridLayout()
tradsws_control_grid.addWidget(QtGui.QLabel("Run ID: "), 0, 0)
tradsws_control_grid.addWidget(self.runidtradsws_entry, 0, 1)
tradsws_control_grid.addWidget(QtGui.QLabel("Epoch: "), 0, 2)
tradsws_control_grid.addWidget(self.epochidtradsws_entry, 0, 3)
tradsws_control_grid.addWidget(self.tradsws_button, 1, 0)
lines_control_grid= QtGui.QGridLayout()
lines_control_grid.addWidget(QtGui.QLabel("Run ID: "), 0, 0)
lines_control_grid.addWidget(self.runidlines_entry, 0, 1)
lines_control_grid.addWidget(QtGui.QLabel("Epoch: "), 0, 2)
lines_control_grid.addWidget(self.nepochlines_entry, 0, 3)
lines_control_grid.addWidget(QtGui.QLabel("Lambda Min: "), 0, 4)
lines_control_grid.addWidget(self.lamin_entry, 0, 5)
lines_control_grid.addWidget(QtGui.QLabel("Lambda Max: "), 0, 6)
lines_control_grid.addWidget(self.lamax_entry, 0, 7)
lines_control_grid.addWidget(self.lineshist_button, 1, 0)
kromer_control_grid= QtGui.QGridLayout()
kromer_control_grid.addWidget(QtGui.QLabel("Run ID: "), 0, 0)
kromer_control_grid.addWidget(self.runidkromer_entry, 0, 1)
kromer_control_grid.addWidget(QtGui.QLabel("Epoch: "), 0, 2)
kromer_control_grid.addWidget(self.nepochkromer_entry, 0, 3)
kromer_control_grid.addWidget(self.lineskromer_button, 1, 0)
ion_control_grid = QtGui.QGridLayout()
ion_control_grid.addWidget(QtGui.QLabel("Run ID: "), 0, 0)
ion_control_grid.addWidget(self.runidion_entry, 0, 1)
ion_control_grid.addWidget(QtGui.QLabel("Epoch: "), 0, 2)
ion_control_grid.addWidget(self.nepochion_entry, 0, 3)
ion_control_grid.addWidget(QtGui.QLabel("Name of the Element: "), 0, 4)
ion_control_grid.addWidget(self.ion_entry, 0, 5)
ion_control_grid.addWidget(self.ion_button, 0, 6)
abundance_vbox = QtGui.QVBoxLayout()
abundance_vbox.addLayout(table_hbox)
abundance_vbox.addLayout(abundance_control_grid)
diagnostics_tab_widget = QtGui.QTabWidget()
spectrum_tab = QtGui.QWidget()
spectrum_vbox = QtGui.QVBoxLayout(spectrum_tab)
spectrum_vbox.addWidget(self.spectrum_figure)
spectrum_vbox.addWidget(self.spectrum_figure.toolbar)
spectrum_vbox.addLayout(spectrum_control_grid)
diagnostics_tab_widget.addTab(spectrum_tab, "Spectrum")
convergence_tab = QtGui.QWidget()
convergence_vbox = QtGui.QVBoxLayout(convergence_tab)
convergence_vbox.addWidget(self.convergence_figure)
convergence_vbox.addWidget(self.convergence_figure.toolbar)
convergence_vbox.addLayout(convergence_control_grid)
diagnostics_tab_widget.addTab(convergence_tab, "Convergence")
abundances_tab= QtGui.QWidget()
abundances_vbox= QtGui.QVBoxLayout(abundances_tab)
abundances_vbox.addWidget(self.abundances_figure)
abundances_vbox.addWidget(self.abundances_figure.toolbar)
abundances_vbox.addLayout(abundances_control_grid)
diagnostics_tab_widget.addTab(abundances_tab, "Abundances")
tradsws_tab= QtGui.QWidget()
tradsws_vbox= QtGui.QVBoxLayout(tradsws_tab)
tradsws_vbox.addWidget(self.tradsws_figure)
tradsws_vbox.addWidget(self.tradsws_figure.toolbar)
tradsws_vbox.addLayout(tradsws_control_grid)
diagnostics_tab_widget.addTab(tradsws_tab, "Trads and Ws")
lines_tab= QtGui.QWidget()
lines_vbox= QtGui.QVBoxLayout(lines_tab)
lines_vbox.addWidget(self.lines_figure)
lines_vbox.addWidget(self.lines_figure.toolbar)
lines_vbox.addLayout(lines_control_grid)
diagnostics_tab_widget.addTab(lines_tab, "Lines Identification")
kromer_tab= QtGui.QWidget()
kromer_vbox= QtGui.QVBoxLayout(kromer_tab)
kromer_vbox.addWidget(self.kromer_figure)
kromer_vbox.addWidget(self.kromer_figure.toolbar)
kromer_vbox.addLayout(kromer_control_grid)
diagnostics_tab_widget.addTab(kromer_tab, "Kromer Plot")
ion_tab= QtGui.QWidget()
ion_vbox= QtGui.QVBoxLayout(ion_tab)
ion_vbox.addWidget(self.ion_figure)
ion_vbox.addWidget(self.ion_figure.toolbar)
ion_vbox.addLayout(ion_control_grid)
diagnostics_tab_widget.addTab(ion_tab, "Ionization")
main_hbox = QtGui.QHBoxLayout()
main_hbox.addWidget(diagnostics_tab_widget)
main_hbox.addLayout(abundance_vbox)
self.setLayout(main_hbox)
self.addshell_entry.textChanged[str].connect(self.addshell_entry_changed)
self.removeshell_entry.textChanged[str].connect(self.removeshell_entry_changed)
self.oldrunid_entry.textChanged[str].connect(self.oldrunid_entry_changed)
self.runid_entry.textChanged[str].connect(self.runid_entry_changed)
self.nepochplot_entry.textChanged[str].connect(self.nepochplot_entry_changed)
self.risetime_entry.textChanged[str].connect(self.risetime_entry_changed)
self.addshell_button.clicked.connect(self.on_addshell_clicked)
self.removeshell_button.clicked.connect(self.on_removeshell_clicked)
self.appendshell_button.clicked.connect(self.on_appendshell_clicked)
self.loadabundances_button.clicked.connect(self.load_abundance_file)
self.saveabundances_button.clicked.connect(self.save_input_files)
self.loadobservation_button.clicked.connect(self.load_observation_file)
self.bbconvergence_button.clicked.connect(self.plot_bb_convergence)
self.abundancesraw_button.clicked.connect(self.plot_abundances_raw)
self.abundancesmix_cbox.stateChanged.connect(self.abundancesmix_changed)
self.tradsws_button.clicked.connect(self.plot_tradsws_convergence)
self.lineshist_button.clicked.connect(self.plot_lineshist)
self.lineskromer_button.clicked.connect(self.plot_lineskromer)
self.ion_button.clicked.connect(self.plot_ion)
self.runtardis_button.clicked.connect(self.start_tardis)
self.updateplots_button.clicked.connect(self.update_plots)
self.distance_entry.textChanged[str].connect(self.distance_entry_changed)
self.reddening_entry.textChanged[str].connect(self.reddening_entry_changed)
self.window_entry.textChanged[str].connect(self.window_entry_changed)
self.savemodel_cbox.stateChanged.connect(self.savemodel_changed)
self.rescalemodel_cbox.stateChanged.connect(self.rescalemodel_changed)
self.reddenmodel_cbox.stateChanged.connect(self.reddenmodel_changed)
self.virtualmodel_cbox.stateChanged.connect(self.virtualmodel_changed)
self.showoldrun_cbox.stateChanged.connect(self.showoldrun_changed)
self.filtermodel_cbox.stateChanged.connect(self.filtermodel_changed)
self.runidplot_entry.textChanged[str].connect(self.runidplot_entry_changed)
self.oldrunidplot_entry.textChanged[str].connect(self.oldrunidplot_entry_changed)
self.showgui_button.clicked.connect(self.show_gui)
self.runidconvergence_entry.textChanged[str].connect(self.runidconvergence_entry_changed)
self.epochidconvergence_entry.textChanged[str].connect(self.epochidconvergence_entry_changed)
self.runidtradsws_entry.textChanged[str].connect(self.runidtradsws_entry_changed)
self.epochidtradsws_entry.textChanged[str].connect(self.epochidtradsws_entry_changed)
self.runidabundances_entry.textChanged[str].connect(self.runidabundances_entry_changed)
self.nepochabundances_entry.textChanged[str].connect(self.nepochabundances_entry_changed)
self.nepochlines_entry.textChanged[str].connect(self.nepochlines_entry_changed)
self.nepochion_entry.textChanged[str].connect(self.nepochion_entry_changed)
self.runidlines_entry.textChanged[str].connect(self.runidlines_entry_changed)
self.lamin_entry.textChanged[str].connect(self.lamin_entry_changed)
self.lamax_entry.textChanged[str].connect(self.lamax_entry_changed)
self.runidkromer_entry.textChanged[str].connect(self.runidkromer_entry_changed)
self.nepochkromer_entry.textChanged[str].connect(self.nepochkromer_entry_changed)
self.runidion_entry.textChanged[str].connect(self.runidion_entry_changed)
self.ion_entry.textChanged[str].connect(self.ion_entry_changed)
self.clearplot_button.clicked.connect(self.clear_plot)
self.runlocalmachine_cbox.stateChanged.connect(self.runlocalmachine_changed)
self.runbatch_cbox.stateChanged.connect(self.runbatch_changed)
self.setGeometry(300, 300, 400, 300)
self.setWindowTitle('Tardis Abundance Tomography')
self.show()
def show_gui(self):
if self.mdl is None:
print("Warning: no model available")
return False
mygui = gui.ModelViewer()
mygui.show_model(self.mdl)
#mygui = gui.Tardis()
#mygui.show_model(self.mdl)
def filtermodel_changed(self, state):
if state == QtCore.Qt.Checked:
self.filter_model = True
else:
self.filter_model = False
def showoldrun_changed(self, state):
if state == QtCore.Qt.Checked:
self.show_oldrun = True
else:
self.show_oldrun = False
self.old_spectrum.remove()
self.old_spectrum = None
self.old_data = None
#self.spectrum_figure.figure.canvas.draw()
def abundancesmix_changed(self, state):
if state == QtCore.Qt.Checked:
self.plot_abundances_mix()
else:
[line.remove() for line in self.mixed_lines]
self.mixed_lines = None
self.abundances_figure.figure.canvas.draw()
def virtualmodel_changed(self, state):
if state == QtCore.Qt.Checked:
self.virtual_model = True
else:
self.virtual_model = False
def reddenmodel_changed(self, state):
if state == QtCore.Qt.Checked:
self.redden_model = True
else:
self.redden_model = False
def savemodel_changed(self, state):
if state == QtCore.Qt.Checked:
self.save_model = True
else:
self.save_model = False
def rescalemodel_changed(self, state):
if state == QtCore.Qt.Checked:
self.rescale_model = True
else:
self.rescale_model = False
def runlocalmachine_changed(self, state):
if state == QtCore.Qt.Checked:
self.runlocalmachine = True
else:
self.runlocalmachine = False
def runbatch_changed(self, state):
if state == QtCore.Qt.Checked:
self.runbatch = True
else:
self.runbatch = False
def savingfiles_started(self, sig):
print("Saving files started")
self.runtardis_button.setEnabled(False)
def savingfiles_ended(self, sig):
print("Saving files ended")
self.runtardis_button.setEnabled(True)
def read_reddening(self):
try:
reddening = float(self.reddeningtext)
except ValueError:
print("Warning: invalid reddening '%s'" % self.reddeningtext)
raise Exception
self.reddening = reddening
def define_run_mode(self):
if self.runbatch or self.runlocalmachine:
if self.runbatch:
self.run_mode = "batch"
if self.runlocalmachine:
self.run_mode = "local"
else:
self.run_mode = None
def define_numberOfEpochs(self):
return self.numberOfEpochs
def read_window(self):
try:
window = int(self.windowtext)
except ValueError:
print("Warning: invalid reddening '%s'" % self.windowtext)
raise Exception
self.window = window
def read_lamin(self):
try:
lamin = float(self.lamintext)
except ValueError:
print("Warning: invalid minimum value '%s' for lambda" % self.lamintext)
raise Exception
self.lamin = lamin
def read_lamax(self):
try:
lamax = float(self.lamaxtext)
except ValueError:
print("Warning: invalid maximum value '%s' for lambda" % self.lamaxtext)
raise Exception
self.lamax = lamax
def read_risetime(self):
try:
risetime = float(self.risetimetext)
except ValueError:
print("Warning: invalid risetime '%s'" % self.risetimetext)
raise Exception
self.risetime = risetime
def read_runid(self):
try:
runid = int(self.runidtext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidtext)
raise Exception
try:
oldrunid = int(self.oldrunidtext)
except ValueError:
print("Warning: invalid old runid '%s'" % self.oldrunidtext)
raise Exception
self.runid = runid
self.oldrunid = oldrunid
def read_nepochplot(self):
try:
nepochplot = int(self.nepochplottext)
except ValueError:
print ("Warning: invalid epoch '%s'" % nepochplottext)
raise Exception
self.nepochplot = nepochplot
def read_runidplot(self):
try:
runid = int(self.runidplottext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidplottext)
raise Exception
try:
oldrunid = int(self.oldrunidplottext)
except ValueError:
print("Warning: invalid old runid '%s'" % self.oldrunidplottext)
raise Exception
self.runidplot = runid
self.oldrunidplot = oldrunid
def read_epochidconvergence(self):
try:
epochid = int(self.epochidconvergencetext)
except ValueError:
print("Warning: invalid epochid '%s'" % self.epochidconvergencetext)
raise Exception
self.epochidconvergence = epochid
def read_epochidtradsws(self):
try:
epochid = int(self.epochidtradswstext)
except ValueError:
print("Warning: invalid epochid '%s'" % self.epochidtradsws)
raise Exception
self.epochidtradsws = epochid
def read_runidconvergence(self):
try:
runid = int(self.runidconvergencetext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidconvergencetext)
raise Exception
self.runidconvergence = runid
def read_runidabundances(self):
try:
runid = int(self.runidabundancestext)
except ValueError:
print ("Warning: invalid runid '%s'" % self.runidabundancestext)
raise Exception
self.runidabundances = runid
def read_nepochabundances(self):
try:
nepochabundances = int(self.nepochabundancestext)
except ValueError:
print ("Warning: invalid epoch '%s'" % self.nepochabundancestext)
raise Exception
self.nepochabundances = nepochabundances
def read_nepochlines(self):
try:
nepochlines = int(self.nepochlinestext)
except ValueError:
print ("Warning: invalid epoch '%s'" % self.nepochlinestext)
raise Exception
self.nepochlines = nepochlines
def read_nepochion(self):
try:
nepochion = int(self.nepochiontext)
except ValueError:
print ("Warning: invalid epoch '%s'" % self.nepochiontext)
raise Exception
self.nepochion = nepochion
def read_runidtradsws(self):
try:
runid = int(self.runidtradswstext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidtradswstext)
raise Exception
self.runidtradsws = runid
def read_runidlines(self):
try:
runid = int(self.runidlinestext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidlinestext)
raise Exception
self.runidlines = runid
def read_runidkromer(self):
try:
runid = int(self.runidkromertext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidkromertext)
raise Exception
self.runidkromer = runid
def read_nepochkromer(self):
try:
nepochkromer = int(self.nepochkromertext)
except ValueError:
print ("Warning: invalid epoch '%s'" % self.nepochkromertext)
raise Exception
self.nepochkromer = nepochkromer
def read_runidion(self):
try:
runid = int(self.runidiontext)
except ValueError:
print("Warning: invalid runid '%s'" % self.runidiontext)
raise Exception
self.runidion = runid
def read_ion(self):
try:
ion = str(self.iontext)
except ValueError:
print("Warning: invalid runid '%f'" % self.iontext)
raise Exception
self.ion = ion
def start_tardis(self):
try:
self.read_runid()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print("Warning: could not determine runids")
return False
fname = "tardis_%05d_%d.yml" % (self.runid, max(self.numberOfEpochs))
try:
self.tardis_config = yaml.safe_load(open(fname, "r"))
except IOError:
print("Warning: could not open Tardis config '%s'" % fname)
return False
thread = tardisthread(self)
thread.starttrigger.connect(self.tardis_started)
thread.endtrigger.connect(self.tardis_ended)
thread.start()
def tardis_started(self, sig):
self.runtardis_button.setEnabled(False)
def tardis_ended(self, sig):
self.runtardis_button.setEnabled(True)
if sig == 0:
self.finish_tardis_run()
def finish_tardis_run(self):
try:
self.read_runid()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print("Warning: could not determine runids")
return False
try:
self.define_numberOfEpochs()
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
print(ex_type)
print("Warning: could not determine the number of epochs")
return False
self.runidplot_entry.setText(str(self.runid))
self.oldrunidplot_entry.setText(str(self.oldrunid))
self.nepochplot_entry.setText(str(max(self.numberOfEpochs)))
self.runidconvergence_entry.setText(str(self.runid))
self.epochidconvergence_entry.setText(str(max(self.numberOfEpochs)))
self.runidabundances_entry.setText(str(self.runid))
self.nepochabundances_entry.setText(str(max(self.numberOfEpochs)))
self.runidtradsws_entry.setText(str(self.runid))
self.epochidtradsws_entry.setText(str(max(self.numberOfEpochs)))
self.runidlines_entry.setText(str(self.runid))
self.nepochlines_entry.setText(str(max(self.numberOfEpochs)))
self.runidkromer_entry.setText(str(self.runid))
self.nepochkromer_entry.setText(str(max(self.numberOfEpochs)))
self.runidion_entry.setText(str(self.runid))
self.nepochion_entry.setText(str(max(self.numberOfEpochs)))