Skip to content

Commit

Permalink
Instrument broadening from Spectrum1D: fix weighting
Browse files Browse the repository at this point in the history
There seem to be two y-axis conventions at work; for "sparse" data
that has not been binned, the weights indicate a symmetry weighting or
possible neutron scattering intensity. For data in a spectrum, there
is also a weight for the bin width to compensate for bin-size effects.

The variable-width broadening machinery currently expects the
former (which makes sense for adaptive DOS broadening) and converts to
the latter (which is the expected form for spectrum
objects). Broadening _from_ a spectrum object therefore needs to
account for this.
  • Loading branch information
ajjackson committed Oct 24, 2022
1 parent 17bbbda commit 7c640d5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion euphonic/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,15 @@ def broaden_with_polynomial(self: T,
else:
raise ValueError('width_convention must be "std" or "fwhm".')

bin_widths = np.diff(self.get_bin_edges())
if not np.all(np.isclose(bin_widths, bin_widths[0])):
raise ValueError('Not all bins are the same width: this method '
'requires a regular sampling grid.')

y_broadened = polynomial_broadening(
self.get_bin_edges(), self.get_bin_centres(), polynomial,
self.y_data.magnitude,
(self.y_data.magnitude
* bin_widths[0].to(1/self.y_data.units).magnitude),
width_unit=width_unit, width_lower_limit=width_lower_limit,
adaptive_error=adaptive_error)

Expand Down

0 comments on commit 7c640d5

Please sign in to comment.