Skip to content

Commit

Permalink
FIX: Calculation of R0 prefactor for resolution
Browse files Browse the repository at this point in the history
Resolves #57

Incorrect propagation of FWHM to gaussian RMS width conversion factor fixed.

Incorrect matrix indices during calculation with sample mosaics.

Went back to Matlab ResLib code to generate new tests for a more simple case. More tests will need to be generated.
  • Loading branch information
pseudocubic committed Mar 22, 2016
1 parent 263a722 commit 799d857
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions neutronpy/instrument.py
Expand Up @@ -1057,6 +1057,12 @@ def calc_resolution_in_Q_coords(self, Q, W):
else:
s2theta = np.real(s2theta)

# correct sign of curvatures
monorh = monorh * sm
monorv = monorv * sm
anarh = anarh * sa
anarv = anarv * sa

thetas = s2theta / 2.
phi = np.arctan2(-kf * np.sin(s2theta), ki - kf * np.cos(s2theta))

Expand Down
12 changes: 6 additions & 6 deletions neutronpy/instrument_tools.py
Expand Up @@ -74,13 +74,13 @@ def ellipse(saxis1, saxis2, phi=0, origin=None, npts=31):


def get_bragg_widths(RM):
bragg = [np.sqrt(8 * np.log(2)) / np.sqrt(RM[0, 0]),
np.sqrt(8 * np.log(2)) / np.sqrt(RM[1, 1]),
np.sqrt(8 * np.log(2)) / np.sqrt(RM[2, 2]),
get_phonon_width(0, RM, [0, 0, 0, 1])[1],
np.sqrt(8 * np.log(2)) / np.sqrt(RM[3, 3])]
bragg = np.array([np.sqrt(8 * np.log(2)) / np.sqrt(RM[0, 0]),
np.sqrt(8 * np.log(2)) / np.sqrt(RM[1, 1]),
np.sqrt(8 * np.log(2)) / np.sqrt(RM[2, 2]),
get_phonon_width(0, RM, [0, 0, 0, 1])[1],
np.sqrt(8 * np.log(2)) / np.sqrt(RM[3, 3])])

return bragg
return bragg * 2


def get_phonon_width(r0, M, C):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resolution.py
Expand Up @@ -195,7 +195,7 @@ def test_cooper_nathans(self):
NP = EXP.RMS
R = EXP.R0
BraggWidths = get_bragg_widths(NP)
angles = self.EXP_popovici.get_angles_and_Q(hkle)[0]
angles = self.EXP_coopernathans.get_angles_and_Q(hkle)[0]
ResVol = (2 * np.pi) ** 2 / np.sqrt(np.linalg.det(NP)) * 2

self.assertTrue(np.all(np.abs((RMS - NP)) < 100))
Expand Down

0 comments on commit 799d857

Please sign in to comment.