예제 #1
0
    def test_HFIRCalculateGoniometer_HB3A_phi(self):
        omega = np.deg2rad(42)
        chi = np.deg2rad(-3)
        phi = np.deg2rad(23)
        R1 = np.array([
            [np.cos(omega), 0, -np.sin(omega)],  # omega 0,1,0,-1
            [0, 1, 0],
            [np.sin(omega), 0, np.cos(omega)]
        ])
        R2 = np.array([
            [np.cos(chi), np.sin(chi), 0],  # chi 0,0,1,-1
            [-np.sin(chi), np.cos(chi), 0],
            [0, 0, 1]
        ])
        R3 = np.array([
            [np.cos(phi), 0, -np.sin(phi)],  # phi 0,1,0,-1
            [0, 1, 0],
            [np.sin(phi), 0, np.cos(phi)]
        ])
        R = np.dot(np.dot(R1, R2), R3)

        wl = 1.54
        k = 2 * np.pi / wl
        theta = np.deg2rad(47)
        phi = np.deg2rad(13)

        q_lab = np.array([
            -np.sin(theta) * np.cos(phi), -np.sin(theta) * np.sin(phi),
            1 - np.cos(theta)
        ]) * k

        q_sample = np.dot(np.linalg.inv(R), q_lab)

        peaks = CreatePeaksWorkspace(OutputType="LeanElasticPeak",
                                     NumberOfPeaks=0)
        AddSampleLog(peaks, "Wavelength", str(wl), "Number")
        SetGoniometer(peaks, Axis0='42,0,1,0,-1',
                      Axis1='-3,0,0,1,-1')  # don't set phi

        p = peaks.createPeakQSample(q_sample)
        peaks.addPeak(p)

        HFIRCalculateGoniometer(peaks,
                                OverrideProperty=True,
                                InnerGoniometer=True)

        g = Goniometer()
        g.setR(peaks.getPeak(0).getGoniometerMatrix())
        YZY = g.getEulerAngles('YZY')
        self.assertAlmostEqual(YZY[0], -42, delta=1e-10)  # omega
        self.assertAlmostEqual(YZY[1], 3, delta=1e-10)  # chi
        self.assertAlmostEqual(YZY[2], -23, delta=1e-1)  # phi

        self.assertAlmostEqual(peaks.getPeak(0).getWavelength(),
                               1.54,
                               delta=1e-10)
    def PyExec(self):

        peaks = self.getProperty('Workspace').value

        wavelength = self.getProperty("Wavelength").value
        if wavelength == Property.EMPTY_DBL:
            wavelength = float(peaks.run()['wavelength'].value)

        if self.getProperty("OverrideProperty").value:
            flip_x = self.getProperty("FlipX").value
            inner = self.getProperty("InnerGoniometer").value
        else:
            flip_x = peaks.getInstrument().getName() == "HB3A"

            if peaks.getInstrument().getName() == "HB3A":
                inner = math.isclose(peaks.run().getTimeAveragedStd("omega"),
                                     0.0)
            else:
                inner = False

        starting_goniometer = peaks.run().getGoniometer().getR()

        for n in range(peaks.getNumberPeaks()):
            p = peaks.getPeak(n)
            g = Goniometer()
            g.setR(starting_goniometer)
            g.calcFromQSampleAndWavelength(V3D(*p.getQSampleFrame()),
                                           wavelength, flip_x, inner)
            self.log().information(
                "Found goniometer omega={:.2f} chi={:.2f} phi={:.2f} for peak {} with Q_sample {}"
                .format(*g.getEulerAngles('YZY'), n, p.getQSampleFrame()))
            p.setWavelength(wavelength)
            p.setGoniometerMatrix(g.getR())
예제 #3
0
    def test_HFIRCalculateGoniometer_HB2C_omega(self):
        omega = np.deg2rad(42)

        R = np.array([[np.cos(omega), 0, np.sin(omega)], [0, 1, 0],
                      [-np.sin(omega), 0, np.cos(omega)]])

        wl = 1.54
        k = 2 * np.pi / wl
        theta = np.deg2rad(47)
        phi = np.deg2rad(13)

        q_lab = np.array([
            -np.sin(theta) * np.cos(phi), -np.sin(theta) * np.sin(phi),
            1 - np.cos(theta)
        ]) * k

        q_sample = np.dot(np.linalg.inv(R), q_lab)

        peaks = CreatePeaksWorkspace(OutputType="LeanElasticPeak",
                                     NumberOfPeaks=0)

        p = peaks.createPeakQSample(q_sample)
        peaks.addPeak(p)

        HFIRCalculateGoniometer(peaks, wl)

        g = Goniometer()
        g.setR(peaks.getPeak(0).getGoniometerMatrix())
        YZY = g.getEulerAngles('YZY')
        self.assertAlmostEqual(YZY[0], 42, delta=1e-10)  # omega
        self.assertAlmostEqual(YZY[1], 0, delta=1e-10)  # chi
        self.assertAlmostEqual(YZY[2], 0, delta=1e-10)  # phi

        self.assertAlmostEqual(peaks.getPeak(0).getWavelength(),
                               1.54,
                               delta=1e-10)
    InputWorkspace='ConvertHFIRSCDtoMDETest_data', Wavelength=1.488)
