-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathco2.py
102 lines (84 loc) · 3.5 KB
/
co2.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
import time
import MDSplus
import numpy
import numpy as np
class gadata:
def __init__(
self,
signal,
shot,
tree=None,
connection=None,
nomds=False
):
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
t0 = time.time()
found = 0
if self.connection is None:
print('No connection!!!')
self.connection = MDSplus.Connection('atlas.gat.com')
if nomds == False:
try:
if tree != None:
tag = self.signal
fstree = tree
found = 1
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.rank(self.zdata)
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()
if self.rank > 1:
self.ydata = self.connection.get('dim_of(_s,1)').data()
self.yunits = self.connection.get('units_of(dim_of(_s,1))').data()
if self.yunits == '' or self.yunits == ' ':
self.yunits = self.connection.get('units(dim_of(_s,1))').data()
found = 1
# MDSplus seems to return 2-D arrays transposed. Change them back.
if numpy.rank(self.zdata) == 2: self.zdata = numpy.transpose(self.zdata)
if numpy.rank(self.ydata) == 2: self.ydata = numpy.transpose(self.ydata)
if numpy.rank(self.xdata) == 2: self.xdata = numpy.transpose(self.xdata)
except Exception as e:
#print ' Signal not in MDSplus: %s' % (signal,)
pass
# Retrieve data from PTDATA
if found == 0:
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
found = 1
# Retrieve data from Pseudo-pointname
if found == 0:
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
found = 1
if found == 0:
#print " No such signal: %s" % (signal,)
return
print(' GADATA Retrieval Time : ',time.time() - t0)
atlconn = MDSplus.Connection('atlas.gat.com')
shot = 132708
signal = "denr0_uf_1"
mydata = gadata(signal, shot, connection=atlconn)
tmin = 0
tmax = 3000
itime = (tmin <= mydata.xdata) & (mydata.xdata <= tmax)
print(mydata.xdata)