-
Notifications
You must be signed in to change notification settings - Fork 0
/
janus_widget_ion_pl_grid.py
1081 lines (743 loc) · 32.2 KB
/
janus_widget_ion_pl_grid.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
################################################################################
##
## Janus -- GUI Software for Processing Thermal-Ion Measurements from the
## Wind Spacecraft's Faraday Cups
##
## Copyright (C) 2016 Bennett A. Maruca (bmaruca@udel.edu)
##
## This program 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.
##
## This program 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
## this program. If not, see http://www.gnu.org/licenses/.
##
################################################################################
################################################################################
## LOAD THE NECESSARY MODULES.
################################################################################
# Load the modules necessary for the graphical interface.
from PyQt4.QtCore import Qt, QPointF, SIGNAL
from PyQt4.QtGui import QGridLayout, QWidget, QLabel, QFont
# Load the modules necessary for plotting.
from pyqtgraph import AxisItem, GraphicsLayoutWidget, LabelItem, mkBrush, \
mkPen, PlotDataItem, TextItem
from janus_event_ViewBox import event_ViewBox
# Load the module necessary handling step functions.
from janus_step import step
# Load the necessary "numpy" array modules and numeric-function modules.
from numpy import amax, amin, array, ceil, floor, log10, sqrt, tile, where, \
float64, shape
# Load the necessary threading modules.
from threading import Thread
from janus_thread import n_thread, thread_chng_nln_sel
# Load the modules necessary handling dates and times.
from datetime import datetime, timedelta
# Load the module for TESTING joint
from scipy.io import readsav
from janus_pl_spec import pl_spec
from numpy import zeros
################################################################################
## DEFINE THE "widget_pl_grid" CLASS TO CUSTOMIZE "QWidget" FOR Wind/PL PLOTS.
################################################################################
class widget_pl_grid( QWidget ) :
#-----------------------------------------------------------------------
# DEFINE THE INITIALIZATION FUNCTION.
#-----------------------------------------------------------------------
def __init__( self, core, n,
n_plt_x=None, n_plt_y=None, n_plt=None ) :
# Inherit all attributes of an instance of "QWidget".
super( widget_pl_grid, self ).__init__( )
# Initialize the counter of repaint events for this widget as
# well as a maximum value for this counter.
# Note. For some reason, adjusting the individual plots to have
# uniform sizes is difficult to achieve before the widget
# is rendered. Thus, once a paint event occurs, the
# "self.paintEvent( )" function picks it up and makes a
# call to "self.ajst_grd( )". This counter and its
# maximum value are used ensure that "self.paintEvent( )"
# makes such a call only in response to the intial few
# painting (so as to prevent an infinite loop).
# Note. The first paint seems to be a "dummy" of some sort.
# Whatever the case, "self.n_paint_max = 1" seems to
# generally be insufficient.
self.n_painted = 0
self.n_painted_max = 3
# Disable user events
self.setDisabled( True )
self.core = core
self.n = n
self.t = []
self.delta_t = []
self.time_label = QLabel( ' ' )
self.time_label.setAlignment( Qt.AlignCenter )
self.time_label.setContentsMargins( 0,5,0,0 )
font = QFont( )
font.setBold(True)
self.time_label.setFont( font )
# Prepare to respond to signals received from the Janus core.
self.connect( self.core, SIGNAL('janus_rset'), self.resp_rset )
self.connect( self.core, SIGNAL('janus_chng_pl_spc'),
self.resp_chng_pl_spc )
self.connect( self.core, SIGNAL('janus_chng_mom_pl_sel'),
self.resp_chng_mom_pl_sel )
self.connect( self.core, SIGNAL('janus_chng_mom_pl_res'),
self.resp_chng_mom_pl_res )
self.connect( self.core, SIGNAL('janus_chng_nln_gss'),
self.resp_chng_nln_gss )
self.connect( self.core, SIGNAL('janus_chng_nln_sel_all'),
self.resp_chng_nln_sel_all )
self.connect( self.core, SIGNAL('janus_chng_nln_res'),
self.resp_chng_nln_res )
self.connect( self.core, SIGNAL('janus_chng_dsp'),
self.resp_chng_dsp )
#TODO add more signals
# Assign (if not done so already) and store the shape of the
# plot-grid array.
self.n_plt_x = 5 if ( n_plt_x is None ) else n_plt_x
self.n_plt_y = 5 if ( n_plt_y is None ) else n_plt_y
if ( n_plt is None ) :
self.n_plt = self.n_plt_x * self.n_plt_y
# Initizalize the pens, brushes, and fonts used by this widget.
self.pen_plt = mkPen( color='k' )
self.pen_hst = mkPen( color='k' )
self.pen_pnt_c = mkPen( color='k' )
self.pen_pnt_y = mkPen( color='k' )
self.pen_pnt_r = mkPen( color='k' )
self.pen_crv_b = mkPen( color='b' )
self.pen_crv_g = mkPen( color='g' )
self.bsh_pnt_c = mkBrush( color='c' )
self.bsh_pnt_y = mkBrush( color='y' )
self.bsh_pnt_r = mkBrush( color='r' )
self.fnt = self.core.app.font( )
# Set the maximum number of velocity channels and the maximum
# number of ion species.
self.n_k = 14
self.n_ion = self.core.nln_n_pop
# Initialize the widget and it's plot's.
self.init_plt( )
# Populate the plots with the histograms (and labels), the
# selection points, and the fit curves.
self.make_hst( )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR INITIALIZING THE WIDGET AND ITS PLOTS.
#-----------------------------------------------------------------------
def init_plt( self ) :
# Initialize the "GraphicsLayoutWidget" for this widget. This
# will allow a grid of "GraphicsItem" objects, which will
# include the plots themselves, the axes, and the axis labels.
# Note. The "QGridLayout" object given to this widget as its
# layout is essentially a dummy. I tried to just having
# this widget be an extention of "GraphicsLayoutWidget"
# (i.e., having it inheret that type), but I couldn't get
# it to display anything at all.
self.setLayout( QGridLayout( ) )
self.grd = GraphicsLayoutWidget( )
self.grd.setBackground( 'w' )
self.layout( ).addWidget( self.time_label )
self.layout( ).addWidget( self.grd )
self.layout().setContentsMargins( 0, 0, 0, 0 )
# Initialize the text for the x- and y-axis labels. Then,
# create the labels themselves and add them to the grid.
self.txt_axs_x = 'Projected Proton Inflow Velocity [km/s]'
self.txt_axs_y = 'Phase-space Density' +\
u'[cm\u00AF\u00B3/(km/s)\u00B3]'
if ( self.core.app.res_lo ) :
size = '8pt'
else :
size = '10pt'
self.lab_axs_x = LabelItem( self.txt_axs_x, angle=0 ,
color='b', size=size )
self.lab_axs_y = LabelItem( self.txt_axs_y, angle=270,
color='b', size=size )
self.grd.addItem( self.lab_axs_x, self.n_plt_y + 1, 2,
1, self.n_plt_x )
self.grd.addItem( self.lab_axs_y, 0, 0,
self.n_plt_y, 1 )
# Initialize the arrays that will contain the individual axes,
# plots, and plot elements (i.e., the histograms, fit curves,
# labels, and selection points).
self.plt = tile( None, [ self.n_plt_y, self.n_plt_x ] )
self.axs_x = tile( None, self.n_plt_x )
self.axs_y = tile( None, self.n_plt_y )
self.hst = tile( None, [ self.n_plt_y, self.n_plt_x ] )
self.lbl = tile( None, [ self.n_plt_y, self.n_plt_x ] )
self.crv = tile( None, [ self.n_plt_y, self.n_plt_x ] )
self.crv_ion = tile( None, [ self.n_plt_y, self.n_plt_x,
self.n_ion ] )
self.pnt = tile( None, [ self.n_plt_y, self.n_plt_x,
self.n_k ] )
# Initialize the scale-type for each axis, then generate the
# (default) axis-limits and adjusted axis-limits.
self.log_x = False
self.log_y = True
self.make_lim( )
# Create, store, and add to the grid the individual axes: first
# the horizontal and then the vertical.
for i in range( self.n_plt_x ) :
self.axs_x[i] = AxisItem( 'bottom', maxTickLength=5 )
self.axs_x[i].setLogMode( self.log_x )
self.axs_x[i].setRange( self.x_lim[0], self.x_lim[1] )
self.axs_x[i].setTickFont( self.fnt )
if ( self.core.app.res_lo ) :
self.axs_x[i].setHeight( 10 )
else :
self.axs_x[i].setHeight( 20 )
self.grd.addItem( self.axs_x[i], self.n_plt_y, i + 2 )
for j in range( self.n_plt_y ) :
self.axs_y[j] = AxisItem( 'left', maxTickLength=5 )
self.axs_y[j].setLogMode( self.log_y )
self.axs_y[j].setRange( self.y_lim[0], self.y_lim[1] )
self.axs_y[j].setTickFont( self.fnt )
if ( self.core.app.res_lo ) :
self.axs_y[j].setWidth( 32 )
else :
self.axs_y[j].setWidth( 40 )
self.grd.addItem( self.axs_y[j], j, 1 )
# Create, store, and add to the grid the individual plots.
# Likewise, create, store, and add to each plot a label.
for t in range( self.n_plt_y ) :
for p in range( self.n_plt_x ) :
# Compute the plot number of this plot.
d = p + ( t * self.n_plt_x )
# If creating this plot would exceed the
# specified number of plots, don't create it.
if ( d >= self.n_plt ) :
continue
# Create and store this plot, adjust its limits,
# and add it to the grid.
# Note: locations of plots are inverted along
# theta
self.plt[t,p] = event_ViewBox( self,
border=self.pen_plt,
enableMouse=False,
enableMenu=False )
self.plt[t,p].setRange( xRange=self.x_lim,
yRange=self.y_lim,
padding=0. )
self.grd.addItem( self.plt[t,p], self.n_plt_y-t-1, p + 2 )
# Create and store an (empty) label and add it
# to this plot.
self.lbl[t,p] = TextItem( anchor=(1,0) )
self.lbl[t,p].setFont( self.fnt )
self.plt[t,p].addItem( self.lbl[t,p] )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR GENERATING AXIS-LIMITS (AND ADJUSTED LIMITS).
#-----------------------------------------------------------------------
def make_lim( self ) :
# If no spectrum has been loaded, use the default limits;
# otherwise, use the spectral data to compute axis limits.
# Note: velocities are recorded in reverse order.
if ( self.core.pl_spec_arr == [] ) :
self.domain = [ 300. , 900. ]
self.range = [ 1.e-10, 1.e-5 ]
else :
self.domain = [self.core.pl_spec_arr[self.n]['vel_strt'][0],
self.core.pl_spec_arr[self.n]['vel_stop'][-1]]
arr_psd_flat = [self.core.pl_spec_arr[self.n]['psd_flat'][i] for i
in (where(array(self.core.pl_spec_arr[self.n]['psd_flat'])
!= 0.)[0])]
self.range = [ self.core.mom_psd_min, self.core.mom_psd_max ]
# Note: psd values are less than 1
if ( self.log_y ) :
self.range[0] = self.range[0] ** 1.05
self.range[1] = self.range[1] ** 0.9
else :
self.range[1] += 0.1 * ( self.range[1] -
self.range[0] )
# Compute the "adjusted limits" for each axis.
if ( self.log_x ) :
self.x_lim = [ log10( x ) for x in self.domain ]
else :
self.x_lim = self.domain
if ( self.log_y ) :
self.y_lim = [ log10( y ) for y in self.range ]
else :
self.y_lim = self.range
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR CREATING THE PLOTS' HISTOGRAMS (AND LABELS).
#-----------------------------------------------------------------------
def make_hst( self ) :
# Reset the timestamp label
self.time_label.setText( ' ' )
# If no spectrum has been loaded, abort.
if ( self.core.pl_spec_arr == [] ) :
return
# If the index of this P-L grid is outside the bounds of the P-L
# spectrum currently loaded, abort.
if ( self.n >= len( self.core.pl_spec_arr ) ) :
return
# Generate the timestamp label
self.t = self.t + [self.core.pl_spec_arr[self.n]['time'][0]]
self.t_0 = self.core.fc_spec['time']
self.delta_t = self.delta_t + [( self.t[-1]-
self.t_0 ).total_seconds( )]
self.time_label.setText( str(self.t[-1])[0:-7] + ' ' +
u'\u0394t = {}'.format(
round( self.delta_t[-1], 0) ) + 's' )
# Use the spectral data to compute new axis-limits.
self.make_lim( )
for p in range( self.n_plt_x ) :
self.axs_x[p].setRange( self.x_lim[0], self.x_lim[1] )
for t in range( self.n_plt_y ) :
self.axs_y[t].setRange( self.y_lim[0], self.y_lim[1] )
# Histograms are broken down by phi horizontally and
# theta vertically
for t in range( self.core.pl_spec_arr[self.n]['n_the'] ):
for p in range ( self.core.pl_spec_arr[self.n]['n_phi'] ):
# If this plot does not exist, move onto
# the next one.
if ( self.plt[t,p] is None ) :
continue
#-----------------------------#
#---DATA GENERATION SECTION---#
#-----------------------------#
# Generate a step function for the
# look direction associated with this widget.
self.stp = array( [step( self.core.pl_spec_arr[self.n]['vel_cen'],
self.core.pl_spec_arr[self.n]['vel_del'],
self.core.pl_spec_arr[self.n]['psd'][t][p])])
# Calculate the points to be plotted from the
# step function
stp_pnt = array( [ array( datum.calc_pnt(
lev_min=self.range[0]/2.) )
for datum in self.stp ] )
self.x_set = stp_pnt[:,0][0]
self.y_set = stp_pnt[:,1][0]
# If plotting log(y) and there are any psd
# values of zero, replace those points with an
# arbitrary minimum y value
if ( self.log_y ) :
y_min = self.range[0]/2.
self.y_lim[0] = log10(y_min)
self.y_set = [ max( y, y_min ) for y
in self.y_set ]
# If generating a log plot, take the log of the
# points to be plotted
self.x_pnts = log10( self.x_set ) if ( self.log_x ) else \
self.x_set
self.y_pnts = log10( self.y_set ) if ( self.log_y ) else \
self.y_set
#---------------------------------#
#---GRAPHICS GENERATION SECTION---#
#---------------------------------#
# If a histogram already exists for this plot,
# remove and delete it.
if ( self.hst[t,p] is not None ) :
self.plt[t,p].removeItem(self.hst[t,p])
self.hst[t,p] = None
# Clear this plot's label of text.
self.lbl[t,p].setText( '' )
# Adjust this plot's limits and then move it's
# label in response.
self.plt[t,p].setRange( xRange=self.x_lim,
yRange=self.y_lim,
padding=0. )
self.lbl[t,p].setPos( self.x_lim[1],
self.y_lim[1] )
# Update this plot's label with appropriate text
# indicating the pointing direction.
elev = round( self.core.pl_spec_arr[self.n]['elev_cen'][t] )
azim = round( self.core.pl_spec_arr[self.n]['azim_cen'][p] )
txt = ( u'({0:+.0f}\N{DEGREE SIGN}, ' +
u'{1:+.0f}\N{DEGREE SIGN})' ).format(
elev, azim-180 )
self.lbl[t,p].setText( txt, color=(0,0,0) )
# Generate the histogram for the data from this
# look direction and display it in the plot.
self.hst[t,p] = PlotDataItem( self.x_pnts,
self.y_pnts,
pen=self.pen_hst )
self.plt[t,p].addItem( self.hst[t,p] )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR CREATING THE PLOTS' SELECTION POINTS.
#-----------------------------------------------------------------------
def make_pnt( self ) :
# If no spectrum has been loaded, abort.
if ( self.core.pl_spec_arr == [] ) : return
# If the index of this P-L grid is outside the bounds of the P-L
# spectrum currently loaded, abort.
if ( self.n >= len( self.core.pl_spec_arr ) ) : return
# Add selection points to each plot.
for d in range( min( self.core.pl_spec_arr[self.n]['n_dir'], self.n_plt ) ) :
# Determine the location of this plot within the grid
# layout.
t = d // self.n_plt_x
p = d % self.n_plt_y
# If this plot does not exist, move onto the next one.
if ( self.plt[t,p] is None ) :
continue
# Add the selection points to this plot.
for b in range( self.core.pl_spec_arr[self.n]['n_bin'] ) :
sel_bin = False
sel_dir = True
sel_alt = None
if( self.core.dsp == 'mom' ):
sel_bin = self.core.pl_spec_arr[self.n].arr[t][p][b]['mom_sel']
elif ( ( self.core.dsp == 'gsl' or self.core.dsp == 'nln' ) and
( self.core.nln_pl_sel is not None ) ) :
sel_bin = self.core.nln_pl_sel[self.n][t][p][b]
# elif ( ( self.core.dsp == 'nln' ) and
# ( self.core.pl_spec_arr[self.n].nln_res_sel
# is not None ) ) :
# sel_bin = \
# self.core.nln_pl_sel[t][p][b]
# if ( self.core.pl_spec_arr[self.n].nln_sel is None ) :
# sel_alt = None
# else :
# sel_alt = \
# self.core.pl_spec_arr[self.n].nln_sel[t][p][b]
self.chng_pnt( t, p, b, sel_bin,
sel_alt=sel_alt )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR CHANGING THE VISIBILITY OF A DATUM'S POINTS.
#-----------------------------------------------------------------------
def chng_pnt( self, t, p, b, sel_bin, sel_alt=None ) :
# If no spectrum has been loaded, abort.
if ( self.core.pl_spec_arr == [] ) : return
# If the index of this P-L grid is outside the bounds of the P-L
# spectrum currently loaded, abort.
if ( self.n >= len( self.core.pl_spec_arr ) ) : return
# If this point already exists, remove it from its plot and
# delete it.
if ( self.pnt[t,p,b] is not None ) :
self.plt[t,p].removeItem( self.pnt[t,p,b] )
self.pnt[t,p,b] = None
# If this point was not selected (based on both its primary and
# secondary states), return (since there's nothing more to be
# done).
if ( not sel_bin or self.core.pl_spec_arr[self.n]['psd'][t][p][b] == 0) :
return
# Determine the "d" index corresponding to this look direction.
d = p + ( t * self.n_plt_x )
# Computed the adjusted point location in the "ViewBox".
if ( self.log_x ) :
ax = log10( self.core.pl_spec_arr[self.n]['vel_cen'][b] )
else :
ax = self.core.pl_spec_arr[self.n]['vel_cen'][b]
if ( self.log_y ) :
ay = log10( self.core.pl_spec_arr[self.n]['psd'][t][p][b] )
else :
ay = self.core.pl_spec_arr[self.n]['psd'][t][p][b]
# Select the color for the point (i.e., the brush and pen used
# to render it) based on whether or not this datum's look
# direction has been selected and whether or not the primary and
# secondary selection states match.
# if ( sel_bin == sel_alt ) :
pen = self.pen_pnt_c
brush = self.bsh_pnt_c
# else :
# pen = self.pen_pnt_y
# brush = self.bsh_pnt_y
# else :
# pen = self.pen_pnt_r
# brush = self.bsh_pnt_r
# Select the symbol based on the values of the primary and
# secondary selection states.
# Note. At this point in the code, at least one of these two
# states must be "True" since this -- when both states
# are "False", this function returns before it reaches
# this point.
if ( sel_bin ) :
symbol = 'o'
else :
symbol = 't'
# Create, store, and add this selection point to the plot.
if ( self.core.app.res_lo ) :
size = 3
else :
size = 6
self.pnt[t,p,b] = PlotDataItem( [ax], [ay],
symbol=symbol,
symbolSize=size,
symbolPen=pen,
symbolBrush=brush )
self.plt[t,p].addItem( self.pnt[t,p,b] )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR CREATING THE PLOTS' FIT CURVES.
#-----------------------------------------------------------------------
def make_crv( self ) :
# If no "list" of "p" index-values has been provided by the
# user, assume that the curves in all plots should be
# (re-)rendered.
if ( self.core.pl_spec_arr == [] ) :
return
# If the index of this P-L grid is outside the bounds of the P-L
# spectrum currently loaded, abort.
if ( self.n >= len( self.core.pl_spec_arr ) ) : return
# Return the "nln_psd_gss_ion axes to their original order.
if( self.core.nln_psd_gss_ion is not None ) :
if( self.core.nln_psd_gss_ion != [ ] ) :
nln_psd_gss_ion = [ [ [ [ [
self.core.nln_psd_gss_ion[n][t][f][b][p]
for b in range( self.core.pl_spec_arr[n]['n_bin'] ) ]
for f in range( self.core.pl_spec_arr[n]['n_phi'] ) ]
for t in range( self.core.pl_spec_arr[n]['n_the'] ) ]
for n in range( len( self.core.pl_spec_arr ) ) ]
for p in range( self.core.nln_gss_n_pop ) ]
# Return the "nln_res_psd_ion axes to their original order.
if( self.core.nln_res_psd_ion is not None ) :
if( self.core.nln_res_psd_ion != [ ] ) :
nln_res_psd_ion = [ [ [ [ [
self.core.nln_res_psd_ion[n][t][f][b][p]
for b in range( self.core.pl_spec_arr[n]['n_bin'] ) ]
for f in range( self.core.pl_spec_arr[n]['n_phi'] ) ]
for t in range( self.core.pl_spec_arr[n]['n_the'] ) ]
for n in range( len( self.core.pl_spec_arr ) ) ]
for p in range( self.core.nln_gss_n_pop ) ]
# For each plot in the grid, generate and display a fit curve
# based on the results of the analysis.
vel_cen = self.core.pl_spec_arr[self.n]['vel_cen']
for t in range( self.core.pl_spec_arr[self.n]['n_the'] ) :
for p in range( self.core.pl_spec_arr[self.n]['n_phi'] ) :
# If this plot does not exist, move onto the next grid
# element.
if ( self.plt[t,p] is None ) :
continue
# If any curves already exist for this plot, remove and
# delete them.
if ( self.crv[t,p] is not None ) :
self.plt[t,p].removeItem( self.crv[t,p] )
self.crv[t,p] = None
for n in range( self.n_ion ) :
if ( self.crv_ion[t,p,n] is not None ) :
self.plt[t,p].removeItem(
self.crv_ion[t,p,n] )
self.crv_ion[t,p,n] = None
# Create and add the curve of the indiviadual
# contributions to the modeled psd to the plot.
for n in range( ( 1 if self.core.dsp == 'mom' else self.core.nln_gss_n_pop ) ) :
# Extract the points for this fit curve.
x = array( vel_cen )
if( self.core.dsp == 'mom' ) :
y = array( self.core.pl_spec_arr[self.n]['psd_mom'][t][p] )
elif( self.core.dsp == 'gsl' ) :
y = array( nln_psd_gss_ion[n][self.n][t][p] )
elif( self.core.dsp == 'nln' ) :
y = array( nln_res_psd_ion[n][self.n][t][p] )
# If any points are 0 or None, set them
# to an arbitrary minimum value
for tk in range(len(y)):
if ( ( y[tk] == 0 ) or
( y[tk] is None ) ) :
y[tk] = 1e-20
if ( self.log_x ) :
ax = log10( x )
else :
ax = x
if ( self.log_y ) :
ay = array( [ log10( v )
for v in y ] )
else :
ay = y
# Create, store, and add to the plot
# this fit curve.
self.crv_ion[t,p,n] = PlotDataItem(
ax, ay, pen=( self.pen_crv_b if self.core.dsp=='mom' else self.pen_crv_g ) )
self.plt[t,p].addItem(
self.crv_ion[t,p,n] )
# If applicable, create and add the curve of the
# total contributions to the modeled psd to the
# plot
if( self.core.dsp == 'gsl' ) :
x = array( vel_cen )
y = array( self.core.nln_psd_gss_tot[self.n][t][p] )
# If any points are 0 or None, set them
# to an arbitrary minimum value
for tk in range(len(y)):
if ( ( y[tk] == 0 ) or
( y[tk] is None ) ) :
y[tk] = 1e-20
if ( self.log_x ) :
ax = log10( x )
else :
ax = x
if ( self.log_y ) :
ay = array( [ log10( v )
for v in y ] )
else :
ay = y
# Create, store, and add to the plot
# this fit curve.
self.crv[t,p] = PlotDataItem(
ax, ay, pen=( self.pen_crv_b ) )
self.plt[t,p].addItem(
self.crv[t,p] )
# If applicable, create and add the curve of the
# total contributions to the non-linear psd to
# the plot
if( ( self.core.dsp == 'nln' ) and
( self.core.nln_res_psd_tot is not None ) ) :
x = array( vel_cen )
y = array( self.core.nln_res_psd_tot[self.n][t][p] )
# If any points are 0 or None, set them
# to an arbitrary minimum value
for tk in range(len(y)):
if ( ( y[tk] == 0 ) or
( y[tk] is None ) ) :
y[tk] = 1e-20
if ( self.log_x ) :
ax = log10( x )
else :
ax = x
if ( self.log_y ) :
ay = array( [ log10( v )
for v in y ] )
else :
ay = y
# Create, store, and add to the plot
# this fit curve.
self.crv[t,p] = PlotDataItem(
ax, ay, pen=( self.pen_crv_b ) )
self.plt[t,p].addItem(
self.crv[t,p] )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESETTING THE PLOTS' HISTOGRAMS (AND LABELS).
#-----------------------------------------------------------------------
def rset_hst( self, rset_lbl=False ) :
self.time_label.setText( '' )
self.t = []
self.delta_t = []
# For each plot that exists in the grid, remove and delete it's
# histogram. Likewise, if requested, empty it's label (but
# still leave the label itself intact).
for t in range( self.n_plt_y ) :
for p in range( self.n_plt_x ) :
# If the plot does not exist, move onto the the
# next one.
if ( self.plt[t,p] is None ) :
continue
# If a histogram exists for this plot, remove
# and delete it.
if ( self.hst[t,p] is not None ) :
self.plt[t,p].removeItem(
self.hst[t,p] )
self.hst[t,p] = None
# If requested, reset this plot's label text to
# the empty string.
if ( rset_lbl ) :
self.lbl[t,p].setText( '',
color=(0,0,0) )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESETTING THE PLOTS' SELECTION POINTS.
#-----------------------------------------------------------------------
def rset_pnt( self ) :
# For each plot that exists in the grid, hide and remove its
# selection points.
for t in range( self.n_plt_y ) :
for p in range( self.n_plt_x ) :
# If the plot does not exist, move onto the the
# next grid element.
if ( self.plt[t,p] is None ) :
continue
# Remove and then delete each of this plot's
# selection points.
for b in range( self.n_k ) :
if ( self.pnt[t,p,b] is not None ) :
self.plt[t,p].removeItem(
self.pnt[t,p,b] )
self.pnt[t,p,b] = None
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESETTING THE PLOTS' FIT CURVES.
#-----------------------------------------------------------------------
def rset_crv( self ) :
# For each plot that exists in the grid, remove and delete its
# fit curves.
for t in range( self.n_plt_y ) :
for p in range( self.n_plt_x ) :
# If the plot does not exist, move onto the the
# next one.
if ( self.plt[t,p] is None ) :
continue
# Remove and delete this plot's fit curve.
if ( self.crv[t,p] is not None ) :
self.plt[t,p].removeItem(
self.crv[t,p] )
self.crv[t,p] = None
for n in range( self.n_ion ) :
if ( self.crv_ion[t,p,n] is not None ) :
self.plt[t,p].removeItem(
self.crv_ion[t,p,n] )
self.crv_ion[t,p,n] = None
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESPONDING TO THE "rset" SIGNAL.
#-----------------------------------------------------------------------
def resp_rset( self ) :
# Clear the plots of all their elements.
self.rset_hst( )
self.rset_pnt( )
self.rset_crv( )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESPONDING TO THE "chng_spc" SIGNAL.
#-----------------------------------------------------------------------
def resp_chng_pl_spc( self ) :
# Clear the plots of all their elements and regenerate them.
self.rset_crv( )
self.rset_pnt( )
self.rset_hst( )
self.make_hst( )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESPONDING TO THE "chng_mom_pl_res" SIGNAL.
#-----------------------------------------------------------------------
def resp_chng_mom_pl_sel( self ) :
# If the results of the moments analysis are being displayed,
# reset any existing fit curves and make new ones.
self.make_pnt( )