forked from JanusWind/FC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjanus_core.py
3626 lines (2498 loc) · 103 KB
/
janus_core.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 ([email protected])
##
## 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 signaling the graphical interface.
from PyQt4.QtCore import QObject, SIGNAL, QThread
# Load the modules necessary for file operations.
import os.path
# Load the modules necessary for handling dates and times.
from time import sleep
from datetime import datetime, timedelta
from janus_time import calc_time_epc, calc_time_sec, calc_time_val
# Load the module necessary handling step functions.
from janus_step import step
# Load the dictionary of physical constants.
from janus_const import const
# Load the modules necessary for loading Wind/FC and Wind/MFI data.
from janus_fc_arcv import fc_arcv
from janus_mfi_arcv import mfi_arcv
# Load the necessary array modules and mathematical functions.
from numpy import amax, amin, append, arccos, arange, argsort, array, average, \
cos, deg2rad, diag, dot, exp, indices, interp, mean, pi, \
polyfit, rad2deg, reshape, sign, sin, sum, sqrt, std, tile, \
transpose, where, zeros
from numpy.linalg import lstsq
from scipy.interpolate import interp1d
from scipy.optimize import curve_fit
from scipy.special import erf
from scipy.stats import pearsonr, spearmanr
from janus_helper import round_sig
# Load the "pyon" module.
from janus_pyon import plas, series
# Load the modules necessary for saving results to a data file.
import pickle
################################################################################
## DEFINE THE "core" CLASS: THE ANLYSIS CORE OF JANUS.
################################################################################
class core( QObject ) :
# +-------------------+------------------------------+
# | SIGNAL('janus_*') | Arguments |
# +-------------------+------------------------------+
# | busy_beg | |
# | busy_end | |
# | mesg | mesg_src, mesg_typ, mesg_obj |
# | rset | |
# | chng_spc | |
# | chng_mfi | |
# | chng_mom_sel_cur | t, p, v |
# | chng_mom_sel_azm | t, p |
# | chng_mom_sel_all | |
# | chng_mom_res | |
# | chng_nln_ion | |
# | chng_nln_set | |
# | chng_nln_gss | |
# | chng_nln_sel_cur | t, p, v |
# | chng_nln_sel_all | |
# | chng_nln_res | |
# | chng_dsp | |
# | chng_dyn | |
# | done_auto_run | |
# | exit | |
# +-------------------+------------------------------+
#-----------------------------------------------------------------------
# DEFINE THE INITIALIZATION FUNCTION.
#-----------------------------------------------------------------------
def __init__( self, app=None, time=None ) :
# Inheret all attributes of the "QObject" class.
# Note. This class does not directly provide any graphical
# interface. Rather, the functions of the "QObject"
# class are used principally for signal the classes that
# do.
super( core, self ).__init__( )
self.app = app
# Read and store the version information.
# Note. The "[:-1]" array operation used below trims the final
# character (which should be an end-line) from the line
# read from the file.
fl = open( os.path.join( os.path.dirname( __file__ ),
'janus.dat' ) )
self.version = fl.readline( )[:-1]
fl.close( )
# Initialially deactiveate the debugging mode.
self.debug = False
# Initialize and store the archive of Wind/FC ion spectra.
self.fc_arcv = fc_arcv( core=self )
###self.fc_arcv = fc_arcv( core=self, use_idl=True,
### buf=-1. )
# Initialize and store the archive of Wind/MFI magnetic field
# data.
self.mfi_arcv = mfi_arcv( core=self )
###self.mfi_arcv = mfi_arcv( core=self, use_k0=True,
### buf=-1., tol=90. )
###self.mfi_arcv = mfi_arcv( core=self, use_idl=True,
### buf=-1., tol=90. )
# Initialize a log of the analysis results.
self.series = series( )
# Initialize the variables that will contain the Wind/FC ion
# spectrum's data, the associated Wind/MFI magnetic field data,
# the ion spectrum's point selection, and the results of the
# moments analysis of the ion spectrum.
self.init_var( )
# Load the requested Wind/FC ion spectrum (if one has been
# requested).
# Note. After loading the Wind/FC ion spectrum,
# "self.load_spec" calls "self.load_mfi" to load the
# associated Wind/MFI magnetic field data and then calls
# "self.auto_sel" to make an automatic selection of the
# spectrum's data. In turn, "self.auto_sel" calls
# "self.anls_mom" to perform a moments analysis on the
# selected data.
if ( time is not None ) :
self.load_spec( time )
#-----------------------------------------------------------------------
# INITIALIZE THE THE DATA AND ANALYSIS VARIABLES.
#-----------------------------------------------------------------------
def init_var( self ) :
# Initialize the variables that will contain the Wind/FC ion
# spectrum's data; the associated Wind/MFI magnetic field data;
# and the settings, data selections, and results from all
# analyses.
self.rset_var( var_swe=True, var_mfi=True,
var_mom_win=True, var_mom_sel=True,
var_mom_res=True, var_nln_ion=True,
var_nln_set=True, var_nln_gss=True,
var_nln_sel=True, var_nln_res=True,
var_dsp=True, var_dyn=True )
# Define the data array with values for effective collecting
# area, "eff_area", as a function of inflow angle, "deg".
self.eff_deg = arange( 0., 91., dtype=float )
self.eff_area = 1.e-5 * array( [
3382000.0, 3383000.0, 3383000.0, 3382000.0, 3381000.0,
3380000.0, 3378000.0, 3377000.0, 3376000.0, 3374000.0,
3372000.0, 3369000.0, 3368000.0, 3364000.0, 3362000.0,
3359000.0, 3355000.0, 3351000.0, 3347000.0, 3343000.0,
3338700.0, 3334100.0, 3329300.0, 3324300.0, 3318200.0,
3312800.0, 3306300.0, 3299600.0, 3292800.0, 3285900.0,
3277800.0, 3270700.0, 3261600.0, 3253500.0, 3244500.0,
3234600.0, 3224900.0, 3200100.0, 3161500.0, 3114000.0,
3058820.0, 2997170.0, 2930000.0, 2857000.0, 2779000.0,
2694000.0, 2586999.7, 2465000.0, 2329999.6, 2183000.0,
2025999.6, 1859000.1, 1682999.6, 1497000.1, 1301999.6,
1099000.1, 887799.56, 668500.16, 452099.62, 257500.16,
96799.784, 539.96863, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000,
0.0000000 ] )
# Initialize the value of the indicator variable of whether the
# automatic analysis should be aborted.
# Note. This variable provides the user with a means of
# prematurely stopping the automatic analysis of a series
# of spectra by the function "self.auto_run". When that
# function is called, this indicator's value is set to
# "False". After the function processes a given
# spectrum, it procedes on to the next one only if this
# indicator is still "False".
self.stop_auto_run = False
#-----------------------------------------------------------------------
# RESET THE DATA AND ANALYSIS VARIABLES.
#-----------------------------------------------------------------------
def rset_var( self,
var_swe=False, var_mfi=False,
var_mom_win=False, var_mom_sel=False,
var_mom_res=False, var_nln_ion=False,
var_nln_set=False, var_nln_gss=False,
var_nln_sel=False, var_nln_res=False,
var_dsp=False, var_dyn=False ) :
# If requested, (re-)initialize the variables associated with
# the ion spectrum's data.
if ( var_swe ) :
self.time_epc = None
self.time_val = None
self.time_txt = ''
self.time_vld = True
self.rot_sec = 3.
self.dur_sec = 0.
self.alt = None
self.azm = None
self.vel_cen = None
self.vel_wid = None
self.cur = None
self.cur_vld = None
self.cur_jmp = 100.
self.cur_min = 1.
self.mag_t = None
self.mag_x = None
self.mag_y = None
self.mag_z = None
self.n_alt = 0
self.n_azm = 0
self.n_vel = 0
# If requested, (re-)initialize the varaibles for the Wind/MFI
# data associated with this spectrum.
if ( var_mfi ) :
self.n_mfi = 0
self.mfi_dur = 0.
self.mfi_t = None
self.mfi_b = None
self.mfi_b_x = None
self.mfi_b_y = None
self.mfi_b_z = None
self.mfi_avg_mag = None
self.mfi_avg_vec = None
self.mfi_avg_nrm = None
self.mfi_hat_dir = None
# If requested, (re-)initialize the varaibles for the windows
# associated with automatic data selection for the moments
# analysis.
if ( var_mom_win ) :
self.mom_win_azm_req = 7
self.mom_win_cur_req = 7
self.mom_win_azm_txt = ''
self.mom_win_cur_txt = ''
self.mom_win_azm = self.mom_win_azm_req
self.mom_win_cur = self.mom_win_azm_req
# If requested, (re-)initialize the variables associated with
# the data seleciton for the moments analysis.
if ( var_mom_sel ) :
self.mom_n_sel_azm = 0
self.mom_n_sel_cur = None
self.mom_min_sel_azm = 5
self.mom_min_sel_cur = 3
self.mom_sel_azm = None
self.mom_sel_cur = None
# If requested, (re-)initialize and store the variables
# associated with the results of the moments analysis.
if ( var_mom_res ) :
self.mom_n_eta = 0
self.mom_eta_ind_t = None
self.mom_eta_ind_p = None
self.mom_eta_n = None
self.mom_eta_v = None
self.mom_eta_w = None
self.mom_eta_t = None
self.mom_corr_pears = None
self.mom_corr_spear = None
self.mom_n = None
self.mom_v = None
self.mom_w = None
self.mom_t = None
self.mom_r = None
self.mom_v_vec = None
self.mom_w_per = None
self.mom_w_par = None
self.mom_t_per = None
self.mom_t_par = None
self.mom_cur = None
# If requested, (re-)initialize the variables associated with
# the ion species and populations for the non-linear analysis.
# Note. This includes both the "self.nln_spc_?" and
# "self.nln_pop_?" arrays. These are done together since
# they are so interconnected by the "self.nln_pyon"
# object, which is also handled here.
if ( var_nln_ion ) :
self.nln_n_spc = 4
self.nln_n_pop = 5
self.nln_pyon = plas( enforce=True )
self.nln_pop_use = tile( False, self.nln_n_pop )
self.nln_pop_vld = tile( False, self.nln_n_pop )
for s in range ( self.nln_n_spc ) :
if ( s == 0 ) :
self.nln_pyon.add_spec( name='Proton',
sym='p', m=1., q=1. )
elif ( s == 1 ) :
self.nln_pyon.add_spec( name='Alpha' ,
sym='a', m=4., q=2. )
else :
self.nln_pyon.add_spec( )
for p in range ( self.nln_n_pop ) :
if ( p == 0 ) :
self.nln_pop_use[p] = True
self.nln_pop_vld[p] = True
self.nln_pyon.add_pop(
'p', name='Core', sym='c',
drift=False, aniso=True )
elif ( p == 1 ) :
self.nln_pop_use[p] = False
self.nln_pop_vld[p] = True
self.nln_pyon.add_pop(
'p', name='Beam', sym='b',
drift=True , aniso=False )
elif ( p == 2 ) :
self.nln_pop_use[p] = True
self.nln_pop_vld[p] = True
self.nln_pyon.add_pop(
'a', name='Core', sym='c',
drift=True , aniso=True )
elif ( p == 3 ) :
self.nln_pop_use[p] = False
self.nln_pop_vld[p] = True
self.nln_pyon.add_pop(
'a', name='Beam', sym='b',
drift=True , aniso=False )
else :
self.nln_pop_use[p] = False
self.nln_pop_vld[p] = False
self.nln_pyon.add_pop( None )
# If requested, (re-)initialize the variables associated with
# the settings for the automatic initial guess generation and
# the automatic point selection.
if ( var_nln_set ) :
self.nln_set_gss_n = tile( None , self.nln_n_pop )
self.nln_set_gss_d = tile( None , self.nln_n_pop )
self.nln_set_gss_w = tile( None , self.nln_n_pop )
self.nln_set_gss_vld = tile( False, self.nln_n_pop )
self.nln_set_sel_a = tile( None , self.nln_n_pop )
self.nln_set_sel_b = tile( None , self.nln_n_pop )
self.nln_set_sel_vld = tile( False, self.nln_n_pop )
self.nln_set_gss_n[0] = 1.00
self.nln_set_gss_n[1] = 0.20
self.nln_set_gss_n[2] = 0.02
self.nln_set_gss_n[3] = 0.01
self.nln_set_gss_d[1] = 0.03
self.nln_set_gss_d[2] = 0.01
self.nln_set_gss_d[3] = 0.05
self.nln_set_gss_w[0] = 1.00
self.nln_set_gss_w[1] = 1.25
self.nln_set_gss_w[2] = 1.00
self.nln_set_gss_w[3] = 1.25
self.nln_set_gss_vld[0] = True
self.nln_set_gss_vld[1] = True
self.nln_set_gss_vld[2] = True
self.nln_set_gss_vld[3] = True
self.nln_set_sel_a[0] = -3.00
self.nln_set_sel_a[1] = -3.00
self.nln_set_sel_a[2] = -3.00
self.nln_set_sel_a[3] = -3.00
self.nln_set_sel_a[4] = -3.00
self.nln_set_sel_b[0] = 3.00
self.nln_set_sel_b[1] = 3.00
self.nln_set_sel_b[2] = 3.00
self.nln_set_sel_b[3] = 3.00
self.nln_set_sel_b[4] = 3.00
self.nln_set_sel_vld[0] = True
self.nln_set_sel_vld[1] = True
self.nln_set_sel_vld[2] = True
self.nln_set_sel_vld[3] = True
self.nln_set_sel_vld[4] = True
# If requested, (re-)initialize the variables associated with
# the initial guesses for the non-linear analysis.
if ( var_nln_gss ) :
for p in range( self.nln_n_pop ) :
self.nln_pyon.arr_pop[p]['n'] = None
self.nln_pyon.arr_pop[p]['dv'] = None
self.nln_pyon.arr_pop[p]['w'] = None
self.nln_pyon.arr_pop[p]['w_per'] = None
self.nln_pyon.arr_pop[p]['w_par'] = None
self.nln_gss_vld = tile( False, self.nln_n_pop )
self.nln_gss_pop = array( [ ] )
self.nln_gss_prm = array( [ ] )
self.nln_gss_cur_tot = None
self.nln_gss_cur_ion = None
# If requested, (re-)initialize the variables associated with
# the data selection for the non-linear analysis.
if ( var_nln_sel ) :
self.nln_sel = None
self.nln_n_sel = 0
self.nln_min_sel = 30
# If requested, (re-)initialize the variables associated with
# the results of the non-linear analysis.
if ( var_nln_res ) :
self.nln_res_plas = plas( enforce=False )
self.nln_res_sel = None
self.nln_res_cur_tot = None
self.nln_res_cur_ion = None
# If requested, (re-)initialize the variables which indicate of
# the analyses have their results displayed in widgets which
# support output from multiple analyses.
if ( var_dsp ) :
self.dsp = 'mom'
# If requested, (re-)initialize the variables which indicate
# which analyses are updated automatically when a change is
# made to their settings.
if ( var_dyn ) :
self.dyn_mom = True
self.dyn_gss = True
self.dyn_sel = True
self.dyn_nln = False
#-----------------------------------------------------------------------
# LOAD THE REQUESTED WIND/FC SPECTRUM.
#-----------------------------------------------------------------------
def load_spec( self, time_req=None,
get_prev=False, get_next=False,
tmin=None, tmax=None ) :
# Reset the variables that contain the Wind/FC ion spectrum's
# data, the associated Wind/MFI magnetic field data, and the
# results of all analyses.
# Note. Not all of the "self.rset_var" keywords are set to
# "True" so as to retain the general settings (even
# though a new spectrum is being loaded).
self.emit( SIGNAL('janus_rset') )
self.rset_var( var_swe=True, var_mfi=True,
var_mom_sel=True, var_mom_res=True,
var_nln_gss=True, var_nln_sel=True,
var_nln_res=True )
# If a special code has been entered, take the specified action.
if ( str( time_req ).lower( ) == 'iddqd' ) :
self.emit( SIGNAL('janus_chng_spc') )
if ( self.debug ) :
self.debug = False
self.emit( SIGNAL('janus_mesg'),
'core', 'end', 'debug' )
else :
self.debug = True
self.emit( SIGNAL('janus_mesg'),
'core', 'begin', 'debug' )
return
# Convert the argument "time_req" into the standard, second-
# precision, string format. If this conversion returns "None",
# label the requested time as invalid.
self.time_txt = calc_time_sec( time_req )
if ( self.time_txt is None ) :
if ( type( time_req ) == str ) :
self.time_txt = time_req
else :
self.time_txt = ''
self.time_vld = False
else :
self.time_vld = True
# If necessary, adjust "self.dsp" and "self.dyn_???" keywords to
# make them a bit more mutually consistent.
if ( ( self.dsp == 'gsl' ) or ( self.dsp == 'nln' ) ) :
self.dyn_mom = True
self.dyn_gss = True
self.dyn_sel = True
if ( ( self.dsp == 'nln' ) and ( not self.dyn_nln ) ) :
self.dsp = 'gsl'
self.emit( SIGNAL('janus_chng_dyn') )
self.emit( SIGNAL('janus_chng_dsp') )
# If no valid time was requested, alert the user and abort.
if ( not self.time_vld ) :
self.emit( SIGNAL('janus_mesg'),
'core', 'fail', 'time' )
return
# Message the user that a new Wind/FC ion spectrum is about to
# be loaded.
self.emit( SIGNAL('janus_mesg'), 'core', 'begin', 'fc' )
# Load the Wind/FC ion spectrum with a timestamp closest to that
# requested.
spec = self.fc_arcv.load_spec( self.time_txt,
get_prev=get_prev,
get_next=get_next,
tmin=tmin, tmax=tmax )
# If no spectrum was found, abort.
if ( spec is None ) :
self.emit( SIGNAL('janus_chng_spc') )
return
# Extract the parameters of the loaded Wind/FC ion spectrum.
( time_epc,
cup1_azm , cup2_azm , cup1_c_vol, cup2_c_vol,
cup1_d_vol, cup2_d_vol, cup1_cur , cup2_cur ) = spec
# Calculate and store the spectrum's properly formatted
# timestamp both as a float and as a string.
self.time_epc = time_epc
self.time_val = calc_time_val( time_epc )
self.time_txt = calc_time_sec( time_epc )
self.time_vld = True
# Convert bin centers and widths from voltages [V] to velocities
# [km/s].
cup1_vol_a = cup1_c_vol - ( cup1_d_vol / 2. )
cup1_vol_b = cup1_c_vol + ( cup1_d_vol / 2. )
cup2_vol_a = cup2_c_vol - ( cup2_d_vol / 2. )
cup2_vol_b = cup2_c_vol + ( cup2_d_vol / 2. )
cup1_c_vel = 1E-3 * sqrt( 2 * const['q_p'] * cup1_c_vol /
const['m_p'] )
cup1_vel_a = 1E-3 * sqrt( 2 * const['q_p'] * cup1_vol_a /
const['m_p'] )
cup1_vel_b = 1E-3 * sqrt( 2 * const['q_p'] * cup1_vol_b /
const['m_p'] )
cup2_c_vel = 1E-3 * sqrt( 2 * const['q_p'] * cup2_c_vol /
const['m_p'] )
cup2_vel_a = 1E-3 * sqrt( 2 * const['q_p'] * cup2_vol_a /
const['m_p'] )
cup2_vel_b = 1E-3 * sqrt( 2 * const['q_p'] * cup2_vol_b /
const['m_p'] )
cup1_d_vel = cup1_vel_b - cup1_vel_a
cup2_d_vel = cup2_vel_b - cup2_vel_a
# Determine the number of valid speed windows by searching
# through the "c_vel_?" arrays and indentifying the first time
# that an element is immediately followed by an element with a
# smaller value.
# Note. The velocity windows should be assending order, and
# unused windows sould occur at the end of the "?_vel_?"
# and be indicated by having their corresponding elements
# in these arrays set to the instrument's minimum value
# for that parameter.
n_vel = 1
while ( ( n_vel < len( cup1_c_vel ) ) and
( n_vel < len( cup2_c_vel ) ) ) :
if ( ( cup1_c_vel[n_vel] < cup1_c_vel[n_vel-1] ) or
( cup2_c_vel[n_vel] < cup2_c_vel[n_vel-1] ) ) :
break
else :
n_vel += 1
# Truncate the arrays to remove fill data.
cup1_c_vel = cup1_c_vel[0:n_vel]
cup1_d_vel = cup1_d_vel[0:n_vel]
cup1_cur = cup1_cur[:,0:n_vel]
cup2_c_vel = cup2_c_vel[0:n_vel]
cup2_d_vel = cup2_d_vel[0:n_vel]
cup2_cur = cup2_cur[:,0:n_vel]
# Merge and store the arrays from the two cups. As part of this
# step, define the array of altitudes.
# CAUTION! There is currently no check to ensure that "c_vel_1"
# and "c_vel_2" are (to with floating point precision)
# identical. Likewise, there is no check on "d_vel_1"
# and "d_vel_2".
self.alt = array( [ 15., -15. ] ) # deg
self.azm = array( [ cup1_azm, cup2_azm ] ) # deg
self.vel_cen = cup1_c_vel # km/s
self.vel_wid = cup1_d_vel # km/s
self.cur = array( [ cup1_cur, cup2_cur ] ) # pA
# Store the counts of velocity bins and angles.
self.n_alt = 2
self.n_azm = 20
self.n_vel = n_vel
# Examine each measured current value and determine whether or
# not it's valid for use in the proceding analyses.
self.cur_vld = tile( True,
[ self.n_alt, self.n_azm, self.n_vel ] )
for t in range( self.n_alt ) :
if ( n_vel < 2 ) :
continue
for p in range( self.n_azm ) :
for v in range( self.n_vel ) :
if ( self.cur[t,p,v] < self.cur_min ) :
self.cur_vld[t,p,v] = False
continue
if ( v == 0 ) :
if ( self.cur[t,p,v] >
( self.cur_jmp *
self.cur[t,p,v+1] ) ) :
self.cur_vld[t,p,v] = \
False
continue
if ( v == ( self.n_vel - 1 ) ) :
if ( self.cur[t,p,v] >
( self.cur_jmp *
self.cur[t,p,v-1] ) ) :
self.cur_vld[t,p,v] = \
False
continue
if ( ( self.cur[t,p,v] >
( self.cur_jmp *
self.cur[t,p,v-1] ) ) and
( self.cur[t,p,v] >
( self.cur_jmp *
self.cur[t,p,v+1] ) ) ) :
self.cur_vld[t,p,v] = False
# Estimate the duration of each spectrum and the mean time
# offset of each velocity bin.
self.rot_sec = 3.
self.dur_sec = self.rot_sec * self.n_vel
self.mag_t = self.rot_sec * ( arange( self.n_vel ) + 0.5 )
# Message the user that a new Wind/FC ion spectrum has been
# loaded.
self.emit( SIGNAL('janus_mesg'), 'core', 'end', 'fc' )
# Emit a signal that indicates that a new Wind/FC ion spectrum
# has now been loaded.
self.emit( SIGNAL('janus_chng_spc') )
# Load the associated Wind/MFI magnetic field data associated
# with this spectrum.
self.load_mfi( )
# If requested, run the moments analysis.
if ( self.dyn_mom ) :
self.anls_mom( )
# FIXME
"""
# If requested (and required), generate an initial guess for
# the non-linear analysis.
if ( ( self.dyn_gss ) and
( len( self.nln_gss_prm ) == 0 ) ) :
self.auto_nln_gss( )
# If requested (and required), select data for the non-linear
# analysis.
if ( ( self.dyn_sel ) and
( self.nln_sel is None ) ) :
self.auto_nln_sel( )
# If requested (and required), run the non-linear analysis.
if ( ( self.dyn_nln ) and
( self.nln_res_n_ion == 0 ) ) :
self.anls_nln( )
"""
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR LOADING THE Wind/MFI MAGNETIC FIELD DATA.
#-----------------------------------------------------------------------
def load_mfi( self ) :
# Reset the contents of the "self.mfi_*" arrays.
self.rset_var( var_mfi=True )
# If no Wind/FC ion spectrum has been loaded, abort.
if ( ( self.time_epc is None ) or
( self.n_vel is None ) or
( self.n_vel == 0 ) ) :
return
# Message the user that new Wind/MFI data are about to be
# loaded.
self.emit( SIGNAL('janus_mesg'), 'core', 'begin', 'mfi' )
# Load the Wind/MFI magnetic field data associated with this
# spectrum.
( mfi_t, mfi_b_x, mfi_b_y, mfi_b_z ) = \
self.mfi_arcv.load_rang( self.time_val, self.dur_sec )
# Establish the number of data.
self.n_mfi = len( mfi_t )
# If no magnetic field data were returned, abort with a signal
# that the data have changed.
if ( self.n_mfi == 0 ) :
self.emit( SIGNAL('janus_chng_mfi') )
return
# Store the loaded data. As part of this step, shift the data's
# timestamps to be relative to the start time of this Wind/FC
# ion spectrum.
self.mfi_t = array( [ ( t - self.time_epc ).total_seconds( )
for t in mfi_t ] )
self.mfi_b_x = mfi_b_x
self.mfi_b_y = mfi_b_y
self.mfi_b_z = mfi_b_z
# Compute the magnetic field magnitude.
self.mfi_b = sqrt( self.mfi_b_x**2 + self.mfi_b_y**2
+ self.mfi_b_z**2 )
# Compute the average magetic field.
self.mfi_avg_vec = array( [ mean( self.mfi_b_x ),
mean( self.mfi_b_y ),
mean( self.mfi_b_z ) ] )
self.mfi_avg_mag = sqrt( self.mfi_avg_vec[0]**2 +
self.mfi_avg_vec[1]**2 +
self.mfi_avg_vec[2]**2 )
self.mfi_avg_nrm = self.mfi_avg_vec / self.mfi_avg_mag
# Compute the dot product between the average, normalized
# magnetic field and each look direction.
self.mfi_hat_dir = array( [ [
dot( self.calc_dir_look( self.alt[t], self.azm[t,p] ),
self.mfi_avg_nrm )
for p in range( self.n_azm ) ]
for t in range( self.n_alt ) ] )
# Use interpolation to estimate a magnetic-field vector for each
# velocity bin.
var_t = self.mag_t
tk_lo = where( var_t < amin( self.mfi_t ) )
tk_hi = where( var_t > amax( self.mfi_t ) )
var_t[tk_lo] = amin( self.mfi_t )
var_t[tk_hi] = amax( self.mfi_t )
self.mag_x = interp1d( self.mfi_t, self.mfi_b_x,
bounds_error=False )( var_t )
self.mag_y = interp1d( self.mfi_t, self.mfi_b_y,
bounds_error=False )( var_t )
self.mag_z = interp1d( self.mfi_t, self.mfi_b_z,
bounds_error=False )( var_t )
# Message the user that new Wind/MFI data have been loaded.
self.emit( SIGNAL('janus_mesg'), 'core', 'end', 'mfi' )
# Emit a signal that indicates that a new Wind/MFI data have now
# been loaded.
self.emit( SIGNAL('janus_chng_mfi') )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR COMPUTING A DOT PRODUCT OR ARRAY THEREOF.
#-----------------------------------------------------------------------
def calc_arr_dot( self, a, b ) :
# CAUTION! It is assumed that "a" and "b" are "numpy" arrays.
# For increased speed, no checks are made of this.
# If "a" and "b" are arrays of vectors, return an array where