imas-idstools 2.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. idstools/__init__.py +40 -0
  2. idstools/_version.py +7 -0
  3. idstools/cocos.py +436 -0
  4. idstools/compute/__init__.py +0 -0
  5. idstools/compute/common.py +1140 -0
  6. idstools/compute/core_profiles.py +995 -0
  7. idstools/compute/core_sources.py +572 -0
  8. idstools/compute/core_transport.py +108 -0
  9. idstools/compute/distribution_sources.py +104 -0
  10. idstools/compute/distributions.py +351 -0
  11. idstools/compute/edge_profiles.py +991 -0
  12. idstools/compute/equilibrium.py +1814 -0
  13. idstools/compute/magnetics.py +312 -0
  14. idstools/compute/pf_active.py +114 -0
  15. idstools/compute/pf_passive.py +116 -0
  16. idstools/compute/spectrometer_visible.py +108 -0
  17. idstools/compute/summary.py +279 -0
  18. idstools/compute/tf.py +76 -0
  19. idstools/compute/wall.py +295 -0
  20. idstools/compute/waves.py +571 -0
  21. idstools/database.py +968 -0
  22. idstools/domain/__init__.py +0 -0
  23. idstools/domain/ecstray.py +194 -0
  24. idstools/domain/kineticprofiles.py +2039 -0
  25. idstools/eqdsk2ids.py +755 -0
  26. idstools/idschk.py +1063 -0
  27. idstools/idsperf.py +130 -0
  28. idstools/init_mendeleiev.py +270 -0
  29. idstools/input_processing.py +754 -0
  30. idstools/machinedescription.py +396 -0
  31. idstools/scenariodescription.py +343 -0
  32. idstools/set_logger.py +57 -0
  33. idstools/test/idstools_tests/__init__.py +0 -0
  34. idstools/test/idstools_tests/compute/__init__.py +0 -0
  35. idstools/test/idstools_tests/compute/common/__init__.py +0 -0
  36. idstools/test/idstools_tests/compute/common/test_functions.py +58 -0
  37. idstools/utils/__init__.py +0 -0
  38. idstools/utils/clihelper.py +248 -0
  39. idstools/utils/idshelper.py +1135 -0
  40. idstools/utils/idslogger.py +45 -0
  41. idstools/utils/utility_functions.py +23 -0
  42. idstools/view/__init__.py +0 -0
  43. idstools/view/common.py +313 -0
  44. idstools/view/core_profiles.py +519 -0
  45. idstools/view/core_sources.py +425 -0
  46. idstools/view/core_transport.py +333 -0
  47. idstools/view/distribution_sources.py +58 -0
  48. idstools/view/distributions.py +193 -0
  49. idstools/view/domain/__init__.py +0 -0
  50. idstools/view/domain/ecstray.py +182 -0
  51. idstools/view/domain/kineticprofiles.py +401 -0
  52. idstools/view/domain/mdplot.py +164 -0
  53. idstools/view/edge_profiles.py +285 -0
  54. idstools/view/equilibrium.py +809 -0
  55. idstools/view/magnetics.py +373 -0
  56. idstools/view/pf_active.py +277 -0
  57. idstools/view/pf_passive.py +247 -0
  58. idstools/view/polygon.py +141 -0
  59. idstools/view/spectrometer_visible.py +130 -0
  60. idstools/view/styles/scientific.mplstyle +68 -0
  61. idstools/view/summary.py +264 -0
  62. idstools/view/tf.py +171 -0
  63. idstools/view/wall.py +246 -0
  64. idstools/view/waves.py +595 -0
  65. imas_idstools-2.4.0.data/data/bin/create_db_entry +820 -0
  66. imas_idstools-2.4.0.data/data/bin/create_db_entry_disruption +311 -0
  67. imas_idstools-2.4.0.data/data/bin/dbconverter +179 -0
  68. imas_idstools-2.4.0.data/data/bin/dblist +549 -0
  69. imas_idstools-2.4.0.data/data/bin/dbperf +463 -0
  70. imas_idstools-2.4.0.data/data/bin/dbscraper +162 -0
  71. imas_idstools-2.4.0.data/data/bin/dbselector +88 -0
  72. imas_idstools-2.4.0.data/data/bin/disruption_summary +479 -0
  73. imas_idstools-2.4.0.data/data/bin/eqdsk2ids +174 -0
  74. imas_idstools-2.4.0.data/data/bin/geqdsk/example.gfile +319 -0
  75. imas_idstools-2.4.0.data/data/bin/idscp +238 -0
  76. imas_idstools-2.4.0.data/data/bin/idsdiff +902 -0
  77. imas_idstools-2.4.0.data/data/bin/idslist +205 -0
  78. imas_idstools-2.4.0.data/data/bin/idsperf +191 -0
  79. imas_idstools-2.4.0.data/data/bin/idsprint +600 -0
  80. imas_idstools-2.4.0.data/data/bin/idsquery +160 -0
  81. imas_idstools-2.4.0.data/data/bin/idsresample +233 -0
  82. imas_idstools-2.4.0.data/data/bin/idsrescale_equilibrium +121 -0
  83. imas_idstools-2.4.0.data/data/bin/idsrosettacode +280 -0
  84. imas_idstools-2.4.0.data/data/bin/idsshift_equilibrium +116 -0
  85. imas_idstools-2.4.0.data/data/bin/idssize +76 -0
  86. imas_idstools-2.4.0.data/data/bin/input/ec_waveforms.yaml +190 -0
  87. imas_idstools-2.4.0.data/data/bin/input/scenario.yaml +51 -0
  88. imas_idstools-2.4.0.data/data/bin/input/wall2d.txt +19 -0
  89. imas_idstools-2.4.0.data/data/bin/mappings/h-mode-db-mapping.csv +192 -0
  90. imas_idstools-2.4.0.data/data/bin/md_status +81 -0
  91. imas_idstools-2.4.0.data/data/bin/md_summary +197 -0
  92. imas_idstools-2.4.0.data/data/bin/plotcoresources +114 -0
  93. imas_idstools-2.4.0.data/data/bin/plotcoretransport +191 -0
  94. imas_idstools-2.4.0.data/data/bin/ploteccomposition +158 -0
  95. imas_idstools-2.4.0.data/data/bin/plotecray +293 -0
  96. imas_idstools-2.4.0.data/data/bin/plotecstrayradiation +193 -0
  97. imas_idstools-2.4.0.data/data/bin/plotedgeprofiles +204 -0
  98. imas_idstools-2.4.0.data/data/bin/plotequicomp +405 -0
  99. imas_idstools-2.4.0.data/data/bin/plotequilibrium +217 -0
  100. imas_idstools-2.4.0.data/data/bin/plothcd +468 -0
  101. imas_idstools-2.4.0.data/data/bin/plothcddistributions +127 -0
  102. imas_idstools-2.4.0.data/data/bin/plothcdwaves +166 -0
  103. imas_idstools-2.4.0.data/data/bin/plotkineticprofiles +100 -0
  104. imas_idstools-2.4.0.data/data/bin/plotmachinedescription +81 -0
  105. imas_idstools-2.4.0.data/data/bin/plotneutron +142 -0
  106. imas_idstools-2.4.0.data/data/bin/plotpressure +102 -0
  107. imas_idstools-2.4.0.data/data/bin/plotrotation +104 -0
  108. imas_idstools-2.4.0.data/data/bin/plotscenario +240 -0
  109. imas_idstools-2.4.0.data/data/bin/plotspectrometry +141 -0
  110. imas_idstools-2.4.0.data/data/bin/printcoresources +72 -0
  111. imas_idstools-2.4.0.data/data/bin/printfluxes +72 -0
  112. imas_idstools-2.4.0.data/data/bin/printplasmacompo +244 -0
  113. imas_idstools-2.4.0.data/data/bin/results/s134173_r22_t29.94_pX.txt +11 -0
  114. imas_idstools-2.4.0.data/data/bin/results/s134173_r22_t30.94_pX.txt +11 -0
  115. imas_idstools-2.4.0.data/data/bin/results/s134173_r22_t31.94_pX.txt +11 -0
  116. imas_idstools-2.4.0.data/data/bin/scenario_status +105 -0
  117. imas_idstools-2.4.0.data/data/bin/scenario_summary +288 -0
  118. imas_idstools-2.4.0.data/data/bin/show_db_entry +54 -0
  119. imas_idstools-2.4.0.data/data/bin/validation_schemas/ITER/core_profiles.yml +6 -0
  120. imas_idstools-2.4.0.data/data/bin/validation_schemas/ITER/edge_profiles.yml +5 -0
  121. imas_idstools-2.4.0.data/data/bin/validation_schemas/ITER/equilibrium.yml +6 -0
  122. imas_idstools-2.4.0.data/data/bin/validation_schemas/ITER/summary.yml +8 -0
  123. imas_idstools-2.4.0.data/data/bin/validation_schemas/generic/core_profiles.yml +52 -0
  124. imas_idstools-2.4.0.data/data/bin/validation_schemas/generic/edge_profiles.yml +90 -0
  125. imas_idstools-2.4.0.data/data/bin/validation_schemas/generic/edge_sources.yml +65 -0
  126. imas_idstools-2.4.0.data/data/bin/validation_schemas/generic/edge_transport.yml +78 -0
  127. imas_idstools-2.4.0.data/data/bin/validation_schemas/generic/equilibrium.yml +19 -0
  128. imas_idstools-2.4.0.data/data/bin/validation_schemas/generic/summary.yml +36 -0
  129. imas_idstools-2.4.0.data/data/bin/watch_db_entry +85 -0
  130. imas_idstools-2.4.0.dist-info/METADATA +161 -0
  131. imas_idstools-2.4.0.dist-info/RECORD +181 -0
  132. imas_idstools-2.4.0.dist-info/WHEEL +5 -0
  133. imas_idstools-2.4.0.dist-info/licenses/LICENSE.md +165 -0
  134. imas_idstools-2.4.0.dist-info/top_level.txt +2 -0
  135. scripts/create_db_entry +820 -0
  136. scripts/create_db_entry_disruption +311 -0
  137. scripts/dbconverter +179 -0
  138. scripts/dblist +549 -0
  139. scripts/dbperf +463 -0
  140. scripts/dbscraper +162 -0
  141. scripts/dbselector +88 -0
  142. scripts/disruption_summary +479 -0
  143. scripts/eqdsk2ids +174 -0
  144. scripts/idscp +238 -0
  145. scripts/idsdiff +902 -0
  146. scripts/idslist +205 -0
  147. scripts/idsperf +191 -0
  148. scripts/idsprint +600 -0
  149. scripts/idsquery +160 -0
  150. scripts/idsresample +233 -0
  151. scripts/idsrescale_equilibrium +121 -0
  152. scripts/idsrosettacode +280 -0
  153. scripts/idsshift_equilibrium +116 -0
  154. scripts/idssize +76 -0
  155. scripts/md_status +81 -0
  156. scripts/md_summary +197 -0
  157. scripts/plotcoresources +114 -0
  158. scripts/plotcoretransport +191 -0
  159. scripts/ploteccomposition +158 -0
  160. scripts/plotecray +293 -0
  161. scripts/plotecstrayradiation +193 -0
  162. scripts/plotedgeprofiles +204 -0
  163. scripts/plotequicomp +405 -0
  164. scripts/plotequilibrium +217 -0
  165. scripts/plothcd +468 -0
  166. scripts/plothcddistributions +127 -0
  167. scripts/plothcdwaves +166 -0
  168. scripts/plotkineticprofiles +100 -0
  169. scripts/plotmachinedescription +81 -0
  170. scripts/plotneutron +142 -0
  171. scripts/plotpressure +102 -0
  172. scripts/plotrotation +104 -0
  173. scripts/plotscenario +240 -0
  174. scripts/plotspectrometry +141 -0
  175. scripts/printcoresources +72 -0
  176. scripts/printfluxes +72 -0
  177. scripts/printplasmacompo +244 -0
  178. scripts/scenario_status +105 -0
  179. scripts/scenario_summary +288 -0
  180. scripts/show_db_entry +54 -0
  181. scripts/watch_db_entry +85 -0
