def test_replace_axis(self): x_axis = NumericAxis.create(1) x_axis.setValue(0, 0) ws1 = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument( 2, 1, False) ws1.replaceAxis(0, x_axis) ws2 = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument( 2, 1, False) ws2.replaceAxis(0, x_axis) try: del ws1, ws2 except: self.fail( "Segmentation violation when deleting the same axis twice")
def testFailLimits(self): w2=WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('w2',w2) w3=CloneWorkspace('w2') w4=CloneWorkspace('w2') try: MaskAngle(w2,-100,20) self.fail("Should not have got here. Wrong angle.") except RuntimeError: pass finally: DeleteWorkspace('w2') try: MaskAngle(w3,10,200) self.fail("Should not have got here. Wrong angle.") except ValueError: pass finally: DeleteWorkspace('w3') try: MaskAngle(w4,100,20) self.fail("Should not have got here. Wrong angle.") except RuntimeError: pass finally: DeleteWorkspace('w4')
def test_TotScatCalculateSelfScattering_executes(self): raw_ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(6, 100, True) mtd.addOrReplace("tot_scat_test", raw_ws) correction_ws = TotScatCalculateSelfScattering(InputWorkspace="tot_scat_test", CalFileName=self.cal_file_path, SampleGeometry=self.geometry, SampleMaterial=self.material) self.assertEqual(correction_ws.getNumberHistograms(), 2)
def testGroupMaskAngle(self): ws1=WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('ws1GMA',ws1) ws2=WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('ws2GMA',ws2) group = GroupWorkspaces(['ws1GMA', 'ws2GMA']) MaskAngle(group, 10, 20) for w in group: detInfo = w.detectorInfo() for i in arange(w.getNumberHistograms()): if(i<9) or (i>18): self.assertFalse(detInfo.isMasked(int(i))) else: self.assertTrue(detInfo.isMasked(int(i))) DeleteWorkspace(group)
def testMaskAngleInPlane(self): w_inplane = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('w_inplane',w_inplane) MaskAngle(w_inplane,-5,5,Angle='InPlane') detInfo = w_inplane.detectorInfo() print('num spectra = {}'.format(w_inplane.getNumberHistograms())) for i in arange(w_inplane.getNumberHistograms()): # the entire instrument is at an in-plane angle of zero degrees self.assertTrue(detInfo.isMasked(int(i)), 'index={}'.format(i)) DeleteWorkspace(w_inplane)
def testMaskAnglePhi(self): w=WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('w',w) MaskAngle(w,0,45,Angle='Phi') detInfo = w.detectorInfo() for i in arange(w.getNumberHistograms()): if i==0: self.assertTrue(detInfo.isMasked(int(i))) else: self.assertFalse(detInfo.isMasked(int(i))) DeleteWorkspace(w)
def testMaskAngle(self): w=WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('w',w) masklist = MaskAngle(w,MinAngle=10,MaxAngle=20) detInfo = w.detectorInfo() for i in arange(w.getNumberHistograms()): if (i<9) or (i>18): self.assertFalse(detInfo.isMasked(int(i))) else: self.assertTrue(detInfo.isMasked(int(i))) DeleteWorkspace(w) self.assertTrue(array_equal(masklist,arange(10)+10))
def testMaskBTPWrongInstrument(self): w = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument( 30, 5, False, False) AnalysisDataService.add('w', w) try: MaskBTP(Workspace=w, Pixel="1") self.fail( "Should not have got here. Should throw because wrong instrument." ) except RuntimeError: pass finally: DeleteWorkspace(w)
def testGroupFailNoInstrument(self): ws1=WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(30,5,False,False) AnalysisDataService.add('ws1GFNI',ws1) ws2 = CreateWorkspace(arange(5), arange(5)) AnalysisDataService.add('ws2GFNI',ws2) group = GroupWorkspaces(['ws1GFNI', 'ws2GFNI']) try: MaskAngle(group, 10, 20) self.fail("Should not have gotten here. Should throw because no instrument.") except (RuntimeError, ValueError, TypeError): pass finally: DeleteWorkspace(group)
def testSortDetectors(self): w = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument( 10, 2, False, False) AnalysisDataService.add('w', w) MoveInstrumentComponent(w, DetectorID=3, X=0., Y=0, Z=-7., RelativePosition=0) x = SortDetectors(w) DeleteWorkspace(w) self.assertTrue(array_equal(x[0], array([2]))) self.assertTrue(array_equal(x[1], array([7.]))) self.assertTrue(array_equal(x[2], array([0, 1, 3, 4, 5, 6, 7, 8, 9]))) self.assertEqual(x[3][0], 5.)
def test_MaskWorkspace_Is_Retrievable(self): dummy_ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(2, 102, False) # no monitors ws_name = "dummy" AnalysisDataService.add(ws_name, dummy_ws) run_algorithm('MaskDetectors', Workspace=ws_name, WorkspaceIndexList=1) mask_name = 'mask_ws' run_algorithm('ExtractMask', InputWorkspace=ws_name, OutputWorkspace=mask_name) masked_ws = AnalysisDataService[mask_name] self.assertTrue(isinstance(masked_ws, IMaskWorkspace)) self.assertEqual(1, masked_ws.getNumberMasked()) # single number self.assertTrue(not masked_ws.isMasked(1)) self.assertTrue(masked_ws.isMasked(2)) # list self.assertTrue(not masked_ws.isMasked([1])) self.assertTrue(masked_ws.isMasked([2]))
def setUp(self): if self._test_ws is None: self.__class__._test_ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument( 2, 102, False) # no monitors
def _createMultiSpectra(self, wkspname): wksp = WCH.create2DWorkspaceWithFullInstrument(30, 5, False, False) AnalysisDataService.add(wkspname, wksp)
def setUp(self): """ Setup Workspace to use""" if self.__class__._ws is None: self.__class__._ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument( 2, 1, False) # no monitors self.__class__._ws.getSpectrum(0).clearDetectorIDs()
def setUp(self): if self.__class__._ws is None: self.__class__._ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(2, 1, False) # no monitors self.__class__._ws.getSpectrum(0).clearDetectorIDs()
def setUp(self): if self.__testws is None: self.__class__.__testws = \ WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(1,1)