Add model type output to physics plot proc#4214
Conversation
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>
…e output in plasma calculations
… 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>
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
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>
b8b2571 to
6683aa7
Compare
There was a problem hiding this comment.
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 physicsIntEnums and surface them in text output + summary plots. - Add/reuse a shared
PlasmaGeom.calculate_iter_physics_basis_elongation()helper, outputkappa_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.
| # 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)) |
There was a problem hiding this comment.
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).
| 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}", |
There was a problem hiding this comment.
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.
| 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}", |
| """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. |
There was a problem hiding this comment.
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.
| [^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 |
There was a problem hiding this comment.
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.
| [^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. |
1e06a23 to
00ca811
Compare
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:
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.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:
MW/m³instead ofMW/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: