Skip to content

Add model type output to physics plot proc#4214

Open
chris-ashe wants to merge 21 commits intomainfrom
add_model_type_output_to_physics_plot_proc
Open

Add model type output to physics plot proc#4214
chris-ashe wants to merge 21 commits intomainfrom
add_model_type_output_to_physics_plot_proc

Conversation

@chris-ashe
Copy link
Copy Markdown
Collaborator

@chris-ashe chris-ashe commented Apr 30, 2026

This pull request introduces several improvements and corrections to plasma physics documentation, plotting routines, and constraint definitions. The main themes are: enhanced plot summaries and visualizations, improved model labeling and clarity in plots, and consistent use of SI units (especially superscript formatting) throughout constraint equations and documentation.

Plotting and Visualization Improvements:

  • Added a new function, plot_max_normalised_beta_comparison, to visualize and compare different models of maximum normalized beta (β_N) using violin and box plots, including statistical summaries (average, standard deviation, median). This plot is integrated into the main plotting routine.
  • Improved axis titles and labels for clarity and scientific accuracy in several comparison plots, such as explicitly using LaTeX notation for physical quantities (f_\text{BS}, $P_\text{LH}, $I_p, etc.).

Model and Output Labeling Enhancements:

  • Updated plot text to include the full names of the models used for bootstrap current fraction, normalized internal inductance, L-H threshold, and density limit, improving interpretability of plot outputs.
    Documentation and Reference Updates:

  • Added a section on the ITER physics basis definition for separatrix elongation in the plasma geometry documentation, including the relevant formula and citation.

Constraint Equation and Unit Consistency:

  • Standardized all SI units in constraint equation decorators and docstrings to use superscript formatting (e.g., MW/m³ instead of MW/m3), and made related docstring corrections for clarity and consistency.

These changes collectively improve the scientific accuracy, clarity, and usability of the codebase and its outputs.## Description

Checklist

I confirm that I have completed the following checks:

  • My changes follow the PROCESS style guide
  • I have justified any large differences in the regression tests caused by this pull request in the comments.
  • I have added new tests where appropriate for the changes I have made.
  • If I have had to change any existing unit or integration tests, I have justified this change in the pull request comments.
  • If I have made documentation changes, I have checked they render correctly.
  • I have added documentation for my change, if appropriate.

chris-ashe and others added 11 commits April 29, 2026 15:27
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…current calculations

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
… PlasmaInductance

Co-authored-by: Copilot <copilot@github.com>
…ents for clarity

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…tency

Co-authored-by: Copilot <copilot@github.com>
…ns for clarity

Co-authored-by: Copilot <copilot@github.com>
@chris-ashe chris-ashe added Input/Output Files Issues related to the input and output data files Refactor labels Apr 30, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 21.24711% with 341 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.14%. Comparing base (14ef433) to head (d160390).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/models/physics/physics.py 4.71% 263 Missing ⚠️
process/models/physics/plasma_current.py 5.88% 32 Missing ⚠️
process/core/io/plot/summary.py 12.12% 29 Missing ⚠️
process/models/physics/bootstrap_current.py 75.86% 7 Missing ⚠️
process/models/physics/density_limit.py 76.19% 5 Missing ⚠️
process/models/physics/plasma_geometry.py 42.85% 4 Missing ⚠️
process/models/physics/profiles.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4214   +/-   ##
=======================================
  Coverage   52.13%   52.14%           
=======================================
  Files         148      148           
  Lines       30419    30515   +96     
=======================================
+ Hits        15858    15911   +53     
- Misses      14561    14604   +43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

chris-ashe and others added 8 commits April 30, 2026 10:20
Co-authored-by: Copilot <copilot@github.com>
- Updated PlasmaProfileShapeType to include descriptive strings for each profile type.
- Introduced a new __new__ method to handle the creation of enum members with both value and description.
- Added a DynamicClassAttribute to provide access to the description of each profile type.

Co-authored-by: Copilot <copilot@github.com>
…tting

