Skip to content

Commit

Permalink
Merge pull request #385 from neutrons/d_spacing_fix
Browse files Browse the repository at this point in the history
Fix error in calculation of d-spacing from 2theta
  • Loading branch information
peterfpeterson authored Feb 13, 2020
2 parents c1f8d3e + 7774f74 commit 35b9adf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions pyrs/peaks/peak_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ def get_dspacing_center(self):
A two-item tuple containing the peak center and its uncertainty.
"""
effective_values, effective_errors = self.get_effective_params()
theta_center_value = np.array([value['Center'] / 2 for value in effective_values])
theta_center_error = np.array([error['Center'] / 2 for error in effective_errors])
dspacing_center = self._wavelength / (2 * np.sin(theta_center_value))
dspacing_center_error = self._wavelength * abs(np.cos(theta_center_value)) * theta_center_error /\
(2 * np.sin(theta_center_value)**2)
theta_center_value = 0.5 * effective_values['Center']
theta_center_error = 0.5 * effective_errors['Center']
dspacing_center = 0.5 * self._wavelength / np.sin(np.deg2rad(theta_center_value))
dspacing_center_error = 0.5 * self._wavelength * abs(np.cos(theta_center_value)) * theta_center_error /\
(np.sin(np.deg2rad(theta_center_value))**2)
return dspacing_center, dspacing_center_error

def get_integrated_intensity(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_peak_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def check_peak_collection(peak_shape, NUM_SUBRUN, target_errors,
else:
raw_peaks_array['Height'] = [1, 2]
raw_peaks_array['Sigma'] = np.array([4, 5], dtype=float)
raw_peaks_array['PeakCentre'] = [3, 4]
raw_peaks_array['PeakCentre'] = [90., 91.]

# background terms are both zeros
raw_peaks_errors = np.zeros(NUM_SUBRUN, dtype=get_parameter_dtype(peak_shape, 'Linear'))
Expand Down Expand Up @@ -127,8 +127,8 @@ def check_peak_collection(peak_shape, NUM_SUBRUN, target_errors,
else:
peaks.set_d_reference(values=d_reference)
strain, strain_error = peaks.get_strain()
np.testing.assert_allclose(strain, target_strain, atol=0.01)
np.testing.assert_allclose(strain_error, target_strain_error, atol=0.01)
np.testing.assert_allclose(strain, target_strain, atol=0.0001)
np.testing.assert_allclose(strain_error, target_strain_error, atol=0.0001)


def test_peak_collection_Gaussian():
Expand All @@ -137,8 +137,8 @@ def test_peak_collection_Gaussian():
check_peak_collection('Gaussian', NUM_SUBRUN, np.zeros(NUM_SUBRUN, dtype=get_parameter_dtype(effective=True)))
# with wavelength
check_peak_collection('Gaussian', NUM_SUBRUN, np.zeros(NUM_SUBRUN, dtype=get_parameter_dtype(effective=True)),
wavelength=3.15, d_reference=2.5, target_d_spacing_center=[1.57, 1.73],
target_d_spacing_center_error=[0.0, 0.0], target_strain=[-0.378, -0.308],
wavelength=1.53229, d_reference=1.08, target_d_spacing_center=[1.08, 1.07],
target_d_spacing_center_error=[0.0, 0.0], target_strain=[0.0032, -0.0054],
target_strain_error=[0.0, 0.0])


Expand All @@ -154,8 +154,8 @@ def test_peak_collection_PseudoVoigt():
np.array([(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)],
dtype=get_parameter_dtype(effective=True)),
wavelength=3.15, d_reference=2.5, target_d_spacing_center=[1.57, 1.73],
target_d_spacing_center_error=[0.0, 0.0], target_strain=[-0.378, -0.308],
wavelength=1.53229, d_reference=1.08, target_d_spacing_center=[1.08, 1.07],
target_d_spacing_center_error=[0.0, 0.0], target_strain=[0.0032, -0.0054],
target_strain_error=[0.0, 0.0])


Expand Down

0 comments on commit 35b9adf

Please sign in to comment.