Include wavelength component in Q resolution calculation#112
Include wavelength component in Q resolution calculation#112welbournR wants to merge 19 commits into
Conversation
29769c9 to
d345d2b
Compare
effa7f0 to
7d8dff9
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #112 +/- ##
==========================================
+ Coverage 85.16% 85.25% +0.09%
==========================================
Files 23 24 +1
Lines 2925 3032 +107
==========================================
+ Hits 2491 2585 +94
- Misses 434 447 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
for more information, see https://pre-commit.ci
…mination from logs into a method
253e844 to
9b19294
Compare
There was a problem hiding this comment.
Pull request overview
Updates LR’s Q-resolution calculation to include both wavelength (λ) and angular (θ) components, and wires the resulting per-bin resolution through the reduction/template/workflow outputs.
Changes:
- Add new θ- and λ-based resolution helpers and return
dq_over_qalongside reduced R(Q) results. - Introduce a SymPy-based
UserDefinedFunctionto evaluate the wavelength-resolution function string. - Update workflow/output plumbing and adjust unit/integration tests for the new return signatures and new resolution behavior.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/lr_reduction/event_reduction.py |
Implements new θ/λ resolution computation and returns dq_over_q_bins from specular. |
src/lr_reduction/template.py |
Propagates dq_over_q through process_from_template_ws and switches θ selection to CoordinateSystem. |
src/lr_reduction/workflow.py |
Stores dq (absolute) in outputs and updates explorer return to include dq. |
src/lr_reduction/user_defined_function.py |
Adds SymPy-based parser/evaluator for user-provided resolution functions. |
src/lr_reduction/data_info.py |
Adds CoordinateSystem enum and refactors DataType.from_workspace to use it. |
src/lr_reduction/gravity_correction.py |
Uses CoordinateSystem.from_workspace for θ-in selection. |
src/lr_reduction/time_resolved.py |
Keeps legacy resolution for backwards compatibility; updates slice reductions/plotting to use dq. |
src/lr_reduction/output.py |
Adds fwhm flag to ASCII header labeling for dq column. |
tests/unit/lr_reduction/test_user_defined_function.py |
New unit tests for parsing/evaluating user-defined functions. |
tests/unit/lr_reduction/test_event_reduction.py |
Adds tests for θ- and λ-resolution helpers; adjusts mock log exception type. |
tests/unit/lr_reduction/test_data_info.py |
Rewrites tests to use real Mantid workspaces; adds CoordinateSystem tests. |
tests/test_reduction.py |
Updates test expectations/unpacking for new dq_over_q return; removes obsolete wavelength test. |
tests/test_dead_time.py |
Updates unpacking for new return shape. |
pyproject.toml |
Adds sympy (runtime + env) and jupyter (env) dependencies. |
pixi.lock |
Lockfile updates for new dependencies and pixi options. |
docs/api/lr_reduction.rst |
Fixes API docs module reference from typing to types. |
.gitattributes |
Marks pixi.lock as generated and binary-merged. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| print("Could not find BL4B:Mot:xi.RBV: using supplied dQ/Q") | ||
| return default_dq | ||
| theta_deg = np.degrees(theta) | ||
| return theta_deg, default_dq |
There was a problem hiding this comment.
In the fallback branch when BL4B:Mot:xi.RBV is missing, compute_theta_resolution returns (theta_deg, default_dq), but default_dq is documented as a fractional dθ/θ (and historically was used as a dimensionless dQ/Q). Returning it as degrees makes the later (delta_th_deg / theta_deg) term scale as default_dq/theta_deg, which is incorrect. Convert the default fractional value into degrees (e.g., dtheta_deg = default_dq * theta_deg) or rename/retune the parameter so units are consistent across all return paths.
| return theta_deg, default_dq | |
| dtheta_deg = default_dq * theta_deg | |
| return theta_deg, dtheta_deg |
There was a problem hiding this comment.
@welbournR This is a good catch by copilot! Previously, when there was only a theta component, the fallback value if theta could not be computed would be dQ/Q = 0.027, but now this value is returned as the fallback dtheta, which is combined with the wavelength resolution.
What would be a reasonable default dtheta?
| Returns | ||
| ------- | ||
| tuple of np.ndarray | ||
| (wavelength, d_lambda): | ||
| wavelength: the fitted wavelength values | ||
| d_lambda: the difference between wavelength and the fit | ||
|
|
||
| Raises | ||
| ------ | ||
| ValueError : if ws does not have exactly one spectrum | ||
| """ |
There was a problem hiding this comment.
compute_wavelength_resolution’s docstring still describes the old Mantid-EvaluateFunction behavior ("fitted wavelength values" and "difference between wavelength and the fit"). The new implementation simply evaluates the provided resolution function on wl_list and returns (wl_list, d_lambda), so the return-value description should be updated to match what the function actually returns (and clarify expected units/meaning of d_lambda).
| # TODO: tighten the tolerance here once the equation has been updated | ||
| dq_over_q_expected = [0.014] * np.ones(43) | ||
| np.testing.assert_array_almost_equal(dq_over_q, dq_over_q_expected, decimal=3) |
There was a problem hiding this comment.
These assertions currently hard-code nearly-constant dq_over_q arrays with very loose/placeholder expectations (and TODOs to revisit). This weakens the regression protection for the new Q-resolution calculation. Prefer asserting against values computed from the underlying resolution model (theta+lambda terms) or against a known-good reference dataset so the test fails meaningfully if the resolution implementation changes.
Description of work:
Q-resolution calculation updated to include both lambda and theta components. Includes prior functions that weren't integrated into the workflow.
DRAFT - this needs tests to be updated. Request other eyes on the code to check the changes.
Check all that apply:
References:
(Instructions for testing here)
Check list for the reviewer