Co-authored-by: Copilot <copilot@github.com>
@chris-ashe chris-ashe force-pushed the add_model_type_output_to_physics_plot_proc branch 3 times, most recently from b8b2571 to 6683aa7 Compare April 30, 2026 15:02
@chris-ashe chris-ashe requested review from j-a-foster May 1, 2026 09:08
@chris-ashe chris-ashe assigned clmould and unassigned clmould May 1, 2026
@chris-ashe chris-ashe marked this pull request as ready for review May 1, 2026 09:11
@chris-ashe chris-ashe requested a review from a team as a code owner May 1, 2026 09:11
Copilot AI review requested due to automatic review settings May 1, 2026 09:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances PROCESS physics reporting by emitting the selected model type alongside key physics outputs and plotting annotations, and by adding ITER Physics Basis (IPB) elongation as a first-class quantity for output/documentation.

Changes:

  • Add human-readable model labels (full_name / description) to several physics IntEnums and surface them in text output + summary plots.
  • Add/reuse a shared PlasmaGeom.calculate_iter_physics_basis_elongation() helper, output kappa_ipb, and document the IPB elongation definition.
  • Improve output/plot labeling (symbols, units with superscripts) across physics outputs and constraints metadata.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/models/physics/test_plasma_geom.py Adds a unit test for the new ITER Physics Basis elongation helper.
process/models/physics/profiles.py Extends PlasmaProfileShapeType enum with a human-readable description.
process/models/physics/plasma_geometry.py Adds IPB elongation calculation helper and outputs kappa_ipb; improves geometry output labels.
process/models/physics/plasma_fields.py Improves magnetic field output labels with symbols.
process/models/physics/plasma_current.py Adds model-name-aware output for plasma current and diamagnetic current sections.
process/models/physics/physics.py Refactors/updates plasma outputs to include selected model names; reorganizes profile output into a helper method.
process/models/physics/density_limit.py Adds density limit model selection output + exposes i_density_limit and nd_plasma_electrons_max more explicitly.
process/models/physics/confinement_time.py Switches IPB elongation calculation to call the shared geometry helper.
process/models/physics/bootstrap_current.py Adds model-name-aware output and cleans up bootstrap fraction labeling.
process/core/solver/constraints.py Updates constraint unit strings to use superscripts (e.g., m³, m²) and adjusts related doc text.
process/core/io/plot/summary.py Adds model names to plot annotations and introduces a “Max Normalised Beta comparison” plot.
documentation/source/physics-models/plasma_geometry.md Documents IPB elongation definition and adds a new reference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11869 to +11881
# Create the violin plot
axis.violinplot(data.values(), showextrema=False)

# Create the box plot
axis.boxplot(
data.values(), showfliers=True, showmeans=True, meanline=True, widths=0.3
)

# Scatter plot for each data point
colors = plt.cm.plasma(np.linspace(0, 1, len(data.values())))
for index, (key, value) in enumerate(data.items()):
axis.scatter(1, value, color=colors[index], label=key, alpha=1.0)
axis.legend(loc="upper left", bbox_to_anchor=(1.1, 1))
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plot_max_normalised_beta_comparison passes scalar values (from mfile.get(..., scan=scan)) directly into axis.violinplot()/axis.boxplot(). Matplotlib expects each dataset to be a 1D sequence; scalars will raise at runtime (0-d arrays are not sized). Consider switching this to a simple bar/scatter comparison across models, or wrap each value as a 1-element list/array and set explicit positions + x tick labels so the plot is meaningful (and avoid plotting all points at x=1).

Copilot uses AI. Check for mistakes.
Comment on lines +11885 to +11900
avg_density_limit = np.mean(data_values)
std_density_limit = np.std(data_values)
median_density_limit = np.median(data_values)

