Skip to content

Commit 8c9559c

Browse files
committed
Skip b_field_tor which was renamed to b_field_psi in DDv4
This keeps the snippet valid for both DDv3 and DDv4
1 parent 840cb2e commit 8c9559c

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

docs/source/courses/basic/imaspy_snippets/transform_grid.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
22

3-
import imaspy.training
43
import matplotlib
54
import numpy as np
65
from scipy.interpolate import RegularGridInterpolator
76

7+
import imaspy.training
8+
89
if "DISPLAY" not in os.environ:
910
matplotlib.use("agg")
1011
else:
@@ -20,8 +21,7 @@
2021
input_times = eq_in.time
2122

2223
# Create output data entry
23-
output_entry = imaspy.DBEntry(
24-
imaspy.ids_defs.MEMORY_BACKEND, "imaspy-course", 2, 1)
24+
output_entry = imaspy.DBEntry(imaspy.ids_defs.MEMORY_BACKEND, "imaspy-course", 2, 1)
2525
output_entry.create()
2626

2727
# Loop over each time slice
@@ -53,18 +53,16 @@
5353
grid_z = z_axis + rho_grid * np.sin(theta_grid)
5454
interpolation_points = np.dstack((grid_r.flatten(), grid_z.flatten()))
5555

56-
# Interpolate all data nodes on the new grid
57-
for data_node in ["b_field_r", "b_field_z", "b_field_tor", "psi"]:
56+
# Interpolate data nodes on the new grid
57+
for data_node in ["b_field_r", "b_field_z", "psi"]:
5858
# `.value` so we can plot the original values after the IDS node is overwritten
5959
data = p2d[data_node].value
6060
interp = RegularGridInterpolator((r, z), data)
6161
new_data = interp(interpolation_points).reshape(grid_r.shape)
6262
p2d[data_node] = new_data
6363

6464
# Update coordinate identifier
65-
p2d.grid_type.index = 2
66-
p2d.grid_type.name = "inverse"
67-
p2d.grid_type.description = "Rhopolar_polar 2D polar coordinates (rho=dim1, theta=dim2) with magnetic axis as centre of grid; theta and values following the COCOS=11 convention; the polar angle is theta=atan2(z-zaxis,r-raxis)" # noqa: E501
65+
p2d.grid_type = "inverse"
6866

6967
# Update coordinates
7068
p2d.grid.dim1 = rho
@@ -83,14 +81,14 @@
8381

8482
rzmesh = np.meshgrid(r, z, indexing="ij")
8583
mesh = ax1.pcolormesh(*rzmesh, data, vmin=vmin, vmax=vmax)
86-
ax1.contour(*rzmesh, data, contour_levels, colors='black')
84+
ax1.contour(*rzmesh, data, contour_levels, colors="black")
8785

8886
ax2.pcolormesh(grid_r, grid_z, new_data, vmin=vmin, vmax=vmax)
89-
ax2.contour(grid_r, grid_z, new_data, contour_levels, colors='black')
87+
ax2.contour(grid_r, grid_z, new_data, contour_levels, colors="black")
9088

9189
rho_theta_mesh = np.meshgrid(rho, theta, indexing="ij")
9290
ax3.pcolormesh(*rho_theta_mesh, new_data, vmin=vmin, vmax=vmax)
93-
ax3.contour(*rho_theta_mesh, new_data, contour_levels, colors='black')
91+
ax3.contour(*rho_theta_mesh, new_data, contour_levels, colors="black")
9492

9593
ax1.set_xlabel("r [m]")
9694
ax2.set_xlabel("r [m]")

0 commit comments

Comments
 (0)