-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_models.py
executable file
·2429 lines (1724 loc) · 84.2 KB
/
view_models.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
"""
This file is part of Sprout.
Sprout is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Sprout is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Sprout. If not, see <http://www.gnu.org/licenses/>.
Copyright 2013, Michihiro Takami, Hyosun Kim, Jennifer Karr
All rights reserved.
Contact: Jennifer Karr ([email protected])
-----
This is the GUI for viewing models created by run_models.py
Version 1.0 (release) Last Updated May 25 2013
"""
from Tkinter import *
import tkMessageBox
import tkFileDialog
from pylab import *
import scipy
import scipy.stats
import numpy
import numpy.ma as ma
from numpy import outer
import pickle
import pyfits
import Pmw
import os
import string
import sys
import convolve_psf as c
import congrid
from textfile_window import *
##------------------------------------------------------------------------
class cmap_window(Frame):
def __init__(self,master=None):
"""
This routine creates a popup window to select colour maps, and will display
a view of the available colour maps.
"""
Frame.__init__(self,master)
##CURRENT SPECTRAL MAP AND LIST OF OPTIONS
self.cmap='spectral'
##LIST OF COLOUR MAPS
self.cmaps=['spectral','autumn','bone','cool','copper','flag','gray','hot','hsv','jet','pink','prism','spring','summer','winter']
self.cmaps_num=range(15)
self.col=IntVar() ##VARIABE TO HOLD COLOUR CHOICE
##CREATE WINDOW AND GET LIST
top=Toplevel(self)
fm=Frame(top,relief=RAISED, bd=1)
mb2=Button(fm,text='Done',command=top.destroy).pack(side=LEFT,anchor=W)
mb2=Button(fm,text='Show Colours',command=self.cmap_show).pack(side=LEFT,anchor=W)
fm.pack()
fm=Frame(top,relief=RAISED, bd=1)
i=0
for i in range(len(self.cmaps)):
col=self.cmaps[i]
mb2=Radiobutton(fm,text=col,variable=self.col,value=i,command=self.cmap_get).pack(side=TOP,anchor=W)
fm.pack()
##SET TO DEFAULT VALUE
self.col.set(0)
##------------------------------------------------------------------------
def cmap_get(self):
##SET THE COLOUR MAP
self.cmap=self.cmaps[self.col.get()]
##------------------------------------------------------------------------
def cmap_show(self):
"""
A routine to show the availible colour maps in graphical form.
"""
##SHOW THE AVAILABLE COLOUR MAPS GRAPHICALLY
##CREATE A NEW FIGURE AND CLEAR IT
fig=figure(3)
clf()
##CREATE AN ARRAY THAT VARIES FROM ZERO TO ONE IN THE X AXIS,
##AND IS CONSTANT IN THE Y AXIS
a=outer(ones(10),arange(0,1,0.01))
i=0
##FOR EACH COLOUR
for col in self.cmaps:
subplot(len(self.cmaps),1,i)
##THIS PLOTS A BAND STRETCHING OVER THE WHOLE COLOUR MAP
plot=imshow(a,aspect='auto',cmap=get_cmap(col),origin="lower")
##NO TICKMARKS
plot.axes.get_xaxis().set_ticks([])
plot.axes.get_yaxis().set_ticks([])
##AND LABELS IT WITH THE COLOUR NAME
annotate(col, (0,1),color='white')
i=i+1
##AND RESET THE FIGURE NUMBER
fig=figure(1)
if(string.lower(sys.platform) != "darwin"):
show()
##------------------------------------------------------------------------
class parameter_view(Frame):
def __init__(self,master=None):
"""
This is the class for creating a GUI to run a grid of models.
"""
Frame.__init__(self,master)
##INITIALIZE VARIABLES
##GENERAL VARIABLES
self.convol=IntVar() ##FLAG FOR CONVOLUTION WITH PSF
self.masksize=StringVar() ##MASK SIZE IN PIXELS
self.loaded=0 ##HAS THE DATA BEEN LOADED
self.image_log=IntVar() ##FLAG FOR LOG IMAGE
self.contour_loaded=0 ##HAS TEH CONTOUR BEEN LOADED
self.which_pol=StringVar() ##VARIABLE FOR WHICH DISPLAY MODE TO USE
##CONTOUR VARIABLES
self.contour=IntVar() ##FLAG FOR PLOTTING CONTOURS
self.contour_num=IntVar() ##NUMBER OF CONTOURS
self.contour_low=DoubleVar() ##LOW CONTOUR VALUE
self.contour_high=DoubleVar() ##HIGH CONTOUR VALUE
self.contour_log=IntVar() ##FLAG FOR LOG CONTOURS
self.contour_cust=IntVar() ##FLAG FOR CUSTOM CONTOURS
self.contour_levels=StringVar() ##VALUES OF CONTOURS
self.contour_colour=StringVar() ##COLOUR OF CONTOURS
self.rotvar=DoubleVar() ##ROTATION OF THE CONTOURS
##H, BETA, RHO AND ANGLE VARIABES FOR SCROLLING
self.h_val=StringVar() ##CURRENT H VALUE
self.beta_val=StringVar() ##CURRENT BETA VALUE
self.rho_val=StringVar() ##CURRENT RHO VALUE
self.angle_val=DoubleVar() ##CURRENT ANGLE VALUE
##VARIABLES FOR BATCH PLOT
self.p_angle_val1=StringVar() ##FIRST ANGLE FOR BATCH PLOT
self.p_angle_val2=StringVar() ##SECOND ANGLE FOR BATCH PLOT
self.p_h_val1=StringVar() ##FIRST H FOR BATCH PLOT
self.p_h_val2=StringVar() ##SECOND H FOR BATCH PLOT
self.p_rho_val1=StringVar() ##FIRST RHO FOR BATCH PLOT
self.p_rho_val2=StringVar() ##SECOND RHO FOR BATCH PLOT
self.p_beta_val1=StringVar() ##FIRST BETA FOR BATCH PLOT
self.p_beta_val2=StringVar() ##SECOND BETA FOR BATCH PLOT
self.choice1=IntVar() ##FIRST VARIABLE FOR BATCH PLOT
self.choice2=IntVar() ##SECOND VARIABLE FOR BATCH PLOT
##POLARIZATION VECTOR VARIABLES
self.showvect=IntVar() ##FLAG FOR SHOWING POLARIZATION VECTORS
self.vectsamp=StringVar() ##VECTOR RESAMPLING FACTOR
self.vectscale=StringVar() ##VECTOR SCALING FACTOR
self.vectcolour=StringVar() ##VECTOR COLOUR
##PROFILE VARIABLES
self.prof=IntVar() ##FLAG TO SELECT SLICE OR WEDGE
self.whichax=IntVar() ##VARIABLE TO SELECT WHICH AXIS TO TAKE THE PROFILE
self.profangle=StringVar() ##ANGLE IN DEGREES FOR THE WEDGE PROFILE
self.profwidth=StringVar() ##WIDTH IN PIXELS FOR THE SLICE PROFILE
self.profunit=StringVar() ##VARIABILE TO SET THE UNITS (DEGREES OR PIXELS)
self.whichlab=StringVar() ##VARIABILE TO SET THE LABEL (WIDTH/ANGLE)
self.proflogx=IntVar() ##FLAG FOR LOG SCALE IN X AXIS
self.proflogy=IntVar() ##FLAG FOR LOG SCALE IN Y AXIS
self.datascale=StringVar() ##FACTOR BY WHICH TO SCALE THE DATA
self.xo=0 ##VARIABLES FOR ROTATION
self.yo=0
##LABEL AND TYPES FOR PLOTS
self.plottype={"PI Image":0,"I Image":1,"Q Image":2,"U Image":3,"V Image":4,"Density Distribution":5,
"Radial Profile (I)":6,"Radial Profile (PI)":7}
self.plotlab={"PI Image":"PI","I Image":"I","Q Image":"Q","U Image":"U","V Image":"V","Density Distribution":"rho",
"Radial Profile (I)":"profi","Radial Profile (PI)":"profpi"}
##PSF VARIABLES
self.whichpsf=IntVar() ##WHICH TYPE OF PSF
self.psfunit=StringVar() ##UNITS LABEL FOR PSF INFO
self.psflab=StringVar() ##LABABEL FOR PSF INFO
self.psfinfo=StringVar() ##USER DEFINED INFO FOR PSF
self.goodpsf=0 ##FLAG FOR GOOD PSF
self.oldpsfinfo="a" ##VARIABLE TO CHECK PSF VALUES
self.convflag=1 ##FLAG TO CHOOSE CONVOLUTION METHOD. SET HERE.
##----------------------------------------------------------------------
##SET UP THE GUI
##TOP BAR - QUITTING AND LOADING OPTIONS
fm=Frame(self, relief=RAISED, bd=1)
mb=Button(fm,text='Quit',command=self.quit).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Help',command=self.show_help).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Load Simulation',command=self.load_simulation_dir).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Load Observations',command=self.load_contour_data).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Save Current File',command=self.save_current).pack(side=LEFT,anchor=W)
fm.pack(side=TOP,anchor=W,fill=X)
##OPTIONS FOR IMAGE DISPLAY TYPE
fm=Frame(self, relief=RAISED, bd=1)
mb=Label(fm,text="Display Format ",width=12).pack(side=LEFT,anchor=W)
opt=OptionMenu(fm,self.which_pol,"PI Image","I Image","Q Image","U Image","V Image","Density Distribution",
"Radial Profile (I)","Radial Profile (PI)",command=self.update_plot)
opt.pack(side=LEFT,anchor=W)
mb=Checkbutton(fm,text="Show Data Contour? ",variable=self.contour, command=self.start_loop).pack(side=LEFT,anchor=W)
mb=Label(fm,text='Contour Rotation (deg)').pack(side=LEFT,anchor=W)
mb=Entry(fm,textvariable=self.rotvar,width=5).pack(side=LEFT,anchor=W)
fm.pack(side=TOP,anchor=W,fill=X)
##SECOND BAR - GLOBAL OPTIONS LINE 1 (PSF)
fm=Frame(self, relief=RAISED, bd=1)
mb=Checkbutton(fm,text="Convolve with PSF?",variable=self.convol, command=self.start_loop).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="Gaussian PSF",variable=self.whichpsf,command=self.set_convol_parms,value=2).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="File PSF",variable=self.whichpsf,command=self.set_convol_parms,value=1).pack(side=LEFT,anchor=W)
self.convtype=Label(fm, textvariable=self.psflab, width=8)
self.convtype.pack(side=LEFT,anchor=W)
mb=Entry(fm,textvariable=self.psfinfo,width=20).pack(side=LEFT,anchor=W)
self.convtype=Label(fm, textvariable=self.psfunit, width=8)
self.convtype.pack(side=LEFT,anchor=W)
fm.pack(side=TOP,anchor=W,fill=X)
self.psfunit.set('pixels')
self.whichpsf.set(2)
self.psfinfo.set('8')
self.psflab.set('FWHM=')
##SECOND BAR - GLOBAL OPTIONS LINE 1 (VECTORS, MASK)
fm=Frame(self, relief=RAISED, bd=1)
mb=Checkbutton(fm, text="Show Polarization Vectors? ",variable=self.showvect, command=self.start_loop).pack(side=LEFT,anchor=W)
mb=Label(fm,text='Mask Size (pixels)').pack(side=LEFT,anchor=W)
mb=Entry(fm,textvariable=self.masksize,width=3).pack(side=LEFT,anchor=W)
fm.pack(side=TOP,anchor=W,fill=X)
##THIRD BAR - GLOBAL OPTIONS LINE 2 (CONTOURS)
##SET ROTATION ANGLE AND MASK SIZE DEFAULTS
fm=Frame(self)
mb=Button(fm,text='Plot/Refresh Plot',command=self.start_loop).pack(side=LEFT,anchor=W)
fm.pack(side=BOTTOM)
##SET DEFAULT VALUES
self.which_pol.set('PI Image')
self.rotvar.set(0)
self.masksize.set('10')
##----------------------------------------------------------------------
##USE PMW NOTEBOOK TABS TO ORGANIZE THE OPTIONS. FOUR TABS, ONE FOR
##THE SCROLLING OPTIONS, ONE FOR IMAGE DISPLAY OPTIONS, ONE FOR
##SNAPSHOT MODE, AND ONE FOR PROFILE DISPLAY OPTIONS
notebook=Pmw.NoteBook(self) ##INITIALIZE THE NOTEBOOK
##FIRST NOTEBOOK WINDOW; SCROLLING OPTIONS
page1 = notebook.add('Model Controls')
notebook.tab('Model Controls').focus_set()
##TITLE
fm=Frame(page1)
Label(fm, text="Model Controls", width=50,background="honeydew3").pack(side=LEFT,anchor=W)
fm.pack()
##SCALEBAR FOR ANGLE. INITIALIZE TO ZERO, TO BE UPDATED WHEN MODEL IS LOADED
fm=Frame(page1, relief=RAISED, bd=1)
self.ang_label = Label(fm, text="Angle", width=8).pack(side=LEFT,anchor=W)
self.ang_value = Label(fm, text="", width=10)
self.ang_value.pack(side=LEFT,anchor=W)
fm.pack()
self.angle_scale = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_plot, length=300)
self.angle_scale.pack()
fm.pack()
#SCALEBAR FOR H_0. INITIALIZE TO ZERO, TO BE UPDATED WHEN MODEL IS LOADED
fm=Frame(page1, relief=RAISED, bd=1)
self.h_label = Label(fm, text="h_0", width=8).pack(side=LEFT,anchor=W)
self.h_value = Label(fm, text="", width=10)
self.h_value.pack(side=LEFT,anchor=W)
fm.pack()
self.h_scale = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_plot, length=300)
self.h_scale.pack()
fm.pack()
##SCALEBAR FOR RHO. INITIALIZE TO ZERO, TO BE UPDATED WHEN MODEL IS LOADED
fm=Frame(page1, relief=RAISED, bd=1)
self.rho_label = Label(fm, text=u"\u03c1_0", width=8).pack(side=LEFT,anchor=W)
self.rho_value = Label(fm, text="", width=10)
self.rho_value.pack(side=LEFT,anchor=W)
fm.pack()
self.rho_scale = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_plot, length=300)
self.rho_scale.pack()
fm.pack()
##SCALEBAR FOR BETA. INITIALIZE TO ZERO, TO BE UPDATED WHEN MODEL IS LOADED
fm=Frame(page1, relief=RAISED, bd=1)
self.beta_label = Label(fm, text=u"\u03b2_0", width=8).pack(side=LEFT,anchor=W)
self.beta_value = Label(fm, text="", width=10)
self.beta_value.pack(side=LEFT,anchor=W)
fm.pack()
self.beta_scale = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_plot, length=300)
self.beta_scale.pack()
fm.pack()
##OPEN THE DISPLAY WINDOW AND SET UP THE MOUSE BINDINGS FOR ROTATING THE CONTOUR INTERACTIVELY
##CREATE THE FIGURE
self.fig = plt.figure()
ax=self.fig.add_subplot(111)
##ON CLICKING THE MOUSE BUTTON
def onclick(event):
##READ THE X AND Y POSITIONS OF THE START POINT
self.xo=event.xdata
self.yo=event.ydata
##ON RELEASING THE MOUSE BUTTON
def offclick(event):
##READ THE X AND Y POSITIONS OF THE END POINT
self.xn=event.xdata
self.yn=event.ydata
##SET THE ROTATION FLAG TO TELL START_LOOP TO UPDATE
self.rotit=1
##CALCULATE THE CHANGE IN ANGLE, AND ADD IT TO ROTVAR
angle1=180*numpy.arctan(self.yo/self.xo)/numpy.pi
angle2=180*numpy.arctan(self.yn/self.xn)/numpy.pi
self.rotangle=self.rotangle+angle2-angle1
self.rotvar.set(self.rotangle)
##UPDATE THE PLOT
self.start_loop()
##THIS CONNECTS THE TWO ABOVE ROUTINES TO THE MOUSE ACTIONS
cid = self.fig.canvas.mpl_connect('button_press_event', onclick)
cid = self.fig.canvas.mpl_connect('button_release_event', offclick)
##----------------------------------------------------------------------
##SECOND NOTEBOOK TAB - IMAGE OPTIONS
page2 = notebook.add('Image Options')
notebook.tab('Image Options').focus_set()
##TITLE
fm=Frame(page2)
Label(fm, text="Image Options", width=50,background="honeydew3").pack(side=LEFT,anchor=W)
fm.pack()
##SCALEBAR FOR SCALE. INITIALIZE TO FULL RANGE
bound=Frame(page2,relief=RAISED, bd=1)
fm=Frame(bound)
self.low_label = Label(fm, text="Lower Limit", width=10).pack(side=LEFT,anchor=W)
self.low_lim = Scale(fm, from_=0, to=100,
orient=HORIZONTAL, command=self.update_plot, length=300)
self.low_lim.pack()
self.low_lim.set(0)
fm.pack()
fm=Frame(bound)
self.high_label = Label(fm, text="Upper Limit", width=10).pack(side=LEFT,anchor=W)
self.high_lim = Scale(fm, from_=0, to=100,
orient=HORIZONTAL, command=self.update_plot, length=300)
self.high_lim.pack()
self.high_lim.set(100)
fm.pack()
fm=Frame(bound)
self.padd = Label(fm, text=" ", width=10).pack(side=LEFT,anchor=W)
fm.pack()
##IMAGE SCALE AND COLOUR OPTIONS
fm=Frame(bound)
mb=Checkbutton(fm,text="Logarithmic Image Scale ",variable=self.image_log,command=self.start_loop).pack(side=LEFT,anchor=W)
mb=Button(fm,text="Change Colour Map",command=self.get_new_cmap).pack(side=LEFT,anchor=W)
fm.pack()
bound.pack(fill=X)
self.image_log.set(0)
##CONTOUR OPTIONS
bound=Frame(page2,relief=RAISED, bd=1)
fm=Frame(bound)
Label(fm, text="Contour Options", width=50,background="honeydew3").pack(side=LEFT,anchor=W)
fm.pack()
##LOG OR LINEAR CONTOURS, CONTOUR COLOURS
fm=Frame(bound)
mb=Checkbutton(fm,text="Logarithmic Contours ",variable=self.contour_log).pack(side=LEFT,anchor=W)
self.contour_label = Label(fm, text=" Contour Colour", width=12).pack(side=LEFT,anchor=W)
self.contour_label = Entry(fm, textvariable=self.contour_colour, width=10).pack(side=LEFT,anchor=W)
fm.pack()
bound.pack(fill=X)
self.contour_colour.set('white')
##GENERATE CUSTOM CONTOURS, VIEW DATA STATISTICS
fm=Frame(bound)
mb=Checkbutton(fm,text="Custom Contours",variable=self.contour_cust,command=self.start_loop).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Generate',command=self.generate_contours).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Data Statistics',command=self.calculate_data_stats).pack(side=LEFT,anchor=W)
fm.pack()
self.contour_cust.set(0)
##CHOOSE PARAMETERS FOR CONTOURS
fm=Frame(bound)
self.contour_label = Label(fm, text="Number of Contours", width=20).pack(side=LEFT,anchor=W)
self.contour_label = Entry(fm, textvariable=self.contour_num, width=10).pack(side=LEFT,anchor=W)
self.contour_label = Label(fm, text="Contour Limits", width=15).pack(side=LEFT,anchor=W)
self.contour_label = Entry(fm, textvariable=self.contour_low, width=10).pack(side=LEFT,anchor=W)
self.contour_label = Entry(fm, textvariable=self.contour_high, width=10).pack(side=LEFT,anchor=W)
fm.pack()
##SHOW OR EDIT THE CONTOURS MANUALLY
fm=Frame(bound)
self.contour_label = Label(fm, text="Levels", width=15).pack(side=LEFT,anchor=W)
self.contour_label = Entry(fm, textvariable=self.contour_levels, width=40).pack(side=LEFT,anchor=W)
##A BIT FO PADDING BEFORE FOR VISUAL CLARITY
fm.pack()
fm=Frame(bound)
self.padd = Label(fm, text=" ", width=10).pack(side=LEFT,anchor=W)
fm.pack()
bound.pack(fill=X)
##POLARIZATION VECTOR OPTIONS
fm=Frame(page2)
Label(fm, text="Polarization Options", width=50,background="honeydew3").pack(side=LEFT,anchor=W)
fm.pack()
fm=Frame(page2, relief=RAISED, bd=1)
mb=Label(fm,text='Vector Resampling').pack(side=LEFT,anchor=W)
mb=Entry(fm, textvariable=self.vectsamp, width=3).pack(side=LEFT,anchor=W)
mb=Label(fm,text='Length Scale').pack(side=LEFT,anchor=W)
mb=Entry(fm, textvariable=self.vectscale, width=3).pack(side=LEFT,anchor=W)
mb=Label(fm,text='Vector Colour').pack(side=LEFT,anchor=W)
mb=Entry(fm, textvariable=self.vectcolour, width=8).pack(side=LEFT,anchor=W)
fm.pack()
self.vectsamp.set('1')
self.vectscale.set('1')
self.vectcolour.set('white')
##----------------------------------------------------------------------
##THIRD PAGE FOR THE NOTEBOOK; SNAPSHOT VIEW
page3 = notebook.add('Snapshot View')
notebook.tab('Snapshot View').focus_set()
##TITLE
fm=Frame(page3)
Label(fm, text="Snapshot View", width=50,background="honeydew3").pack(side=LEFT,anchor=W)
fm.pack()
##BUTTONS FOR MAKING THE IMAGES
fm=Frame(page3)
mb=Button(fm,text='Make Figs',command=self.make_all_figs).pack(side=LEFT,anchor=W)
mb=Button(fm,text='Save All Figs',command=self.cycle_all).pack(side=LEFT,anchor=W)
fm.pack()
##ANGLE VARIABLE SCALES. SET TO ZERO, AS THE DEFAULTS WILL BE RESET WHEN THE
##SIMULATION IS LOADED
fm=Frame(page3, relief=RAISED, bd=1)
mb=Radiobutton(fm,variable=self.choice1,value=1).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,variable=self.choice2,value=1).pack(side=LEFT,anchor=W)
self.p_ang_label = Label(fm, text="Angle Range", width=15).pack(side=LEFT,anchor=W)
self.p_ang_value1 = Label(fm,text="",width=10)
self.p_ang_value1.pack(side=LEFT,anchor=W)
self.p_angle_scale1 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_angle_scale1.pack(side=LEFT,anchor=W)
self.p_ang_value2 = Label(fm,text="",width=10)
self.p_ang_value2.pack(side=LEFT,anchor=W)
self.p_angle_scale2 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_angle_scale2.pack(side=LEFT,anchor=W)
fm.pack()
##H0 VARIABLE SCALES SET TO ZERO, AS THE DEFAULTS WILL BE RESET WHEN THE
##SIMULATION IS LOADED
fm=Frame(page3, relief=RAISED, bd=1)
mb=Radiobutton(fm,variable=self.choice1,value=2).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,variable=self.choice2,value=2).pack(side=LEFT,anchor=W)
self.p_h_label = Label(fm, text="h Range", width=15).pack(side=LEFT,anchor=W)
self.p_h_value1 = Label(fm,text="",width=10)
self.p_h_value1.pack(side=LEFT,anchor=W)
self.p_h_scale1 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_h_scale1.pack(side=LEFT,anchor=W)
self.p_h_value2 = Label(fm,text="",width=10)
self.p_h_value2.pack(side=LEFT,anchor=W)
self.p_h_scale2 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_h_scale2.pack(side=LEFT,anchor=W)
fm.pack()
##RHO VARIABLE SCALES SET TO ZERO, AS THE DEFAULTS WILL BE RESET WHEN THE
##SIMULATION IS LOADED
fm=Frame(page3, relief=RAISED, bd=1)
mb=Radiobutton(fm,variable=self.choice1,value=3).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,variable=self.choice2,value=3).pack(side=LEFT,anchor=W)
self.p_rho_label = Label(fm, text=u"\u03c1_0 Range", width=15).pack(side=LEFT,anchor=W)
self.p_rho_value1 = Label(fm,text="",width=10)
self.p_rho_value1.pack(side=LEFT,anchor=W)
self.p_rho_scale1 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_rho_scale1.pack(side=LEFT,anchor=W)
self.p_rho_value2 = Label(fm,text="",width=10)
self.p_rho_value2.pack(side=LEFT,anchor=W)
self.p_rho_scale2 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_rho_scale2.pack(side=LEFT,anchor=W)
fm.pack()
##BETA VARIABLE SCALES SET TO ZERO, AS THE DEFAULTS WILL BE RESET WHEN THE
##SIMULATION IS LOADED
fm=Frame(page3, relief=RAISED, bd=1)
mb=Radiobutton(fm,variable=self.choice1,value=4).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,variable=self.choice2,value=4).pack(side=LEFT,anchor=W)
self.p_beta_label = Label(fm, text=u"\u03b2_0 Range", width=15).pack(side=LEFT,anchor=W)
self.p_beta_value1 = Label(fm,text="",width=10)
self.p_beta_value1.pack(side=LEFT,anchor=W)
self.p_beta_scale1 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_beta_scale1.pack(side=LEFT,anchor=W)
self.p_beta_value2 = Label(fm,text="",width=10)
self.p_beta_value2.pack(side=LEFT,anchor=W)
self.p_beta_scale2 = Scale(fm, from_=0, to=0,
orient=HORIZONTAL, command=self.update_figs, length=150)
self.p_beta_scale2.pack(side=LEFT,anchor=W)
fm.pack()
##DEFAULT VALUES FOR THE RADIO BUTTONS
self.choice1.set(1)
self.choice2.set(2)
##----------------------------------------------------------------------
##FOURTH NOTEBOOK PAGE, PROFILE OPTIONS
page4 = notebook.add('Profile Options')
notebook.tab('Profile Options').focus_set()
##TITLE
fm=Frame(page4)
Label(fm, text="Profile Options", width=50,background="honeydew3").pack(side=LEFT,anchor=W)
fm.pack()
##SAVE FUNCTION
fm=Frame(page4)
mb=Button(fm,text='Save Current Profile',command=self.save_radial_prof).pack(side=LEFT,anchor=W)
fm.pack()
##CHOOSE TYPE OF PROFILE
fm=Frame(page4, relief=RAISED, bd=1)
mb = Label(fm, text="Profile Type", width=10).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="Wedge",variable=self.prof,command=self.set_prof_parms,value=1).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="Slice",variable=self.prof,command=self.set_prof_parms,value=2).pack(side=LEFT,anchor=W)
self.profangle_lab=Label(fm, textvariable=self.whichlab, width=15)
self.profangle_lab.pack(side=LEFT,anchor=W)
self.profangle_ent=Entry(fm, textvariable=self.profangle, width=10).pack(side=LEFT,anchor=W)
self.profangle_unit=Label(fm, textvariable=self.profunit, width=10)
self.profangle_unit.pack(side=LEFT,anchor=W)
fm.pack()
##CHOOSE THE AXIS
fm=Frame(page4, relief=RAISED, bd=1)
mb = Label(fm, text="Axis", width=10).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="+X",variable=self.whichax,command=self.set_prof_parms,value=1).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="+Y",variable=self.whichax,command=self.set_prof_parms,value=2).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="-X",variable=self.whichax,command=self.set_prof_parms,value=3).pack(side=LEFT,anchor=W)
mb=Radiobutton(fm,text="-Y",variable=self.whichax,command=self.set_prof_parms,value=4).pack(side=LEFT,anchor=W)
fm.pack()
##LOGARITHMIC OR LINEAR, SSCALING
fm=Frame(page4, relief=RAISED, bd=1)
mb=Checkbutton(fm,text="Logarithmic Plot Scale (X)",variable=self.proflogx, command=self.set_prof_parms).pack(side=LEFT,anchor=W)
mb=Checkbutton(fm,text="Logarithmic Plot Scale (Y)",variable=self.proflogy, command=self.set_prof_parms).pack(side=LEFT,anchor=W)
mb=Label(fm,text='Scale data by',width=15).pack(side=LEFT,anchor=W)
Entry(fm, textvariable=self.datascale, width=10).pack(side=LEFT,anchor=W)
fm.pack()
self.modelplot=StringVar()
self.dataplot=StringVar()
self.modelcol=StringVar()
self.datacol=StringVar()
##PLOTTING OPTIONS
fm=Frame(page4, relief=RAISED, bd=1)
mb = Label(fm, text="Plot Type (Model)", width=15).pack(side=LEFT,anchor=W)
opt=OptionMenu(fm,self.modelplot,'Diamond','Circle','Square','Triangle','Plus','None',command=self.update_plot)
opt.pack(side=LEFT,anchor=W)
mb=Label(fm,text='Plot Color (Model)',width=15).pack(side=LEFT,anchor=W)
Entry(fm, textvariable=self.modelcol, width=10).pack(side=LEFT,anchor=W)
fm.pack()
fm=Frame(page4, relief=RAISED, bd=1)
mb = Label(fm, text="Plot Type (Data)", width=15).pack(side=LEFT,anchor=W)
opt=OptionMenu(fm,self.dataplot,'Diamond','Circle','Square','Triangle','Plus','None',command=self.update_plot)
opt.pack(side=LEFT,anchor=W)
mb=Label(fm,text='Plot Color (Data)',width=15).pack(side=LEFT,anchor=W)
Entry(fm, textvariable=self.datacol, width=10).pack(side=LEFT,anchor=W)
fm.pack()
##SET DEFAULT VALUES FOR PROFILES
self.datascale.set('1')
self.whichlab.set('Angle of Wedge')
self.prof.set(1)
self.whichax.set(1)
self.profangle.set('5')
self.profunit.set('degrees')
self.proflogx.set(1)
self.proflogy.set(0)
self.modelplot.set('None')
self.dataplot.set('Diamond')
self.modelcol.set('black')
self.datacol.set('green')
##NOW PACK THE NOTEBOOK AND SET THE SIZE TO CONTAIN ALL THE CONTENTS
notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
notebook.setnaturalsize()
##------------------------------------------------------------------------
def set_convol_parms(self):
"""
Set the appropriate labels and defults
"""
##SET THE PARAMETERS APPROPRIATELY
convtype=self.whichpsf.get()
if(convtype==1):
self.psflab.set('PSF File=')
self.psfunit.set('')
self.psfinfo.set('psf_refstar_cropped.fits')
if(convtype==2):
self.psflab.set('FWHM=')
self.psfunit.set('pixels')
self.psfinfo.set('8')
##------------------------------------------------------------------------
def show_disk_profile(self):
"""
Displays a disk density profiles.
"""
##DISPLAY A DISK DENSITY PROFILE
#clf()
##SET REASONABLE VALUES FOR MIN AND MAX OF DISPLAY
mmin=self.twod[0,self.twod.shape[1]-1]
mmax=self.twod[0,self.twod.shape[1]/10]
try:
self.cmap=get_cmap(self.cc.cmap)
except:
self.cmap=cm.spectral
self.cmap.set_bad('black',1) ##MISSING OR BAD PIXELS ARE BLACK
##DO THE PLOT
self.plotit=imshow(self.twod,origin='lower',interpolation='nearest',extent=[0,self.maxr,0,self.maxr],vmin=mmin,vmax=mmax,cmap=self.cmap)
plot(self.r_array,self.z_array,'w-' )
if(string.lower(sys.platform) != "darwin"):
show()
##--------------------------------------------------------------------------------------------
def generate_contours(self):
"""
Create custom contour levels and format as a string, based on user input
"""
##ROUTINE TO CREATE CUSTOM CONTOURS
contourstring="" ##STRING CONTAINING THE CONTOUR VALUES, SEPARATED BY COMMAS
##mmin MINIMUM VALUE FOR CONTOURS
##mmax MAXIMUM VALUE FOR CONTOURS
##ncont NUMBER OF CONTOURS
##levels ARRAY OF CONTOUR LEVELS
if self.contour.get() == 1:
##GET MIN/MAX/NUMBER
mmin=self.contour_low.get()
mmax=self.contour_high.get()
ncont=self.contour_num.get()
##CHECK FOR VALID NUMBERS AND RESET IF INPUT IS INVALID
if (mmin == mmax or mmin > mmax or ncont<=0):
tkMessageBox.showwarning("Warning", "Incorrect Contour Parameters. \nValues must be positive, minimum value must be less than maximum")
levels=0
contourstring=""
else:
##LINEAR CONTOURS
if(self.contour_log.get() == 0):
levels=numpy.linspace(mmin,mmax,ncont)
print numpy.linspace(mmin,mmax,ncont)
#print "A",levels
##LOGARITHMIC CONTOURS
else:
if(mmin > 0):
levels=10**numpy.linspace(start=log10(mmin),stop=log10(mmax),num=ncont,endpoint="True")
numpy.linspace(start=log10(mmin),stop=log10(mmax),num=ncont,endpoint="True")
print "B",levels
#GET LOGARITHMIC INTERVALS FOR VALUES < 0
if(mmin <=0):
lrange=abs(mmax-mmin)
mmin1=lrange/20.
mmax1=lrange
levels=10**numpy.linspace(start=log10(mmin1),stop=log10(mmax1),num=ncont,endpoint="True")-mmin1+mmin
print numpy.linspace(start=log10(mmin1),stop=log10(mmax1),num=ncont,endpoint="True")-mmin1+mmin
print "C",levels
print "AAA", self.contour_log.get(),levels
##CREATE THE STRING
for val in levels:
print "VAL",val
contourstring=contourstring+str("%5.3e" % val)+','
##STRIP OF THE FINAL COMMA
contourstring=contourstring[:-1]
print contourstring
##write THE STRING IN THE WINDOW
self.contour_levels.set(contourstring)
##------------------------------------------------------------------------
def make_all_figs(self):
"""
Generates the snapshot mode images.
"""
##h ARRAY OF H VALUES FOR THE PLOT
##rho ARRAY OF RHO VALUES FOR THE PLOT
##beta ARRAY OF BETA VALUES FOR THE PLOT
##angle_ind ARRAY OF ANGLES FOR THE PLOT
##ncols NUMBER OF COLUMNS IN THE PLOT
##xlabel STRING FOR THE X AXIS LABEL
##nrows NUMBER OF ROWS IN THE PLOT
##ylabel STRING FOR THE Y AXIS LABEL
##sgn SET TO -1 OR +1 DEPENDING ON WHETHER THE FIRST INDEX IS >= THAN THE SECOND FOR A VARIABLE
##ii COUNTER FOR THE # OF PLOTS DONE SO FAR
##i,j,k,l LOOP VARIABLES
##THIS ROUTINE GENERATE THE SNAPSHOT MODE IMAGE GRID.
##CLOSE THE WINDOW IF ONE IS ALREADY OPEN
close(4)
##HAS THE DATA BEEN LOADED? IF NOT, EXIT
if self.loaded == 0:
tkMessageBox.showwarning("", "Load Simulation Data")
return
##MAKE SURE THAT THE THERE ARE TWO UNIQUE IMAGES CHOSEN
if(self.choice1.get() == self.choice2.get()):
tkMessageBox.showwarning("Warning", "Choose Two Different Variables")
return
##SET THE VALUE OF EACH VARIABLE TO THE FIRST VALUE FROM THE SLIDER FOR EACH VARIABLE
##THIS WILL BE THE VALUE FOR THE UNSELECTED PARAMETERS
angle_ind=[int(self.p_angle_scale1.get())]
h=[self.h_array[int(self.p_h_scale1.get())]]
rho=[self.rho_array[self.p_rho_scale1.get()]]
beta=[self.beta_array[self.p_beta_scale1.get()]]
##NOW GET THE FIRST AND SECOND CHOICES FOR THE VARIABLES, CALCULATE THE NUMBER OF IMAGES TO PLOT
##AND SET THE AXIS LABELS
##SGN WILL BE POSITIVE IF THE FIRST INDEX IS SMALLER THAN THE LAST AND NEGATIVE OTHERWISE (SETS THE DIRECTION OF THE
##PLOTS CORRECTLY. IF THE FIRST INDEX=SECOND INDEX, DEFAULTS TO 1
##THEN CALCULATE THE ARRAY OF VALUES FOR EACH VARIABLE, AND USE SGN TO GET THE ORDER RIGHT.
##CALCULATE THE NUMBER OF COLUMNS AND THE LABEL FOR THE AXIS
##THIS CODE GETS THE DIRECTION OF THE VARIABLES TO PLOT, AND SETS THE ARRAYS OF VALUES
##IT'S THE SAME BASIC CODE, REPEATED FOR DIFFERENT FIRST VARIABLES AND SECOND VARIABLES.
##FOR THE FIRST VARIABLE
if(self.choice1.get()==1):
try:
sgn=abs(int(self.p_angle_scale2.get())-int(self.p_angle_scale1.get()))/(int(self.p_angle_scale2.get())-int(self.p_angle_scale1.get()))
except:
sgn=1
angle_ind=int(self.p_angle_scale1.get())+sgn*arange(abs(int(self.p_angle_scale2.get())-int(self.p_angle_scale1.get()))+1)
ncols=len(angle_ind)
if(sgn > 0):
xlabel="Angle="+str(self.angles[min(angle_ind)])+" to "+str(self.angles[max(angle_ind)])
if(sgn < 0):
xlabel="Angle="+str(self.angles[max(angle_ind)])+" to "+str(self.angles[min(angle_ind)])
if(self.choice1.get()==2):
try:
sgn=abs(int(self.p_h_scale2.get())-int(self.p_h_scale1.get()))/(int(self.p_h_scale2.get())-int(self.p_h_scale1.get()))
except:
sgn=1
h=self.h_array[int(self.p_h_scale1.get())+sgn*arange(abs(int(self.p_h_scale2.get())-int(self.p_h_scale1.get()))+1)]
ncols=len(h)
if(sgn > 0):
xlabel="h="+str("%5.2f" % min(h))+" to "+str("%5.2f" % max(h))
if(sgn < 0):
xlabel="h="+str("%5.2f" % max(h))+" to "+str("%5.2f" % min(h))
if(self.choice1.get()==3):
try:
sgn=abs(int(self.p_rho_scale2.get())-int(self.p_rho_scale1.get()))/(int(self.p_rho_scale2.get())-int(self.p_rho_scale1.get()))
except:
sgn=1
rho=self.rho_array[int(self.p_rho_scale1.get())+sgn*arange(abs(int(self.p_rho_scale2.get())-int(self.p_rho_scale1.get()))+1)]
ncols=len(rho)
if(sgn > 0):
xlabel=u"\u03c1_0="+str("%5.2e" % min(rho))+" to "+str("%5.2e" % max(rho))
if(sgn < 0):
xlabel=u"\u03c1_0="+str("%5.2e" % max(rho))+" to "+str("%5.2e" % min(rho))
if(self.choice1.get()==4):
try:
sgn=abs(int(self.p_beta_scale2.get())-int(self.p_beta_scale1.get()))/(int(self.p_beta_scale2.get())-int(self.p_beta_scale1.get()))
except:
sgn=1
beta=self.beta_array[int(self.p_beta_scale1.get())+sgn*arange(abs(int(self.p_beta_scale2.get())-int(self.p_beta_scale1.get()))+1)]
ncols=len(beta)
if(sgn > 0):
xlabel=u"\u03b2_0="+str("%5.2f" % min(beta))+" to "+str("%5.2f" % max(beta))
if(sgn < 0):
xlabel=u"\u03b2_0="+str("%5.2f" % max(beta))+" to "+str("%5.2f" % min(beta))
##FOR THE SECOND VARIABLE DO THE SAME THING, BUT FOR NROWS AND YLABEL
if(self.choice2.get()==1):
try:
sgn=abs(int(self.p_angle_scale2.get())-int(self.p_angle_scale1.get()))/(int(self.p_angle_scale2.get())-int(self.p_angle_scale1.get()))
except:
sgn=1
angle_ind=int(self.p_angle_scale1.get())+sgn*arange(abs(int(self.p_angle_scale2.get())-int(self.p_angle_scale1.get()))+1)
angle_ind=angle_ind[::-1]
nrows=len(angle_ind)
if(sgn > 0):
ylabel="Angle="+str(self.angles[min(angle_ind)])+" to "+str(self.angles[max(angle_ind)])
if(sgn < 0):
ylabel="Angle="+str(self.angles[max(angle_ind)])+" to "+str(self.angles[min(angle_ind)])
if(self.choice2.get()==2):
try:
sgn=abs(int(self.p_h_scale2.get())-int(self.p_h_scale1.get()))/(int(self.p_h_scale2.get())-int(self.p_h_scale1.get()))
except:
sgn=1
h=self.h_array[int(self.p_h_scale1.get())+sgn*arange(abs(int(self.p_h_scale2.get())-int(self.p_h_scale1.get()))+1)]
h=h[::-1]
nrows=len(h)