ConvertHFIRSCDtoMDETest_peaks = FindPeaksMD(
    InputWorkspace=ConvertHFIRSCDtoMDETest_Q,
    PeakDistanceThreshold=2.2,
    CalculateGoniometerForCW=True,
    Wavelength=1.488)
ConvertHFIRSCDtoMDETest_leanpeaks = FindPeaksMD(
    InputWorkspace=ConvertHFIRSCDtoMDETest_Q,
    PeakDistanceThreshold=2.2,
    OutputType='LeanElasticPeak')

LoadMD('./ExternalData/Testing/Data/SystemTest/HB2C_WANDSCD_norm.nxs',
       OutputWorkspace='ConvertWANDSCDtoQTest_norm')
ConvertWANDSCDtoQTest_Q = ConvertWANDSCDtoQ(
    InputWorkspace='ConvertHFIRSCDtoMDETest_data',
    NormalisationWorkspace='ConvertWANDSCDtoQTest_norm')
ConvertWANDSCDtoQTest_peaks = FindPeaksMD(
    InputWorkspace=ConvertWANDSCDtoQTest_Q,
    PeakDistanceThreshold=2,
    CalculateGoniometerForCW=True,
    Wavelength=1.488)

from mantid.geometry import Goniometer
wavelength = 1.488
for n in range(ConvertHFIRSCDtoMDETest_leanpeaks.getNumberPeaks()):
    p = ConvertHFIRSCDtoMDETest_leanpeaks.getPeak(n)
    g = Goniometer()
    g.calcFromQSampleAndWavelength(p.getQSampleFrame(), wavelength)
    p.setWavelength(wavelength)
    p.setGoniometerMatrix(g.getR())
    print(g.getEulerAngles('YZY'))
예제 #5
0
q_lab = np.array([
    -np.sin(theta) * np.cos(phi), -np.sin(theta) * np.sin(phi),
    1 - np.cos(theta)
]) * k

q_sample = np.dot(np.linalg.inv(R), q_lab)

peaks = CreatePeaksWorkspace(OutputType="LeanElasticPeak", NumberOfPeaks=0)

p = peaks.createPeakQSample(q_sample)
peaks.addPeak(p)

HFIRCalculateGoniometer(peaks, wl, OverrideProperty=True, InnerGoniometer=True)

g = Goniometer()
g.setR(peaks.getPeak(0).getGoniometerMatrix())
print(g.getEulerAngles('YZY'))
assert np.isclose(g.getEulerAngles('YZY')[0], 42)

chi = np.deg2rad(-3)
phi = np.deg2rad(23)

