Skip to content

common

Common functions for PROCESS summary plots.

load_plot_image(name)

Load an image bundled with the PROCESS plotting resources.

Source code in process/core/io/plot/summary/common.py
41
42
43
44
45
def load_plot_image(name: str):
    """Load an image bundled with the PROCESS plotting resources."""
    image = resources.files("process.core.io.plot.images").joinpath(name)
    with image.open("rb") as image_file:
        return mpimg.imread(image_file)

place_plot_image(axis, name, bounds, *, zorder=10)

Place a bundled image in an inset axes and hide its frame.

Source code in process/core/io/plot/summary/common.py
48
49
50
51
52
53
def place_plot_image(axis, name: str, bounds, *, zorder: int = 10):
    """Place a bundled image in an inset axes and hide its frame."""
    image_axis = axis.inset_axes(bounds, transform=axis.transAxes, zorder=zorder)
    image_axis.imshow(load_plot_image(name))
    image_axis.axis("off")
    return image_axis

get_pulse_timings(mfile, scan)

Construct pulse timings from an MFILE scan.

Source code in process/core/io/plot/summary/common.py
56
57
58
59
60
61
62
63
64
65
66
def get_pulse_timings(mfile, scan: int) -> PulseTimings:
    """Construct pulse timings from an MFILE scan."""
    keys = (
        "t_plant_pulse_coil_precharge",
        "t_plant_pulse_plasma_current_ramp_up",
        "t_plant_pulse_fusion_ramp",
        "t_plant_pulse_burn",
        "t_plant_pulse_plasma_current_ramp_down",
        "t_plant_pulse_dwell",
    )
    return PulseTimings(**{key: mfile.get(key, scan=scan) for key in keys})

box_style(colour, alpha=1.0, linewidth=2, **kwargs)

Matplotlib boxstyle

Source code in process/core/io/plot/summary/common.py
69
70
71
72
73
74
75
76
77
def box_style(colour: str, alpha: float = 1.0, linewidth: float | None = 2, **kwargs):
    """Matplotlib boxstyle"""
    return {
        "boxstyle": "round",
        "facecolor": colour,
        "alpha": alpha,
        "linewidth": linewidth,
        **kwargs,
    }

text_layout(fig, h_align='left', v_align='bottom')

Matplotlib text layout

Source code in process/core/io/plot/summary/common.py
80
81
82
83
84
85
86
87
def text_layout(fig, h_align="left", v_align="bottom"):
    """Matplotlib text layout"""
    return {
        "fontsize": 9,
        "verticalalignment": v_align,
        "horizontalalignment": h_align,
        "transform": fig.transFigure,
    }

setup_axis(axis, xmin, xmax, ymin, ymax)

Matplotlib axis setup

Source code in process/core/io/plot/summary/common.py
90
91
92
93
94
95
96
def setup_axis(axis, xmin, xmax, ymin, ymax):
    """Matplotlib axis setup"""
    axis.set_ylim(ymin, ymax)
    axis.set_xlim(xmin, xmax)
    axis.set_axis_off()
    axis.set_autoscaley_on(False)
    axis.set_autoscalex_on(False)

add_colourbar(contour_fill, axis, colourbar_axis)

Add colourbar to axis

Source code in process/core/io/plot/summary/common.py
 99
100
101
102
103
104
def add_colourbar(contour_fill, axis, colourbar_axis):
    """Add colourbar to axis"""
    # Use a dedicated colorbar axes when provided so the main axes width is unchanged.
    if colourbar_axis is None:
        return axis.figure.colorbar(contour_fill, ax=axis, pad=0.02)
    return axis.figure.colorbar(contour_fill, cax=colourbar_axis)

color_key(axis, mfile, scan, colour_scheme)

Function to plot the colour key

Source code in process/core/io/plot/summary/common.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def color_key(axis: plt.Axes, mfile: MFile, scan: int, colour_scheme: Literal[1, 2]):
    """Function to plot the colour key"""
    axis.set_ylim(0, 10)
    axis.set_xlim(0, 10)
    axis.set_axis_off()
    axis.set_autoscaley_on(False)
    axis.set_autoscalex_on(False)

    labels = [
        ("CS coil", SOLENOID_COLOUR[colour_scheme - 1]),
        ("CS comp", CSCOMPRESSION_COLOUR[colour_scheme - 1]),
        (
            "TF coil",
            (
                TFC_COLOUR[colour_scheme - 1]
                if mfile.get("i_tf_sup", scan=scan) != 0
                else "#b87333"
            ),
        ),
        ("Thermal shield", THERMAL_SHIELD_COLOUR[colour_scheme - 1]),
        ("VV & shield", VESSEL_COLOUR[colour_scheme - 1]),
        ("Blanket", BLANKET_COLOUR[colour_scheme - 1]),
        ("First wall", FIRSTWALL_COLOUR[colour_scheme - 1]),
        ("Plasma", PLASMA_COLOUR[colour_scheme - 1]),
        ("PF coils", "none"),
        ("Divertor", "black"),
    ]

    if (mfile.get("i_hcd_primary", scan=scan) in {5, 8}) or (
        mfile.get("i_hcd_secondary", scan=scan) in {5, 8}
    ):
        labels.extend((
            ("NB duct shield", NBSHIELD_COLOUR[colour_scheme - 1]),
            ("Cryostat", CRYOSTAT_COLOUR[colour_scheme - 1]),
        ))
    else:
        labels.append(("Cryostat", CRYOSTAT_COLOUR[colour_scheme - 1]))

    for i, (text, color) in enumerate(labels):
        row = i // 4
        col = i % 4
        y_pos = 9 - row * 1.5
        x_pos = col * 2.5

        axis.text(x_pos, y_pos, text, ha="left", va="top", size="small")
        axis.add_patch(
            patches.Rectangle(
                (x_pos + 1.5, y_pos - 0.35),
                0.5,
                0.4,
                lw=0 if color != "none" else 1,
                facecolor=color if color != "none" else "none",
                edgecolor="black" if color == "none" else "none",
            )
        )