Skip to content

Commit 7fa3b8f

Browse files
author
+Julian Kates-Harbeck
committed
working d3d download script
1 parent 8a331f5 commit 7fa3b8f

File tree

4 files changed

+51
-33
lines changed

4 files changed

+51
-33
lines changed

data/d3d_signals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
r'\bol_l15_p', #Radiated Power core
3030
r'\bol_l03_p', #Radiated Power Edge
3131
'bmspinj', #Total Beam Power
32-
'bmstinj', #Total Beam Torque
33-
'pcechpwrf'] #Total ECH Power
32+
'bmstinj',] #Total Beam Torque
33+
#'pcechpwrf'] #Total ECH Power Not always on!
3434

3535
signal_paths = ['d3d/' + path for path in signal_paths]
3636

3737
### 1D EFIT signals ###
3838
signal_paths += [
39-
'AOT/EQU.te', #electron temperature profile vs rho (uniform mapping over time)
39+
'AOT/EQU.t_e', #electron temperature profile vs rho (uniform mapping over time)
4040
'AOT/EQU.dens_e'] #electron density profile vs rho (uniform mapping over time)
4141

4242
#make into list of lists format to be consistent with jet_signals.py

data/gadata.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def __init__(self,signal,shot,tree=None,connection=None,nomds=False):
1818
self.yunits = ''
1919
self.rank = -1
2020
self.connection = connection
21+
2122

2223
## Retrieve Data
2324
t0 = time.time()
24-
found = False
25+
self.found = False
2526

2627
# Create the MDSplus connection (thin) if not passed in
2728
if self.connection is None:
@@ -31,6 +32,7 @@ def __init__(self,signal,shot,tree=None,connection=None,nomds=False):
3132
if nomds == False:
3233
#first try, retrieve directly from tree and tag
3334
try:
35+
#print 'trying direct using tree and tag'
3436
if tree != None:
3537
tag = self.signal
3638
fstree = tree
@@ -48,41 +50,44 @@ def __init__(self,signal,shot,tree=None,connection=None,nomds=False):
4850
self.xunits = self.connection.get('units(dim_of(_s))').data()
4951
if self.rank > 1:
5052
self.ydata = self.connection.get('dim_of(_s,1)').data()
51-
self.yunits = self.connection.get('units_of(dim_of(_s,1))').data()
53+
self.yunits = self.connection.get('units_of(dim_of(_s,1))').data()
5254
if self.yunits == '' or self.yunits == ' ':
5355
self.yunits = self.connection.get('units(dim_of(_s,1))').data()
54-
found = True
56+
#print 'zdata: ' + str(self.zdata)
57+
self.found = True
5558

5659
# MDSplus seems to return 2-D arrays transposed. Change them back.
57-
if numpy.ndim(self.zdata) == 2: self.zdata = numpy.transpose(self.zdata)
58-
if numpy.ndim(self.ydata) == 2: self.ydata = numpy.transpose(self.ydata)
59-
if numpy.ndim(self.xdata) == 2: self.xdata = numpy.transpose(self.xdata)
60+
#if numpy.ndim(self.zdata) == 2: self.zdata = numpy.transpose(self.zdata)
61+
#if numpy.ndim(self.ydata) == 2: self.ydata = numpy.transpose(self.ydata)
62+
#if numpy.ndim(self.xdata) == 2: self.xdata = numpy.transpose(self.xdata)
6063

61-
except Exception,e:
64+
except Exception,e:
6265
#node not found
6366
# print ' Signal not in MDSplus: %s' % (signal,)
6467
pass
6568

6669
# Retrieve data from PTDATA if node not found
67-
if not found:
68-
self.zdata = self.connection.get('_s = ptdata2("'+signal+'",'+str(shot)+')')
69-
if len(self.zdata) != 1:
70-
self.xdata = self.connection.get('dim_of(_s)')
71-
self.rank = 1
72-
found = True
70+
if not self.found:
71+
#print 'Trying ptdata: %s' % (signal,)
72+
self.zdata = self.connection.get('_s = ptdata2("'+signal+'",'+str(shot)+')')
73+
if len(self.zdata) != 1:
74+
self.xdata = self.connection.get('dim_of(_s)')
75+
self.rank = 1
76+
self.found = True
7377

7478
# Retrieve data from Pseudo-pointname if not in ptdata
75-
if not found:
76-
# print ' Signal not in PTDATA: %s' % (signal,)
77-
self.zdata = self.connection.get('_s = pseudo("'+signal+'",'+str(shot)+')')
78-
if len(self.zdata) != 1:
79-
self.xdata = self.connection.get('dim_of(_s)')
80-
self.rank = 1
81-
found = True
79+
if not self.found:
80+
#print ' Signal not in PTDATA: %s' % (signal,)
81+
self.zdata = self.connection.get('_s = pseudo("'+signal+'",'+str(shot)+')')
82+
if len(self.zdata) != 1:
83+
self.xdata = self.connection.get('dim_of(_s)')
84+
self.rank = 1
85+
self.found = True
8286

