forked from PPPLDeepLearning/plasma-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgadata.py
More file actions
94 lines (80 loc) · 3.01 KB
/
gadata.py
File metadata and controls
94 lines (80 loc) · 3.01 KB
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
import MDSplus
import numpy
import time
import sys
class gadata:
"""GA Data Obj"""
def __init__(self,signal,shot,tree=None,connection=None,nomds=False):
# Save object values
self.signal = signal
self.shot = shot
self.zdata = -1
self.xdata = -1
self.ydata = -1
self.zunits = ''
self.xunits = ''
self.yunits = ''
self.rank = -1
self.connection = connection
## Retrieve Data
t0 = time.time()
self.found = False
# Create the MDSplus connection (thin) if not passed in
if self.connection is None:
self.connection = MDSplus.Connection('atlas.gat.com')
# Retrieve data from MDSplus (thin)
if nomds == False:
#first try, retrieve directly from tree and tag
try:
#print 'trying direct using tree and tag'
if tree != None:
tag = self.signal
fstree = tree
else:
tag = self.connection.get('findsig("'+self.signal+'",_fstree)').value
fstree = self.connection.get('_fstree').value
self.connection.openTree(fstree,shot)
self.zdata = self.connection.get('_s = '+tag).data()
self.zunits = self.connection.get('units_of(_s)').data()
self.rank = numpy.ndim(self.zdata)
if self.rank > 1:
self.xdata = self.connection.get('dim_of(_s,1)').data()
self.xunits = self.connection.get('units_of(dim_of(_s,1))').data()
if self.xunits == '' or self.xunits == ' ':
self.xunits = self.connection.get('units(dim_of(_s,1))').data()
self.ydata = self.connection.get('dim_of(_s)').data()
self.yunits = self.connection.get('units_of(dim_of(_s))').data()
if self.yunits == '' or self.yunits == ' ':
self.yunits = self.connection.get('units(dim_of(_s))').data()
else:
self.xdata = self.connection.get('dim_of(_s)').data()
self.xunits = self.connection.get('units_of(dim_of(_s))').data()
if self.xunits == '' or self.xunits == ' ':
self.xunits = self.connection.get('units(dim_of(_s))').data()
#print 'zdata: ' + str(self.zdata)
self.found = True
# MDSplus seems to return 2-D arrays transposed. Change them back.
if numpy.ndim(self.zdata) == 2: self.zdata = numpy.transpose(self.zdata)
if numpy.ndim(self.ydata) == 2: self.ydata = numpy.transpose(self.ydata)
if numpy.ndim(self.xdata) == 2: self.xdata = numpy.transpose(self.xdata)
except Exception as e:
pass
# Retrieve data from PTDATA if node not found
if not self.found:
#print 'Trying ptdata: %s' % (signal,)
self.zdata = self.connection.get('_s = ptdata2("'+signal+'",'+str(shot)+')')
if len(self.zdata) != 1:
self.xdata = self.connection.get('dim_of(_s)')
self.rank = 1
self.found = True
# Retrieve data from Pseudo-pointname if not in ptdata
if not self.found:
#print ' Signal not in PTDATA: %s' % (signal,)
self.zdata = self.connection.get('_s = pseudo("'+signal+'",'+str(shot)+')')
if len(self.zdata) != 1:
self.xdata = self.connection.get('dim_of(_s)')
self.rank = 1
self.found = True
if not self.found: #this means the signal wasn't found
pass
return