def setUpClass(cls): cls.histo_ws = CreateMDHistoWorkspace( Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(100), ErrorInput=range(100), NumberOfBins='5,5,4', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_2d') cls.histo_ws_positive = CreateMDHistoWorkspace( Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(1, 101), ErrorInput=range(100), NumberOfBins='5,5,4', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_2d_pos') cls.hkl_ws = CreateMDWorkspace(Dimensions=3, Extents='-10,10,-9,9,-8,8', Names='A,B,C', Units='r.l.u.,r.l.u.,r.l.u.', Frames='HKL,HKL,HKL', OutputWorkspace='hkl_ws') expt_info = CreateSampleWorkspace() cls.hkl_ws.addExperimentInfo(expt_info) SetUB('hkl_ws', 1, 1, 1, 90, 90, 90)
def test_unary_ops_with_workspaces_not_in_ADS(self): mdws = CreateMDHistoWorkspace(SignalInput=[0], ErrorInput=[0], Dimensionality=1, Extents=[0, 1], NumberOfBins=1, Names=['a'], Units=['TOF'], StoreInADS=False) mdws_ads = CreateMDHistoWorkspace(SignalInput=[0], ErrorInput=[0], Dimensionality=1, Extents=[0, 1], NumberOfBins=1, Names=['a'], Units=['TOF'], StoreInADS=True) result1 = ~mdws self.assertTrue(mtd.doesExist('result1')) result2 = ~mdws_ads self.assertTrue(mtd.doesExist('result2'))
def setUpClass(cls): cls.g1da = config['graph1d.autodistribution'] config['graph1d.autodistribution'] = 'On' cls.ws2d_histo = CreateWorkspace(DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], DataE=[1, 2, 3, 4], NSpec=2, Distribution=True, YUnitLabel="Counts per $\\AA$", UnitX='Wavelength', VerticalAxisUnit='DeltaE', VerticalAxisValues=[4, 6, 8], OutputWorkspace='ws2d_histo') cls.ws2d_histo_non_dist = CreateWorkspace(DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], DataE=[1, 2, 3, 4], NSpec=2, Distribution=False, YUnitLabel='Counts', UnitX='Wavelength', OutputWorkspace='ws2d_histo_non_dist') cls.ws2d_histo_rag = CreateWorkspace(DataX=[1, 2, 3, 4, 5, 2, 4, 6, 8, 10], DataY=[2] * 8, NSpec=2, VerticalAxisUnit='DeltaE', VerticalAxisValues=[5, 7, 9], OutputWorkspace='ws2d_histo_rag') cls.ws_MD_2d = CreateMDHistoWorkspace(Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(25), ErrorInput=range(25), NumberOfEvents=10 * np.ones(25), NumberOfBins='5,5,1', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_2d') cls.ws_MD_1d = CreateMDHistoWorkspace(Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(5), ErrorInput=range(5), NumberOfEvents=10 * np.ones(5), NumberOfBins='1,5,1', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_1d') cls.ws2d_point_uneven = CreateWorkspace(DataX=[10, 20, 30], DataY=[1, 2, 3], NSpec=1, OutputWorkspace='ws2d_point_uneven') wp = CreateWorkspace(DataX=[15, 25, 35, 45], DataY=[1, 2, 3, 4], NSpec=1) ConjoinWorkspaces(cls.ws2d_point_uneven, wp, CheckOverlapping=False) cls.ws2d_point_uneven = mantid.mtd['ws2d_point_uneven'] cls.ws2d_histo_uneven = CreateWorkspace(DataX=[10, 20, 30, 40], DataY=[1, 2, 3], NSpec=1, OutputWorkspace='ws2d_histo_uneven') AddTimeSeriesLog(cls.ws2d_histo, Name="my_log", Time="2010-01-01T00:00:00", Value=100) AddTimeSeriesLog(cls.ws2d_histo, Name="my_log", Time="2010-01-01T00:30:00", Value=15) AddTimeSeriesLog(cls.ws2d_histo, Name="my_log", Time="2010-01-01T00:50:00", Value=100.2)
def create_histo_workspace(self, name): signal = list(range(0, 100)) error = np.zeros(100) + 2 workspace = CreateMDHistoWorkspace(Dimensionality=2, Extents='0,100,0,100', SignalInput=signal, ErrorInput=error, NumberOfBins='10,10', Names='Dim1,Dim2', Units='U,U', OutputWorkspace=name) workspace = wrap_workspace(workspace, name) workspace.is_PSD = True return workspace
def wrapper(self): if dimensions == 2: S = range(0, 100) ERR = range(0, 100) mdws = CreateMDHistoWorkspace(Dimensionality=2, Extents='-3,3,-10,10', SignalInput=S, ErrorInput=ERR, NumberOfBins='10,10', Names='Dim1,Dim2', Units='MomentumTransfer,EnergyTransfer') else: S = range(0, 1000) ERR = range(0, 1000) mdws = CreateMDHistoWorkspace(Dimensionality=3, Extents='-3,3,-10,10,-20,20', SignalInput=S, ErrorInput=ERR, NumberOfBins='10,10,10', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,EnergyTransfer') return func(self, mdws)
def setUpClass(self): self.ws_MD_3D = CreateMDHistoWorkspace( Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(100), ErrorInput=range(100), NumberOfBins='5,5,4', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_3D') self.ws_MDE_3D = CreateMDWorkspace(Dimensions='3', Extents='-3,3,-4,4,-5,5', Names='h,k,l', Units='rlu,rlu,rlu', SplitInto='4', OutputWorkspace='ws_MDE_3D') FakeMDEventData('ws_MDE_3D', PeakParams='100000,0,0,0,0.1', RandomSeed='63759', RandomizeSignal='1') FakeMDEventData('ws_MDE_3D', PeakParams='40000,1,0,0,0.1', RandomSeed='63759', RandomizeSignal='1') self.ws2d_histo = CreateWorkspace(DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], DataE=[1, 2, 3, 4], NSpec=2, Distribution=True, UnitX='Wavelength', VerticalAxisUnit='DeltaE', VerticalAxisValues=[4, 6, 8], OutputWorkspace='ws2d_histo')
def test_save_cut_to_ascii(self, output_method): ws_name = output_workspace_name("workspace", -1.5, 2) raw_ws = CreateMDHistoWorkspace(SignalInput=[1, 2], ErrorInput=[4, 5], Dimensionality=1, Extents=[-1, 5], NumberOfBins=2, Names='Dim1', Units="units", OutputWorkspace=ws_name) ws = HistogramWorkspace(raw_ws, ws_name) _save_cut_to_ascii(ws, ws_name, "some_path") output_method.assert_called_once() self.assertEqual(output_method.call_args[0][0], 'some_path') np.testing.assert_array_equal(output_method.call_args[0][1], [[-1, 1, 4], [5, 2, 5]])
def _compute_cut_nonPSD(selected_workspace, cut_axis, integration_axis, emode): cut_binning = " ,".join(map(str, (cut_axis.start_meV, cut_axis.step_meV, cut_axis.end_meV))) int_binning = " ,".join(map(str, (integration_axis.start_meV, integration_axis.end_meV - integration_axis.start_meV, integration_axis.end_meV))) idx = 0 unit = 'DeltaE' name = 'EnergyTransfer' if is_momentum(cut_axis.units): ws_out = _cut_nonPSD_momentum(cut_binning, int_binning, emode, selected_workspace) idx = 1 unit = 'MomentumTransfer' name = '|Q|' elif is_twotheta(cut_axis.units): ws_out = _cut_nonPSD_theta(cut_binning, int_binning, selected_workspace) idx = 1 unit = 'Degrees' name = 'Theta' elif integration_axis.units == '|Q|': ws_out = _cut_nonPSD_momentum(int_binning, cut_binning, emode, selected_workspace) else: ws_out = _cut_nonPSD_theta(int_binning, cut_binning, selected_workspace) xdim = ws_out.getDimension(idx) extents = " ,".join(map(str, (xdim.getMinimum(), xdim.getMaximum()))) # Hack to (deep) copy log data (ExperimentInfo) _tmpws = CreateSimulationWorkspace(Instrument='MAR', BinParams=[-1, 1, 1], UnitX='DeltaE', OutputWorkspace=name, EnableLogging=False) CopyLogs(ws_out, _tmpws, EnableLogging=False) AddSampleLog(_tmpws, LogName='Ei', LogText='3.', LogType='Number', EnableLogging=False) _tmpws = ConvertToMD(_tmpws, EnableLogging=False, StoreInADS=False, PreprocDetectorsWS='-', QDimensions='|Q|', dEAnalysisMode='Direct') # TODO: Refactor the above code after Mantid framework has been changed to avoid the hack. # The above lines create an empty MD workspace with the same logs as the calculated Workspace2D output of the # cut algorithms. These logs are then copied (using copyExperimentInfos below) to the generated MDHistoWorkspace # Ideally we should be able to use the CopyLogs algorithm between a Workspace2D and MD workspace or # copyExperimentInfos should understand a Workspace2D input, either of which will need changes to Mantid. ws_out = CreateMDHistoWorkspace(SignalInput=ws_out.extractY(), ErrorInput=ws_out.extractE(), Dimensionality=1, Extents=extents, NumberOfBins=xdim.getNBins(), Names=name, Units=unit, StoreInADS=False, EnableLogging=False) ws_out.copyExperimentInfos(_tmpws) DeleteWorkspace(_tmpws, EnableLogging=False) return ws_out
def create_histo_ws_positive(): histo_ws_positive = CreateMDHistoWorkspace(Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(1, 101), ErrorInput=range(100), NumberOfBins='5,5,4', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_2d_pos') return histo_ws_positive
def test_save_slice_to_ascii(self, output_method): raw_ws = CreateMDHistoWorkspace(SignalInput=[1, 2, 3, 4], ErrorInput=[3, 4, 5, 6], Dimensionality=2, Extents=[-10, 10, -10, 10], NumberOfBins='2,2', Names='Dim1,Dim2', Units="units1,units2", OutputWorkspace='workspace') ws = HistogramWorkspace(raw_ws, 'workspace') _save_slice_to_ascii(ws, "path1") output_method.assert_called_once() self.assertEqual(output_method.call_args[0][0], 'path1') np.testing.assert_array_equal(output_method.call_args[0][1], [[-10, -10, 1, 3], [-10, 10, 3, 5], [10, -10, 2, 4], [10, 10, 4, 6]])
def setUpClass(cls): signal = list(range(0, 100)) error = np.zeros(100) + 2 cls.workspace = HistogramWorkspace( CreateMDHistoWorkspace( Dimensionality=2, Extents='0,100,0,100', SignalInput=signal, ErrorInput=error, NumberOfBins='10,10', Names='Dim1,Dim2', Units='U,U', OutputWorkspace='testHistoWorkspace', ), 'testHistoWorkspace')
def test_when_MDWorkspace_is_in_ADS(self): ws_saver = workspacesaver.WorkspaceSaver(self.working_directory) ws1 = CreateMDHistoWorkspace(SignalInput='1,2,3,4,5,6,7,8,9', ErrorInput='1,1,1,1,1,1,1,1,1', Dimensionality='2', Extents='-1,1,-1,1', NumberOfBins='3,3', Names='A,B', Units='U,T') ws1_name = "ws1" ADS.addOrReplace(ws1_name, ws1) ws_saver.save_workspaces([ws1_name]) list_of_files = listdir(self.working_directory) self.assertEqual(len(list_of_files), 1) self.assertTrue(ws1_name + ".nxs" in list_of_files) self._load_MDWorkspace_and_test_it(ws1_name)
def setUp(self): if self._test_ws is None: self.__class__._test_ws = WorkspaceFactory.Instance().create( "Workspace2D", NVectors=2, YLength=5, XLength=5) if self._test_md_ws is None: self._test_md_ws = CreateMDHistoWorkspace( SignalInput='1,2,3,4,2,1', ErrorInput='1,1,1,1,1,1', Dimensionality=3, Extents='-1,1,-1,1,0.5,6.5', NumberOfBins='1,1,6', Names='x,y,|Q|', Units='mm,km,AA^-1', OutputWorkspace='test_plot_md_from_names_ws')
def setUp(self): self.ws_widget = WorkspaceWidget(QMainWindow()) mat_ws = CreateSampleWorkspace() table_ws = CreateEmptyTableWorkspace() group_ws = GroupWorkspaces([mat_ws, table_ws]) single_val_ws = CreateSingleValuedWorkspace(5, 6) self.w_spaces = [mat_ws, table_ws, group_ws, single_val_ws] self.ws_names = ['MatWS', 'TableWS', 'GroupWS', 'SingleValWS'] # create md workspace md_ws = CreateMDHistoWorkspace(SignalInput='1,2,3,4,2,1', ErrorInput='1,1,1,1,1,1', Dimensionality=3, Extents='-1,1,-1,1,0.5,6.5', NumberOfBins='1,1,6', Names='x,y,|Q|', Units='mm,km,AA^-1', OutputWorkspace='MDHistoWS1D') # self.w_spaces = [mat_ws, table_ws, group_ws, single_val_ws, md_ws] # self.ws_names = ['MatWS', 'TableWS', 'GroupWS', 'SingleValWS', 'MDHistoWS1D'] for ws_name, ws in zip(self.ws_names, self.w_spaces): self.ws_widget._ads.add(ws_name, ws) self.ws_names.append(md_ws.name()) self.w_spaces.append(md_ws)
def setUpClass(cls): cls.ws_widget = WorkspaceWidget(QMainWindow()) mat_ws = CreateSampleWorkspace() table_ws = CreateEmptyTableWorkspace() group_ws = GroupWorkspaces([mat_ws, table_ws]) single_val_ws = CreateSingleValuedWorkspace(5, 6) # Create ragged workspace ws2d_ragged = CreateWorkspace(DataX=[10, 20, 30], DataY=[1, 2, 3], NSpec=1, OutputWorkspace='Ragged') temp = CreateWorkspace(DataX=[15, 25, 35, 45], DataY=[1, 2, 3, 4], NSpec=1) ConjoinWorkspaces(ws2d_ragged, temp, CheckOverlapping=False) ws2d_ragged = AnalysisDataService.retrieve('Ragged') cls.w_spaces = [mat_ws, table_ws, group_ws, single_val_ws] cls.ws_names = ['MatWS', 'TableWS', 'GroupWS', 'SingleValWS'] # create md workspace md_ws = CreateMDHistoWorkspace(SignalInput='1,2,3,4,2,1', ErrorInput='1,1,1,1,1,1', Dimensionality=3, Extents='-1,1,-1,1,0.5,6.5', NumberOfBins='1,1,6', Names='x,y,|Q|', Units='mm,km,AA^-1', OutputWorkspace='MDHistoWS1D') # self.w_spaces = [mat_ws, table_ws, group_ws, single_val_ws, md_ws] # self.ws_names = ['MatWS', 'TableWS', 'GroupWS', 'SingleValWS', 'MDHistoWS1D'] for ws_name, ws in zip(cls.ws_names, cls.w_spaces): cls.ws_widget._ads.add(ws_name, ws) cls.ws_names.append(md_ws.name()) cls.w_spaces.append(md_ws) cls.ws_names.append(ws2d_ragged.name()) cls.w_spaces.append(ws2d_ragged)
def testInputFail(self): signal = range(0, 1000) error = range(0, 1000) samplews = CreateMDHistoWorkspace(Dimensionality=3, SignalInput=signal, ErrorInput=error, Extents='-3,3,-3,3,-3,3', NumberOfBins='10,10,10', Names='x,y,z', Units='MomentumTransfer,EnergyTransfer,EnergyTransfer') # A MDHisto WS with no experiment info should fail with self.assertRaises(RuntimeError): HB3AAdjustSampleNorm(InputWorkspaces=samplews, DetectorHeightOffset=0.0, DetectorDistanceOffset=0.0, OutputWorkspace="__tmpout", Wavelength=2.0) DeleteWorkspace(samplews)
def test_deleted_on_close(self): ws = CreateMDHistoWorkspace(Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(100), ErrorInput=range(100), NumberOfBins='5,5,4', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_2d') pres = SliceViewer(ws) self.assert_widget_created() pres.view.close() QApplication.processEvents() self.assert_no_toplevel_widgets()
def _compute_cut_nonPSD(selected_workspace, cut_axis, integration_axis, emode): cut_binning = " ,".join( map(str, (cut_axis.start, cut_axis.step, cut_axis.end))) int_binning = " ,".join( map(str, (integration_axis.start, integration_axis.end - integration_axis.start, integration_axis.end))) idx = 0 unit = 'DeltaE' name = 'EnergyTransfer' if cut_axis.units == '|Q|': ws_out = _cut_nonPSD_momentum(cut_binning, int_binning, emode, selected_workspace) idx = 1 unit = 'MomentumTransfer' name = '|Q|' elif cut_axis.units == 'Degrees': ws_out = _cut_nonPSD_theta(cut_binning, int_binning, selected_workspace) idx = 1 unit = 'Degrees' name = 'Theta' elif integration_axis.units == '|Q|': ws_out = _cut_nonPSD_momentum(int_binning, cut_binning, emode, selected_workspace) else: ws_out = _cut_nonPSD_theta(int_binning, cut_binning, selected_workspace) xdim = ws_out.getDimension(idx) extents = " ,".join(map(str, (xdim.getMinimum(), xdim.getMaximum()))) return CreateMDHistoWorkspace(SignalInput=ws_out.extractY(), ErrorInput=ws_out.extractE(), Dimensionality=1, Extents=extents, NumberOfBins=xdim.getNBins(), Names=name, Units=unit, StoreInADS=False)
def setUpClass(cls): def gaussian(x,y,z,x0,y0,z0,ox,oy,oz,A): return A*np.exp(-(x-x0)**2/(2*ox**2)-(y-y0)**2/(2*oy**2)-(z-z0)**2/(2*oz**2)) def peaks(i,j,k): return gaussian(i,j,k,16,100,50,2,2,2,20)+gaussian(i,j,k,16,150,50,1,1,1,10) S=np.fromfunction(peaks,(32,240,100)) ConvertWANDSCDtoQTest_data=CreateMDHistoWorkspace(Dimensionality=3,Extents='0.5,32.5,0.5,240.5,0.5,100.5', SignalInput=S.ravel('F'),ErrorInput=np.sqrt(S.ravel('F')), NumberOfBins='32,240,100',Names='y,x,scanIndex',Units='bin,bin,number') ConvertWANDSCDtoQTest_dummy = CreateSingleValuedWorkspace() ConvertWANDSCDtoQTest_data.addExperimentInfo(ConvertWANDSCDtoQTest_dummy) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty('s1', list(np.arange(0,50,0.5)), True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty('duration', [60.]*100, True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty('monitor_count', [120000.]*100, True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty('twotheta', list(np.linspace(np.pi*2/3,0,240).repeat(32)), True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty('azimuthal', list(np.tile(np.linspace(-0.15,0.15,32),240)), True) SetUB(ConvertWANDSCDtoQTest_data, 5,5,7,90,90,120,u=[-1,0,1],v=[1,0,1]) # Create Normalisation workspace S=np.ones((32,240,1)) ConvertWANDSCDtoQTest_norm=CreateMDHistoWorkspace(Dimensionality=3,Extents='0.5,32.5,0.5,240.5,0.5,1.5',SignalInput=S,ErrorInput=S, NumberOfBins='32,240,1',Names='y,x,scanIndex',Units='bin,bin,number') ConvertWANDSCDtoQTest_dummy2 = CreateSingleValuedWorkspace() ConvertWANDSCDtoQTest_norm.addExperimentInfo(ConvertWANDSCDtoQTest_dummy2) ConvertWANDSCDtoQTest_norm.getExperimentInfo(0).run().addProperty('monitor_count', [100000.], True)
def setUpClass(cls): """Sets up all operations and supported workspace types for testing.""" cls.operations = ['+', '-', '/', '*', 'WM'] cls.single_value_lhs = 'single_value_lhs' CreateSingleValuedWorkspace(DataValue=1, ErrorValue=0.1, OutputWorkspace=cls.single_value_lhs) cls.single_value_rhs = 'single_value_rhs' CreateSingleValuedWorkspace(DataValue=2, ErrorValue=0.2, OutputWorkspace=cls.single_value_rhs) ws1 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10) ws2 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10) ws3 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10) ws4 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10) cls.matrix_lhs = 'matrix_lhs' cls.matrix_rhs = 'matrix_rhs' CloneWorkspace(InputWorkspace=ws1, OutputWorkspace=cls.matrix_lhs) CloneWorkspace(InputWorkspace=ws2, OutputWorkspace=cls.matrix_rhs) cls.matrix_group_lhs = 'matrix_group_lhs' GroupWorkspaces(InputWorkspaces=[ws1, ws2], OutputWorkspace=cls.matrix_group_lhs) cls.matrix_group_rhs = 'matrix_group_rhs' GroupWorkspaces(InputWorkspaces=[ws3, ws4], OutputWorkspace=cls.matrix_group_rhs) cls.matrix_group_larger = 'matrix_group_large' lhs_group_clone = CloneWorkspace(InputWorkspace=cls.matrix_group_lhs) rhs_group_clone = CloneWorkspace(InputWorkspace=cls.matrix_group_rhs) GroupWorkspaces(InputWorkspaces=[lhs_group_clone, rhs_group_clone], OutputWorkspace=cls.matrix_group_larger) ws_event_1 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10, WorkspaceType='Event') ws_event_2 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10, WorkspaceType='Event') ws_event_3 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10, WorkspaceType='Event') ws_event_4 = CreateSampleWorkspace(NumEvents=2, XMax=100, BinWidth=10, WorkspaceType='Event') cls.event_lhs = 'event_lhs' cls.event_rhs = 'event_rhs' CloneWorkspace(InputWorkspace=ws_event_1, OutputWorkspace=cls.event_lhs) CloneWorkspace(InputWorkspace=ws_event_2, OutputWorkspace=cls.event_rhs) cls.event_group_lhs = 'event_group_lhs' GroupWorkspaces(InputWorkspaces=[ws_event_1, ws_event_2], OutputWorkspace=cls.event_group_lhs) cls.event_group_rhs = 'event_group_rhs' GroupWorkspaces(InputWorkspaces=[ws_event_3, ws_event_4], OutputWorkspace=cls.event_group_rhs) cls.event_group_larger = 'event_group_large' lhs_group_clone = CloneWorkspace(InputWorkspace=cls.event_group_lhs) rhs_group_clone = CloneWorkspace(InputWorkspace=cls.event_group_rhs) GroupWorkspaces(InputWorkspaces=[lhs_group_clone, rhs_group_clone], OutputWorkspace=cls.event_group_larger) ws_matrix_group_1 = CloneWorkspace(InputWorkspace=ws1) ws_event_group_1 = CloneWorkspace(InputWorkspace=ws_event_1) cls.mixed_group = "matrix_event_mixed_group" GroupWorkspaces(InputWorkspaces=[ws_matrix_group_1, ws_event_group_1], OutputWorkspace=cls.mixed_group) S1 = range(0, 10) S2 = range(5, 15) ERR = range(0, 10) # create HistoMD workspace cls.md_lhs = 'md_lhs' CreateMDHistoWorkspace(Dimensionality=2, Extents='-3,3,-10,10', SignalInput=S1, ErrorInput=ERR, NumberOfBins='2,5', Names='Dim1,Dim2', Units='MomentumTransfer,EnergyTransfer', OutputWorkspace=cls.md_lhs) cls.md_rhs = 'md_rhs' CreateMDHistoWorkspace(Dimensionality=2, Extents='-3,3,-10,10', SignalInput=S2, ErrorInput=ERR, NumberOfBins='2,5', Names='Dim1,Dim2', Units='MomentumTransfer,EnergyTransfer', OutputWorkspace=cls.md_rhs) tmp_lhs = CloneWorkspace(InputWorkspace=cls.md_lhs) tmp_rhs = CloneWorkspace(InputWorkspace=cls.md_rhs) cls.md_group_lhs = 'md_group_lhs' GroupWorkspaces(InputWorkspaces=[cls.md_lhs, tmp_lhs], OutputWorkspace=cls.md_group_lhs) cls.md_group_rhs = 'md_group_rhs' GroupWorkspaces(InputWorkspaces=[cls.md_rhs, tmp_rhs], OutputWorkspace=cls.md_group_rhs) tmp_md_group_lhs = CloneWorkspace(InputWorkspace=cls.md_group_lhs) tmp_md_group_rhs = CloneWorkspace(InputWorkspace=cls.md_group_rhs) cls.md_group_larger = 'md_group_large' GroupWorkspaces(InputWorkspaces=[tmp_md_group_lhs, tmp_md_group_rhs], OutputWorkspace=cls.md_group_larger) cls.md_mixed_group = 'md_mixed_group' ws_matrix_group_2 = CloneWorkspace(InputWorkspace=cls.matrix_group_lhs) ws_md_group = CloneWorkspace(InputWorkspace=cls.md_group_lhs) GroupWorkspaces(InputWorkspaces=[ws_matrix_group_2, ws_md_group], OutputWorkspace=cls.md_mixed_group)
# convolve signal = ws.getSignalArray().copy() G1D = Gaussian1DKernel(2).array G3D = G1D * G1D.reshape((-1, 1)) * G1D.reshape((-1, 1, 1)) convolved = convolve(signal, G3D) convolved_fft = np.fft.fftshift(np.fft.fftn(np.fft.fftshift(convolved))) convolved_out = (convolved_fft * np.conj(convolved_fft)).real # Create output workspace CreateMDHistoWorkspace(SignalInput=out, ErrorInput=out**2, Dimensionality=3, Extents=extents, NumberOfBins='{},{},{}'.format(*signal.shape), Names='x,y,z', Units='A,A,A', OutputWorkspace='output') integ = IntegrateMDHistoWorkspace(ws, P3Bin='-0.1,0.1') signal = integ.getSignalArray().copy() G1D = Gaussian1DKernel(2).array G3D = G1D * G1D.reshape((-1, 1)) * G1D.reshape((-1, 1, 1)) convolved = convolve(signal, G3D) signal[np.isnan(signal)] = 0 signal[np.isinf(signal)] = 0 axes = (0, 1)
def setUpClass(cls): def gaussian(x, y, z, x0, y0, z0, ox, oy, oz, A): return A * np.exp(-(x - x0)**2 / (2 * ox**2) - (y - y0)**2 / (2 * oy**2) - (z - z0)**2 / (2 * oz**2)) def peaks(i, j, k): return gaussian(i, j, k, 16, 100, 50, 2, 2, 2, 20) + gaussian( i, j, k, 16, 150, 50, 1, 1, 1, 10) S = np.fromfunction(peaks, (32, 240, 100)) ConvertWANDSCDtoQTest_data = CreateMDHistoWorkspace( Dimensionality=3, Extents='0.5,32.5,0.5,240.5,0.5,100.5', SignalInput=S.ravel('F'), ErrorInput=np.sqrt(S.ravel('F')), NumberOfBins='32,240,100', Names='y,x,scanIndex', Units='bin,bin,number') ConvertWANDSCDtoQTest_dummy = CreateSingleValuedWorkspace() ConvertWANDSCDtoQTest_data.addExperimentInfo( ConvertWANDSCDtoQTest_dummy) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 's1', list(np.arange(0, 50, 0.5)), True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'duration', [60.] * 100, True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'monitor_count', [120000.] * 100, True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'twotheta', list(np.linspace(np.pi * 2 / 3, 0, 240).repeat(32)), True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'azimuthal', list(np.tile(np.linspace(-0.15, 0.15, 32), 240)), True) SetUB(ConvertWANDSCDtoQTest_data, 5, 5, 7, 90, 90, 120, u=[-1, 0, 1], v=[1, 0, 1]) # Create Normalisation workspace S = np.ones((32, 240, 1)) ConvertWANDSCDtoQTest_norm = CreateMDHistoWorkspace( Dimensionality=3, Extents='0.5,32.5,0.5,240.5,0.5,1.5', SignalInput=S, ErrorInput=S, NumberOfBins='32,240,1', Names='y,x,scanIndex', Units='bin,bin,number') ConvertWANDSCDtoQTest_dummy2 = CreateSingleValuedWorkspace() ConvertWANDSCDtoQTest_norm.addExperimentInfo( ConvertWANDSCDtoQTest_dummy2) ConvertWANDSCDtoQTest_norm.getExperimentInfo(0).run().addProperty( 'monitor_count', [100000.], True)
for n, run in enumerate(runs): filename = '/HFIR/HB2C/IPTS-{}/nexus/HB2C_{}.nxs.h5'.format(ipts, run) print(filename) with h5py.File(filename, 'r') as f_in: bc = np.zeros((pixels), dtype=np.int64) for b in range(8): bc += np.bincount(f_in['/entry/bank' + str(b + 1) + '_events/event_id'].value, minlength=pixels) bc = bc.reshape((-1, 512)).T data_array[n] = bc phi_array[n] = f_in[ 'entry/DASlogs/HB2C:Mot:s1.RBV/average_value'].value[0] t1 = time.time() print(t1 - t0) print(data_array.shape) md = CreateMDHistoWorkspace(SignalInput=data_array.flatten('F'), ErrorInput=data_array.flatten('F'), Dimensionality=3, Extents='{},{},0.5,512.5,0.5,3840.5'.format( phi_array[0], phi_array[-1]), NumberOfBins='{},{},{}'.format(npoints, 512, 3840), Names='phi,x,y', Units='degrees,bin,bin', EnableLogging=False) t2 = time.time() print(t2 - t1)
def setUpClass(cls): cls.g1da = config['graph1d.autodistribution'] config['graph1d.autodistribution'] = 'On' cls.ws2d_non_distribution = CreateWorkspace( DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], DataE=[1, 2, 3, 4], NSpec=2, Distribution=False, UnitX='Wavelength', YUnitLabel='Counts per microAmp.hour', VerticalAxisUnit='DeltaE', VerticalAxisValues=[4, 6, 8], OutputWorkspace='ws2d_non_distribution') cls.ws2d_distribution = CreateWorkspace( DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5, 6], DataE=[1, 2, 3, 4, 6], NSpec=1, Distribution=True, UnitX='Wavelength', YUnitLabel='Counts per microAmp.hour', OutputWorkspace='ws2d_distribution') cls.ws2d_histo = CreateWorkspace(DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], DataE=[1, 2, 3, 4], NSpec=2, Distribution=True, UnitX='Wavelength', VerticalAxisUnit='DeltaE', VerticalAxisValues=[4, 6, 8], OutputWorkspace='ws2d_histo') cls.ws2d_point = CreateWorkspace( DataX=[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4], DataY=[2] * 12, NSpec=3, OutputWorkspace='ws2d_point') cls.ws1d_point = CreateWorkspace(DataX=[1, 2], DataY=[1, 2], NSpec=1, Distribution=False, OutputWorkspace='ws1d_point') cls.ws2d_histo_rag = CreateWorkspace( DataX=[1, 2, 3, 4, 5, 2, 4, 6, 8, 10], DataY=[2] * 8, NSpec=2, VerticalAxisUnit='DeltaE', VerticalAxisValues=[5, 7, 9], OutputWorkspace='ws2d_histo_rag') cls.ws2d_point_rag = CreateWorkspace(DataX=[1, 2, 3, 4, 2, 4, 6, 8], DataY=[2] * 8, NSpec=2, OutputWorkspace='ws2d_point_rag') cls.ws_MD_2d = CreateMDHistoWorkspace( Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(25), ErrorInput=range(25), NumberOfEvents=10 * np.ones(25), NumberOfBins='5,5,1', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_2d') cls.ws_MD_1d = CreateMDHistoWorkspace( Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(5), ErrorInput=range(5), NumberOfEvents=10 * np.ones(5), NumberOfBins='1,5,1', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_1d') cls.ws2d_point_uneven = CreateWorkspace( DataX=[10, 20, 30], DataY=[1, 2, 3], NSpec=1, OutputWorkspace='ws2d_point_uneven') cls.ws2d_high_counting_detector = CreateWorkspace( DataX=[1, 2, 3, 4] * 1000, DataY=[2] * 4 * 12 + [200] * 4 + [2] * 987 * 4, NSpec=1000, OutputWorkspace='ws2d_high_counting_detector') wp = CreateWorkspace(DataX=[15, 25, 35, 45], DataY=[1, 2, 3, 4], NSpec=1) ConjoinWorkspaces(cls.ws2d_point_uneven, wp, CheckOverlapping=False) cls.ws2d_point_uneven = mantid.mtd['ws2d_point_uneven'] cls.ws2d_histo_uneven = CreateWorkspace( DataX=[10, 20, 30, 40], DataY=[1, 2, 3], NSpec=1, OutputWorkspace='ws2d_histo_uneven') wp = CreateWorkspace(DataX=[15, 25, 35, 45, 55], DataY=[1, 2, 3, 4], NSpec=1) ConjoinWorkspaces(cls.ws2d_histo_uneven, wp, CheckOverlapping=False) cls.ws2d_histo_uneven = mantid.mtd['ws2d_histo_uneven'] newYAxis = mantid.api.NumericAxis.create(3) newYAxis.setValue(0, 10) newYAxis.setValue(1, 15) newYAxis.setValue(2, 25) cls.ws2d_histo_uneven.replaceAxis(1, newYAxis) AddTimeSeriesLog(cls.ws2d_histo, Name="my_log", Time="2010-01-01T00:00:00", Value=100) AddTimeSeriesLog(cls.ws2d_histo, Name="my_log", Time="2010-01-01T00:30:00", Value=15) AddTimeSeriesLog(cls.ws2d_histo, Name="my_log", Time="2010-01-01T00:50:00", Value=100.2)
def runTest(self): S = np.random.random(32 * 240 * 100) ConvertWANDSCDtoQTest_data = CreateMDHistoWorkspace( Dimensionality=3, Extents='0.5,32.5,0.5,240.5,0.5,100.5', SignalInput=S.ravel('F'), ErrorInput=np.sqrt(S.ravel('F')), NumberOfBins='32,240,100', Names='y,x,scanIndex', Units='bin,bin,number') ConvertWANDSCDtoQTest_dummy = CreateSingleValuedWorkspace() LoadInstrument(ConvertWANDSCDtoQTest_dummy, InstrumentName='WAND', RewriteSpectraMap=False) ConvertWANDSCDtoQTest_data.addExperimentInfo( ConvertWANDSCDtoQTest_dummy) log = FloatTimeSeriesProperty('s1') for t, v in zip(range(100), np.arange(0, 50, 0.5)): log.addValue(t, v) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run()['s1'] = log ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'duration', [60.] * 100, True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'monitor_count', [120000.] * 100, True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'twotheta', list(np.linspace(np.pi * 2 / 3, 0, 240).repeat(32)), True) ConvertWANDSCDtoQTest_data.getExperimentInfo(0).run().addProperty( 'azimuthal', list(np.tile(np.linspace(-0.15, 0.15, 32), 240)), True) peaks = CreatePeaksWorkspace(NumberOfPeaks=0, OutputType='LeanElasticPeak') SetUB(ConvertWANDSCDtoQTest_data, 5, 5, 7, 90, 90, 120, u=[-1, 0, 1], v=[1, 0, 1]) SetGoniometer(ConvertWANDSCDtoQTest_data, Axis0='s1,0,1,0,1', Average=False) CopySample(InputWorkspace=ConvertWANDSCDtoQTest_data, OutputWorkspace=peaks, CopyName=False, CopyMaterial=False, CopyEnvironment=False, CopyShape=False, CopyLattice=True) Q = ConvertWANDSCDtoQ(InputWorkspace=ConvertWANDSCDtoQTest_data, UBWorkspace=peaks, Wavelength=1.486, Frame='HKL', Uproj='1,1,0', Vproj='-1,1,0', BinningDim0='-6.04,6.04,151', BinningDim1='-6.04,6.04,151', BinningDim2='-6.04,6.04,151') data_norm = ConvertHFIRSCDtoMDE(ConvertWANDSCDtoQTest_data, Wavelength=1.486, MinValues='-6.04,-6.04,-6.04', MaxValues='6.04,6.04,6.04') HKL = ConvertQtoHKLMDHisto(data_norm, PeaksWorkspace=peaks, Uproj='1,1,0', Vproj='-1,1,0', Extents='-6.04,6.04,-6.04,6.04,-6.04,6.04', Bins='151,151,151') for i in range(HKL.getNumDims()): print(HKL.getDimension(i).getUnits(), Q.getDimension(i).getUnits()) np.testing.assert_equal( HKL.getDimension(i).getUnits(), Q.getDimension(i).getUnits()) hkl_data = mtd["HKL"].getSignalArray() Q_data = mtd["Q"].getSignalArray() print(np.isnan(Q_data).sum()) print(np.isclose(hkl_data, 0).sum()) xaxis = mtd["HKL"].getXDimension() yaxis = mtd["HKL"].getYDimension() zaxis = mtd["HKL"].getZDimension() x, y, z = np.meshgrid( np.linspace(xaxis.getMinimum(), xaxis.getMaximum(), xaxis.getNBins()), np.linspace(yaxis.getMinimum(), yaxis.getMaximum(), yaxis.getNBins()), np.linspace(zaxis.getMinimum(), zaxis.getMaximum(), zaxis.getNBins()), indexing="ij", copy=False, ) print( x[~np.isnan(Q_data)].mean(), y[~np.isnan(Q_data)].mean(), z[~np.isnan(Q_data)].mean(), ) print( x[~np.isclose(hkl_data, 0)].mean(), y[~np.isclose(hkl_data, 0)].mean(), z[~np.isclose(hkl_data, 0)].mean(), ) np.testing.assert_almost_equal(x[~np.isnan(Q_data)].mean(), x[~np.isclose(hkl_data, 0)].mean(), decimal=2) np.testing.assert_almost_equal(y[~np.isnan(Q_data)].mean(), y[~np.isclose(hkl_data, 0)].mean(), decimal=2) np.testing.assert_almost_equal(z[~np.isnan(Q_data)].mean(), z[~np.isclose(hkl_data, 0)].mean(), decimal=1)