2D fields¶
This page demonstrates 2D visualization, including streamlines and contours.
The data is taken from the AmbipolarWind test setup (https://github.com/idefix-code/idefix/tree/master/test/MHD/AmbipolarWind)
1from idefix2python import RunContext, Pipeline, MapMovie2D
2import numpy as np
3from pathlib import Path
4
5projectPath = Path(__file__).parent / "data_test"
6task = "2D_test"
7
8
9def compute_mach_p(data):
10 cs2 = data["PRS"] / data["RHO"]
11 return np.sqrt(data["VX1"] ** 2 + data["VX2"] ** 2) / cs2
12
13
14custom_fields2D = [
15 MapMovie2D(
16 "RHO",
17 r"$\rho$",
18 plot_coords=[0, 0],
19 title="Density",
20 streamlines=["VX1", "VX2"],
21 ),
22 # Create a computed field for Mach_p and draw a contour at Mach_p = 1
23 MapMovie2D(
24 "Mach_p",
25 r"$\mathcal{M}_p$",
26 plot_coords=[0, 1],
27 title="Poloidal Mach Number",
28 compute=compute_mach_p,
29 contours=[1],
30 contour_color="green",
31 ),
32]
33MapMovie2D.suptitle = "Density and Mach number on a heatmap"
34runContext = RunContext(task, projectPath)
35pipeline = Pipeline(runContext, movies2D=custom_fields2D)
36pipeline.run()
2D_test.mp4
The result is not very good because the pipeline automatically computed the bounds of the colorbar by looking at the minimum/maximum values all over the simulation. Also, you might want a different colormap.
There are two ways to add bounds:
Passing
vminandvmaxarguments to the quantities (see the Particle quantities page for an example).Adding a
config.jsonfile.
1from idefix2python import RunContext, Pipeline, MapMovie2D
2import numpy as np
3from pathlib import Path
4
5projectPath = Path(__file__).parent / "data_test"
6task = "2D_test"
7configPath = projectPath / "config.json"
8
9
10def compute_mach_p(data):
11 cs2 = data["PRS"] / data["RHO"]
12 return np.sqrt(data["VX1"] ** 2 + data["VX2"] ** 2) / cs2
13
14
15custom_fields2D = [
16 MapMovie2D(
17 "RHO",
18 r"$\rho$",
19 plot_coords=[0, 0],
20 title="Density",
21 streamlines=["VX1", "VX2"],
22 ),
23 # Create a computed field for Mach_p and draw a contour at Mach_p = 1
24 MapMovie2D(
25 "Mach_p",
26 r"$\mathcal{M}_p$",
27 plot_coords=[0, 1],
28 title="Poloidal Mach Number",
29 compute=compute_mach_p,
30 contours=[1],
31 contour_color="green",
32 ),
33]
34MapMovie2D.suptitle = "Density and Mach number on a beautiful heatmap"
35runContext = RunContext(task, projectPath, configPath=configPath)
36pipeline = Pipeline(runContext, movies2D=custom_fields2D)
37pipeline.run()
config.json¶
1{
2 "RHO": {
3 "norm": "log",
4 "bounds": [
5 1e-7,
6 1
7 ],
8 "cmap": "inferno"
9 },
10 "Mach_p": {
11 "bounds": [
12 0.1,
13 20
14 ],
15 "cmap": "cool",
16 "norm": "log"
17 }
18}
config_2D_test.mp4