Skip to content

plotting functions for d2 and scattering cross section - #93

Merged
rcjackson merged 4 commits into
ARM-DOE:mainfrom
jtgasparik:plot_d2
Sep 9, 2026
Merged

plotting functions for d2 and scattering cross section#93
rcjackson merged 4 commits into
ARM-DOE:mainfrom
jtgasparik:plot_d2

Conversation

@jtgasparik

Copy link
Copy Markdown
Collaborator

This pull request introduces a new visualization function for statistical distance analysis and updates test cases for plotting functions to use more accurate parameter conversions. The main highlights are the addition of the plot_d2 function to visualize Moteki & Kondo statistical distance, and the corresponding test to ensure its correctness. Additionally, all test cases now use FWTM-to-sigma conversions for relevant parameters, improving consistency and accuracy.

New plotting functionality:

  • Added plot_d2 function to pysp2/util/normalized_derivative_method.py for visualizing Moteki & Kondo statistical distance $d^2(k)$, including options for log-scaling, threshold lines, and highlighting the optimal $k$ value.

Testing improvements:

  • Added test_plot_d2 in tests/test_vis.py to validate the new plot_d2 function using pytest's image comparison, ensuring visual correctness of the plot.
  • Imported plot_d2 in tests/test_vis.py to enable testing of the new plotting function.

Parameter conversion consistency:

  • Updated all test cases (test_ndm_moteki_kondo, test_plot_incident_irradiance, test_plot_scattering_cross_section, and test_plot_d2) to convert FWTM values to sigma by dividing by 2.335, ensuring parameter consistency with the model's requirements. [1] [2] [3] [4]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new plot_d2 currently drops the DataArray’s k coordinate (misaligning the x-axis/best-k marker), and the updated tests use an inconsistent FWHM→σ conversion constant.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds a new visualization helper to plot Moteki & Kondo statistical distance (d^2(k)) and updates the existing NDM/plotting tests to apply width-to-sigma conversions more consistently.

Changes:

  • Added plot_d2 to visualize (d^2(k)) with optional log scaling, threshold line, and best-(k) highlighting.
  • Added test_plot_d2 (mpl image comparison) and imported plot_d2 into the plotting test suite.
  • Updated NDM and plotting tests to convert width-like inputs to (\sigma) before constructing MLEConfig.
File summaries
File Description
pysp2/util/normalized_derivative_method.py Adds plot_d2 plotting function for Moteki & Kondo (d^2(k)).
tests/test_vis.py Imports plot_d2, adds image-based test for it, and updates width conversion constants in plotting-related tests.
tests/test_ndm.py Updates width conversion constants in Moteki & Kondo NDM test configuration.
Review details

Suppressed comments (2)

tests/test_vis.py:119

  • Same conversion issue as above: 2.335 is not the standard Gaussian FWHM→σ factor used elsewhere in this repo (2.35482). Keeping a single factor avoids subtle mismatches across plotting tests.
    sigma_bar= (18.5/2.335)*0.4,  # example; use your measured average width
    delta_sigma=(1.2/2.335)*0.4, # example; use your measured width std dev

tests/test_vis.py:183

  • Same conversion issue as the other plotting tests: 2.335 should be 2.35482 (Gaussian FWHM→σ), consistent with other modules (e.g., plot_wave / leo_fit).
    sigma_bar= (18.5/2.335)*0.4,  # example; use your measured average width
    delta_sigma=(1.2/2.335)*0.4, # example; use your measured width std dev
  • Files reviewed: 3/5 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pysp2/util/normalized_derivative_method.py Outdated
Comment thread pysp2/util/normalized_derivative_method.py
Comment thread tests/test_ndm.py Outdated
Comment thread tests/test_vis.py Outdated
Comment thread pysp2/util/normalized_derivative_method.py Outdated
Comment thread tests/test_vis.py Outdated
@rcjackson
rcjackson merged commit 5e99284 into ARM-DOE:main Sep 9, 2026
20 checks passed
@jtgasparik
jtgasparik deleted the plot_d2 branch September 9, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants