def test_loadInst(self): indirect_common.loadInst('IRIS') ws_name = '__empty_IRIS' ws = mtd[ws_name] instrument = ws.getInstrument() self.assertEqual(instrument.getName(), 'IRIS')
def test_transposeFitParametersTable(self): ws = self.make_dummy_QENS_workspace() params_table = self.make_multi_domain_parameter_table(ws) indirect_common.transposeFitParametersTable(params_table) self.assert_table_workspace_dimensions(params_table, expected_row_count=5, expected_column_count=11)
def test_convertToElasticQ_workspace_already_in_Q(self): ws = self.make_dummy_QENS_workspace() e_fixed = indirect_common.getEfixed(ws) ConvertSpectrumAxis(ws,Target='ElasticQ',EMode='Indirect',EFixed=e_fixed,OutputWorkspace=ws) indirect_common.convertToElasticQ(ws) self.assert_workspace_units_match_expected('MomentumTransfer', ws) self.assert_has_numeric_axis(ws)
def test_transposeFitParametersTable_rename_output(self): ws = self.make_dummy_QENS_workspace() params_table = self.make_multi_domain_parameter_table(ws) output_name = "new_table" indirect_common.transposeFitParametersTable(params_table, output_name) self.assert_table_workspace_dimensions(params_table, expected_row_count=26, expected_column_count=3) self.assert_table_workspace_dimensions(output_name, expected_row_count=5, expected_column_count=11)
def test_addSampleLogs(self): ws = CreateSampleWorkspace() logs = {} logs['FloatLog'] = 3.149 logs['IntLog'] = 42 logs['StringLog'] = "A String Log" logs['BooleanLog'] = True indirect_common.addSampleLogs(ws, logs) self.assert_logs_match_expected(ws.name(), logs)
def test_convertToElasticQ_output_in_different_workspace(self): ws = self.make_dummy_QENS_workspace() output_workspace = 'ws2' indirect_common.convertToElasticQ(ws, output_ws=output_workspace) #check original wasn't modified self.assert_workspace_units_match_expected('Label', ws) self.assert_has_spectrum_axis(ws) #check new workspace matches what we expect self.assert_workspace_units_match_expected('MomentumTransfer', output_workspace) self.assert_has_numeric_axis(output_workspace)
def test_convertToElasticQ_workspace_already_in_Q(self): ws = self.make_dummy_QENS_workspace() e_fixed = indirect_common.getEfixed(ws) ConvertSpectrumAxis(ws, Target='ElasticQ', EMode='Indirect', EFixed=e_fixed, OutputWorkspace=ws) indirect_common.convertToElasticQ(ws) self.assert_workspace_units_match_expected('MomentumTransfer', ws) self.assert_has_numeric_axis(ws)
def test_convertParametersToWorkspace(self): ws = self.make_dummy_QENS_workspace() #make a parameter table to search in function = "name=LinearBackground, A0=0, A1=0;" function += "name=Gaussian, Sigma=0.1, PeakCentre=0, Height=10;" table_ws = PlotPeakByLogValue(Input=ws + ",v0:10", Function=function) param_names = ['A0', 'Sigma', 'PeakCentre'] indirect_common.convertParametersToWorkspace(table_ws.name(), 'axis-1', param_names, "params_workspace") params_workspace = mtd["params_workspace"] self.assert_matrix_workspace_dimensions(params_workspace.name(), expected_num_histograms=3, expected_blocksize=5)
def test_getWSprefix_ILL(self): config["default.facility"] = "ILL" ws = self.make_dummy_QENS_workspace(instrument_name="IN16B") ws_name = indirect_common.getWSprefix(ws) self.assertEqual(ws_name, "in16b_1_", "The workspace prefix does not match the expected value")
def test_getEFixed(self): ws = CreateSampleWorkspace() ws = self.load_instrument(ws, 'IRIS') e_fixed = indirect_common.getEfixed(ws.name()) self.assertEqual(e_fixed, 1.8450, "The EFixed value does not match the expected value")
def test_getDefaultWorkingDirectory(self): path = os.path.join(os.path.expanduser('~'), "") config['defaultsave.directory'] = path workdir = indirect_common.getDefaultWorkingDirectory() self.assertEqual( path, workdir, "The working directory does not match the expected one")
def test_getEFixed(self): ws = CreateSampleWorkspace() ws = self.load_instrument(ws,'IRIS') e_fixed = indirect_common.getEfixed(ws.name()) self.assertEqual(e_fixed, 1.8450, "The EFixed value does not match the expected value")
def test_getWSprefix_ISIS(self): config["default.facility"] = "ISIS" ws = self.make_dummy_QENS_workspace() ws_name = indirect_common.getWSprefix(ws) self.assertEqual(ws_name, "irs1_graphite002_", "The workspace prefix does not match the expected value")
def test_getInstrRun_from_workspace(self): ws = self.make_dummy_QENS_workspace(add_logs=False) ws = RenameWorkspace(ws, OutputWorkspace="IRS26173") (instrument, run_number) = indirect_common.getInstrRun(ws.name()) self.assertEqual(run_number, '26173') self.assertEqual(instrument, 'irs')
def test_GetWSangles(self): ws = self.make_dummy_QENS_workspace() expected_result = [ 29.700000000000006, 32.32, 34.949999999999996, 37.58, 40.209999999999994 ] actual_result = indirect_common.GetWSangles(ws) self.assert_lists_almost_match(expected_result, actual_result)
def test_createQaxis(self): ws = self.make_dummy_QENS_workspace() expected_result = [ 0.48372274526965614, 0.5253047207470043, 0.5667692111215948, 0.6079351677527526, 0.6487809073399486 ] actual_result = indirect_common.createQaxis(ws) self.assert_lists_almost_match(expected_result, actual_result)
def test_getWSprefix_ILL(self): config['default.facility'] = 'ILL' ws = self.make_dummy_QENS_workspace(instrument_name='IN16B') ws_name = indirect_common.getWSprefix(ws) self.assertEqual(ws_name, 'in16b_1_', "The workspace prefix does not match the expected value")
def test_getWSprefix_ILL(self): config['default.facility'] = 'ILL' ws = self.make_dummy_QENS_workspace(instrument_name='IN16B') ws_name = indirect_common.getWSprefix(ws) self.assertEqual( ws_name, 'in16b_1_', "The workspace prefix does not match the expected value")
def test_getWSprefix_ISIS(self): config['default.facility'] = 'ISIS' ws = self.make_dummy_QENS_workspace() ws_name = indirect_common.getWSprefix(ws) self.assertEqual( ws_name, 'irs1_graphite002_', "The workspace prefix does not match the expected value")
def test_createQaxis(self): ws = self.make_dummy_QENS_workspace() expected_result = [ 0.48372274526965614, 0.5253047207470043, 0.5667692111215948, 0.6079351677527526, 0.6487809073399486, ] actual_result = indirect_common.createQaxis(ws) self.assert_lists_almost_match(expected_result, actual_result)
def test_convertToElasticQ_with_numeric_axis_not_in_Q(self): ws = self.make_dummy_QENS_workspace() #convert spectrum axis to units of Q e_fixed = indirect_common.getEfixed(ws) ConvertSpectrumAxis(ws,Target='ElasticQ',EMode='Indirect',EFixed=e_fixed,OutputWorkspace=ws) #set the units to be something we didn't expect unit = mtd[ws].getAxis(1).setUnit("Label") unit.setLabel('Random Units', '') self.assertRaises(RuntimeError, indirect_common.convertToElasticQ, ws)
def test_search_for_fit_params(self): ws = self.make_dummy_QENS_workspace() #make a parameter table to search in function = "name=LinearBackground, A0=0, A1=0;" function += "name=Gaussian, Sigma=0.1, PeakCentre=0, Height=10;" table_ws = PlotPeakByLogValue(Input=ws+",v", Function=function) params = indirect_common.search_for_fit_params("Sigma", table_ws.name()) self.assertEqual(len(params), 1) self.assertEqual(params[0], "f1.Sigma")
def test_search_for_fit_params(self): ws = self.make_dummy_QENS_workspace() #make a parameter table to search in function = "name=LinearBackground, A0=0, A1=0;" function += "name=Gaussian, Sigma=0.1, PeakCentre=0, Height=10;" table_ws = PlotPeakByLogValue(Input=ws + ",v", Function=function) params = indirect_common.search_for_fit_params("Sigma", table_ws.name()) self.assertEqual(len(params), 1) self.assertEqual(params[0], "f1.Sigma")
def test_GetThetaQ(self): ws = self.make_dummy_QENS_workspace() expected_theta_result = [ 29.700000000000006, 32.32, 34.949999999999996, 37.58, 40.209999999999994 ] expected_Q_result = [ 0.48372274526965625, 0.5253047207470042, 0.5667692111215948, 0.6079351677527525, 0.6487809073399485 ] actual_theta_result, actual_Q_result = indirect_common.GetThetaQ(ws) self.assert_lists_almost_match(expected_theta_result, actual_theta_result) self.assert_lists_almost_match(expected_Q_result, actual_Q_result)
def test_convertToElasticQ_with_numeric_axis_not_in_Q(self): ws = self.make_dummy_QENS_workspace() #convert spectrum axis to units of Q e_fixed = indirect_common.getEfixed(ws) ConvertSpectrumAxis(ws, Target='ElasticQ', EMode='Indirect', EFixed=e_fixed, OutputWorkspace=ws) #set the units to be something we didn't expect unit = mtd[ws].getAxis(1).setUnit("Label") unit.setLabel('Random Units', '') self.assertRaises(RuntimeError, indirect_common.convertToElasticQ, ws)
def test_convertToElasticQ(self): ws = self.make_dummy_QENS_workspace() indirect_common.convertToElasticQ(ws) self.assert_workspace_units_match_expected('MomentumTransfer', ws) self.assert_has_numeric_axis(ws)
def test_loadNexus(self): ws_name = indirect_common.loadNexus('IRS26173_ipg.nxs') self.assertEqual(ws_name, 'IRS26173_ipg') self.assertTrue(mtd.doesExist(ws_name))
def test_PadArray(self): data = [0, 1, 2, 3, 4, 5] expected_result = [0, 1, 2, 3, 4, 5, 0, 0, 0, 0] actual_result = indirect_common.PadArray(data, 10) self.assert_lists_match(expected_result, actual_result)
def test_getInstrRun_from_name(self): ws = self.make_dummy_QENS_workspace() (instrument, run_number) = indirect_common.getInstrRun(ws) self.assertEqual(run_number, '1') self.assertEqual(instrument, 'irs')
def test_ExtractFloat(self): data = "0.0 1 .2 3e-3 4.3 -5.5 6.0" expected_result = [0, 1, 0.2, 3e-3, 4.3, -5.5, 6.0] actual_result = indirect_common.ExtractFloat(data) self.assert_lists_almost_match(expected_result, actual_result)
def test_getDefaultWorkingDirectory(self): config['defaultsave.directory'] = os.path.expanduser('~') workdir = indirect_common.getDefaultWorkingDirectory() self.assertEquals(os.path.expanduser('~'), workdir, "The working directory does not match the expected one")
def test_ExtractInt(self): data = "-2 -1 0 1 2 3 4 5" expected_result = [-2, -1, 0, 1, 2, 3, 4, 5] actual_result = indirect_common.ExtractInt(data) self.assert_lists_match(expected_result, actual_result)