idstools/__init__.py ADDED
@@ -0,0 +1,40 @@
1
+ try:
2
+ import imaspy as imas
3
+ except ImportError:
4
+ import imas
5
+
6
+
7
+ try:
8
+ from ._version import ( # noqa: F401
9
+ GIT_DATE,
10
+ GIT_DESCRIBE,
11
+ GIT_REV,
12
+ __version__,
13
+ version_tuple, # noqa: F401
14
+ )
15
+ except ImportError:
16
+ __version__ = "unknown"
17
+ version_tuple = (0, 0, 0)
18
+ GIT_REV = GIT_DESCRIBE = GIT_DATE = "unknown"
19
+
20
+
21
+ if not hasattr(imas, "ids_defs"):
22
+ print(
23
+ """
24
+ [ERROR] Detected an outdated version of the 'imas' module.
25
+
26
+ The installed 'imas' package appears to be an incompatible legacy version of \
27
+ the high-level Python interface of the IMAS Access Layer.
28
+
29
+ To resolve this, remove / unload this version and re-install using:
30
+
31
+ pip install imas-python
32
+
33
+ or load the appropriate environment module on your system, e.g.
34
+
35
+ module load IMAS-Python
36
+
37
+ More info: https://pypi.org/project/imas-python/
38
+ """
39
+ )
40
+ exit(1)
idstools/_version.py ADDED
@@ -0,0 +1,7 @@
1
+ # file generated by setuptools_scm; DO NOT edit
2
+ __all__ = ["__version__", "GIT_REV", "GIT_DESCRIBE", "GIT_DATE"]
3
+ __version__ = "2.4.0"
4
+ version_tuple = tuple("2.4.0".replace("-", ".").split("."))
5
+ GIT_REV = "None"
6
+ GIT_DESCRIBE = "2.4.0-0-None"
7
+ GIT_DATE = "None"
idstools/cocos.py ADDED
@@ -0,0 +1,436 @@
1
+ import logging
2
+ import traceback
3
+
4
+ try:
5
+ import imaspy as imas
6
+ except ImportError:
7
+ import imas
8
+ import numpy as np
9
+
10
+ # set cocos in the DD version from the environment
11
+ IDS_COCOS = int(imas.dd_zip.dd_etree().find("cocos").text)
12
+
13
+
14
+ logger = logging.getLogger(f"module.{__name__}")
15
+
16
+
17
+ class COCOS:
18
+ """
19
+ COCOS module in Python.
20
+
21
+ This module provides functionality related to coordinate conventions in tokamak physics.
22
+
23
+ References:
24
+ O. Sauter and S. Yu. Medvedev, "Tokamak Coordinate Conventions: COCOS",Comput. Physics Commun 84 (2013), 293.
25
+ `cocos_module.f90 (CHEASE)`.
26
+ """
27
+
28
+ def __init__(self, index=None, values=None):
29
+ """
30
+ Initialize COCOS index using values, or values using COCOS index.
31
+
32
+ Parameters
33
+ ----------
34
+ index : dict, optional
35
+ COCOS index dictionary with signs of Ip and B0.
36
+ Example: ``{"COCOS": 11, "ipsign": 1, "b0sign": 1}``
37
+ values : dict, optional
38
+ COCOS values dictionary with coordinate convention parameters.
39
+ """
40
+
41
+ if (index is None) and (values is None):
42
+ raise ValueError("Initialize COCOS with either index or values: both not given")
43
+ return
44
+
45
+ elif (index is not None) and (values is not None):
46
+ raise ValueError("Initialize COCOS with either index or values: both given")
47
+ return
48
+
49
+ # in case of init. by index
50
+ elif index is not None:
51
+
52
+ COCOS = index["COCOS"]
53
+ ipsign = index["ipsign"]
54
+ b0sign = index["b0sign"]
55
+ #
56
+ # Parameters from Table I
57
+ #
58
+ if COCOS in [1, 11]:
59
+ # ITER, Boozer are cocos=11
60
+ val = (+1, +1, +1, +1, -1)
61
+ elif COCOS in [2, 12]:
62
+ # CHEASE, ONETWO, Hinton-Hazeltine, LION is cocos=2
63
+ val = (+1, -1, +1, +1, -1)
64
+ elif COCOS in [3, 13]:
65
+ # Freidberg, CAXE, KINX are cocos=3
66
+ # EU-ITM up to end of 2011 is COCOS=13
67
+ val = (-1, +1, -1, -1, +1)
68
+ elif COCOS in [4, 14]:
69
+ #
70
+ val = (-1, -1, -1, -1, +1)
71
+ elif COCOS in [5, 15]:
72
+ #
73
+ val = (+1, +1, -1, -1, -1)
74
+ elif COCOS in [6, 16]:
75
+ #
76
+ val = (+1, -1, -1, -1, -1)
77
+ elif COCOS in [7, 17]:
78
+ # TCV psitbx is cocos=7
79
+ val = (-1, +1, +1, +1, +1)
80
+ elif COCOS in [8, 18]:
81
+ #
82
+ val = (-1, -1, +1, +1, +1)
83
+ else:
84
+ # Should not be here since all cases defined
85
+ raise ValueError(f"error: COCOS = {COCOS} does not exist")
86
+ return
87
+
88
+ (
89
+ sigma_bp,
90
+ sigma_rphi_z,
91
+ sigma_rhothetaphi,
92
+ sign_q_pos,
93
+ sign_pprime_pos,
94
+ ) = val
95
+
96
+ # cocos=i or 10+i have similar coordinate conventions except psi/2pi for
97
+ # cocos=i and psi for cocos=10+i
98
+
99
+ if COCOS >= 11:
100
+ exp_bp = 1
101
+ else:
102
+ exp_bp = 0
103
+
104
+ theta_sign_clockwise = sigma_rphi_z * sigma_rhothetaphi
105
+
106
+ self.COCOS = COCOS
107
+ self.sigma_ip = ipsign
108
+ self.sigma_b0 = b0sign
109
+ self.exp_bp = exp_bp
110
+ self.sigma_bp = sigma_bp
111
+ self.sigma_rphi_z = sigma_rphi_z
112
+ self.sigma_rhothetaphi = sigma_rhothetaphi
113
+ self.sign_q_pos = sign_q_pos
114
+ self.sign_pprime_pos = sign_pprime_pos
115
+ self.theta_sign_clockwise = theta_sign_clockwise
116
+
117
+ # in case of init. by values
118
+ else:
119
+
120
+ sigma_ip = values["ipsign"]
121
+ sigma_b0 = values["b0sign"]
122
+ exp_bp = values["exp_Bp"]
123
+ sigma_bp = values["sigma_Bp"]
124
+ sigma_rphi_z = values["sigma_RphiZ"]
125
+ sigma_rhothetaphi = values["sigma_rhothetaphi"]
126
+ sign_q_pos = values["sign_q_pos"]
127
+ sign_pprime_pos = values["sign_pprime_pos"]
128
+
129
+ val = (
130
+ sigma_bp,
131
+ sigma_rphi_z,
132
+ sigma_rhothetaphi,
133
+ sign_q_pos,
134
+ sign_pprime_pos,
135
+ )
136
+
137
+ #
138
+ # Parameters from Table I
139
+ #
140
+ if val == (+1, +1, +1, +1, -1):
141
+ # ITER, Boozer are cocos=11
142
+ COCOS = [1, 11]
143
+ elif val == (+1, -1, +1, +1, -1):
144
+ # CHEASE, ONETWO, Hinton-Hazeltine, LION is cocos=2
145
+ COCOS = [2, 12]
146
+ elif val == (-1, +1, -1, -1, +1):
147
+ # Freidberg, CAXE, KINX are cocos=3
148
+ # EU-ITM up to end of 2011 is COCOS=13
149
+ COCOS = [3, 13]
150
+ elif val == (-1, -1, -1, -1, +1):
151
+ #
152
+ COCOS = [4, 14]
153
+ elif val == (+1, +1, -1, -1, -1):
154
+ #
155
+ COCOS = [5, 15]
156
+ elif val == (+1, -1, -1, -1, -1):
157
+ #
158
+ COCOS = [6, 16]
159
+ elif val == (-1, +1, +1, +1, +1):
160
+ #
161
+ COCOS = [7, 17]
162
+ elif val == (-1, -1, +1, +1, +1):
163
+ #
164
+ COCOS = [8, 18]
165
+ else:
166
+ # Should not be here since all cases defined
167
+ raise ValueError(f"error: COCOS Values not match {val}")
168
+ return
169
+
170
+ theta_sign_clockwise = sigma_rphi_z * sigma_rhothetaphi
171
+
172
+ self.COCOS = COCOS[exp_bp]
173
+ self.sigma_ip = sigma_ip
174
+ self.sigma_b0 = sigma_b0
175
+ self.exp_bp = exp_bp
176
+ self.sigma_bp = sigma_bp
177
+ self.sigma_rphi_z = sigma_rphi_z
178
+ self.sigma_rhothetaphi = sigma_rhothetaphi
179
+ self.sign_q_pos = sign_q_pos
180
+ self.sign_pprime_pos = sign_pprime_pos
181
+ self.theta_sign_clockwise = theta_sign_clockwise
182
+
183
+ def get(self):
184
+ """
185
+ Return COCOS index and values
186
+
187
+ Returns
188
+ -------
189
+ dict
190
+ COCOS index and values in type dict
191
+ """
192
+
193
+ return {
194
+ "COCOS": self.COCOS,
195
+ "sigma_Ip": self.sigma_ip,
196
+ "sigma_B0": self.sigma_b0,
197
+ "exp_Bp": self.exp_bp,
198
+ "sigma_Bp": self.sigma_bp,
199
+ "sigma_RphiZ": self.sigma_rphi_z,
200
+ "sigma_rhothetaphi": self.sigma_rhothetaphi,
201
+ "sign_q_pos": self.sign_q_pos,
202
+ "sign_pprime_pos": self.sign_pprime_pos,
203
+ "theta_sign_clockwise": self.theta_sign_clockwise,
204
+ }
205
+
206
+ @classmethod
207
+ def values_coefficients(self, COCOS_in, COCOS_out, ip_in, b0_in, ipsign_out, b0sign_out):
208
+ """
209
+ Provide transformation values for a set of quantities for a given pair
210
+ of input/output COCOS numbers.
211
+
212
+ Parameters
213
+ ----------
214
+ COCOS_in : int
215
+ COCOS input
216
+ COCOS_out : int
217
+ COCOS output
218
+ ip_in : float
219
+ Plasma current (toroidal component) [A]
220
+ b0_in : float
221
+ Vacuum toroidal field [T]
222
+ ipsign_out : int
223
+ Desired sign of Ip in output
224
+ b0sign_out : int
225
+ Desired sign of B0 in output
226
+
227
+ Returns
228
+ -------
229
+ dict
230
+ COCOS transformation values in type dict
231
+ """
232
+
233
+ # Default outputs
234
+ sigma_ip_eff = 1.0
235
+ sigma_b0_eff = 1.0
236
+ sigma_bp_eff = 1.0
237
+ sigma_rhothetaphi_eff = 1.0
238
+ sigma_rphi_z_eff = 1.0
239
+ exp_bp_eff = 1.0
240
+ fact_psi = 1.0
241
+ fact_q = 1.0
242
+ fact_dpsi = 1.0
243
+ fact_dtheta = 1.0
244
+
245
+ # Check inputs
246
+ sigma_ip_in = np.sign(ip_in)
247
+ sigma_b0_in = np.sign(b0_in)
248
+
249
+ # Get COCOS related parameters
250
+ c_v_i = COCOS(index={"COCOS": COCOS_in, "ipsign": sigma_ip_in, "b0sign": sigma_b0_in}).get()
251
+ c_v_o = COCOS(index={"COCOS": COCOS_out, "ipsign": ipsign_out, "b0sign": b0sign_out}).get()
252
+
253
+ # Define effective variables: sigma_Ip_eff, si1gma_B0_eff, sigma_Bp_eff,
254
+ # exp_Bp_eff as in Appendix C
255
+ sigma_rphi_z_eff = float(c_v_o["sigma_RphiZ"] * c_v_i["sigma_RphiZ"])
256
+
257
+ # sign(Ip) in output
258
+ if ipsign_out == 0:
259
+ sigma_ip_eff = sigma_rphi_z_eff # sign folllowing transformation
260
+ else:
261
+ sigma_ip_eff = sigma_ip_in * float(ipsign_out)
262
+ # sigma_Ip_out = sigma_Ip_in * sigma_Ip_eff
263
+
264
+ # sign(B0) in output
265
+ if b0sign_out == 0:
266
+ sigma_b0_eff = sigma_rphi_z_eff # sign folllowing transformation
267
+ else:
268
+ sigma_b0_eff = sigma_b0_in * float(b0sign_out)
269
+ # sigma_B0_out = sigma_B0_in * sigma_B0_eff
270
+
271
+ sigma_bp_eff = float(c_v_o["sigma_Bp"] * c_v_i["sigma_Bp"])
272
+ exp_bp_eff = float(c_v_o["exp_Bp"] - c_v_i["exp_Bp"])
273
+ sigma_rhothetaphi_eff = float(c_v_o["sigma_rhothetaphi"] * c_v_i["sigma_rhothetaphi"])
274
+ #
275
+ # Note that sign(sigma_RphiZ*sigma_rhothetaphi) gives theta in clockwise or counter-clockwise respectively
276
+ # Thus sigma_RphiZ_eff*sigma_rhothetaphi_eff negative if the direction of
277
+ # theta has changed from cocos_in to _out
278
+ #
279
+ fact_psi = sigma_ip_eff * sigma_bp_eff * (2.0 * np.pi) ** exp_bp_eff
280
+ fact_dpsi = sigma_ip_eff * sigma_bp_eff / (2.0 * np.pi) ** exp_bp_eff
281
+ fact_q = sigma_ip_eff * sigma_b0_eff * sigma_rhothetaphi_eff
282
+ fact_dtheta = sigma_rphi_z_eff * sigma_rhothetaphi_eff
283
+
284
+ self.sigma_ip_eff = sigma_ip_eff
285
+ self.sigma_b0_eff = sigma_b0_eff
286
+ self.sigma_bp_eff = sigma_bp_eff
287
+ self.sigma_rhothetaphi_eff = sigma_rhothetaphi_eff
288
+ self.sigma_rphi_z_eff = sigma_rphi_z_eff
289
+ self.exp_bp_eff = exp_bp_eff
290
+ self.fact_psi = fact_psi
291
+ self.fact_q = fact_q
292
+ self.fact_dpsi = fact_dpsi
293
+ self.fact_dtheta = fact_dtheta
294
+
295
+ return {
296
+ "sigma_Ip_eff": self.sigma_ip_eff,
297
+ "sigma_B0_eff": self.sigma_b0_eff,
298
+ "sigma_Bp_eff": self.sigma_bp_eff,
299
+ "sigma_rhothetaphi_eff": self.sigma_rhothetaphi_eff,
300
+ "sigma_RphiZ_eff": self.sigma_rphi_z_eff,
301
+ "exp_Bp_eff": self.exp_bp_eff,
302
+ "fact_psi": self.fact_psi,
303
+ "fact_q": self.fact_q,
304
+ "fact_dpsi": self.fact_dpsi,
305
+ "fact_dtheta": self.fact_dtheta,
306
+ }
307
+
308
+
309
+ def compute_COCOS(ids, itime=None, i1=0):
310
+ """
311
+ Compute COCOS values using experimental data in IDS/equilibrium.
312
+
313
+ Parameters
314
+ ----------
315
+ ids : object
316
+ IDS/equilibrium for COCOS estimation
317
+ itime : int, optional
318
+ Index of struct_array time_slice in IDS/equilibrium
319
+ i1 : int, optional
320
+ Index of struct_array profiles_2d in IDS/equilibrium. Default is 0.
321
+
322
+ Returns
323
+ -------
324
+ dict
325
+ Dictionary with COCOS values
326
+ """
327
+
328
+ # COCOS Values in the middle of time sequence
329
+ if itime is None:
330
+ itime = int(np.floor(float(len(ids.time_slice)) / 2.0))
331
+
332
+ # Sign(Ip) and Sign(B0) from input
333
+ ipsign = np.sign(ids.time_slice[itime].global_quantities.ip)
334
+ b0sign = np.sign(ids.vacuum_toroidal_field.b0[itime])
335
+
336
+ # 1 Eq.(22)
337
+ dpsi = ids.time_slice[itime].profiles_1d.psi[-1] - ids.time_slice[itime].profiles_1d.psi[0]
338
+ sigma_bp = np.sign(dpsi) * ipsign
339
+
340
+ # 2 Eq.(22)
341
+ q = ids.time_slice[itime].profiles_1d.q
342
+ sign_q = np.sign(np.sum(np.sign(q)))
343
+ sign_q_pos = sign_q * ipsign * b0sign
344
+
345
+ # 3 Eq.(22)
346
+ sigma_rhothetaphi = sign_q_pos
347
+
348
+ # 4 Eq.(22)
349
+ dpressure_dpsi = ids.time_slice[itime].profiles_1d.dpressure_dpsi
350
+ sign_pprime_pos = np.sign(np.sum(np.sign(dpressure_dpsi))) * ipsign
351
+
352
+ # 5 sigma_RphiZ from Eq.(19)
353
+ bz = ids.time_slice[itime].profiles_2d[i1].b_field_z
354
+ psi2d = ids.time_slice[itime].profiles_2d[i1].psi
355
+ r2d = ids.time_slice[itime].profiles_2d[i1].r
356
+
357
+ dpsi2d = np.gradient(psi2d)
358
+ dr2d = np.gradient(r2d)
359
+ dpsi2drdr = dpsi2d[0] / dr2d[0] / r2d
360
+
361
+ # todo - reduce num. of data for COCOS discrimination
362
+ # - compute rtol(s) instead of fixed ones.
363
+ dim2 = ids.time_slice[itime].profiles_2d[i1].grid.dim2
364
+ z_axis = ids.time_slice[itime].global_quantities.magnetic_axis.z
365
+ psi_axis = ids.time_slice[itime].profiles_1d.psi[0]
366
+
367
+ # grid of magnetic axis in Z
368
+ iz = np.argmin(np.abs(dim2 - z_axis))
369
+ # psi ref. inside LCFS
370
+ psi_ref = psi_axis + dpsi * 0.5
371
+
372
+ # grids close to psi ref.
373
+ rows, cols = np.where((np.isclose(psi2d, psi_ref, rtol=0.25)) & (bz != 0))
374
+ if (not rows.any()) or (not cols.any()):
375
+ raise ValueError("COCOS discrimination failed, len(grids) and/or Bz is zero")
376
+
377
+ # discard grids in private flux region)
378
+ w = np.where(np.isclose(cols, iz, rtol=0.1))
379
+
380
+ twopi_exp_bp_sigma_rphi_z = np.zeros(bz.shape)
381
+ twopi_exp_bp_sigma_rphi_z = -sigma_bp * dpsi2drdr[rows[w], cols[w]] / bz[rows[w], cols[w]]
382
+ sigma_rphi_z = np.sign(np.sum(np.sign(twopi_exp_bp_sigma_rphi_z)))
383
+
384
+ # 6 exp_Bp from Eq.(19)
385
+ x = np.average(twopi_exp_bp_sigma_rphi_z * sigma_rphi_z)
386
+ exp_bp = np.where(np.isclose(x, 2.0 * np.pi, rtol=0.5), 1, 0)
387
+
388
+ #
389
+ values = {
390
+ "ipsign": int(ipsign),
391
+ "b0sign": int(b0sign),
392
+ "exp_Bp": int(exp_bp),
393
+ "sigma_Bp": int(sigma_bp),
394
+ "sigma_RphiZ": int(sigma_rphi_z),
395
+ "sigma_rhothetaphi": int(sigma_rhothetaphi),
396
+ "sign_q_pos": int(sign_q_pos),
397
+ "sign_pprime_pos": int(sign_pprime_pos),
398
+ }
399
+
400
+ cocos = COCOS(values=values).get()
401
+
402
+ return cocos
403
+
404
+
405
+ def ids_compute_cocos(ids, itime=None, i1=0):
406
+ """
407
+ Function Interface for computing COCOS.
408
+
409
+ Parameters
410
+ ----------
411
+ ids : object
412
+ IDS for cocos estimation
413
+ itime : int, optional
414
+ Index of struct_array time_slice in IDS/equilibrium
415
+ i1 : int, optional
416
+ Index of struct_array profiles_2d in IDS/equilibrium. Default is 0.
417
+
418
+ Returns
419
+ -------
420
+ int
421
+ COCOS number computed
422
+ """
423
+
424
+ key = "COCOS"
425
+
426
+ if ids.metadata.name == "equilibrium":
427
+ try:
428
+ cocos = compute_COCOS(ids, itime, i1)
429
+ except Exception as e:
430
+ logger.debug(f"{e}")
431
+ logger.error(traceback.format_exc())
432
+
433
+ else:
434
+ exit(f"equilibrium instead of {ids.metadata.name}")
435
+
436
+ return cocos[key]
File without changes