def run_test(v1, v2): cell = OrientedLattice() testhelpers.assertRaisesNothing(self, cell.setUFromVectors, v1, v2) rot = cell.getUB(); expected = np.array([(0,1.,0.), (0.,0.,1.), (1.,0.,0.)]) np.testing.assert_array_almost_equal(expected, rot, 8)
from mantid.simpleapi import * from mantid.geometry import OrientedLattice from itertools import permutations import numpy as np ol = OrientedLattice(5, 7, 12, 90, 90, 120) ub = ol.getUB() print(ub) peaks = CreatePeaksWorkspace(NumberOfPeaks=0) peaks.addPeak(peaks.createPeakQSample(2 * np.pi * np.dot(ub, [1, 1, 1]))) peaks.addPeak(peaks.createPeakQSample(2 * np.pi * np.dot(ub, [1, 1, 0]))) peaks.addPeak(peaks.createPeakQSample(2 * np.pi * np.dot(ub, [1, 2, 0]))) peaks2 = CreatePeaksWorkspace(NumberOfPeaks=0) peaks2.addPeak(peaks2.createPeakQSample(2 * np.pi * np.dot(ub, [1, 1, 1]))) peaks2.addPeak(peaks2.createPeakQSample(2 * np.pi * np.dot(ub, [1, 1, 0]))) peaks2.addPeak(peaks2.createPeakQSample(2 * np.pi * np.dot(ub, [1, 2, 0]))) CompareWorkspaces(peaks, peaks2, Tolerance=1e-4) ws = CreateSampleWorkspace() peaks = CreatePeaksWorkspace(InstrumentWorkspace='ws') peaks2 = CreatePeaksWorkspace(InstrumentWorkspace='ws') peaks.getPeak(0).setRunNumber(123) CompareWorkspaces(peaks, peaks2, Tolerance=1e-4)
def run_test(v1, v2): cell = OrientedLattice() testhelpers.assertRaisesNothing(self, cell.setUFromVectors, v1, v2) rot = cell.getUB() expected = np.array([(0, 1., 0.), (0., 0., 1.), (1., 0., 0.)]) np.testing.assert_array_almost_equal(expected, rot, 8)
def _qangle_validate_inputs( hkl: np.array, Ei: float or np.array, DeltaE: float or np.array, sign: float or np.array, lattice: OrientedLattice, detector_constraints: bool, horizontal_extent: np.array, vertical_extent: np.array, horizontal_extent_low: np.array, vertical_extent_low: np.array, goniometer_constraints: bool, goniometer_range): """ Validate inputs for qangle function, according to the rules for that function """ try: len_hkl = len(hkl) if len(hkl[0]) != 3: raise ValueError() except (TypeError, ValueError): raise ValueError('hkl is not an array of triplets') try: # check if float Ei = float(Ei) Ei = np.full(len_hkl, Ei) except ValueError: raise ValueError('Ei is not a float or numpy array') except TypeError: if len(Ei) != len_hkl: raise ValueError('Ei has different length than hkl') try: # check if float DeltaE = float(DeltaE) DeltaE = np.full(len_hkl, DeltaE) except ValueError: raise ValueError('DeltaE is not a float or numpy array') except TypeError: if len(DeltaE) != len_hkl: raise ValueError('DeltaE has different length than hkl') try: # check if int sign = int(sign) sign = np.full(len_hkl, sign) except ValueError: raise ValueError('sign is not an int or numpy array') except TypeError: if len(sign) != len_hkl: raise ValueError('sign has different length than hkl') try: UB = lattice.getUB() * 2. * np.pi except: raise ValueError("Can't get the UB matrix from the lattice object") # inputs for geometry and goniometer constraints if detector_constraints: if horizontal_extent[0] < -180 or horizontal_extent[ 1] < horizontal_extent[0] or horizontal_extent[1] > 180: raise ValueError( f"Horizontal constraints must obey -180 <= horizontal_extent[0]" f" ({horizontal_extent[0]}) <= horizontal_extent[1] ({horizontal_extent[1]})<=180" ) if vertical_extent[0] < -180 or vertical_extent[1] < vertical_extent[ 0] or vertical_extent[1] > 180: raise ValueError( f"Vertical constraints must obey -180 <= vertical_extent[0] ({vertical_extent[0]}) " f"<= vertical_extent[1] ({vertical_extent[1]}) <=180") if horizontal_extent_low[0] < -180 or horizontal_extent_low[ 1] < horizontal_extent_low[0] or horizontal_extent_low[1] > 180: raise ValueError( f"Horizontal constraints must obey -180 <= horizontal_extent_low[0]" f" ({horizontal_extent_low[0]}) <= horizontal_extent_low[1] ({horizontal_extent_low[1]}) <=180" ) if vertical_extent_low[0] < -180 or vertical_extent_low[ 1] < vertical_extent_low[0] or vertical_extent_low[1] > 180: raise ValueError( f"Vertical constraints must obey -180 <= vertical_extent_low[0] ({vertical_extent_low[0]}) " f"<= vertical_extent_low[1] ({vertical_extent_low[1]}) <=180") if goniometer_constraints: if goniometer_range[1]<goniometer_range[0] or \ goniometer_range[0]<-180. or goniometer_range[1]>180.: raise ValueError("goniometer_range must be an increasing array, " "with both limits between -180 and 180 degrees") return (Ei, DeltaE, sign, UB)