Source code for xgc_analysis.analysis.divertor.plots

"""Figures for reusable divertor profile, width, total, and load-map results."""

from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np

from xgc_analysis.analysis.plot_data import PlotData, PlotDataCollection, PlotVariable

from .eich import (DivertorEichProfile, DivertorLambdaQPoint, DivertorLoadMap,
                   DivertorTargetTotalsPoint, DivertorWidthScalings)


[docs] def divertor_eich_plot_data( profiles: list[DivertorEichProfile], *, show_particle: bool = True, show_energy: bool = True, show_ions: bool = True, show_electrons: bool = True, show_total: bool = True, source_uri: str | None = None, ) -> PlotDataCollection: """Select every curve and fit displayed in divertor Eich profile panels. Parameters ---------- profiles Computed target profiles and optional Eich fits. show_particle, show_energy Physical channels to display. show_ions, show_electrons, show_total Components to display; fits follow the total component. source_uri Optional run directory or ACA URI for provenance. Returns ------- PlotDataCollection One view per enabled panel, with target-specific x coordinates, measured component curves, and the exact fitted overlay arrays. """ if not show_particle and not show_energy: raise ValueError("At least one of particle or energy must be enabled.") plots = {} for channel in ("particle", "energy"): if (channel == "particle" and not show_particle) or (channel == "energy" and not show_energy): continue variables = {} curve_order = [] fit_annotations = {} units = "m^-2 s^-1" if channel == "particle" else "MW m^-2" for profile in profiles: target = profile.label.lower() xname = f"{target}_delta_sep_mm" variables[xname] = PlotVariable( np.asarray(profile.x_mm), f"{profile.label} target midplane-mapped separatrix offset", xname, r"\Delta_{\mathrm{sep}}", "mm", (xname,), "coordinate") scale = 1.0 if channel == "particle" else 1.0e-6 ion = np.asarray(getattr(profile, f"{channel}_i"))*scale electron = np.asarray(getattr(profile, f"{channel}_e"))*scale for component, enabled, values, style in ( ("ions", show_ions, ion, "--"), ("electrons", show_electrons, electron, ":"), ("total", show_total, ion + electron, "-"), ): if not enabled: continue name = f"{target}_{channel}_{component}" variables[name] = PlotVariable( values, f"{profile.label} target {channel} flux density, {component}", name, rf"q_{{\mathrm{{{target},{component}}}}}" if channel == "energy" else rf"\Gamma_{{\mathrm{{{target},{component}}}}}", units, (xname,), "curve", f"{profile.label} {component}") curve_order.append(name) fit = getattr(profile, f"fit_{channel}") if show_total and fit is not None: params, fit_xy = fit fit_xname = f"{target}_{channel}_fit_delta_sep_mm" fit_name = f"{target}_{channel}_eich_fit" variables[fit_xname] = PlotVariable( np.asarray(fit_xy[:, 0]), f"{profile.label} {channel} Eich fit offset", fit_xname, r"\Delta_{\mathrm{sep}}", "mm", (fit_xname,), "coordinate") variables[fit_name] = PlotVariable( np.asarray(fit_xy[:, 1])*scale, f"{profile.label} target {channel} Eich fit", fit_name, (rf"q_{{\mathrm{{{target},\mathrm{{fit}}}}}}" if channel == "energy" else rf"\Gamma_{{\mathrm{{{target},\mathrm{{fit}}}}}}"), units, (fit_xname,), "fit", f"{profile.label} Eich fit") curve_order.append(fit_name) fit_annotations[target] = {"lambda_mm": float(params[2]*1.0e3), "s_mm": float(params[3]*1.0e3)} plots[channel] = PlotData(variables, { "analysis": "divertor_eich_profiles", "quantity": channel, "curve_order": curve_order, "fit_annotations": fit_annotations, "source_product": "xgc.heatdiag2.bp", "source_uri": source_uri, }) return PlotDataCollection(plots)
[docs] def plot_divertor_eich_profiles( profiles: list[DivertorEichProfile], *, show_particle: bool = True, show_energy: bool = True, show_ions: bool = True, show_electrons: bool = True, show_total: bool = True, xlim: tuple[float, float] | None = None, ylim: tuple[float, float] | None = None, plot_data: PlotDataCollection | None = None, ): """ Plot divertor particle/energy profiles with optional Eich fit overlays. Parameters ---------- profiles : list[DivertorEichProfile] Profiles returned by :func:`compute_divertor_eich_profiles`. show_particle, show_energy : bool Select which physical channels are shown. At least one must be enabled. show_ions, show_electrons, show_total : bool Select species/component curves. Eich fits are only overlaid for total profiles. xlim, ylim : tuple[float, float] | None Optional display limits. ``xlim`` is in millimeters. ``ylim`` applies to whichever axes are displayed. plot_data : PlotDataCollection | None Preselected panel data for image sidecars; selected here when omitted. Returns ------- matplotlib.figure.Figure Figure owned by the caller. GUI code can save it to PNG; scripts can display or further customize it. """ collection = plot_data if plot_data is not None else divertor_eich_plot_data( profiles, show_particle=show_particle, show_energy=show_energy, show_ions=show_ions, show_electrons=show_electrons, show_total=show_total) nrows = len(collection.plots) fig, axes = plt.subplots(nrows=nrows, ncols=1, figsize=(7.4, 3.6*nrows), dpi=150, squeeze=False) axes_flat = list(axes[:, 0]) colors = {"Outer": "#0f5ea8", "Inner": "#a04400"} for ax, (channel, view) in zip(axes_flat, collection.plots.items()): for name in view.metadata["curve_order"]: variable = view.variables[name] x = view.variables[variable.dimensions[0]].values label = name.split("_", 1)[0].capitalize() if variable.role == "fit": ax.plot(x, variable.values, color=colors.get(label, "#333333"), linewidth=1.2, alpha=0.85) annotation = view.metadata["fit_annotations"][label.lower()] ax.text(0.02, 0.92 if label == "Outer" else 0.82, f"{label}: lambda={annotation['lambda_mm']:.2f} mm, S={annotation['s_mm']:.2f} mm", transform=ax.transAxes, fontsize=8, color=colors.get(label, "#333333")) else: component = name.rsplit("_", 1)[-1] ax.plot(x, variable.values, linestyle={"ions": "--", "electrons": ":", "total": "-"}[component], linewidth={"ions": 1.0, "electrons": 1.1, "total": 1.6}[component], label=variable.display_label) ax.set_ylabel(r"Particle flux density [m$^{-2}$ s$^{-1}$]" if channel == "particle" else r"Energy flux density [MW m$^{-2}$]") ax.axvline(0.0, color="black", linewidth=0.8, alpha=0.45) ax.set_xlabel(r"$\Delta_{sep}$ [mm]") ax.grid(alpha=0.25, linewidth=0.4) ax.legend(loc="best", fontsize=7, ncol=2) if xlim is not None: ax.set_xlim(xlim) if ylim is not None: ax.set_ylim(ylim) fig.suptitle("Divertor heatdiag profile mapped to midplane radius", fontsize=11) fig.tight_layout(pad=0.35) return fig
[docs] def divertor_lambda_q_plot_data( points: list[DivertorLambdaQPoint], *, scalings: DivertorWidthScalings | None = None, show_eich_uncertainty: bool = False, show_chang_uncertainty: bool = False, source_uri: str | None = None, ) -> PlotData: """Select target widths, scaling lines, and displayed uncertainty bounds. Parameters ---------- points Converged total-energy Eich width samples. scalings Optional upstream-midplane width estimates. show_eich_uncertainty, show_chang_uncertainty Include the selected published parameter and RMS bounds. source_uri Optional run directory or ACA URI. Returns ------- PlotData Target-specific time coordinates and measured width curves, plus reference width lines and displayed uncertainty bounds in millimeters. """ if not points: raise ValueError("No converged total-energy Eich fits found in the selected range.") variables = {} curve_order = [] for label in ("Outer", "Inner"): selected = sorted((point for point in points if point.label == label), key=lambda point: point.time_s) if not selected: continue target = label.lower() time_name = f"{target}_time_ms" width_name = f"{target}_lambda_q_mm" variables[time_name] = PlotVariable( np.asarray([point.time_s*1.0e3 for point in selected]), f"{label} heatdiag physics time", time_name, "t", "ms", (time_name,), "coordinate") variables[width_name] = PlotVariable( np.asarray([point.lambda_q_mm for point in selected]), f"{label} target Eich heat-load width", width_name, r"\lambda_q", "mm", (time_name,), "curve", label) curve_order.append(width_name) if not curve_order: raise ValueError("No outer or inner target lambda_q points are available.") all_times = [point.time_s*1.0e3 for point in points if point.label in ("Outer", "Inner")] variables["reference_time_ms"] = PlotVariable( np.asarray([min(all_times), max(all_times)]), "Selected time extent for static width estimates", "reference_time_ms", "t", "ms", ("reference_time_ms",), "coordinate") references = [] bands = [] if scalings is not None: reference_specs = (("eich", scalings.eich_mm, "Eich #14", show_eich_uncertainty), ("chang", scalings.chang_mm, "Chang Eq. 6 (initial T_i)", show_chang_uncertainty)) for key, value, label, show_band in reference_specs: name = f"{key}_lambda_q_mm" variables[name] = PlotVariable( np.full(2, value), f"{label} predicted heat-load width", name, r"\lambda_q", "mm", ("reference_time_ms",), "reference", label) references.append(name) if show_band: if key == "eich": bpol = scalings.bpol_midplane_t powers = (bpol**(-1.19 - 0.08), bpol**(-1.19 + 0.08)) lower, upper = (0.63 - 0.08)*min(powers), (0.63 + 0.08)*max(powers) else: lower, upper = value*(1.0 - 0.187), value*(1.0 + 0.187) for suffix, bound in (("lower", lower), ("upper", upper)): bound_name = f"{key}_lambda_q_{suffix}_mm" variables[bound_name] = PlotVariable( np.full(2, bound), f"{label} width {suffix} bound", bound_name, r"\lambda_q", "mm", ("reference_time_ms",), f"band_{suffix}", related_to=name) bands.append(key) return PlotData(variables, { "analysis": "divertor_lambda_q_timeseries", "curve_order": curve_order, "reference_order": references, "bands": bands, "scalings": None if scalings is None else { "eich_mm": float(scalings.eich_mm), "chang_mm": float(scalings.chang_mm), "bpol_midplane_t": float(scalings.bpol_midplane_t), "minor_radius_m": float(scalings.minor_radius_m), "ion_temperature_ev": float(scalings.ion_temperature_ev), "ion_name": scalings.ion_name, }, "gsteps": {label.lower(): [point.step for point in points if point.label == label] for label in ("Outer", "Inner")}, "source_product": "xgc.heatdiag2.bp", "source_uri": source_uri, })
[docs] def plot_divertor_lambda_q_timeseries( points: list[DivertorLambdaQPoint], *, scalings: DivertorWidthScalings | None = None, ylim: tuple[float, float] | None = None, show_lines: bool = True, show_symbols: bool = False, show_eich_uncertainty: bool = False, show_chang_uncertainty: bool = False, plot_data: PlotData | None = None, ): """ Plot total-energy Eich ``lambda_q`` values versus heatdiag time. Parameters ---------- points : list[DivertorLambdaQPoint] Points returned by :func:`compute_divertor_lambda_q_timeseries`. scalings : DivertorWidthScalings | None Optional static upstream-midplane scaling estimates from Simulation. ylim : tuple[float, float] | None Optional vertical axis limits in millimeters. show_lines, show_symbols : bool Select line, symbol-only, or line-plus-symbol display style. show_eich_uncertainty, show_chang_uncertainty : bool Shade the published Eich parameter bounds and Chang fit RMS range. plot_data : PlotData | None Preselected width data for an image sidecar; selected here when omitted. Returns ------- matplotlib.figure.Figure Figure owned by the caller. GUI code can save it to PNG. """ if not show_lines and not show_symbols: raise ValueError("Enable at least one of lines or symbols.") view = plot_data if plot_data is not None else divertor_lambda_q_plot_data( points, scalings=scalings, show_eich_uncertainty=show_eich_uncertainty, show_chang_uncertainty=show_chang_uncertainty) linestyle = "-" if show_lines else "None" marker = "o" if show_symbols else None colors = {"Outer": "#0f5ea8", "Inner": "#a04400"} fig, ax = plt.subplots(figsize=(7.4, 4.0), dpi=150) for name in view.metadata["curve_order"]: curve = view.variables[name] time_ms = view.variables[curve.dimensions[0]].values ax.plot( time_ms, curve.values, linestyle=linestyle, marker=marker, markersize=4.0, linewidth=1.5, color=colors.get(curve.display_label, "#333333"), label=curve.display_label, ) for key in view.metadata["bands"]: lower = view.variables[f"{key}_lambda_q_lower_mm"].values[0] upper = view.variables[f"{key}_lambda_q_upper_mm"].values[0] ax.axhspan(lower, upper, color="#246b34" if key == "eich" else "#783c9e", alpha=0.16, linewidth=0, label="Eich #14 parameter bounds" if key == "eich" else "Chang Eq. 6 RMS (18.7%)") for name in view.metadata["reference_order"]: reference = view.variables[name] key = name.split("_", 1)[0] ax.axhline(reference.values[0], color="#246b34" if key == "eich" else "#783c9e", linestyle="--" if key == "eich" else ":", linewidth=1.4 if key == "eich" else 1.7, label="Eich #14" if key == "eich" else r"Chang Eq. 6 (initial $T_i$)") ax.set_title(r"Divertor heat-load width") ax.set_xlabel("time [ms]") ax.set_ylabel(r"$\lambda_q$ [mm]") if ylim is not None: ax.set_ylim(ylim) ax.grid(alpha=0.25, linewidth=0.4) ax.legend(loc="best", fontsize=8) fig.tight_layout(pad=0.35) return fig
[docs] def divertor_target_totals_plot_data( points: list[DivertorTargetTotalsPoint], *, show_particle: bool = True, show_power: bool = True, show_outer: bool = True, show_inner: bool = True, show_total: bool = True, show_control: bool = True, show_ions: bool = True, show_electrons: bool = True, show_target_total: bool = True, source_uri: str | None = None, ) -> PlotDataCollection: """Select all displayed target-total time traces in particle and power panels. Parameters ---------- points Computed target and control totals by heatdiag time. show_particle, show_power Physical panels to include. show_outer, show_inner, show_total, show_control Target and wall-control trace selectors. show_ions, show_electrons, show_target_total Components to include for each selected divertor target. source_uri Optional run directory or ACA URI. Returns ------- PlotDataCollection One view per panel, with sorted target-specific times and rates in particles/s or MW, plus displayed trace specifications. """ if not show_particle and not show_power: raise ValueError("At least one of particle flux or power must be enabled.") if not show_outer and not show_inner and not show_total and not show_control: raise ValueError("At least one target/control trace must be enabled.") if not points: raise ValueError("No divertor target total points found in the selected range.") specs = _target_totals_trace_specs( show_outer=show_outer, show_inner=show_inner, show_total=show_total, show_control=show_control, show_ions=show_ions, show_electrons=show_electrons, show_target_total=show_target_total) if not specs: raise ValueError("Enable at least one target/control or ion/electron/target-total line.") plots = {} for panel in ("particle", "power"): if (panel == "particle" and not show_particle) or (panel == "power" and not show_power): continue variables = {} curve_order = [] trace_styles = {} for spec in specs: selected = sorted((point for point in points if point.label == spec["label"]), key=lambda point: point.time_s) if not selected: continue label = spec["label"].lower() time_name = f"{label}_time_ms" if time_name not in variables: variables[time_name] = PlotVariable( np.asarray([point.time_s*1.0e3 for point in selected]), f"{spec['label']} heatdiag physics time", time_name, "t", "ms", (time_name,), "coordinate") name = f"{label}_{panel}_{spec['component']}" values = np.asarray([ _target_totals_particle_value(point, spec["component"]) if panel == "particle" else _target_totals_power_value(point, spec["component"])/1.0e6 for point in selected], dtype=float) units = "particles/s" if panel == "particle" else "MW" variables[name] = PlotVariable( values, f"{spec['label']} {spec['component']} divertor target {panel} total", name, r"\dot N" if panel == "particle" else "P", units, (time_name,), "curve", spec["plot_label"]) curve_order.append(name) trace_styles[name] = {"color": spec["color"], "linestyle": spec["linestyle"]} if not curve_order: raise ValueError("No enabled target/control traces are available.") plots[panel] = PlotData(variables, { "analysis": "divertor_target_totals_timeseries", "quantity": panel, "curve_order": curve_order, "trace_styles": trace_styles, "gsteps": {label: [point.step for point in points if point.label.lower() == label] for label in ("outer", "inner", "total", "control")}, "source_product": "xgc.heatdiag2.bp", "source_uri": source_uri, }) return PlotDataCollection(plots)
[docs] def plot_divertor_target_totals_timeseries( points: list[DivertorTargetTotalsPoint], *, show_particle: bool = True, show_power: bool = True, show_outer: bool = True, show_inner: bool = True, show_total: bool = True, show_control: bool = True, show_ions: bool = True, show_electrons: bool = True, show_target_total: bool = True, xlim_ms: tuple[float, float] | None = None, particle_ylim: tuple[float, float] | None = None, power_ylim_mw: tuple[float, float] | None = None, plot_data: PlotDataCollection | None = None, ): """ Plot integrated target particle flux and power versus heatdiag time. Parameters ---------- points : list[DivertorTargetTotalsPoint] Points returned by :func:`compute_divertor_target_totals_timeseries`. show_particle, show_power : bool Select particle-flux and power panels. show_outer, show_inner, show_total, show_control : bool Select target/control trace groups. ``Total`` is the inner-plus-outer divertor sum, while ``Control`` is the full-wall control quantity after excluding the heatdiag garbage bin. show_ions, show_electrons, show_target_total : bool Select ion, electron, and ion-plus-electron component lines for the inner and outer target groups. xlim_ms : tuple[float, float] | None Optional horizontal axis range in milliseconds. particle_ylim : tuple[float, float] | None Optional particle-flux vertical range in particles per second. power_ylim_mw : tuple[float, float] | None Optional power vertical range in megawatts. plot_data : PlotDataCollection | None Preselected panel data for image sidecars; selected here when omitted. Returns ------- matplotlib.figure.Figure Figure owned by the caller. GUI code can save it to PNG. """ collection = plot_data if plot_data is not None else divertor_target_totals_plot_data( points, show_particle=show_particle, show_power=show_power, show_outer=show_outer, show_inner=show_inner, show_total=show_total, show_control=show_control, show_ions=show_ions, show_electrons=show_electrons, show_target_total=show_target_total) nrows = len(collection.plots) fig, axes = plt.subplots(nrows=nrows, ncols=1, figsize=(7.4, 3.4*nrows), dpi=150, squeeze=False) axes_flat = list(axes[:, 0]) for ax, (panel, view) in zip(axes_flat, collection.plots.items()): for name in view.metadata["curve_order"]: curve = view.variables[name] time_ms = view.variables[curve.dimensions[0]].values style = view.metadata["trace_styles"][name] ax.plot( time_ms, curve.values, linestyle=style["linestyle"], linewidth=1.5, color=style["color"], label=curve.display_label, ) ax.set_xlabel("time [ms]") if panel == "particle": ax.set_ylabel("Particle flux [ptl/s]") if particle_ylim is not None: ax.set_ylim(particle_ylim) else: ax.set_ylabel("Power [MW]") if power_ylim_mw is not None: ax.set_ylim(power_ylim_mw) if xlim_ms is not None: ax.set_xlim(xlim_ms) ax.grid(alpha=0.25, linewidth=0.4) ax.legend(loc="best", fontsize=8) fig.suptitle("Divertor heatdiag target totals", fontsize=11) fig.tight_layout(pad=0.35) return fig
[docs] def divertor_load_map_plot_data(load_map: DivertorLoadMap, *, source_uri: str | None = None) -> PlotData: """Describe the exact displayed divertor load map and its coordinates. Parameters ---------- load_map Computed mapped target load on time or toroidal angle. source_uri Optional run directory or ACA URI. Returns ------- PlotData Separatrix offset, displayed time or toroidal angle, and load values in particles m^-2 s^-1 or MW m^-2. """ x = np.asarray(load_map.x_mm, dtype=float) y = np.asarray(load_map.y_values, dtype=float) z = np.asarray(load_map.values, dtype=float) if z.ndim != 2 or z.shape != (len(y), len(x)): raise ValueError(f"Expected a load map with shape {(len(y), len(x))}, got {z.shape}") if load_map.channel == "energy": z = z/1.0e6 units = "MW m^-2" symbol = r"q_{\mathrm{target}}" else: units = "particles m^-2 s^-1" symbol = r"\Gamma_{\mathrm{target}}" y_name = "time_ms" if load_map.view == "time" else "toroidal_angle_deg" y_values = y*1.0e3 if load_map.view == "time" else y variables = { "delta_sep_mm": PlotVariable(x, "Midplane-mapped separatrix offset", "delta_sep_mm", r"\Delta_{\mathrm{sep}}", "mm", ("delta_sep_mm",), "coordinate"), y_name: PlotVariable(y_values, "Physics time" if load_map.view == "time" else "Toroidal angle", y_name, "t" if load_map.view == "time" else r"\varphi", "ms" if load_map.view == "time" else "deg", (y_name,), "coordinate"), "load": PlotVariable(z, f"{load_map.target_label} {load_map.component} {load_map.channel} target load", "load", symbol, units, (y_name, "delta_sep_mm"), "map"), } return PlotData(variables, { "analysis": "divertor_load_map", "target_label": load_map.target_label, "channel": load_map.channel, "component": load_map.component, "view": load_map.view, "source_product": "xgc.heatdiag2.bp", "source_uri": source_uri, })
[docs] def plot_divertor_load_map( load_map: DivertorLoadMap, *, xlim: tuple[float, float] | None = None, ylim: tuple[float, float] | None = None, clim: tuple[float, float] | None = None, contour_count: int = 256, cmap: str = "seismic", plot_data: PlotData | None = None, ): """ Plot a mapped divertor load map as filled contours without contour lines. Parameters ---------- load_map : DivertorLoadMap Map returned by :func:`compute_divertor_load_map`. xlim, ylim : tuple[float, float] | None Optional display ranges. ``xlim`` is in millimeters. ``ylim`` is in milliseconds for the time view and degrees for the toroidal view. clim : tuple[float, float] | None Optional color scale in displayed units. Energy maps are displayed in MW m^-2; particle maps are displayed in ptl m^-2 s^-1. contour_count : int Number of filled contour levels. Values below two are promoted to two. cmap : str Matplotlib colormap name. The default is ``"seismic"``. plot_data : PlotData | None Preselected map data for an image sidecar; selected here when omitted. Returns ------- matplotlib.figure.Figure Figure owned by the caller. GUI code can save it to PNG. """ contour_count = max(2, int(contour_count)) view = plot_data if plot_data is not None else divertor_load_map_plot_data(load_map) x = view.variables["delta_sep_mm"].values z_plot = view.variables["load"].values if view.metadata["channel"] == "energy": cbar_label = r"Energy flux density [MW m$^{-2}$]" else: cbar_label = r"Particle flux density [ptl m$^{-2}$ s$^{-1}$]" if view.metadata["view"] == "time": y_plot = view.variables["time_ms"].values y_label = "time [ms]" else: y_plot = view.variables["toroidal_angle_deg"].values y_label = "toroidal angle [deg]" finite = z_plot[np.isfinite(z_plot)] if finite.size == 0: raise ValueError("Load map contains no finite values.") if clim is None: zmin = float(np.nanmin(finite)) zmax = float(np.nanmax(finite)) else: zmin, zmax = clim if not np.isfinite(zmin) or not np.isfinite(zmax): raise ValueError("Color scale limits must be finite.") if zmin == zmax: pad = max(abs(zmin)*1.0e-6, 1.0e-12) zmin -= pad zmax += pad if zmin > zmax: zmin, zmax = zmax, zmin levels = np.linspace(zmin, zmax, contour_count) fig, ax = plt.subplots(figsize=(7.4, 4.4), dpi=150) contour = ax.contourf(x, y_plot, z_plot, levels=levels, cmap=cmap, extend="both") ax.set_xlabel(r"$\Delta_{sep}$ [mm]") ax.set_ylabel(y_label) if xlim is not None: ax.set_xlim(xlim) if ylim is not None: ax.set_ylim(ylim) title_channel = "energy" if load_map.channel == "energy" else "particle" ax.set_title(f"{load_map.target_label} divertor {load_map.component} {title_channel} load") cbar = fig.colorbar(contour, ax=ax) cbar.set_label(cbar_label) fig.tight_layout(pad=0.35) return fig
def _target_totals_trace_specs( *, show_outer: bool, show_inner: bool, show_total: bool, show_control: bool, show_ions: bool, show_electrons: bool, show_target_total: bool, ) -> list[dict[str, str]]: """Return line specifications for target-total plots.""" specs: list[dict[str, str]] = [] def add_target(label: str, color: str) -> None: """Append enabled component traces for one divertor target.""" if show_ions: specs.append({"label": label, "component": "ion", "plot_label": f"{label} ions", "color": color, "linestyle": "--"}) if show_electrons: specs.append({"label": label, "component": "electron", "plot_label": f"{label} electrons", "color": color, "linestyle": ":"}) if show_target_total: specs.append({"label": label, "component": "total", "plot_label": f"{label} total", "color": color, "linestyle": "-"}) if show_outer: add_target("Outer", "#0f5ea8") if show_inner: add_target("Inner", "#a04400") if show_total: specs.append({"label": "Total", "component": "total", "plot_label": "Total divertor", "color": "#20845a", "linestyle": "-"}) if show_control: specs.append({"label": "Control", "component": "total", "plot_label": "Wall control", "color": "#333333", "linestyle": "--"}) return specs def _target_totals_particle_value(point: DivertorTargetTotalsPoint, component: str) -> float: """Return one particle-flux component from an integrated totals point.""" if component == "ion": return point.particle_i_rate_per_s if component == "electron": return point.particle_e_rate_per_s return point.particle_rate_per_s def _target_totals_power_value(point: DivertorTargetTotalsPoint, component: str) -> float: """Return one power component from an integrated totals point.""" if component == "ion": return point.power_i_w if component == "electron": return point.power_e_w return point.power_w