def test_hklFromQ(self): ol = OrientedLattice(1, 1, 1) qVec = V3D(1, 1, 1) hkl = ol.hklFromQ(qVec) self.assertAlmostEqual(hkl.X() * 2 * np.pi, qVec.X(), 9) self.assertAlmostEqual(hkl.Y() * 2 * np.pi, qVec.Y(), 9) self.assertAlmostEqual(hkl.Z() * 2 * np.pi, qVec.Z(), 9)
def __move_components(self, exp_info, height, distance): """ Moves all instrument banks by a given height (y) and distance (x-z) in meters, relative to the current instrument position. :param exp_info: experiment info of the run, used to get the instrument components :param height: Distance to move the instrument along y axis :param distance: Distance to move the instrument in the x-z plane """ # Adjust detector height and distance with new offsets component = exp_info.componentInfo() for bank in range(1, 4): # Set height offset (y) first on bank? index = component.indexOfAny("bank{}".format(bank)) if height != 0.0: offset = V3D(0, height, 0) pos = component.position(index) offset += pos component.setPosition(index, offset) # Set distance offset to detector (x,z) on bank?/panel if distance != 0.0: panel_index = int(component.children(index)[0]) # should only have one child panel_pos = component.position(panel_index) panel_rel_pos = component.relativePosition(panel_index) # need to move detector in direction in x-z plane panel_offset = panel_rel_pos * (distance / panel_rel_pos.norm()) panel_offset += panel_pos component.setPosition(panel_index, panel_offset)
def test_qFromHKL(self): ol = OrientedLattice(1, 1, 1) hkl = V3D(1, 1, 1) qVec = ol.qFromHKL(hkl) self.assertAlmostEqual(hkl.X() * 2 * np.pi, qVec.X(), 9) self.assertAlmostEqual(hkl.Y() * 2 * np.pi, qVec.Y(), 9) self.assertAlmostEqual(hkl.Z() * 2 * np.pi, qVec.Z(), 9)
def test_that_ZOOM_can_perform_move(self): beam_coordinates = [45, 25] component = "main-detector-bank" component_key = DetectorType.LAB.value workspace = load_empty_instrument("ZOOM") state = _get_state_obj(SANSInstrument.ZOOM) # Initial move move_component(component_name=component, workspace=workspace, state=state, move_type=MoveTypes.INITIAL_MOVE, beam_coordinates=beam_coordinates) initial_z_position = 20.77408 expected_position = V3D(-beam_coordinates[0], -beam_coordinates[1], initial_z_position) expected_rotation = Quat(1., 0., 0., 0.) compare_expected_position(self, expected_position, expected_rotation, component_key, state.instrument_info, workspace) # Elementary Move component_elementary_move = "LAB" component_elementary_move_key = DetectorType.LAB.value beam_coordinates_elementary_move = [120, 135] check_elementry_displacement_with_translation( self, workspace, state, beam_coordinates_elementary_move, component_elementary_move, component_elementary_move_key) # Reset to zero check_that_sets_to_zero(self, workspace, state)
def _create_workspaces(self): cal=CreateSampleWorkspace(NumBanks=1,BinWidth=20000,PixelSpacing=0.1,BankPixelWidth=100) RotateInstrumentComponent(cal, ComponentName='bank1', X=1, Y=0.5, Z=2, Angle=35) MoveInstrumentComponent(cal, ComponentName='bank1', X=1, Y=1, Z=5) bkg=CloneWorkspace(cal) data=CloneWorkspace(cal) AddSampleLog(cal, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='200') AddSampleLog(bkg, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='50') AddSampleLog(data, LogName="gd_prtn_chrg", LogType='Number', NumberType='Double', LogText='100') AddSampleLog(cal, LogName="duration", LogType='Number', NumberType='Double', LogText='20') AddSampleLog(bkg, LogName="duration", LogType='Number', NumberType='Double', LogText='5') AddSampleLog(data, LogName="duration", LogType='Number', NumberType='Double', LogText='10') def get_cal_counts(n): if n < 5000: return 0.9 else: return 1.0 def get_bkg_counts(n): return 1.5*get_cal_counts(n) def get_data_counts(n,twoTheta): tt1=30 tt2=45 return get_bkg_counts(n)+10*np.exp(-(twoTheta-tt1)**2/1)+20*np.exp(-(twoTheta-tt2)**2/0.2) for i in range(cal.getNumberHistograms()): cal.setY(i, [get_cal_counts(i)*2.0]) bkg.setY(i, [get_bkg_counts(i)/2.0]) twoTheta=data.getInstrument().getDetector(i+10000).getTwoTheta(V3D(0,0,0),V3D(0,0,1))*180/np.pi data.setY(i, [get_data_counts(i,twoTheta)]) return data, cal, bkg
def _create_indexed_workspace(self, fractional_peaks, m1m2): # Create table with the number of columns we need modulated = CloneWorkspace(fractional_peaks) lattice = modulated.sample().getOrientedLattice() lattice.setModVec1(V3D(0.5, 0.0, 0.5)) lattice.setModVec2(V3D(0.333, 0.333, 0.)) for row, peak in enumerate(modulated): row_indices = m1m2[row] mnp = V3D(row_indices[0], row_indices[1], 0) peak.setIntMNP(mnp) # update hkl modvec = lattice.getModVec(0) * mnp[0] + lattice.getModVec(1) * mnp[1] hkl = peak.getHKL() + modvec peak.setHKL(hkl[0], hkl[1], hkl[2]) return modulated
def test_that_quaternion_can_be_converted_to_axis_and_angle_for_180_degree( self): # Arrange angle = 180.0 axis = V3D(0.0, 1.0, 0.0) # There shouldn't be an axis for angle 0 self._do_test_quaternion(angle, axis)
def test_that_missing_beam_centre_is_taken_from_lab_move_state_when_no_component_is_specified(self): # Arrange file_name = "SANS2D00028784" lab_z_translation_correction = 123. workspace = load_workspace(file_name) state = SANSMoveTest._get_simple_state(sample_scatter=file_name, lab_z_translation_correction=lab_z_translation_correction) # These values should be used instead of an explicitly specified beam centre state.move.detectors[DetectorType.to_string(DetectorType.LAB)].sample_centre_pos1 = 26. state.move.detectors[DetectorType.to_string(DetectorType.LAB)].sample_centre_pos2 = 98. # Act # The component input is not relevant for SANS2D's initial move. All detectors are moved component = None self._run_move(state, workspace=workspace, move_type="InitialMove", component=component) # Assert for initial move for low angle bank # These values are on the workspace and in the sample logs, component_to_investigate = DetectorType.to_string(DetectorType.LAB) initial_z_position = 23.281 rear_det_z = 11.9989755859 offset = 4. total_x = 0. total_y = 0. total_z = initial_z_position + rear_det_z - offset + lab_z_translation_correction expected_position = V3D(total_x - 26., total_y - 98., total_z) expected_rotation = Quat(1., 0., 0., 0.) self.compare_expected_position(expected_position, expected_rotation, component_to_investigate, state.move, workspace)
def test_that_missing_beam_centre_is_taken_from_move_state(self): # Arrange file_name = "SANS2D00028784" lab_z_translation_correction = 123. workspace = load_workspace(file_name) state = SANSMoveTest._get_simple_state(sample_scatter=file_name, lab_z_translation_correction=lab_z_translation_correction) # These values should be used instead of an explicitly specified beam centre state.move.detectors[DetectorType.to_string(DetectorType.HAB)].sample_centre_pos1 = 26. state.move.detectors[DetectorType.to_string(DetectorType.HAB)].sample_centre_pos2 = 98. # Act # The component input is not relevant for SANS2D's initial move. All detectors are moved component = "front-detector" self._run_move(state, workspace=workspace, move_type="InitialMove", component=component) # Assert for initial move for high angle bank # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.to_string(DetectorType.HAB) initial_x_position = 1.1 x_correction = -0.187987540973 initial_z_position = 23.281 z_correction = 1.00575649188 total_x = initial_x_position + x_correction total_y = 0. total_z = initial_z_position + z_correction expected_position = V3D(total_x - 26., total_y - 98., total_z) expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.) self.compare_expected_position(expected_position, expected_rotation, component_to_investigate, state.move, workspace)
def _get_v3d_from_str(self, string): if '[' in string and ']' in string: string = string[1:-1] if ',' in string: return V3D(*[float(x) for x in string.split(',')]) else: raise ValueError("'{}' is not a valid V3D string.".format(string))
def test_that_missing_beam_centre_is_taken_from_move_state(self): lab_z_translation_correction = 123. workspace = self._prepare_sans2d_empty_ws() state = _get_state_obj(instrument=SANSInstrument.SANS2D, z_translation=lab_z_translation_correction) # These values should be used instead of an explicitly specified beam centre state.move.detectors[DetectorType.HAB.value].sample_centre_pos1 = 26. state.move.detectors[DetectorType.HAB.value].sample_centre_pos2 = 98. # The component input is not relevant for SANS2D's initial move. All detectors are moved component = "front-detector" move_component(component_name=component, state=state, workspace=workspace, move_type=MoveTypes.INITIAL_MOVE) # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.HAB.value initial_x_position = 1.1 x_correction = -0.187987540973 initial_z_position = 23.281 z_correction = 1.00575649188 total_x = initial_x_position + x_correction total_y = 0. total_z = initial_z_position + z_correction expected_position = V3D(total_x - 26., total_y - 98., total_z) expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.) compare_expected_position(self, expected_position, expected_rotation, component_to_investigate, state.instrument_info, workspace)
def test_directionAngles_rads(self): v = V3D(1, 1, 1) inDegrees = False angles = v.directionAngles(inDegrees) self.assertAlmostEquals(math.acos(1.0 / math.sqrt(3.0)), angles.X()) self.assertAlmostEquals(math.acos(1.0 / math.sqrt(3.0)), angles.Y()) self.assertAlmostEquals(math.acos(1.0 / math.sqrt(3.0)), angles.Z())
def _check_cell(self, cell): self.assertAlmostEqual(cell.a(), 2.5, 10) self.assertAlmostEqual(cell.b(), 6, 10) self.assertAlmostEqual(cell.c(), 8, 10) self.assertAlmostEqual(cell.alpha(), 93, 10) self.assertAlmostEqual(cell.beta(), 88, 10) self.assertAlmostEqual(cell.gamma(), 97, 10) # get the some elements of the B matrix self.assertEquals(type(cell.getB()), np.ndarray) self.assertAlmostEqual(cell.getB()[0][0], 0.403170877311, 10) self.assertAlmostEqual(cell.getB()[2][0], 0.0, 10) self.assertAlmostEqual(cell.getB()[0][2], -0.00360329991666, 10) self.assertAlmostEqual(cell.getB()[2][2], 0.125, 10) # d spacing for direct lattice at (1,1,1) (will automatically check dstar) self.assertAlmostEqual(cell.d(1., 1., 1.), 2.1227107587, 10) self.assertAlmostEqual(cell.d(V3D(1., 1., 1.)), 2.1227107587, 10) # angle self.assertAlmostEqual( cell.recAngle(1, 1, 1, 1, 0, 0, AngleUnits.Radians), 0.471054990614, 10) self.assertEquals(type(cell.getG()), np.ndarray) self.assertEquals(type(cell.getGstar()), np.ndarray)
def test_setScaleFactor_exceptional(self): info = self._ws.componentInfo() sf = V3D(0,0,0) with self.assertRaises(TypeError): info.setScaleFactor("1", sf) with self.assertRaises(TypeError): info.setScaleFactor(1.0, sf)
def test_that_LARMOR_old_Style_can_be_moved(self): # Arrange file_name = "LARMOR00000063" workspace = load_workspace(file_name) state = SANSMoveTest._get_simple_state(sample_scatter=file_name) # Note that both entries are translations beam_coordinates = [24., 38.] # Act component = None move_alg = self._run_move(state, workspace=workspace, move_type="InitialMove", beam_coordinates=beam_coordinates, component=component) # Assert low angle bank for initial move # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.to_string(DetectorType.LAB) # The rotation couples the movements, hence we just insert absolute value, to have a type of regression test # solely. expected_position = V3D(-beam_coordinates[0], -beam_coordinates[1], 25.3) expected_rotation = Quat(1., 0., 0., 0.) self.compare_expected_position(expected_position, expected_rotation, component_to_investigate, state.move, workspace) # Act + Assert for setting to zero position for all self.check_that_sets_to_zero(workspace, move_alg, state.move, comp_name=None)
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())
def test_that_LARMOR_new_style_can_move(self): # Arrange file_name = "LARMOR00002260" lab_x_translation_correction = 123. workspace = load_workspace(file_name) state = SANSMoveTest._get_simple_state(sample_scatter=file_name, lab_x_translation_correction=lab_x_translation_correction) # Note that the first entry is an angle while the second is a translation (in meter) beam_coordinates = [24., 38.] # Act for initial move component = None move_alg = self._run_move(state, workspace=workspace, move_type="InitialMove", beam_coordinates=beam_coordinates, component=component) # Assert low angle bank for initial move # These values are on the workspace and in the sample logs component_to_investigate = DetectorType.to_string(DetectorType.LAB) # The rotation couples the movements, hence we just insert absoltute value, to have a type of regression test. expected_position = V3D(0, -38, 25.3) expected_rotation = Quat(0.978146, 0, -0.20792, 0) self.compare_expected_position(expected_position, expected_rotation, component_to_investigate, state.move, workspace) # Act + Assert for setting to zero position for all self.check_that_sets_to_zero(workspace, move_alg, state.move, comp_name=None)
def test_setPosition(self): """ Test that the component's position can be set correctly. """ info = self._ws.componentInfo() pos = V3D(0,0,0) info.setPosition(0, pos) retPos = info.position(0) self.assertEquals(pos, retPos)
def calcSomeTOF(box, peak, refitIDX=None, q_frame='sample'): xaxis = box.getXDimension() qx = np.linspace(xaxis.getMinimum(), xaxis.getMaximum(), xaxis.getNBins()) yaxis = box.getYDimension() qy = np.linspace(yaxis.getMinimum(), yaxis.getMaximum(), yaxis.getNBins()) zaxis = box.getZDimension() qz = np.linspace(zaxis.getMinimum(), zaxis.getMaximum(), zaxis.getNBins()) QX, QY, QZ = getQXQYQZ(box) if refitIDX is None: refitIDX = np.ones_like(QX).astype(np.bool) if q_frame == 'lab': qS0 = peak.getQLabFrame() elif q_frame == 'sample': qS0 = peak.getQSampleFrame() else: raise ValueError( 'ICCFT:calcSomeTOF - q_frame must be either \'lab\' or \'sample\'; %s was provided' % q_frame) PIXELFACTOR = np.ones_like(QX) * (peak.getL1() + peak.getL2()) * np.sin(0.5 * peak.getScattering()) for i, x in enumerate(qx): print(i) for j, y in enumerate(qy): for k, z in enumerate(qz): if refitIDX[i, j, k]: qNew = V3D(x, y, z) peak.setQSampleFrame(qNew) L = peak.getL1() + peak.getL2() HALFSCAT = 0.5 * peak.getScattering() PIXELFACTOR[i, j, k] = L*np.sin(HALFSCAT) peak.setQSampleFrame(qS0) tofBox = 3176.507 * PIXELFACTOR * 1.0/np.sqrt(QX**2 + QY**2 + QZ**2) return tofBox
def readCalibrationFile(table_name, in_path): """Read a calibration table from file This loads a calibration TableWorkspace from a CSV file. Example of usage: .. code-block:: python saveCalibration('CalibTable','/tmp/myCalibTable.txt') :param table_name: name to call the TableWorkspace :param in_path: the path to the calibration file """ DET = 'Detector ID' POS = 'Detector Position' re_float = re.compile(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?") calibTable = CreateEmptyTableWorkspace(OutputWorkspace=table_name) calibTable.addColumn(type='int', name=DET) calibTable.addColumn(type='V3D', name=POS) with open(in_path, 'r') as file_p: for line in file_p: values = re.findall(re_float, line) if len(values) != 4: continue nextRow = { DET: int(values[0]), POS: V3D(float(values[1]), float(values[2]), float(values[3])) } calibTable.addRow(nextRow)
def test_getUniqueHKLsUsingFilter(self): generator = ReflectionGenerator(self.crystalStructure) hkls = generator.getUniqueHKLsUsingFilter( 1.0, 10.0, ReflectionConditionFilter.StructureFactor) self.assertEqual(len(hkls), 8) self.assertFalse(V3D(2, 2, 2) in hkls)
def get_peak_centre_v3d(self): """ Returned the statistically averaged peak center in V3D :return: """ q_x, q_y, q_z = self.get_peak_centre() q_3d = V3D(q_x, q_y, q_z) return q_3d
def test_hasEquivalentSample(self): """ Check if the samples are equivalent""" info = self._ws.componentInfo() ws_other = CloneWorkspace(self._ws) info_other = ws_other.componentInfo() self.assertEqual(info.hasEquivalentSample(info_other), True) info_other.setPosition(info.sample(), info.samplePosition() + V3D(1. - 6, 0, 0)) self.assertEqual(info.hasEquivalentSample(info_other), False)
def test_trim_calibration_table(self): # create a table with detector id and detector XYZ positions table = CreateEmptyTableWorkspace(OutputWorkspace='CalibTable') table.addColumn(type='int', name='Detector ID') table.addColumn(type='V3D', name='Detector Position') table.addRow([0, V3D(0, 1, 2)]) # add two detectors with ID's 0 and 1 table.addRow([1, V3D(3, 4, 5)]) y_values = [1, 4] # call trim_calibration_table and save to new table table_calibrated = trim_calibration_table( table, output_workspace='table_calibrated') # assert the Y-coordinate hasn't changed assert_allclose(table_calibrated.column(1), y_values, atol=0.0001) # call trim_calibration_table and overwrite the table table_calibrated = trim_calibration_table(table) assert table_calibrated.name( ) == 'CalibTable' # table workspace has been overwritten with the calibrated one assert_allclose(table_calibrated.column(1), y_values, atol=0.0001)
def test_pickle_table_workspace(self): from mantid.kernel import V3D import pickle table = WorkspaceFactory.createTable() table.addColumn(type="int",name="index") table.addColumn(type="str",name="value") table.addColumn(type="V3D",name="position") values = (1, '10', V3D(0, 0, 1)) table.addRow(values) values = (2, '100', V3D(1, 0, 0)) table.addRow(values) p = pickle.dumps(table) table2 = pickle.loads(p) self.assertEqual(table.toDict(), table2.toDict())
def test_directionAngles(self): v = V3D(1, 1, 1) angles = v.directionAngles() self.assertAlmostEquals( math.acos(1.0 / math.sqrt(3.0)) * 180 / math.pi, angles.X()) self.assertAlmostEquals( math.acos(1.0 / math.sqrt(3.0)) * 180 / math.pi, angles.Y()) self.assertAlmostEquals( math.acos(1.0 / math.sqrt(3.0)) * 180 / math.pi, angles.Z())
def findConsistentUB(self, ubFiles, zeroUB, matUB, omega, dOmega, omegaHand, phiRef, dPhiRef, phiTol, phiHand, chiRef, chiTol, gonioTable): # calculate the rotation matrix that maps the UB of the first run onto subsequent UBs # get save directory saveDir = config['defaultsave.directory'] tmpWS = CreateSampleWorkspace() for irun in range(1, len(omega)): chi, phi, u = self.getGonioAngles(matUB[irun], zeroUB, omega[irun]) # phi relative to first run in RH/LH convention of user # check if phi and chi are not within tolerance of expected if abs(chi - chiRef) > chiTol and abs(phi - dPhiRef[irun]) > phiTol: # generate predicted UB to find axes permutation self.log().information( "The following UB\n{}\nis not consistent with the reference, attempting to " "find an axes swap/inversion that make it consistent.") # nominal goniometer axis gonio = getR(omegaHand * dOmega, [0, 0, 1]) @ getR( -chiRef, [1, 0, 0]) @ [0, 0, 1] predictedUB = getR(omega[irun], [0, 0, 1]) @ getR( dPhiRef[irun], gonio) @ zeroUB # try a permutation of the UB axes (as in TransformHKL) # UB' = UB M^-1 # HKL' = M HKL minv = np.linalg.inv(matUB[irun]) @ predictedUB minv = getSignMaxAbsValInCol(minv) # redo angle calculation on permuted UB matUB[irun] = matUB[irun] @ minv chi, phi, u = self.getGonioAngles(matUB[irun], zeroUB, omega[irun]) if abs(chi - chiRef) <= chiTol and abs(phi - dPhiRef[irun]) <= phiTol: # save the consistent UB to the default save directory _, nameUB = path.split(ubFiles[irun]) newUBPath = path.join( saveDir, nameUB[:-4] + '_consistent' + nameUB[-4:]) # set as UB (converting back to non-IPNS convention) SetUB(tmpWS, UB=matUB[irun][[1, 2, 0], :]) SaveIsawUB(tmpWS, newUBPath) # populate row of table phi2print = phiHand * (phi + phiRef[0]) phi2print = phi2print + np.ceil(-phi2print / 360) * 360 nextRow = { 'Run': nameUB[:-4], 'Chi': chi, 'Phi': phi2print, 'GonioAxis': V3D(u[0], u[1], u[2]) } gonioTable.addRow(nextRow) else: warnings.warn( "WARNING: The UB {0} cannot be made consistent with the reference UB. " "Check the goniometer angles and handedness supplied " "and the accuracy of reference UB.".format(ubFiles[irun])) DeleteWorkspace(tmpWS)
def test_peak_setQLabFrame(self): pws = WorkspaceCreationHelper.createPeaksWorkspace(1, True) p = pws.getPeak(0) try: p.setQLabFrame(V3D(1,1,1)) except Exception: self.fail("Tried setQLabFrame with one V3D argument") self.assertAlmostEquals( p.getQLabFrame().X(), 1.0, places=10) self.assertAlmostEquals( p.getQLabFrame().Y(), 1.0, places=10) self.assertAlmostEquals( p.getQLabFrame().Z(), 1.0, places=10) try: p.setQLabFrame(V3D(1,1,1), 1) except Exception: self.fail("Tried setQLabFrame with one V3D argument and a double distance") self.assertAlmostEquals( p.getQLabFrame().X(), 1.0, places=10) self.assertAlmostEquals( p.getQLabFrame().Y(), 1.0, places=10) self.assertAlmostEquals( p.getQLabFrame().Z(), 1.0, places=10)
def test_set_q_sample_frame(self): q_sample = V3D(0, 1, 1) self._peak.setQSampleFrame(q_sample) npt.assert_allclose(self._peak.getQSampleFrame(), q_sample, atol=self._tolerance) npt.assert_allclose(self._peak.getQLabFrame(), q_sample, atol=self._tolerance)
def test_interface(self): """ Rudimentary test to get peak and get/set some values """ pws = WorkspaceCreationHelper.createPeaksWorkspace(1) self.assertTrue(isinstance(pws, IPeaksWorkspace)) self.assertEqual(pws.getNumberPeaks(), 1) p = pws.getPeak(0) # Try a few IPeak get/setters. Not everything. p.setH(234) self.assertEqual(p.getH(), 234) p.setHKL(5,6,7) self.assertEqual(p.getH(), 5) self.assertEqual(p.getK(), 6) self.assertEqual(p.getL(), 7) hkl = p.getHKL() self.assertEquals(hkl, V3D(5,6,7)) p.setIntensity(456) p.setSigmaIntensity(789) self.assertEqual(p.getIntensity(), 456) self.assertEqual(p.getSigmaIntensity(), 789) # Finally try to remove a peak pws.removePeak(0) self.assertEqual(pws.getNumberPeaks(), 0) # Create a new peak at some Q in the lab frame qlab = V3D(1,2,3) p = pws.createPeak(qlab, 1.54) p.getQLabFrame() self.assertAlmostEquals( p.getQLabFrame().X(), 1.0, 3) # Now try to add the peak back pws.addPeak(p) self.assertEqual(pws.getNumberPeaks(), 1) # Check that it is what we added to it p = pws.getPeak(0) self.assertAlmostEquals( p.getQLabFrame().X(), 1.0, 3) # Peaks workspace will not be integrated by default. self.assertTrue(not pws.hasIntegratedPeaks())