Skip to content

XRT DEM Iterative Solver Module - #367

Open
joyvelasquez wants to merge 313 commits into
HinodeXRT:mainfrom
joyvelasquez:xray-plasma-decoder-dem-solver
Open

joyvelasquez wants to merge 313 commits into
HinodeXRT:mainfrom
joyvelasquez:xray-plasma-decoder-dem-solver

Conversation

@joyvelasquez

@joyvelasquez joyvelasquez commented Jul 16, 2025 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces XRTDEMIterative, a Python implementation of the IDL
routine xrt_dem_iterative2.pro for estimating Differential Emission
Measures (DEMs) from Hinode/XRT multi-filter observations.

What's Included

Core Solver (dem_solver.py)

  • XRTDEMIterative class with full DEM solving pipeline
  • Spline-parameterized DEM representation with iterative least-squares
    fitting via lmfit
  • Temperature response interpolation onto a regular log10(T) grid
  • User-supplied or default intensity uncertainty model:
    max(0.03 * intensity, 2 DN/s/pix), matching IDL default behavior
  • Monte Carlo uncertainty estimation via monte_carlo_runs parameter
  • Input validation with informative warnings (saturation, negative
    intensities, missing errors)
  • summary() method for diagnostic output

Plotting (dem_plotting.py)

  • plot_dem() — base DEM solution visualization
  • plot_dem_mc() — base DEM + Monte Carlo ensemble overlay

Tests

  • 70+ unit tests covering input validation, grid construction,
    response interpolation, spline system, residuals, solver, and
    Monte Carlo behavior
  • Currently - heavy work in progress (UPDATED JULY 2026)

Documentation

  • dem_overview.rst — introduction to DEM analysis with XRTpy
  • API reference for xrtpy.xrt_dem_iterative
  • Changelog entry in docs/changelog/0.6.0.rst

Validation -

  • Validated against IDL xrt_dem_iterative2.pro across multiple
    solar observation cases using Monte Carlo comparison
  • Currently - heavy work in progress (UPDATED JULY 2026)

@joyvelasquez joyvelasquez self-assigned this Jul 16, 2025
@joyvelasquez joyvelasquez added this to the 0.6.0 milestone Jul 16, 2025
@joyvelasquez

Copy link
Copy Markdown
Contributor Author

Ensure the function checks for minimum required inputs (filters, observed intensities, etc.) and validates that all observation values are non-zero before proceeding.

@codecov

codecov Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 916 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.69%. Comparing base (357f41d) to head (fa18406).

Files with missing lines Patch % Lines
xrtpy/xrt_dem_iterative/dem_solver.py 0.00% 385 Missing ⚠️
...hysical_data_testing/test_dem_idl_comparison_mc.py 0.00% 168 Missing ⚠️
...rative/tests/physical_data_testing/utils_sav_io.py 0.00% 146 Missing ⚠️
...s/physical_data_testing/test_dem_idl_comparison.py 0.00% 111 Missing ⚠️
xrtpy/xrt_dem_iterative/dem_plotting.py 0.00% 99 Missing ⚠️
..._iterative/tests/physical_data_testing/conftest.py 0.00% 3 Missing ⚠️
xrtpy/xrt_dem_iterative/__init__.py 0.00% 2 Missing ⚠️
xrtpy/xrt_dem_iterative/tests/conftest.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #367       +/-   ##
===========================================
- Coverage   87.97%   49.69%   -38.29%     
===========================================
  Files          26       35        +9     
  Lines        1855     3284     +1429     
  Branches      110      235      +125     
===========================================
  Hits         1632     1632               
- Misses        180     1609     +1429     
  Partials       43       43               

☔ View full report in Codecov by Harness.
📢 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.

Comment thread docs/about_xrt.rst Resolved
@namurphy

namurphy commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

I'd suggest using this repository only for tests that get run in CI, and that we create a separate repository for cross-comparisons.

Moving stuff to a different repository could be done after this PR, but we'd want to update MANIFEST.in to exclude all the extra files so they don't get included in source distributions and wheels.

@namurphy namurphy 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.

Some ideas:

  • Move the validation scripts not used in CI to a top-level folder, such as dem_validation or whatever you prefer
  • Add the data files to a separate PR so that it's easier to review this one?
  • Exclude the validation scripts/data from sdists and wheels (#420)
  • Add regression tests to show that the results stay the same (similar) as they are now? Possibly with pytest-regression?

@joyvelasquez

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

"--save",
action="store_true",
help="Save PNGs instead of showing interactively.",
help="Save ONGs instead of showing interactively.",

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.

need to change back ONGs → PNGs

joyvelasquez and others added 4 commits November 6, 2026 16:02
…mc_comparison.py

Co-authored-by: Nick Murphy <namurphy@users.noreply.github.com>
…mc_comparison.py

Co-authored-by: Nick Murphy <namurphy@users.noreply.github.com>

@namurphy namurphy Nov 6, 2026 •

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.

Two possibilities for this file:

  • Instead of repeating the same commands, a possibility would be to use pytest fixtures.
  • In tests with multiple assert statements, a possibility would be to use pytest-check. That way, if one of the early assertions fails, then the rest of the assertions will still get checked.

This might be a good opportunity to request AI to make the changes since they're pretty straightforward, even if confusing to humans. 😅

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

Labels

Code Improvement For general improvements to the codebase without adding new features. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants