uda-mast 1.3.10.post8__tar.gz
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.
- uda_mast-1.3.10.post8/.gitignore +5 -0
- uda_mast-1.3.10.post8/PKG-INFO +51 -0
- uda_mast-1.3.10.post8/README.md +28 -0
- uda_mast-1.3.10.post8/mast/__init__.py +2 -0
- uda_mast-1.3.10.post8/mast/_version.py +21 -0
- uda_mast-1.3.10.post8/mast/geom/__init__.py +12 -0
- uda_mast-1.3.10.post8/mast/geom/geomBolo.py +351 -0
- uda_mast-1.3.10.post8/mast/geom/geomEfitElements.py +232 -0
- uda_mast-1.3.10.post8/mast/geom/geomEfitLimiter.py +58 -0
- uda_mast-1.3.10.post8/mast/geom/geomElm.py +167 -0
- uda_mast-1.3.10.post8/mast/geom/geomFluxloops.py +84 -0
- uda_mast-1.3.10.post8/mast/geom/geomHaloSaddle.py +206 -0
- uda_mast-1.3.10.post8/mast/geom/geomLangmuir.py +340 -0
- uda_mast-1.3.10.post8/mast/geom/geomPickup.py +293 -0
- uda_mast-1.3.10.post8/mast/geom/geomRog.py +63 -0
- uda_mast-1.3.10.post8/mast/geom/geomTileSurfaceUtils.py +346 -0
- uda_mast-1.3.10.post8/mast/geom/geometry.py +341 -0
- uda_mast-1.3.10.post8/mast/geom/geometryClient.py +182 -0
- uda_mast-1.3.10.post8/mast/geom/geometryFiles.py +57 -0
- uda_mast-1.3.10.post8/mast/geom/geometryUtils.py +407 -0
- uda_mast-1.3.10.post8/mast/geom/signalGeometry.py +185 -0
- uda_mast-1.3.10.post8/mast/geom/structuredWritable.py +99 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/N1.csv +19177 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/N1_no_shift_surface_normals.csv +18488 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/N1_shift_surface_normals.csv +18488 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/N2.csv +22984 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/N2_no_shift_surface_normals.csv +11201 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/N2_shift_surface_normals.csv +11201 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T1.csv +6670 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T1_no_shift_surface_normals.csv +185 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T1_shift_surface_normals.csv +185 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T2.csv +6500 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T2_SN.csv +1001 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T2_no_shift_surface_normals.csv +705 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T2_shift_surface_normals.csv +705 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T3.csv +6500 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T3_SN.csv +1001 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T3_no_shift_surface_normals.csv +609 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T3_shift_surface_normals.csv +609 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T4.csv +6500 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T4_SN.csv +1001 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T4_no_shift_surface_normals.csv +769 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T4_shift_surface_normals.csv +769 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5A.csv +6162 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5A_no_shift_surface_normals.csv +981 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5A_shift_surface_normals.csv +981 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5B.csv +6162 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5C.csv +6162 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5D.csv +6162 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/T5_SN.csv +1001 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/tile_SN_simultaneous_eqs.py +247 -0
- uda_mast-1.3.10.post8/mast/geom/tile_surface_normal_vectors/tile_surface_normals_stencils.py +787 -0
- uda_mast-1.3.10.post8/mast/mast_client.py +754 -0
- uda_mast-1.3.10.post8/pyproject.toml +41 -0
- uda_mast-1.3.10.post8/setup.cfg +4 -0
- uda_mast-1.3.10.post8/tests/put_tests.py +120 -0
- uda_mast-1.3.10.post8/tests/putdata_tests.py +911 -0
- uda_mast-1.3.10.post8/tests/test.py +22 -0
- uda_mast-1.3.10.post8/tests/test_put.py +161 -0
- uda_mast-1.3.10.post8/tests/test_uda_geometry.py +515 -0
- uda_mast-1.3.10.post8/tests/test_uda_images.py +76 -0
- uda_mast-1.3.10.post8/tests/test_uda_meta.py +403 -0
- uda_mast-1.3.10.post8/tests/test_uda_put_get.py +25 -0
- uda_mast-1.3.10.post8/tests/test_uda_signals.py +117 -0
- uda_mast-1.3.10.post8/tests/test_uda_xpad.py +30 -0
- uda_mast-1.3.10.post8/uda_mast.egg-info/PKG-INFO +51 -0
- uda_mast-1.3.10.post8/uda_mast.egg-info/SOURCES.txt +68 -0
- uda_mast-1.3.10.post8/uda_mast.egg-info/dependency_links.txt +1 -0
- uda_mast-1.3.10.post8/uda_mast.egg-info/requires.txt +5 -0
- uda_mast-1.3.10.post8/uda_mast.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: uda-mast
|
|
3
|
+
Version: 1.3.10.post8
|
|
4
|
+
Summary: MAST python wrapper for UDA
|
|
5
|
+
Author-email: Lucy Kogan <lucy.kogan@ukaea.uk>
|
|
6
|
+
License: Apache-2.0 license
|
|
7
|
+
Project-URL: homepage, https://users.mastu.ukaea.uk/data-access-and-tools/
|
|
8
|
+
Project-URL: source, https://git.ccfe.ac.uk/MAST-U/mastcodes
|
|
9
|
+
Project-URL: issues, https://git.ccfe.ac.uk/MAST-U/mastcodes/-/issues
|
|
10
|
+
Project-URL: documentation, https://users.mastu.ukaea.uk/data-access-and-tools/data-access/uda/
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: shapely
|
|
19
|
+
Requires-Dist: numpy<2,>1.7
|
|
20
|
+
Requires-Dist: pandas
|
|
21
|
+
Requires-Dist: scipy
|
|
22
|
+
Requires-Dist: uda
|
|
23
|
+
|
|
24
|
+
uda-mast is a wrapper around the basic [pyuda](https://test.pypi.org/project/uda/) data access layer that provides additional functinality specific to the data systems for [UKAEA's](https://www.gov.uk/government/organisations/uk-atomic-energy-authority) MAST and [MASTU](https://ccfe.ukaea.uk/programmes/mast-upgrade/) experimental fusion devices.
|
|
25
|
+
|
|
26
|
+
Note that the source code is currently hosted on an internal gitlab server that can only be accessed from the UKAEA network.
|
|
27
|
+
|
|
28
|
+
## Quickstart
|
|
29
|
+
|
|
30
|
+
Note that the `mast` module is registered subclient in pyuda, so if uda-mast is pip-installed it's functionality will be available when you import pyuda.
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
export UDA_META_PLUGINNAME=MASTU_DB
|
|
34
|
+
export UDA_METANEW_PLUGINNAME=MASTU_DB
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```py
|
|
38
|
+
import pyuda
|
|
39
|
+
|
|
40
|
+
pyuda.Client.server = "<server_address>"
|
|
41
|
+
pyuda.Client.port = <port_number>
|
|
42
|
+
client = pyuda.Client()
|
|
43
|
+
|
|
44
|
+
signals = client.list_signals(shot=<experiment_id>)
|
|
45
|
+
signal_objects = client.get_batch(signals, <experiment_id>)
|
|
46
|
+
|
|
47
|
+
image_data = client.get_images(<file_alias>, <experiment_id>)
|
|
48
|
+
|
|
49
|
+
geometry_data = client.geometry(<signal_name>, <experiemnt_id>)
|
|
50
|
+
```
|
|
51
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
uda-mast is a wrapper around the basic [pyuda](https://test.pypi.org/project/uda/) data access layer that provides additional functinality specific to the data systems for [UKAEA's](https://www.gov.uk/government/organisations/uk-atomic-energy-authority) MAST and [MASTU](https://ccfe.ukaea.uk/programmes/mast-upgrade/) experimental fusion devices.
|
|
2
|
+
|
|
3
|
+
Note that the source code is currently hosted on an internal gitlab server that can only be accessed from the UKAEA network.
|
|
4
|
+
|
|
5
|
+
## Quickstart
|
|
6
|
+
|
|
7
|
+
Note that the `mast` module is registered subclient in pyuda, so if uda-mast is pip-installed it's functionality will be available when you import pyuda.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
export UDA_META_PLUGINNAME=MASTU_DB
|
|
11
|
+
export UDA_METANEW_PLUGINNAME=MASTU_DB
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```py
|
|
15
|
+
import pyuda
|
|
16
|
+
|
|
17
|
+
pyuda.Client.server = "<server_address>"
|
|
18
|
+
pyuda.Client.port = <port_number>
|
|
19
|
+
client = pyuda.Client()
|
|
20
|
+
|
|
21
|
+
signals = client.list_signals(shot=<experiment_id>)
|
|
22
|
+
signal_objects = client.get_batch(signals, <experiment_id>)
|
|
23
|
+
|
|
24
|
+
image_data = client.get_images(<file_alias>, <experiment_id>)
|
|
25
|
+
|
|
26
|
+
geometry_data = client.geometry(<signal_name>, <experiemnt_id>)
|
|
27
|
+
```
|
|
28
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '1.3.10.post8'
|
|
21
|
+
__version_tuple__ = version_tuple = (1, 3, 10)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .geometryClient import GeomClient
|
|
2
|
+
|
|
3
|
+
from .geomBolo import GeomBolo
|
|
4
|
+
from .geomEfitElements import GeomEfitElements
|
|
5
|
+
from .geomEfitLimiter import GeomEfitLimiter
|
|
6
|
+
from .geomFluxloops import GeomFluxloops
|
|
7
|
+
from .geomHaloSaddle import GeomHaloSaddle
|
|
8
|
+
from .geomLangmuir import GeomLangmuir
|
|
9
|
+
from .geomPickup import GeomPickup
|
|
10
|
+
from .geomRog import GeomRog
|
|
11
|
+
from .geomElm import GeomElm
|
|
12
|
+
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
from .geometry import GeometryData
|
|
2
|
+
from .geometryUtils import (cartesian_cylindrical, cylindrical_cartesian, find_intersection_rz,
|
|
3
|
+
find_intersection_xy, calculate_tangency_radius,
|
|
4
|
+
unit_vector_to_poloidal_angle)
|
|
5
|
+
from collections import namedtuple
|
|
6
|
+
import numpy as np
|
|
7
|
+
from shapely.geometry import LineString, Polygon, Point
|
|
8
|
+
from shapely.geometry.polygon import orient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class GeomBolo(GeometryData):
|
|
12
|
+
"""
|
|
13
|
+
Sub-class for bolometry system
|
|
14
|
+
|
|
15
|
+
Implements:
|
|
16
|
+
- plot: Plot bolometry system in 2D R-Z and x-y. If limiter can be retrieved plots lines of sight.
|
|
17
|
+
- derive_coordinates: Calculate derived LOS coordinates.
|
|
18
|
+
- get_slit_by_id: return the slit object corresponding to the slit_id attribute of a foil
|
|
19
|
+
- _convert_coords_loop: Converts bolometry co-ordinates cartesian <=> cylindrical
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def _get_dependencies(self, limiter_signal='/limiter/efit', limiter_shot=None):
|
|
23
|
+
"""
|
|
24
|
+
Retrieve bolo dependencies, needed for calculating lines-of-sight.
|
|
25
|
+
:param limiter_signal: Geometry limiter signal to use
|
|
26
|
+
:param limiter_shot: Shot to retrieve limiter data for
|
|
27
|
+
:return:
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from .geomEfitLimiter import GeomEfitLimiter
|
|
31
|
+
|
|
32
|
+
self.limiter = None
|
|
33
|
+
|
|
34
|
+
if limiter_shot is None and self.shot is None:
|
|
35
|
+
self._logger.warning("Bolo shot unknown so limiter could not be loaded. Specify limiter shot using limiter_shot keyword")
|
|
36
|
+
return
|
|
37
|
+
elif self.shot is not None:
|
|
38
|
+
limiter_shot = self.shot
|
|
39
|
+
|
|
40
|
+
limiter = GeomEfitLimiter(self._uda_client)
|
|
41
|
+
limiter.get(limiter_signal, limiter_shot)
|
|
42
|
+
|
|
43
|
+
self.limiter = limiter.data
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def plot(self, ax_2d=None, ax_2d_xy=None, show=True, color="green",
|
|
47
|
+
limiter='/limiter/efit', limiter_shot=None):
|
|
48
|
+
"""
|
|
49
|
+
Plot bolometry data
|
|
50
|
+
:param ax_2d: matplotlib.axes._subplots.AxesSubplot for R-Z plot
|
|
51
|
+
:param ax_2d_xy: matplotlib.axes._subplots.AxesSubplot for R-Z plot
|
|
52
|
+
:param show: display plot
|
|
53
|
+
:param color: color for bolometry lines of sight
|
|
54
|
+
:param limiter: signal for limiter. Defaults to /limiter/efit
|
|
55
|
+
:param limiter_shot: Shot for limiter. Defaults to bolometry shot if known.
|
|
56
|
+
If bolometry data was read directly from file must be specified to plot lines-of-sight
|
|
57
|
+
:return:
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
import matplotlib.pyplot as plt
|
|
61
|
+
|
|
62
|
+
self._get_dependencies(limiter_signal=limiter, limiter_shot=limiter_shot)
|
|
63
|
+
|
|
64
|
+
data = self.data
|
|
65
|
+
|
|
66
|
+
# Create axes if necessary
|
|
67
|
+
if ax_2d is None:
|
|
68
|
+
fig = plt.figure()
|
|
69
|
+
if ax_2d is None:
|
|
70
|
+
ax_2d = fig.add_subplot(121)
|
|
71
|
+
ax_2d_xy = fig.add_subplot(122)
|
|
72
|
+
|
|
73
|
+
# Plot
|
|
74
|
+
if ax_2d is not None:
|
|
75
|
+
self._walk_tree_plot_2d(data, ax_2d, ax_2d_xy, color=color, limiter=self.limiter)
|
|
76
|
+
|
|
77
|
+
ax_2d.set_xlabel('R [m]')
|
|
78
|
+
ax_2d.set_ylabel('Z [m]')
|
|
79
|
+
|
|
80
|
+
if ax_2d_xy is not None:
|
|
81
|
+
ax_2d_xy.set_xlabel('x [m]')
|
|
82
|
+
ax_2d_xy.set_ylabel('y [m]')
|
|
83
|
+
|
|
84
|
+
if show:
|
|
85
|
+
plt.show()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _walk_tree_plot_2d(self, data, ax_2d, ax_2d_xy, color="green", limiter=None):
|
|
89
|
+
"""
|
|
90
|
+
Walk bolometry data tree and plot slit and foil locations in R-Z and top-down x-y.
|
|
91
|
+
If limiter data is passed then lines of sight are plotted.
|
|
92
|
+
:param data: bolometry data structure
|
|
93
|
+
:param ax_2d: ax_2d: matplotlib.axes._subplots.AxesSubplot for R-Z plot
|
|
94
|
+
:param ax_2d_xy: ax_2d_xy: matplotlib.axes._subplots.AxesSubplot for top down x-y plot
|
|
95
|
+
:param color: color for bolometry
|
|
96
|
+
:param limiter: limiter data structure
|
|
97
|
+
:return:
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
import matplotlib.pyplot as plt
|
|
101
|
+
|
|
102
|
+
Point3DCart = namedtuple('Point3DCart', ['x', 'y', 'z'])
|
|
103
|
+
Point3DCyl = namedtuple('Point3DCyl', ['r', 'z', 'phi'])
|
|
104
|
+
Point2DCyl = namedtuple('Point2DCyl', ['r', 'z'])
|
|
105
|
+
|
|
106
|
+
child_names = [child.name for child in data.children]
|
|
107
|
+
|
|
108
|
+
if "foils" in child_names and "slits" in child_names:
|
|
109
|
+
# Loop over foils
|
|
110
|
+
for foil in data["foils/data"]:
|
|
111
|
+
foil_centre = foil["centre_point"]
|
|
112
|
+
slit_centre = data["slits/data"][foil.slit_no]["centre_point"]
|
|
113
|
+
|
|
114
|
+
# Get x,y,z and r,phi,z coordinates
|
|
115
|
+
try:
|
|
116
|
+
foil_xyz = Point3DCart(x=foil_centre.x, y=foil_centre.y, z=foil_centre.z)
|
|
117
|
+
slit_xyz = Point3DCart(x=slit_centre.x, y=slit_centre.y, z=slit_centre.z)
|
|
118
|
+
foil_rphiz = cartesian_cylindrical(foil_xyz, phi_degrees=True)
|
|
119
|
+
slit_rphiz = cartesian_cylindrical(slit_xyz, phi_degrees=True)
|
|
120
|
+
foil_rphiz = Point3DCyl(r=foil_rphiz[0], phi=foil_rphiz[2], z=foil_rphiz[1])
|
|
121
|
+
slit_rphiz = Point3DCyl(r=slit_rphiz[0], phi=slit_rphiz[2], z=slit_rphiz[1])
|
|
122
|
+
except AttributeError:
|
|
123
|
+
foil_rphiz = Point3DCyl(r=foil_centre.r, phi=foil_centre.phi, z=foil_centre.z)
|
|
124
|
+
slit_rphiz = Point3DCyl(r=slit_centre.r, phi=slit_centre.phi, z=slit_centre.z)
|
|
125
|
+
foil_xyz = cylindrical_cartesian(foil_rphiz, phi_degrees=True)
|
|
126
|
+
slit_xyz = cylindrical_cartesian(slit_rphiz, phi_degrees=True)
|
|
127
|
+
foil_xyz = Point3DCart(x=foil_xyz[0], y=foil_xyz[1], z=foil_xyz[2])
|
|
128
|
+
slit_xyz = Point3DCart(x=slit_xyz[0], y=slit_xyz[1], z=slit_xyz[2])
|
|
129
|
+
|
|
130
|
+
intersect_points_rz = None
|
|
131
|
+
intersect_points_xy = None
|
|
132
|
+
|
|
133
|
+
# If the limiting surface has been given we can plot LOS
|
|
134
|
+
if limiter is not None:
|
|
135
|
+
|
|
136
|
+
##########################################
|
|
137
|
+
# R-Z intersection with limiting surface
|
|
138
|
+
##########################################
|
|
139
|
+
|
|
140
|
+
# Take the end of the line to be really far away so we definitely catch the intersections.
|
|
141
|
+
# This isn't actually correct for some of the tangential LOS's, which don't intersect the centre column
|
|
142
|
+
line_end = Point2DCyl(r=foil_rphiz.r + (slit_rphiz.r - foil_rphiz.r) * 100.0,
|
|
143
|
+
z=foil_rphiz.z + (slit_rphiz.z - foil_rphiz.z) * 100.0)
|
|
144
|
+
|
|
145
|
+
intersect_points_rz = find_intersection_rz(foil_rphiz, line_end, limiter)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
##########################################
|
|
149
|
+
# x-y intersection with inner & outer limiting surface
|
|
150
|
+
##########################################
|
|
151
|
+
line_end = Point3DCart(x=foil_xyz.x + (slit_xyz.x - foil_xyz.x) * 100.0,
|
|
152
|
+
y=foil_xyz.y + (slit_xyz.y - foil_xyz.y) * 100.0,
|
|
153
|
+
z=foil_xyz.z + (slit_xyz.z - foil_xyz.z * 100.0))
|
|
154
|
+
|
|
155
|
+
# Work out the boundary to intersect with
|
|
156
|
+
# We want the outer limiter boundary - inner boundary to give us the 'ring' that excludes the centre column
|
|
157
|
+
if np.isclose(foil_xyz.z, line_end.z, atol=0.0005):
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
coordTuple = list(zip(limiter.R, limiter.Z))
|
|
161
|
+
except AttributeError:
|
|
162
|
+
coordTuple = list(zip(limiter.r, limiter.z))
|
|
163
|
+
polygonBoundary = Polygon(coordTuple)
|
|
164
|
+
|
|
165
|
+
# If the los is in the same plane, we only need to check the boundary at this height
|
|
166
|
+
# At this z-value find intersect with boundary of horizontal line at z=line_start.z
|
|
167
|
+
line_z = LineString([(0.0, line_end.z), (100.0, line_end.z)])
|
|
168
|
+
intersect = polygonBoundary.intersection(line_z)
|
|
169
|
+
boundR_inner = intersect.coords[0][0]
|
|
170
|
+
boundR_outer = intersect.coords[1][0]
|
|
171
|
+
else:
|
|
172
|
+
# Otherwise, we need to work out where the intersection is in the x-y plane at the appropriate Z-height
|
|
173
|
+
if intersect_points_rz[0][0] < intersect_points_rz[1][0]:
|
|
174
|
+
boundR_outer = intersect_points_rz[1][0]
|
|
175
|
+
boundR_inner = intersect_points_rz[0][0]
|
|
176
|
+
else:
|
|
177
|
+
boundR_outer = intersect_points_rz[0][0]
|
|
178
|
+
boundR_inner = intersect_points_rz[1][0]
|
|
179
|
+
|
|
180
|
+
intersect_points_xy = find_intersection_xy(foil_xyz, line_end, boundR_outer, bound_r_inner=boundR_inner)
|
|
181
|
+
|
|
182
|
+
# Plots
|
|
183
|
+
if ax_2d is not None:
|
|
184
|
+
|
|
185
|
+
# R,Z plot
|
|
186
|
+
ax_2d.plot(foil_rphiz.r, foil_rphiz.z, marker=".", color=color)
|
|
187
|
+
|
|
188
|
+
if intersect_points_rz is not None:
|
|
189
|
+
if len(intersect_points_rz) == 1:
|
|
190
|
+
color_plot = "black"
|
|
191
|
+
else:
|
|
192
|
+
color_plot = color
|
|
193
|
+
|
|
194
|
+
rcoords = [foil_rphiz.r]
|
|
195
|
+
[rcoords.append(x[0]) for x in intersect_points_rz]
|
|
196
|
+
zcoords = [foil_rphiz.z]
|
|
197
|
+
[zcoords.append(x[1]) for x in intersect_points_rz]
|
|
198
|
+
|
|
199
|
+
ax_2d.plot(rcoords, zcoords, linestyle="-", color=color_plot)
|
|
200
|
+
|
|
201
|
+
if ax_2d_xy is not None:
|
|
202
|
+
# x,y plot
|
|
203
|
+
ax_2d_xy.plot(foil_xyz.x, foil_xyz.y, marker=".", color=color)
|
|
204
|
+
|
|
205
|
+
if intersect_points_xy is not None:
|
|
206
|
+
xcoords = [foil_xyz.x]
|
|
207
|
+
[xcoords.append(x[0]) for x in intersect_points_xy]
|
|
208
|
+
|
|
209
|
+
ycoords = [foil_xyz.y]
|
|
210
|
+
[ycoords.append(x[1]) for x in intersect_points_xy]
|
|
211
|
+
|
|
212
|
+
ax_2d_xy.plot(xcoords, ycoords, linestyle="-", color=color)
|
|
213
|
+
|
|
214
|
+
else:
|
|
215
|
+
# Continue down the tree
|
|
216
|
+
for child in data.children:
|
|
217
|
+
self._walk_tree_plot_2d(child, ax_2d, ax_2d_xy, color=color, limiter=limiter)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _convert_coords_loop(self, data, cartesian=True):
|
|
221
|
+
"""
|
|
222
|
+
Convert co-ordinates from cylindrical to cartesian or vice-versa.
|
|
223
|
+
Recursive function, walks the tree to find attributes that match them being co-ordinates
|
|
224
|
+
ie. x, y, z OR R,Z,phi OR r,z,phi attributes exist.
|
|
225
|
+
:param data: instance of StructuredWritable to traverse
|
|
226
|
+
:param cartesian: if set to True looks for cylindrical co-ordinates to convert. Otherwise looks for cartesian co-oridnates to convert.
|
|
227
|
+
:return:
|
|
228
|
+
"""
|
|
229
|
+
|
|
230
|
+
if not cartesian and hasattr(data, 'x') and hasattr(data, 'y') and hasattr(data, 'z'):
|
|
231
|
+
coord_cylindrical = cartesian_cylindrical(data, phi_degrees=True)
|
|
232
|
+
|
|
233
|
+
data.delete_attr('x')
|
|
234
|
+
data.delete_attr('y')
|
|
235
|
+
data.delete_attr('z')
|
|
236
|
+
|
|
237
|
+
data.add_attr('r', coord_cylindrical[0])
|
|
238
|
+
data.add_attr('z', coord_cylindrical[1])
|
|
239
|
+
data.add_attr('phi', coord_cylindrical[2])
|
|
240
|
+
elif cartesian and ( (hasattr(data, 'R') and hasattr(data, 'Z') and hasattr(data, 'phi'))
|
|
241
|
+
or (hasattr(data, 'r') and hasattr(data, 'z') and hasattr(data, 'phi')) ):
|
|
242
|
+
coord_cartesian = cylindrical_cartesian(data)
|
|
243
|
+
|
|
244
|
+
data.delete_attr('R')
|
|
245
|
+
data.delete_attr('r')
|
|
246
|
+
data.delete_attr('Z')
|
|
247
|
+
data.delete_attr('z')
|
|
248
|
+
data.delete_attr('phi')
|
|
249
|
+
|
|
250
|
+
data.add_attr('x', coord_cartesian[0])
|
|
251
|
+
data.add_attr('y', coord_cartesian[1])
|
|
252
|
+
data.add_attr('z', coord_cartesian[2])
|
|
253
|
+
else:
|
|
254
|
+
for child in data.children:
|
|
255
|
+
self._convert_coords_loop(child, cartesian=cartesian)
|
|
256
|
+
|
|
257
|
+
def derive_coordinates(self, limiter_signal='/limiter/efit', limiter_shot=None):
|
|
258
|
+
"""
|
|
259
|
+
Calculate tangency radius, LOS angle and divertor s coordinate.
|
|
260
|
+
|
|
261
|
+
The tangency radius is calculated for tangential channels.
|
|
262
|
+
|
|
263
|
+
For poloidal channels, in both the core and divertor, the s
|
|
264
|
+
coordinate of the intersection of the line of sight with the
|
|
265
|
+
limiter is calculated, as is the angle the line of sight vector
|
|
266
|
+
makes with the outward radial unit vector (increasing clockwise).
|
|
267
|
+
|
|
268
|
+
This function walks the data tree and calculates the
|
|
269
|
+
values for all foils. New attributes containing the derived
|
|
270
|
+
data are added to each foil, overwriting existing attributes if
|
|
271
|
+
present.
|
|
272
|
+
|
|
273
|
+
:param limiter_signal: the name of the signal to use as the limiting surface.
|
|
274
|
+
:param limiter_shot: the shot at which to read the limiter signal.
|
|
275
|
+
"""
|
|
276
|
+
self._get_dependencies(limiter_signal, limiter_shot)
|
|
277
|
+
|
|
278
|
+
limiter = LineString(zip(self.limiter.R, self.limiter.Z))
|
|
279
|
+
# Ensure limiter is anti-clockwise.
|
|
280
|
+
limiter = orient(Polygon(limiter), sign=1).exterior
|
|
281
|
+
# s is defined to be zero at the inboard midplane.
|
|
282
|
+
midplane = LineString([(0, 0), (10, 0)])
|
|
283
|
+
s0_point = min(midplane.intersection(limiter).geoms, key=midplane.project)
|
|
284
|
+
s0 = limiter.project(s0_point)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def recursive_derive(data):
|
|
288
|
+
for child in data.children:
|
|
289
|
+
if getattr(child, 'object_type', None) == 'BolometerFoil':
|
|
290
|
+
foil_centre = child['centre_point']
|
|
291
|
+
slit = self.get_slit_by_id(child.slit_id)
|
|
292
|
+
slit_centre = slit['centre_point']
|
|
293
|
+
if 'tangential' in child.id.lower():
|
|
294
|
+
# Add tangency radius.
|
|
295
|
+
try:
|
|
296
|
+
rtan = calculate_tangency_radius(foil_centre, slit_centre)
|
|
297
|
+
except AttributeError: # Data must be in Cartesian coordinates.
|
|
298
|
+
foil_centre = Point(cylindrical_cartesian(foil_centre))
|
|
299
|
+
slit_centre = Point(cylindrical_cartesian(slit_centre))
|
|
300
|
+
rtan = calculate_tangency_radius(foil_centre, slit_centre)
|
|
301
|
+
child.delete_attr('rtan')
|
|
302
|
+
child.add_attr('rtan', rtan)
|
|
303
|
+
else:
|
|
304
|
+
# Add poloidal angle.
|
|
305
|
+
try:
|
|
306
|
+
dr = slit_centre.r - foil_centre.r
|
|
307
|
+
dz = slit_centre.z - foil_centre.z
|
|
308
|
+
foil_centre = np.asarray([foil_centre.r, foil_centre.z])
|
|
309
|
+
sightline_vector = np.asarray([dr, dz])
|
|
310
|
+
except AttributeError: # Data must be in cylindical coordinates.
|
|
311
|
+
foil_centre = np.asarray(cartesian_cylindrical(foil_centre))[:2]
|
|
312
|
+
slit_centre = np.asarray(cartesian_cylindrical(slit_centre))[:2]
|
|
313
|
+
sightline_vector = slit_centre - foil_centre
|
|
314
|
+
unit_vector = sightline_vector / np.linalg.norm(sightline_vector)
|
|
315
|
+
angle = unit_vector_to_poloidal_angle(*unit_vector, convention='anticlockwise')
|
|
316
|
+
child.delete_attr('angle')
|
|
317
|
+
child.add_attr('angle', angle)
|
|
318
|
+
# Add s coordinate.
|
|
319
|
+
line_end = foil_centre + 100 * unit_vector
|
|
320
|
+
# Extend LOS so it's guaranteed to intersect the limiter.
|
|
321
|
+
long_los = LineString([foil_centre, line_end])
|
|
322
|
+
intersections = limiter.intersection(long_los)
|
|
323
|
+
# LOS end is furthest intersection from foil, to account for
|
|
324
|
+
# entering the limiting surface as well.
|
|
325
|
+
los_end = max(intersections.geoms, key=long_los.project)
|
|
326
|
+
srel = limiter.project(los_end)
|
|
327
|
+
# s increases clockwise and is relative to the midplane.
|
|
328
|
+
s = s0 - srel
|
|
329
|
+
child.delete_attr('s')
|
|
330
|
+
child.add_attr('s', s)
|
|
331
|
+
else:
|
|
332
|
+
recursive_derive(child)
|
|
333
|
+
|
|
334
|
+
recursive_derive(self.data)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def get_slit_by_id(self, slit_id):
|
|
338
|
+
"""
|
|
339
|
+
Return the slit object with id <slit_id>.
|
|
340
|
+
"""
|
|
341
|
+
def walk_tree_find_slit(data):
|
|
342
|
+
for child in data.children:
|
|
343
|
+
if getattr(child, 'object_type', None) == 'BolometerSlit':
|
|
344
|
+
if child.id == slit_id:
|
|
345
|
+
return child
|
|
346
|
+
ret = walk_tree_find_slit(child)
|
|
347
|
+
if ret is not None:
|
|
348
|
+
return ret
|
|
349
|
+
return None
|
|
350
|
+
|
|
351
|
+
return walk_tree_find_slit(self.data)
|