Skip to content

feat: add ChebyshevBackground and first full Rietveld refinement example - #13

Merged
sbillinge merged 9 commits into
diffpy:mainfrom
cadenmyers13:fitcontribution-refinement
Nov 10, 2026
Merged

sbillinge merged 9 commits into
diffpy:mainfrom
cadenmyers13:fitcontribution-refinement

Conversation

@cadenmyers13

Copy link
Copy Markdown
Contributor

What problem does this PR address?

Please merge #12 first.

Add backgrounds and the first full Rietveld refinement with a plain srfit FitContribution ("bragg + background").

  • Background and ChebyshevBackground (backgrounds.py): backgrounds are srfit Calculators registered in the equation. The Chebyshev range is fixed when the background is made, and calculating outside it raises a ValueError.
    • fit_to_data is GSAS-II's automatic background (pybaselines arpls), with fixed points and a weight for them.
    • fit_to_points fits to points the user gives.
    • plot_fit plots the background over the data before refining.
  • Fix: reflections just above the calculation range (PowderDiffractionGenerator): ObjCryst leaves these out, so their tails were missing inside the range (up to 8% of the maximum at the top edge for PbSO4). The generator now calculates on a grid extended upward by ObjCryst's own profile cut-off, which grows with the peak width (including hkl-dependent widths), and returns only the requested points.
  • Top-level exports in __init__.py.
  • New dependencies: matplotlib, bg-mpl-stylesheets, pybaselines.

PbSO4 x-ray refinement in GSAS-II's five stages (tests/test_refinement.py):

Stage Rw GSAS-II Rwp
scale + background 0.441 0.458
cell 0.283 0.321
displacement 0.219 0.274
profile 0.130 0.135
atoms 0.0854 0.101

The final cell is within 0.003 Å of GSAS-II's. Tests: 259 passed locally.

What should the reviewer(s) do?

  • Review the background API (fit_to_data, fit_to_points, plot_fit) and its error messages.
  • Check the top-edge fix in PowderDiffractionGenerator._update_grid and the helpers it calls. It is a workaround until ObjCryst lists reflections past the top of the grid.
  • Run python refine_pbso4_xray.py from the repo root to see the refinement and its plot.

cadenmyers13 and others added 9 commits November 2, 2026 12:10
…n-pr.yml

The pin predates the March-Dollase (#119) and TOF profile (#120)
bindings, which later steps use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diffpy.cmistructure 0.1.1 requires Python <3.14, so CI's tests on 3.14
could not install it. Cap requires-python at <3.14 in pyproject.toml and
cookiecutter.json, and use 3.13 in the getting-started docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge Ready for review. please merge #12 first. Btw, heres the output with the new print_results_table method from srfit

Screenshot 2026-11-05 at 3 26 19 PM

@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (e7f5fd4) to head (fc6f3e6).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
+ Coverage   97.72%   99.08%   +1.36%     
==========================================
  Files           6        9       +3     
  Lines         658     1638     +980     
==========================================
+ Hits          643     1623     +980     
  Misses         15       15              
Files with missing lines Coverage Δ
tests/conftest.py 93.70% <100.00%> (+9.77%) ⬆️
tests/test_backgrounds.py 100.00% <100.00%> (ø)
tests/test_component.py 100.00% <100.00%> (ø)
tests/test_instruments.py 99.35% <100.00%> (+0.01%) ⬆️
tests/test_powderdiffractiongenerator.py 100.00% <100.00%> (ø)
tests/test_refinement.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge this is ready for review now that #12 is merged

@sbillinge
sbillinge merged commit a1386b5 into diffpy:main Nov 10, 2026
7 checks passed
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.

2 participants