R1 = np.array([
    [np.cos(omega), 0, -np.sin(omega)],  # omega 0,1,0,-1
    [0, 1, 0],
    [np.sin(omega), 0, np.cos(omega)]
])
R2 = np.array([
    [np.cos(chi), np.sin(chi), 0],  # chi 0,0,1,-1
    [-np.sin(chi), np.cos(chi), 0],
예제 #6
0
HFIRCalculateGoniometer(filter_int_peaks2)

leanelasticpeaks3 = PredictPeaks("data",
                                 ReflectionCondition='B-face centred',
                                 OutputType='LeanElasticPeak')

ws = CreatePeaksWorkspace()
SetUB(ws, a=2, b=2, c=2)
p = PredictPeaks(ws, OutputType='LeanElasticPeak', CalculateWavelength=False)

peaks = leanelasticpeaks3

wavelength = peaks.run()['wavelength'].value

flip_x = peaks.getInstrument().getName() == "HB3A"

if peaks.getInstrument().getName() == "HB3A":
    inner = math.isclose(peaks.run().getTimeAveragedStd("omega"), 0.0)
else:
    inner = False

for n in range(peaks.getNumberPeaks()):
    p = peaks.getPeak(n)
    g = Goniometer()
    g.calcFromQSampleAndWavelength(V3D(*p.getQSampleFrame()), wavelength,
                                   flip_x, inner)
    p.setWavelength(wavelength)
    p.setGoniometerMatrix(g.getR())
    print(g.getEulerAngles('YZY'))
예제 #7
0
 def test_setR_getR(self):
     g = Goniometer()
     r = np.array([(1., 0., 0.), (0., 0., 1.), (0., -1., 0.)])
     g.setR(r)
     self.assertTrue((g.getR() == r).all())
예제 #8
0
 def test_getEulerAngles(self):
     g = Goniometer()
     self.assertEquals(g.getEulerAngles()[0], 0)
     self.assertEquals(g.getEulerAngles()[1], 0)
     self.assertEquals(g.getEulerAngles()[2], 0)
예제 #9
0
    def runTest(self):
        HB3AAdjustSampleNorm(Filename="HB3A_exp0724_scan0183.nxs",
                             OutputWorkspace='data')

        peaks = PredictPeaks("data",
                             ReflectionCondition='B-face centred',
                             CalculateGoniometerForCW=True,
                             Wavelength=1.008,
                             InnerGoniometer=True,
                             FlipX=True,
                             MinAngle=-2,
                             MaxAngle=90)

        self.assertEqual(peaks.getNumberPeaks(), 57)
        peak0 = peaks.getPeak(0)
        self.assertDelta(peak0.getWavelength(), 1.008, 1e-5)
        self.assertEqual(peak0.getH(), 0)
        self.assertEqual(peak0.getK(), 0)
        self.assertEqual(peak0.getL(), -14)
        q_sample = peak0.getQSampleFrame()
        self.assertDelta(q_sample[0], 4.45402, 1e-5)
        self.assertDelta(q_sample[1], -0.419157, 1e-5)
        self.assertDelta(q_sample[2], 0.0906594, 1e-5)

        # test predicting with LeanElasticPeak, filter any peak with 0 intensity
        PredictPeaks("data",
                     ReflectionCondition='B-face centred',
                     OutputType='LeanElasticPeak',
                     CalculateWavelength=False,
                     OutputWorkspace="leanelasticpeaks")

        IntegratePeaksMD("data",
                         "leanelasticpeaks",
                         PeakRadius=0.1,
                         OutputWorkspace="integrated_peaks")
        filtered_peaks = FilterPeaks("integrated_peaks",
                                     FilterVariable='Intensity',
                                     FilterValue=0,
                                     Operator='>')

        self.assertEqual(filtered_peaks.getNumberPeaks(), 66)
        peak0 = filtered_peaks.getPeak(0)
        self.assertDelta(peak0.getWavelength(), 0, 1e-5)
        self.assertEqual(peak0.getH(), 0)
        self.assertEqual(peak0.getK(), 0)
        self.assertEqual(peak0.getL(), -14)
        q_sample = peak0.getQSampleFrame()
        self.assertDelta(q_sample[0], 4.45541, 1e-5)
        self.assertDelta(q_sample[1], -0.420383, 1e-5)
        self.assertDelta(q_sample[2], 0.0913072, 1e-5)

        g = Goniometer()
        g.setR(peak0.getGoniometerMatrix())
        YZY = g.getEulerAngles('YZY')
        self.assertDelta(YZY[0], 0, 1e-7)
        self.assertDelta(YZY[1], 0, 1e-7)
        self.assertDelta(YZY[2], 0, 1e-7)
        self.assertDelta(peak0.getWavelength(), 0, 1e-9)

        HFIRCalculateGoniometer(filtered_peaks)

        peak0 = filtered_peaks.getPeak(0)
        g = Goniometer()
        g.setR(peak0.getGoniometerMatrix())
        YZY = g.getEulerAngles('YZY')
        self.assertDelta(YZY[0], -20.4997, 1e-7)
        self.assertDelta(YZY[1], 0.0003, 1e-7)
        self.assertDelta(YZY[2], 0.5340761720854811, 1e-7)
        self.assertDelta(peak0.getWavelength(), 1.008, 1e-9)
예제 #10
0
 def test_setR_getR(self):
     g = Goniometer()
     r = np.array([(1., 0., 0.), (0., 0., 1.), (0., -1., 0.)])
     g.setR(r)
     self.assertTrue((g.getR() == r).all())
예제 #11
0
 def test_getEulerAngles(self):
     g = Goniometer()
     self.assertEqual(g.getEulerAngles()[0], 0)
     self.assertEqual(g.getEulerAngles()[1], 0)
     self.assertEqual(g.getEulerAngles()[2], 0)