83-
if not found:
87+
if not self.found: #this means the signal wasn't found
88+
pass
8489
# print ' Signal not in pseudo-pointname: %s' % (signal,)
85-
print " No such signal: %s" % (signal,)
90+
#print " No such signal: %s" % (signal,)
8691

87-
print ' GADATA Retrieval Time : ',time.time() - t0
88-
return
92+
#print ' GADATA Retrieval Time : ',time.time() - t0
93+
return

data/get_mdsplus_data.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'''
77
from __future__ import print_function
88
from MDSplus import *
9-
from pylab import *
9+
#from pylab import *
1010
import numpy as np
1111
import sys
1212
import multiprocessing as mp
@@ -21,7 +21,7 @@
2121

2222
#print("Importing numpy version"+np.__version__)
2323

24-
prepath = '/cscratch/share/frnn'
24+
prepath = '/cscratch/share/frnn/'
2525
shot_numbers_path = 'shot_lists/'
2626
save_path = 'signal_data/'
2727
machine = 'd3d'
@@ -43,7 +43,9 @@
4343
# shot_numbers_files = ['shotlist_JaysonBarr_disrupt.txt']
4444
shot_numbers_files = ['d3d_short_clear.txt']# ,'d3d_clear.txt', 'd3d_disrupt.txt']
4545
server_path = 'atlas.gat.com'
46-
import d3d_signals
46+
from d3d_signals import signal_paths
47+
import itertools
48+
signal_paths = list(itertools.chain.from_iterable(signal_paths))
4749
# signal_paths = ['PINJ','IP','Q95','DENSITY','WMHD'] #,'PRAD'] #PRAD returns a 2D xdata
4850
# Recommended signals from DIII-D
4951
# signal_paths = ['efsli','ipsip','efsbetan','efswmhd','nssampn1l','nssfrqn1l',
@@ -127,6 +129,14 @@ def get_tree_and_tag(path):
127129
tag = '\\' + spl[1]
128130
return tree,tag
129131

132+
def get_tree_and_tag_no_backslash(path):
133+
spl = path.split('/')
134+
tree = spl[0]
135+
tag = spl[1]
136+
return tree,tag
137+
138+
139+
130140

131141
def format_save_path(prepath,signal_path,shot_num):
132142
return prepath + signal_path + '/{}.txt'.format(shot_num)
@@ -161,8 +171,11 @@ def save_shot(shot_num_queue,c,signal_paths,save_prepath,machine):
161171
print('Signal {}, shot {} missing. Filling with zeros'.format(signal_path,shot_num))
162172
time,data = create_missing_value_filler()
163173
elif machine == 'd3d':
174+
tree,tag = get_tree_and_tag_no_backslash(signal_path)
164175
try:
165-
ga1 = gadata.gadata('{}'.format(signal_path),shot_num,tree='d3d',connection=c)
176+
ga1 = gadata.gadata('{}'.format(tag),shot_num,tree=tree,connection=c)
177+
if not ga1.found:
178+
raise
166179
# ga1 = gadata.gadata('\\{}'.format(signal_path),shot_num,tree='d3d',connection=c)
167180
data = ga1.zdata
168181
time = ga1.xdata
@@ -171,7 +184,7 @@ def save_shot(shot_num_queue,c,signal_paths,save_prepath,machine):
171184
print('Signal {}, shot {} missing. Filling with zeros'.format(signal_path,shot_num))
172185
time,data = create_missing_value_filler()
173186

174-
data_two_column = vstack((time,data)).transpose()
187+
data_two_column = np.vstack((np.atleast_2d(time),np.atleast_2d(data))).transpose()
175188
try: #can lead to race condition
176189
mkdirdepth(save_path_full)
177190
except OSError, e:
@@ -181,7 +194,7 @@ def save_shot(shot_num_queue,c,signal_paths,save_prepath,machine):
181194
else:
182195
# Our target dir exists as a file, or different error, reraise the error!
183196
raise
184-
savetxt(save_path_full,data_two_column,fmt = '%f %f')
197+
np.savetxt(save_path_full,data_two_column,fmt = '%.5e')#fmt = '%f %f')
185198
print('.',end='')
186199
except:
187200
print('Could not save shot {}, signal {}'.format(shot_num,signal_path))
File renamed without changes.

0 commit comments

Comments
 (0)