-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_getHBTData.py
executable file
·6220 lines (5379 loc) · 238 KB
/
_getHBTData.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
"""
load HBT data, both processed and unprocessed
NOTES
-----
The convention for units is to maintain everything in SI until they are
plotted.
A few of these functions are merely wrappers for other people's code
In most of the functions below, I've specified default shotno's. This is
largely to make debugging easier as there is nothing special about the
provided shotnos.
"""
###############################################################################
### import libraries
#from __init__ import (_np,_mds,_copy,_sys,_socket,os,_pd,_plt,_plot,_time,_process,_pref)
### import libraries
# common libraries
import numpy as _np
import MDSplus as _mds
from copy import copy as _copy
import sys as _sys
import _socket
import matplotlib.pyplot as _plt
import time as _time
import pandas as _pd
# hbtepLib libraries
import _processData as _process
import _plotTools as _plot
from _processPlasma import thetaCorrection
try:
import _hbtPreferences as _pref
except ImportError:
_sys.exit("Code hault: _hbtPreferences.py file not found. See readme.md" +
" concerning the creation of _hbtPreferences.py")
###############################################################################
### constants
#_REMOTE_DATA_PATH='/opt/hbt/data/control'
if _socket.gethostname()==_pref._HBT_SERVER_NAME:
_ON_HBTEP_SERVER=True;
else:
_ON_HBTEP_SERVER=False;
###############################################################################
### global variables
# default time limits for data. units in seconds
_TSTART = 0*1e-3;
_TSTOP = 10*1e-3;
# list of known bad sensors. likely VERY outdated. also note that the code does not YET do anything with this info...
_SENSORBLACKLIST = ['PA1_S29R', 'PA1_S16P', 'PA2_S13R', 'PA2_S14P', 'PA2_S27P', 'FB03_S4R', 'FB04_S4R', 'FB08_S3P', 'FB10_S1P', 'FB04_S3P', 'FB06_S2P', 'FB08_S4P', 'TA07_S1P', 'TA02_S1P', 'TA02_S2P'];
# directory where unprocessed or minimally processed data is written locally.
#_FILEDIR='/home/john/shotData/'
###############################################################################
### decorators
def _prepShotno(func,debug=False):
"""
If no shot number is None or -1, -2, -3, etc, this decorator grabs the
latest shotnumber for whatever function is called
References
----------
https://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically/30253848#30253848
Notes
-----
# TODO(John) Add a try/except error handling for bad shot numbers or
# missing data
"""
from functools import wraps
@wraps(func) # allows doc-string to be visible through the decorator function
def inner1(*args, **kwargs):
# check to see if shotno is an arg or kwarg. if kwarg, effectively
# move it to be an arg and delete the redundant kwarg key
if len(args)>0:
shotno=args[0]
else:
shotno=kwargs.get('shotno')
del(kwargs['shotno'])
# if shotno == None
if debug==True:
print('args = ')
print(shotno)
print(type(shotno))
# check to see if it is a number (float,int,etc)
if _np.issubdtype(type(shotno),_np.integer):
# shotno = number if int(args[0]) does not throw an error
int(shotno)
# if less than 0, use python reverse indexing notation to return the most recent shots
if shotno<0:
args=(latestShotNumber()+shotno+1,)+args[1:]
waitUntilLatestShotNumber(args[0])
return func(*args, **kwargs)
# if a standard shot number (default case)
else:
# make sure the value is an integer
args=(int(shotno),)+args[1:]
waitUntilLatestShotNumber(int(shotno))
return func(*args, **kwargs)
# except ValueError:
# # it must be a string
# print("string... skipping...")
else:
# it might be None, a list, or an array
# try:
# try if it has a length (ie, it's either an array or list)
n=len(shotno)
out=[]
for i in range(n):
# if less than 0
if shotno[i]<0:
arg=(latestShotNumber()+shotno[i]+1,)+args[1:]
waitUntilLatestShotNumber(int(arg[0]))
out.append(func(*arg, **kwargs))
# if a standard shot number
else:
arg=(shotno[i],)+args[1:]
waitUntilLatestShotNumber(int(arg[0]))
out.append(func(*arg, **kwargs))
return out
# except TypeError:
# # it must be None
#
# args=(latestShotNumber(),)+args[1:]
# waitUntilLatestShotNumber(int(shotno))
# return func(*args, **kwargs)
return inner1
###############################################################################
### MDSplus tree data collection and misc. related functions
def _trimTime(time,data,tStart,tStop):
"""
Trims list of data arrays down to desired time
Parameters
----------
time : numpy.ndarray
time array
data : list (of 1D numpy.ndarrays)
list of data arrays to be trimmed
tStart : float
trims data before start time
tStop : float
trims data after stop time
Returns
-------
time : numpy.ndarray
trimmed time array
data : list (of numpy.ndarrays)
trimmed data
Notes
-----
This function does not concern itself with units (e.g. s or ms). Instead,
it is assumed that tStart and tStop have the same units as the variable, time.
"""
if tStart is None:
iStart=0;
iStop=len(time);
else:
# determine indices of cutoff regions
iStart=_process.findNearest(time,tStart); # index of lower cutoff
iStop=_process.findNearest(time,tStop); # index of higher cutoff
# trim time
time=time[iStart:iStop];
# trim data
if type(data) is not list:
data=[data];
for i in range(0,len(data)):
data[i]=data[i][iStart:iStop];
return time, data
def _initRemoteMDSConnection(shotno):
"""
Initiate remote connection with MDSplus HBT-EP tree
Parameters
----------
shotno : int
Returns
-------
conn : MDSplus.connection
connection class to mdsplus tree
"""
conn = _mds.Connection(_pref._HBT_SERVER_ADDRESS+':8003');
conn.openTree('hbtep2', shotno);
return conn
def latestShotNumber():
"""
Gets the latest shot number from the tree
Parameters
----------
Returns
-------
shot_num : int
latest shot number
"""
conn = _mds.Connection(_pref._HBT_SERVER_ADDRESS+':8003');
shot_num = conn.get('current_shot("hbtep2")')
return int(shot_num)
def waitUntilLatestShotNumber(shotno,debug=False):
"""
If the shotno that you are interested is the latest shotno,
this code checks to see if all of the data has finished recording.
If not, the code pauses until it has. Then it exits the code.
This code is useful to include in anything where you want to make sure
you aren't trying to get data from a shot number that hasn't finished recording yet.
Parameters
----------
shotno : int
shot number
debug : bool
default False.
prints text to screen to help with debugging.
"""
latestShotno=latestShotNumber()
if debug==True:
print("latest shot number : %d"%latestShotno)
print("shot number in question : %d"%shotno)
# if you haven't made it to the latest number yet
if shotno<latestShotno:
return
# if you are trying to access a number that hasn't even been created yet
elif shotno>latestShotno:
print("This shot number hasn't even been created yet. Waiting...")
stop=True
while(stop==True):
if shotno==latestShotNumber():
stop=False
else:
pass
_time.sleep(2)
# if you are trying to access a number that has been created but not finished
# if shotno==latestShotno:
# print("shotno==latestShotno")
stop=False
try:
mdsData(shotno,dataAddress=['\HBTEP2::TOP.DEVICES.WEST_RACK:CPCI:INPUT_96'],
tStart=[],tStop=[])
except _mds.TreeNODATA:
stop=True
print("Shot number has not finished. Waiting...")
while(stop==True):
_time.sleep(2)
try:
mdsData(shotno,
dataAddress=['\HBTEP2::TOP.DEVICES.WEST_RACK:CPCI:INPUT_96'],
tStart=[],tStop=[])
stop=False
_time.sleep(1)
except _mds.TreeNODATA:
pass
return
def mdsData(shotno=None,
dataAddress=['\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_94',
'\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_95'],
tStart=[],tStop=[]):
"""
Get data and optionally associated time from MDSplus tree
Parameters
----------
shotno : int
shotno of data. this function will establish its own mdsConn of this
shotno
dataAddress : list (of strings)
address of desired data on MDSplus tree
tStart : float
trims data before this time
tStop : float
trims data after this time
Returns
-------
data : list (of numpy.ndarray)
requested data
time : numpy.ndarray
time associated with data array
"""
# convert dataAddress to a list if it not one originally
if type(dataAddress) is not list:
dataAddress=[dataAddress];
# # if shotno == -1, use the latest shot number
# if shotno==-1:
# shotno=latestShotNumber()
# init arrays
time = []
data = []
# check if computer is located locally or remotely.
# The way it connects to spitzer remotely can only use one method, but locally, either method can be used.
if _ON_HBTEP_SERVER==True: # if operating local to the tree
# converted from Ian's code
tree = _mds.Tree('hbtep2', shotno)
for i in range(0,len(dataAddress)):
node = tree.getNode(dataAddress[i]) #Get the proper node
data.append(node.data()) #Get the data from this node
if type(data[0]) is _np.ndarray: # if node is an array, return data and time
time = node.dim_of().data()
else: # operaeting remotely
# if shotno is specified, this function gets its own mdsConn
if type(shotno) is float or type(shotno) is int or type(shotno) is _np.int64:
mdsConn=_initRemoteMDSConnection(shotno);
for i in range(0,len(dataAddress)):
data.append(mdsConn.get(dataAddress[i]).data())
# if data is an array, also get time
if type(data[0]) is _np.ndarray:
time = mdsConn.get('dim_of('+dataAddress[0]+')').data(); # time assocated with data
#mdsConn.closeTree('hbtep2', shotno)
mdsConn.closeAllTrees()
mdsConn.disconnect()
if time != [] and type(tStop)!=list:
# trim time and data
time,data= _trimTime(time,data,tStart,tStop)
if time != []:
return data, time
else:
return data
###############################################################################
### get device specific data
@_prepShotno
class ipData:
"""
Gets plasma current (I_p) data
Parameters
----------
shotno : int
shot number of desired data
tStart : float
time (in seconds) to trim data before
default is 0 ms
tStop : float
time (in seconds) to trim data after
default is 10 ms
plot : bool
plots all relevant plots if true
default is False
Attributes
----------
shotno : int
shot number of desired data
title : str
title to go on all plots
ip : numpy.ndarray
plasma current data
time : numpy.ndarray
time data
Subfunctions
------------
plotOfIP :
returns the plot of IP vs time
plot :
Plots all relevant plots
"""
def __init__( self,
shotno=96530,
tStart=_TSTART,
tStop=_TSTOP,
plot=False,
findDisruption=True,
verbose=False,
paIntegrate=False):
self.shotno = shotno
self.title = "%d, Ip Data" % shotno
# use the IP Rogowski coil to get IP
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.ROGOWSKIS:IP'],
tStart=tStart, tStop=tStop)
self.ip=data[0];
self.time=time;
if paIntegrate==True:
# integrate PA1 sensor data to get IP
dfPA=paData(shotno,tStart,tStop).dfDataRaw
dfPA=dfPA.drop(columns=['PA2_S27P','PA2_S14P','PA1_S16P'])
dfPA1=dfPA.iloc[:,dfPA.columns.str.contains('PA1')]
dfPA2=dfPA.iloc[:,dfPA.columns.str.contains('PA2')]
mu0=4*_np.pi*1e-7
minorRadius=0.16
self.ipPA1Integration=_np.array(dfPA1.sum(axis=1)*1.0/dfPA1.shape[1]*2*_np.pi*minorRadius/mu0)
self.ipPA2Integration=_np.array(dfPA2.sum(axis=1)*1.0/dfPA2.shape[1]*2*_np.pi*minorRadius/mu0)
if findDisruption==True:
try:
time=self.time
data=self.ip
# only look at data after breakdown
iStart=_process.findNearest(time,1.5e-3)
ipTime=time[iStart:]
ip=data[iStart:]
# filter data to remove low-frequency offset
ip2,temp=_process.gaussianHighPassFilter(ip,ipTime,
timeWidth=1./20e3,plot=verbose)
# find time derivative of ip2
dip2dt=_np.gradient(ip2)
# find the first large rise in d(ip2)/dt
threshold=40.0
index=_np.where(dip2dt>threshold)[0][0]
# debugging feature
if verbose==True:
_plt.figure()
_plt.plot(ipTime,dip2dt,label=r'$\frac{d(ip)}{dt}$')
_plt.plot([ipTime[0],ipTime[-1]],[threshold,threshold],
label='threshold')
_plt.legend()
# find the max value of ip immediately after the disrup. onset
while(ip[index]<ip[index+1]):
index+=1
self.timeDisruption=ipTime[index]
except:
print("time of disruption could not be found")
self.timeDisruption=None
if plot == True or plot=='all':
self.plot()
def plotOfIP(self):
"""
returns the plot of IP vs time
"""
fig,p1=_plt.subplots()
p1.plot(self.time*1e3,self.ip*1e-3,label='IP Rogowski')
try:
p1.plot(self.time*1e3,self.ipPA1Integration*1e-3,label='PA1')
p1.plot(self.time*1e3,self.ipPA2Integration*1e-3,label='PA2')
except:
pass
try:
p1.plot(self.timeDisruption*1e3,self.ip[self.time==self.timeDisruption]*1e-3,label='Disruption',marker='x',linestyle='')
except:
"Time of disruption not available to plot"
_plot.finalizeSubplot(p1,xlabel='Time (ms)',ylabel='Plasma Current (kA)')
_plot.finalizeFigure(fig,title=self.title)
return p1
def plot(self):
"""
Plot all relevant plots
"""
self.plotOfIP().plot()
@_prepShotno
def ipData_df( shotno=96530,
tStart=_TSTART,
tStop=_TSTOP,
plot=False,
findDisruption=True,
verbose=False,
paIntegrate=True):
"""
Gets plasma current (I_p) data
Parameters
----------
shotno : int
shot number of desired data
tStart : float
time (in seconds) to trim data before
default is 0 ms
tStop : float
time (in seconds) to trim data after
default is 10 ms
plot : bool
plots all relevant plots if true
default is False
Attributes
----------
shotno : int
shot number of desired data
title : str
title to go on all plots
ip : numpy.ndarray
plasma current data
time : numpy.ndarray
time data
Subfunctions
------------
plotOfIP :
returns the plot of IP vs time
plot :
Plots all relevant plots
"""
shotno = shotno
title = "%d, Ip Data" % shotno
# use the IP Rogowski coil to get IP
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.ROGOWSKIS:IP'],
tStart=tStart, tStop=tStop)
ip=data[0];
time=time;
dfData=_pd.DataFrame(index=time)
dfData['ip']=ip*1.0
# dfData.plot()
if paIntegrate==True:
# integrate PA1 sensor data to get IP
dfPA=paData(shotno,tStart,tStop).dfDataRaw
key='PA1'
dfPA=dfPA.iloc[:,dfPA.columns.str.contains(key)]
mu0=4*_np.pi*1e-7
minorRadius=0.16
ipPAIntegration=_np.array(dfPA.sum(axis=1)*1.0/dfPA.shape[1]*2*_np.pi*minorRadius/mu0)
dfData['ip%s'%key]=ipPAIntegration
if findDisruption==True:
try:
dfTemp=dfData[dfData.index>1.5e-3]
# filter data to remove low-frequency offset
ipSmooth,temp=_process.gaussianHighPassFilter(dfTemp.ip.to_numpy()*1.0,dfTemp.index.to_numpy(),
timeWidth=1./20e3,plot=verbose)
# find time derivative of smoothed ip
dip2dt=_np.gradient(ipSmooth)
# find the first large rise in d(ip2)/dt
threshold=15.0
index=_np.where(dip2dt>threshold)[0][0]
# debugging feature
if verbose==True:
_plt.figure()
t=dfTemp.index.to_numpy()
_plt.plot(t,dip2dt,label=r'$\frac{d(ip)}{dt}$')
_plt.plot([t[0],t[-1]],[threshold,threshold],
label='threshold')
_plt.legend()
# find the max value of ip immediately after the disrup. onset
while(dfTemp.ip.to_numpy()[index]<dfTemp.ip.to_numpy()[index+1]):
index+=1
tDisrupt=dfTemp.iloc[index].name
timeDisruption=_np.zeros(dfData.shape[0])
dfData['timeDisruption']=timeDisruption
dfData['timeDisruption'].at[tDisrupt]=dfData['ip'].at[tDisrupt]
# plt.plot(timeDisruption)
except:
print("time of disruption could not be found")
timeDisruption=None
def plot():
"""
returns the plot of IP vs time
"""
fig,p1=_plt.subplots()
p1.plot(time*1e3,ip*1e-3,label='IP Rogowski')
try:
p1.plot(time*1e3,ipPAIntegration*1e-3,label='PA')
except:
pass
try:
p1.plot(timeDisruption*1e3,ip[time==timeDisruption]*1e-3,label='Disruption',marker='x',linestyle='')
except:
"Time of disruption not available to plot"
_plot.finalizeSubplot(p1,xlabel='Time (ms)',ylabel='Plasma Current (kA)')
_plot.finalizeFigure(fig,title=title)
return p1
if plot == True or plot=='all':
plot()
return dfData
@_prepShotno
class egunData:
"""
Gets egun data
Parameters
----------
shotno : int
shot number of desired data
tStart : float
time (in seconds) to trim data before
default is 0 ms
tStop : float
time (in seconds) to trim data after
default is 10 ms
plot : bool
plots all relevant plots if true
default is False
Attributes
----------
shotno : int
shot number of desired data
title : str
title to go on all plots
heatingCurrent : numpy.ndarray
egun heating current
time : numpy.ndarray
time data
Subfunctions
------------
plot :
Plots all relevant plots
"""
def __init__(self,shotno=96530,tStart=_TSTART,tStop=_TSTOP,plot=False):
self.shotno = shotno
self.title = "%d, egun Data" % shotno
# get data
data,time=mdsData(101169,
dataAddress=['\HBTEP2::TOP.OPER_DIAGS.E_GUN:I_EMIS',
'\HBTEP2::TOP.OPER_DIAGS.E_GUN:I_HEAT',
'\HBTEP2::TOP.OPER_DIAGS.E_GUN:V_BIAS',])
self.I_EMIS=data[0]
self.heatingCurrent=data[1]
self.biasVoltage=data[2]
self.heatingCurrentRMS=_np.sqrt(_np.average((self.heatingCurrent-_np.average(self.heatingCurrent))**2));
self.time=time;
if plot == True or plot=='all':
self.plot()
def plotOfHeatingCurrent(self):
"""
returns the plot of heating current vs time
"""
fig,p1=_plt.subplots()
p1.plot(self.time*1e3,self.heatingCurrent)
_plot.finalizeSubplot(p1,xlabel='Time (ms)',ylabel='Current (A)')
_plot.finalizeFigure(fig,title=self.title)
return p1
def plot(self):
"""
Plot all relevant plots
"""
self.plotOfHeatingCurrent().plot()
@_prepShotno
class cos1RogowskiData:
"""
Gets cos 1 rogowski data
Parameters
----------
shotno : int
shot number of desired data
tStart : float
time (in seconds) to trim data before
default is 0 ms
tStop : float
time (in seconds) to trim data after
default is 10 ms
plot : bool
plots all relevant plots if true
default is False
Attributes
----------
shotno : int
shot number of desired data
title : str
title to go on all plots
cos1 : numpy.ndarray
cos1 data
time : numpy.ndarray
time data
cos2Raw : numpy.ndarray
raw cos1 data
Subfunctions
------------
plotOfIP :
returns the plot of IP vs time
plot :
Plots all relevant plots
Notes
-----
This function initially grabs data starting at -1 ms. This is because it
needs time data before 0 ms to calculate the cos1RawOffset value. After
calculating this value, the code trims off the time before tStart.
"""
def __init__(self,shotno=96530,tStart=_TSTART,tStop=_TSTOP,plot=False):
self.shotno = shotno
self.title = "%d, Cos1 Rog. Data" % shotno
# get data. need early time data for offset subtraction
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.ROGOWSKIS:COS_1',
'\HBTEP2::TOP.SENSORS.ROGOWSKIS:COS_1:RAW'],
tStart=-1*1e-3, tStop=tStop)
# calculate offset
self.cos1Raw=data[1]
indices=time<0.0*1e-3
self.cos1RawOffset=_np.mean(self.cos1Raw[indices])
# trime time before tStart
iStart=_process.findNearest(time,tStart)
self.cos1=data[0][iStart:];
self.time=time[iStart:];
self.cos1Raw=self.cos1Raw[iStart:]
if plot == True or plot=='all':
self.plot()
def plotOfCos1(self):
"""
returns the plot of cos1 rog vs time
"""
# p1=_plot.plot(yLabel='',xLabel='time [ms]',title=self.title,
# subtitle='Cos1 Rogowski',shotno=[self.shotno])
# p1.addTrace(xData=self.time*1000,yData=self.cos1)
#
# return p1
fig,p1=_plt.subplots()
p1.plot(self.time*1e3,self.cos1)
_plot.finalizeSubplot(p1,xlabel='Time (ms)',ylabel='')
_plot.finalizeFigure(fig,title=self.title)
return p1
def plot(self):
"""
Plot all relevant plots
"""
self.plotOfCos1().plot()
@_prepShotno
class bpData:
"""
Downloads bias probe data from both probes.
Parameters
----------
shotno : int
shot number of desired data
tStart : float
time (in seconds) to trim data before \line
default is 0 ms
tStop : float
time (in seconds) to trim data after
default is 10 ms
plot : bool
plots all relevant plots if true
default is False
Attributes
----------
shotno : int
shot number of desired data
ip : numpy.ndarray
plasma current data
time : numpy.ndarray
time data
title : str
title of all included figures
bps9Voltage : numpy.ndarray
bps9 voltage
bps9Current : numpy.ndarray
bps9 current
bps5Voltage : numpy.ndarray
bps9 voltage
bps5Current : numpy.ndarray
bps9 current
bps9GPURequestVoltage : numpy.ndarray
CPCI measurement of pre-amp voltage, out from the GPU, and going to
control bps9
Subfunctions
------------
plotOfGPUVoltageRequest :
Plot of gpu request voltage (as measured by the CPCI)
plotOfVoltage :
Plot of both bias probe voltages
plotOfCurrent :
Plot of both bias probe currents
plotOfBPS9Voltage :
Plot of bps9 voltage only
plotOfBPS9Current :
Plot of bps9 current only
plot :
Plots all relevant plots
Notes
-----
BPS5 was moved to section 2 (now BPS2) summer of 2017. Instrumented on May 22, 2018.
"""
# TODO(John) Time should likely be split into s2 and s9 because different
# racks often have slightly different time bases
# TODO(John) Determine when the Tree node for the BP was added, and have
# this code automatically determine whether to use the old or new loading
# method
# TODO(John) Also, one of the BPs was moved recently. Need to figure out
# how to handle this
# TODO(John) these probes have been periodically moved to different nodes.
# implement if lowerbound < shotno < upperbound conditions to handle these cases
def __init__(self,shotno=98147,tStart=_TSTART,tStop=_TSTOP,plot=False):
self.shotno = shotno
self.title = "%s, BP Data." % shotno
if shotno > 99035 or shotno==-1:
# BPS5 was moved to section 2
# get voltage data
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.BIAS_PROBE_9:VOLTAGE',
'\HBTEP2::TOP.SENSORS.BIAS_PROBE_9:CURRENT'],
tStart=tStart, tStop=tStop)
self.bps9Voltage=data[0];
self.bps9Current=data[1];#r*-1; # signs are flipped somewhere
self.time=time;
# get current data
try:
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.BIAS_PROBE_2:VOLTAGE',
'\HBTEP2::TOP.SENSORS.BIAS_PROBE_2:CURRENT'],
# dataAddress=['\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_85',
# '\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_84'],
tStart=tStart, tStop=tStop)
self.bps2Voltage=data[0]#*100; #TODO get actual voltage divider info
self.bps2Current=data[1]*-1#/0.05;
except:
"no bp2"
elif shotno > 96000 and shotno < 99035 :
#TODO(determine when this probe was rewired or moved)
# get voltage data
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.BIAS_PROBE_9:VOLTAGE',
'\HBTEP2::TOP.SENSORS.BIAS_PROBE_9:CURRENT'],
tStart=tStart, tStop=tStop)
self.bps9Voltage=data[0];
self.bps9Current=data[1]*-1; # signs are flipped somewhere
self.time=time;
# get current data
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.BIAS_PROBE_5:VOLTAGE',
'\HBTEP2::TOP.SENSORS.BIAS_PROBE_5:CURRENT'],
tStart=tStart, tStop=tStop)
self.bps5Voltage=data[0];
self.bps5Current=data[1];
## previous BP addresses. do not delete this until implemented
# if probe == 'BPS5' or probe == 'both':
# self.currentBPS5=conn.get('\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_83').data()/.01/5;
# self.voltageBPS5 = conn.get('\HBTEP2::TOP.DEVICES.NORTH_RACK:CPCI:INPUT_82').data()*80;
# if probe == 'BPS9' or probe == 'both':
# self.timeBPS9 = conn.get('dim_of(\TOP.DEVICES.SOUTH_RACK:A14:INPUT_3)').data();
# self.voltageBPS9 = (-1.)*conn.get('\TOP.DEVICES.SOUTH_RACK:A14:INPUT_4').data()/.00971534052268532 / 1.5
else:
# get voltage data
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.BIAS_PROBE:VOLTAGE',
'\HBTEP2::TOP.SENSORS.BIAS_PROBE:CURRENT'],
tStart=tStart, tStop=tStop)
self.bps9Voltage=data[0];
self.bps9Current=data[1]*-1; # signs are flipped somewhere
self.time=time;
# get current data
try:
data, time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.SENSORS.BIAS_PROBE_2:VOLTAGE',
'\HBTEP2::TOP.SENSORS.BIAS_PROBE_2:CURRENT'],
tStart=tStart, tStop=tStop)
self.bps5Voltage=data[0];
self.bps5Current=data[1];
except:
print("skipping bps5")
# transformer primary voltage. first setup for shot 100505 and on.
[primaryVoltage,primaryCurrent], time=mdsData(shotno=shotno,
dataAddress=['\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_86',
'\HBTEP2::TOP.DEVICES.SOUTH_RACK:CPCI_10:INPUT_87'],
tStart=tStart, tStop=tStop)
self.primaryVoltage=primaryVoltage*(0.745/(110+.745))**(-1) # correct for voltage divider
self.primaryCurrent=primaryCurrent*0.01**(-1) # correct for Pearson correction factor
# self.primaryCurrent*=1; #the sign is wrong.
# self.primaryVoltage*=-1; #the sign is wrong.
# get gpu request voltage (for when the BP is under feedforward or feedback control)
data, time=mdsData(shotno=shotno,