# Plot average, standard deviation, and median as text
axis.text(
1.1,
0.15,
rf"Average: {avg_density_limit:.4f}",
transform=axis.transAxes,
fontsize=9,
)
axis.text(
1.1,
0.1,
rf"Standard Dev: {std_density_limit:.4f}",
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local stats variables are named avg_density_limit / std_density_limit / median_density_limit, but they are computed from max normalised beta values. Renaming these to beta-specific names would avoid confusion when maintaining or extending this plotting code.

Suggested change
avg_density_limit = np.mean(data_values)
std_density_limit = np.std(data_values)
median_density_limit = np.median(data_values)
# Plot average, standard deviation, and median as text
axis.text(
1.1,
0.15,
rf"Average: {avg_density_limit:.4f}",
transform=axis.transAxes,
fontsize=9,
)
axis.text(
1.1,
0.1,
rf"Standard Dev: {std_density_limit:.4f}",
avg_beta_norm_max = np.mean(data_values)
std_beta_norm_max = np.std(data_values)
median_beta_norm_max = np.median(data_values)
# Plot average, standard deviation, and median as text
axis.text(
1.1,
0.15,
rf"Average: {avg_beta_norm_max:.4f}",
transform=axis.transAxes,
fontsize=9,
)
axis.text(
1.1,
0.1,
rf"Standard Dev: {std_beta_norm_max:.4f}",

Copilot uses AI. Check for mistakes.
Comment on lines +957 to +979
"""Calculate the ITER physics basis elongation.

This method calculates the ITER physics basis elongation (κₐ) based on the aspect ratio and a scaling factor.

Parameters
----------
vol_plasma :
Plasma volume (m³)
rmajor :
Plasma major radius (m)
rminor :
Plasma minor radius (m)

Returns
-------
kappa_ipb:
The calculated ITER physics basis elongation.

References
----------
- None Otto Kardaun, N. K. Thomsen, and None Alexander Chudnovskiy,
“Corrections to a sequence of papers in Nuclear Fusion,” Nuclear Fusion,
vol. 48, no. 9, pp. 099801099801, Aug. 2008, doi: https://doi.org/10.1088/0029-5515/48/9/099801.
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for calculate_iter_physics_basis_elongation is internally inconsistent: it says the calculation is “based on the aspect ratio and a scaling factor”, but the implementation uses plasma volume, major radius, and minor radius directly. Also the reference text includes stray "None" tokens in the author names; please clean up the citation so it renders correctly in docs and generated outputs.

Copilot uses AI. Check for mistakes.
[^7]: O. Sauter, “Geometric formulas for system codes including the effect of negative triangularity,” Fusion Engineering and Design, vol. 112, pp. 633–645, Nov. 2016, doi: https://doi.org/10.1016/j.fusengdes.2016.04.033.
[^8]: Y. Sakamoto, 'Recent progress in vertical stability analysis in JA', Task meeting EU-JA #16, Fusion for Energy, Garching, 24--25 June 2014 No newline at end of file
[^8]: Y. Sakamoto, 'Recent progress in vertical stability analysis in JA', Task meeting EU-JA #16, Fusion for Energy, Garching, 24--25 June 2014
[^9]: None Otto Kardaun, N. K. Thomsen, and None Alexander Chudnovskiy, “Corrections to a sequence of papers in Nuclear Fusion,” Nuclear Fusion, vol. 48, no. 9, pp. 099801099801, Aug. 2008, doi: https://doi.org/10.1088/0029-5515/48/9/099801. No newline at end of file
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Footnote [^9] has malformed author names ("None Otto Kardaun" / "None Alexander Chudnovskiy"). Please fix the citation metadata/text so the rendered documentation doesn’t include "None" in the author list.

Suggested change
[^9]: None Otto Kardaun, N. K. Thomsen, and None Alexander Chudnovskiy, “Corrections to a sequence of papers in Nuclear Fusion,” Nuclear Fusion, vol. 48, no. 9, pp. 099801099801, Aug. 2008, doi: https://doi.org/10.1088/0029-5515/48/9/099801.
[^9]: Otto Kardaun, N. K. Thomsen, and Alexander Chudnovskiy, “Corrections to a sequence of papers in Nuclear Fusion,” Nuclear Fusion, vol. 48, no. 9, pp. 099801099801, Aug. 2008, doi: https://doi.org/10.1088/0029-5515/48/9/099801.

Copilot uses AI. Check for mistakes.
@chris-ashe chris-ashe force-pushed the add_model_type_output_to_physics_plot_proc branch from 1e06a23 to 00ca811 Compare May 1, 2026 09:31
Copy link
Copy Markdown
Collaborator

@j-a-foster j-a-foster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Input/Output Files Issues related to the input and output data files Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants