-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThom.py
222 lines (164 loc) · 5.51 KB
/
Thom.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
from ts import *
import numpy
from MDSplus import *
import csv
import os
from scipy.io import netcdf
import time
"""
NAME
PyThom: NSTX Thompson Scattering Analysis Code
PURPOSE
Analyze Output of NSTX Thomson Scattering Diagnostic
STATUS
Under development and minimally operational. Modules are in ts.py.
RUN
module load nstx/python
Python PyThom.py [SHOT NUMBER]
USER INPUTS
Shot Number
OTHER INPUTS
- setup.netcdf (see utils, netcdf_gen.py)
- NSTX MDSplus structure
- ./ss/ folder (a crutch till new datastream)
OTHER PARAMETERS
- # of processors on system (nproc)
OUTPUTS
[shot number].npz file which contains timings and \
profile information
- timing information is a (X) length array
- profile information is a (30,2,X) array
LOG
20/06/13: Research Begins
03/07/13: Prototyping Begins
22/07/13: Importing Functional(?)
24/07/13: Scattered Photo-electrons Functional
03/08/13: Fitting Functional
03/13/13: MOC Operational
CONTACT
Ben Horowitz (Yale University)
"""
tic = time.time()
shot = int(sys.argv[1])
good = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
nproc = 8 #Number of system processors
#configuration data
#generated with netcdf_gen.py
conf = netcdf.netcdf_file('setup.netcdf', 'r')
#read in list of paths
ins = open("paths", "r") # file that holds the name of all MDS routes of interest and their natural name
path = [] # path list that will be formed
nb = {} # numerical name to path name
type = {} # key from "natural name" to numerical name in data array
for x,line in enumerate(ins):
columns = line.split()
path.append(str(columns[0]))
nb[x] = str(columns[0])
type[str(columns[1])] = x
ins.close()
# navigate to data
tree = MDSplus.Tree('nstx', shot, 'Readonly')
# get plasma current
p = tree.getNode('\engineering::ip1')
ip1 = p.getData().data()
p = tree.getNode('\engineering::ip2')
ip2 = p.getData().data()
ip = ip2/(1e6)
#shutters, s1 and s2 are either OPEN or CLOSED
s1, s2, r = ts.goto_rawdata(shot)
shut_config = ts.shut_config(s1,s2) # assigns numerical name (0,1,2,3,99) for shutter configuration, used in nfactor querry
R = [[]]
for x in path:
#reads in all data to numpy array structure
p = tree.getNode(x)
ll = p.getData().data()
R.append(ll)
Times_Laser1, Times_Laser2, Times_dark, Times_all, it_las01, it_las02, it_Dark, cond_laser1, cond_laser2 = ts.times(R,type) #gets timing information for shot
data = ts.get_raw(R,type) #loads raw data into array
#anomolout entries in it_las01/02...
it_las01 = numpy.delete(it_las01,-1)
it_las01 = numpy.delete(it_las01,0)
it_las02 = numpy.delete(it_las02,-1)
it_las02 = numpy.delete(it_las02,0)
cgv = numpy.reshape(conf.cgv,(30,6,4))
gain = ts.gain(R,type,cgv) #gets gain for shot
#integrating spherical laser
ev_sph,eavg_sph = ts.sph_int_laser(R, type, Times_all,it_Dark, it_las01, it_las02)
nchannels=30
nshelf=30
e=1.6022e-19 #coulombs
Rfb=5e4 # ohms
nmux=12
tau=50e-9
Gfast = numpy.zeros((1,30))+10
Gfast = Gfast[0]
#anomolous entries at begining of it_las01/02 (2,5)
cfb = conf.cfb #to be passed into photoelectrons
cF = conf.cF
cF = numpy.reshape(cF,(30,6,2))
cfb = numpy.reshape(cfb,(30,6))
dl0, dl, Nsc, dNsc, nkl, ksort, mpts_phase = ts.photoelectrons(it_las01, it_las02, data, nchannels,nmux,gain,Times_all,cfb,Gfast, cF)
#select which wavelengths for initial guess
Rguess = ts.Rguess(Nsc,nchannels,nkl)
tip = numpy.loadtxt('./ss/tip')
dip = numpy.loadtxt('./ss/dip')
tl = Times_all[ksort]
kdrop = ((dip > -40) & (dip > 0))
t_maxip = tip[numpy.argmax(ip)]
tmin=0.005
tmax=10.0
ip_min=0.025
i1 = (tip > tmin)
i2 = (ip > ip_min)
kip = numpy.all([i1,i2], axis=0)
kt = numpy.all([(tl > tmin),(tl < tip[kip].max()),(tl < tmax)],axis=0)
kt = numpy.arange(kt.size)[kt]
kt = numpy.delete(kt, -1)
kt = numpy.delete(kt, -1)
#brief sanatization
time = tl[kt]
nkt = time.size
valid = numpy.zeros((nchannels,nkt))
sat_ok = numpy.zeros((nchannels,nkt))
for i in range(0,nkt):
for j in range(0,nchannels):
ksat_=(dl[j,kt[i],:] > 9.7)
if ksat_.max() == False:
sat_ok[j,i]=1
#nfactor_30, requires ramray_select, shutter select, qt_cal
nfactor_20 = numpy.loadtxt('./ss/nfactor_20_'+str(shut_config),delimiter=',')
nfactor_30 = numpy.loadtxt('./ss/nfactor_30_'+str(shut_config),delimiter=',')
#nfactor can be pre-fabricated!!
Elaser_R_st = numpy.loadtxt('./ss/Elaser_R_st')
Elaser_R_st_20 = numpy.loadtxt('./ss/Elaser_R_st_20')
Elaser_R_sph = numpy.loadtxt('./ss/Elaser_R_sph')
Elaser_R_sph_20 = numpy.loadtxt('./ss/Elaser_R_sph_20')
ev=ev_sph
iElaser_R=Elaser_R_sph
ksort1 = numpy.loadtxt('./ss/ksort', delimiter=',')
#qt = numpy.loadtxt('./QT', delimiter=',')
#QT = numpy.loadtxt('./setup/QT1', delimiter=',')
wv_all =numpy.reshape(conf.wv_all,[30,330])
cg = numpy.reshape(conf.cg,[30,5])
fb = numpy.reshape(conf.fb,[30,330])
theta = conf.theta
#a_tot_above = gtefit(wv_all,nshelf,nkt,Nsc,dNsc,cg,Rguess,QT,fb,theta,kt,ishelf)
QT = numpy.reshape(conf.QT,[5,330])
#gte def
kr = time.time()
print kr-tic
import sys
sys.path.append("/u/bhorowit/pprocess-0.5")
import pprocess
results = pprocess.Map(limit=nproc, reuse=1)
parallel_function = results.manage(pprocess.MakeReusable(gtefitP))
tic=time.time()
[parallel_function(wv_all,nshelf,nkt,Nsc,dNsc,cg,Rguess,QT,fb,theta,kt,ishelf) for ishelf in range(0,nshelf-2)]
a = numpy.zeros([nshelf,2,nkt])
for i in range(0,nshelf-2):
a[i,:,:]=results[i]
print time.time()-tic
timings = tl[kt]
numpy.savez(str(shot),a,timings,Nsc)