def test_remove_intermediate_workspace(self): ws_list = [] ws_names_list = [] ws_single_name = "remove_intermediate_ws-single" ws_single = mantid.CreateSampleWorkspace( OutputWorkspace=ws_single_name, NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1) for i in range(0, 3): out_name = "remove_intermediate_ws_" + str(i) ws_names_list.append(out_name) ws_list.append( mantid.CreateSampleWorkspace(OutputWorkspace=out_name, NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1)) # Check single workspaces are removed self.assertEqual(True, mantid.mtd.doesExist(ws_single_name)) common.remove_intermediate_workspace(ws_single) self.assertEqual(False, mantid.mtd.doesExist(ws_single_name)) # Next check lists are handled for ws_name in ws_names_list: self.assertEqual(True, mantid.mtd.doesExist(ws_name)) common.remove_intermediate_workspace(ws_list) for ws_name in ws_names_list: self.assertEqual(False, mantid.mtd.doesExist(ws_name))
def test_missing_property_is_detected(self): sample_properties = { "cylinder_sample_height": 4.0, "cylinder_sample_radius": 0.25, "cylinder_position": [0., 0., 0.], "chemical_formula": "V" } ws = mantid.CreateSampleWorkspace(Function='Flat background', NumBanks=1, BankPixelWidth=1, XMax=2, BinWidth=1) # Test each key one at a time for blacklisted_key in iterkeys(sample_properties): # Force python to make a shallow copy modified_dict = sample_properties.copy() modified_dict.pop(blacklisted_key) # Check that is raises an error with assertRaisesRegex( self, KeyError, "The following key was not found in the advanced configuration" ): ws = absorb_corrections.create_vanadium_sample_details_obj( config_dict=modified_dict) # Then check the error actually has the key name in it with assertRaisesRegex(self, KeyError, blacklisted_key): ws = absorb_corrections.create_vanadium_sample_details_obj( config_dict=modified_dict)
def merge_workspaces(run, workspaces): """ where workspaces is a tuple of form: (filepath, ws name) """ d_string = "{}; Detector {}" # detectors is a dictionary of {detector_name : [names_of_workspaces]} detectors = {d_string.format(run, x): [] for x in range(1, 5)} # fill dictionary for workspace in workspaces: detector_number = get_detector_num_from_ws(workspace) detectors[d_string.format(run, detector_number)].append(workspace) # initialise a group workspace tmp = mantid.CreateSampleWorkspace() overall_ws = mantid.GroupWorkspaces(tmp, OutputWorkspace=str(run)) # merge each workspace list in detectors into a single workspace for detector, workspace_list in iteritems(detectors): if workspace_list: # sort workspace list according to type_index sorted_workspace_list = [None] * num_files_per_detector # sort workspace list according to type_index for workspace in workspace_list: data_type = workspace.rsplit("_")[1] sorted_workspace_list[spectrum_index[data_type] - 1] = workspace workspace_list = sorted_workspace_list # create merged workspace merged_ws = create_merged_workspace(workspace_list) # add merged ws to ADS mantid.mtd.add(detector, merged_ws) mantid.ConvertToHistogram(InputWorkspace=detector, OutputWorkspace=detector) overall_ws.add(detector) mantid.AnalysisDataService.remove("tmp") # return list of [run; Detector detectorNumber], in ascending order of detector number detector_list = sorted(list(detectors)) return detector_list
def test_event_workspace(self): # numpy 1.7 (on rhel7) doesn't have np.full xmins = np.full((200, ), 2600.0) xmins[11] = 3000.0 xmaxs = np.full((200, ), 6200.0) xmaxs[12] = 5000.0 deltas = np.full(200, 400.0) deltas[13] = 600.0 ws = api.CreateSampleWorkspace(OutputWorkspace='RebinRagged_events', WorkspaceType='Event') orig_y = ws.readY(0) rebinned = api.RebinRagged(ws, XMin=xmins, XMax=xmaxs, Delta=deltas) self.assertEqual(rebinned.getNumberHistograms(), 200) for i in range(rebinned.getNumberHistograms()): label = "index={}".format(i) if i == 11: self.assertEqual(rebinned.readX(i).size, 9, label) elif i == 12 or i == 13: self.assertEqual(rebinned.readX(i).size, 7, label) else: self.assertEqual( rebinned.readX(i).size, 10, ) y = rebinned.readY(i) if i == 13: np.testing.assert_almost_equal(21, y, err_msg=label) else: # parameters are set so all y-values are 0.6 np.testing.assert_almost_equal(14, y, err_msg=label)
def test_crop_in_tof_by_fraction(self): ws_list = [] x_min = 0.2 x_max = 0.8 # Crop 20% from the front and back. expected_number_of_bins = 600 * x_max - 100 * (1 + x_min) for i in range(0, 3): out_name = "crop_banks_in_tof-" + str(i) ws_list.append( mantid.CreateSampleWorkspace(OutputWorkspace=out_name, XMin=100, XMax=600, BinWidth=1)) # Crop a single workspace in TOF tof_single_ws = common.crop_in_tof(ws_to_crop=ws_list[0], x_min=x_min, x_max=x_max) self.assertEqual(tof_single_ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(tof_single_ws) # Crop a list of workspaces in TOF cropped_ws_list = common.crop_in_tof(ws_to_crop=ws_list[1:], x_min=x_min, x_max=x_max) for ws in cropped_ws_list: self.assertEqual(ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(ws)
def test_rebin_workspace_list_defaults(self): new_bin_width = 0.5 number_of_ws = 10 ws_bin_widths = [new_bin_width] * number_of_ws ws_list = [] for i in range(number_of_ws): out_name = "test_rebin_workspace_list_defaults_" + str(i) ws_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, Function='Flat background', NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1)) # What if the item passed in is not a list err_msg_not_list = "was not a list" with assertRaisesRegex(self, RuntimeError, err_msg_not_list): common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=None) with assertRaisesRegex(self, RuntimeError, err_msg_not_list): common.rebin_workspace_list(workspace_list=None, bin_width_list=[]) # What about if the lists aren't the same length with assertRaisesRegex(self, ValueError, "does not match the number of banks"): incorrect_number_bin_widths = [1] * (number_of_ws - 1) common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=incorrect_number_bin_widths) # Does it return all the workspaces as a list - another unit test checks the implementation output = common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths) self.assertEqual(len(output), number_of_ws) for ws in output: mantid.DeleteWorkspace(ws)
def test_rebin_workspace_list_x_start_end(self): new_start_x = 1 new_end_x = 5 new_bin_width = 0.5 number_of_ws = 10 ws_bin_widths = [new_bin_width] * number_of_ws start_x_list = [new_start_x] * number_of_ws end_x_list = [new_end_x] * number_of_ws ws_list = [] for i in range(number_of_ws): out_name = "test_rebin_workspace_list_defaults_" + str(i) ws_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, Function='Flat background', NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1)) # Are the lengths checked incorrect_length = [1] * (number_of_ws - 1) with assertRaisesRegex(self, ValueError, "The number of starting bin values"): common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths, start_x_list=incorrect_length, end_x_list=end_x_list) with assertRaisesRegex(self, ValueError, "The number of ending bin values"): common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths, start_x_list=start_x_list, end_x_list=incorrect_length) output_list = common.rebin_workspace_list(workspace_list=ws_list, bin_width_list=ws_bin_widths, start_x_list=start_x_list, end_x_list=end_x_list) self.assertEqual(len(output_list), number_of_ws) for ws in output_list: self.assertEqual(ws.readX(0)[0], new_start_x) self.assertEqual(ws.readX(0)[-1], new_end_x) mantid.DeleteWorkspace(ws)
def test_crop_banks_using_a_single_fractional_cropping_value(self): bank_list = [] cropping_value = (0.05, 0.95) # Crop to 0-1000 microseconds for unit tests x_min = 500 x_max = 1000 expected_number_of_bins = x_max * cropping_value[-1] - x_min * (1+cropping_value[0]) for i in range(0, 3): out_name = "crop_banks_in_tof-" + str(i) bank_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, XMin=x_min, XMax=x_max, BinWidth=1)) # Check a list of WS and non list or tuple with assertRaisesRegex(self, ValueError, "The cropping values were not in a list or tuple type"): common.crop_banks_using_crop_list(bank_list=bank_list, crop_values_list=1000) # Check a cropping value and a single workspace is detected with assertRaisesRegex(self, RuntimeError, "Attempting to use list based cropping"): common.crop_banks_using_crop_list(bank_list=bank_list[0], crop_values_list=cropping_value) # Check we can crop a single workspace from the list cropped_single_ws_list = common.crop_banks_using_crop_list(bank_list=[bank_list[0]], crop_values_list=cropping_value) self.assertEqual(cropped_single_ws_list[0].blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(Workspace=cropped_single_ws_list[0]) # Check we can crop a whole list cropped_ws_list = common.crop_banks_using_crop_list(bank_list=bank_list[1:], crop_values_list=cropping_value) for ws in cropped_ws_list[1:]: self.assertEqual(ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(Workspace=ws)
def test_crop_in_tof_by_fraction_fails_when_max_less_than_min(self): ws_list = [] x_min = 0.8 x_max = 0.799999 # Crop 20% from the front and back. for i in range(0, 3): out_name = "crop_banks_in_tof-" + str(i) ws_list.append( mantid.CreateSampleWorkspace(OutputWorkspace=out_name, XMin=100, XMax=600, BinWidth=1)) # Crop a single workspace in TOF self.assertRaises(ValueError, common.crop_in_tof, ws_to_crop=ws_list[0], x_min=x_min, x_max=x_max) # Crop a list of workspaces in TOF self.assertRaises(ValueError, common.crop_in_tof, ws_to_crop=ws_list[1:], x_min=x_min, x_max=x_max)
def test_rebin_bin_boundary_specified(self): ws = mantid.CreateSampleWorkspace( OutputWorkspace='test_rebin_bin_boundary_specified', Function='Flat background', NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1) # Originally we had 10 bins from 0, 10. Resize from 0, 0.5, 5 so we should have the same number of output # bins with different boundaries new_bin_width = 0.5 original_number_bins = ws.blocksize() expected_start_x = 1 expected_end_x = 6 ws = common.rebin_workspace(workspace=ws, new_bin_width=new_bin_width, start_x=expected_start_x, end_x=expected_end_x) # Check number of bins is the same as we halved the bin width and interval so we should have n bins self.assertEqual(ws.blocksize(), original_number_bins) # Check bin boundaries were changed self.assertEqual(ws.readX(0)[0], expected_start_x) self.assertEqual(ws.readX(0)[-1], expected_end_x) mantid.DeleteWorkspace(ws)
def test_valid_save(self): path_to_ipf = self._find_file_or_die(self.IPF_FILE) temp_file_path = tempfile.mkdtemp() self._folders_to_remove.add(temp_file_path) wsgroup = [] for i in range(2): wsgroup.append( mantid.CreateSampleWorkspace(OutputWorkspace=str(i), NumBanks=1, BankPixelWidth=1, XMin=-0.5, XMax=0.5, BinWidth=0.01, XUnit='DSpacing', StoreInADS=True)) gem_output_test_ws_group = mantid.GroupWorkspaces(wsgroup) gem_output.save_gda(d_spacing_group=gem_output_test_ws_group, gsas_calib_filename=path_to_ipf, grouping_scheme=self.GROUPING_SCHEME, output_path=temp_file_path + '\\test.gda', raise_warning=False) self._find_file_or_die(temp_file_path + '\\test.gda') with open(temp_file_path + '\\test.gda') as read_file: first_line = read_file.readline() self.assertEquals(first_line, self.CHECK_AGAINST)
def test_crop_in_tof(self): ws_list = [] x_min = 100 x_max = 500 # Crop to 0-500 microseconds for unit tests expected_number_of_bins = x_max - x_min for i in range(0, 3): out_name = "crop_banks_in_tof-" + str(i) ws_list.append( mantid.CreateSampleWorkspace(OutputWorkspace=out_name, XMin=0, XMax=600, BinWidth=1)) # Crop a single workspace in TOF tof_single_ws = common.crop_in_tof(ws_to_crop=ws_list[0], x_min=x_min, x_max=x_max) self.assertEqual(tof_single_ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(tof_single_ws) # Crop a list of workspaces in TOF cropped_ws_list = common.crop_in_tof(ws_to_crop=ws_list[1:], x_min=x_min, x_max=x_max) for ws in cropped_ws_list: self.assertEqual(ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(ws)
def test_crop_in_tof_coverts_units(self): # Checks that crop_in_tof converts to TOF before cropping ws_list = [] x_min = 100 x_max = 200 expected_number_of_bins = 20000 # Hard code number of expected bins for dSpacing for i in range(0, 3): out_name = "crop_banks_in_dSpacing-" + str(i) ws_list.append( mantid.CreateSampleWorkspace(OutputWorkspace=out_name, XMin=0, XMax=20000, BinWidth=1, XUnit="dSpacing")) # Crop a single workspace from d_spacing and check the number of bins tof_single_ws = common.crop_in_tof(ws_to_crop=ws_list[0], x_min=x_min, x_max=x_max) self.assertEqual(tof_single_ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(tof_single_ws) # Crop a list of workspaces in dSpacing cropped_ws_list = common.crop_in_tof(ws_to_crop=ws_list[1:], x_min=x_min, x_max=x_max) for ws in cropped_ws_list: self.assertEqual(ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(ws)
def in_ws(): ws = sapi.CreateSampleWorkspace(SourceDistanceFromSample=10.0, BankDistanceFromSample=1.1, BankPixelWidth=2, NumBanks=1, XMax=200, StoreInADS=False) return ws
def test_that_co_load_run_calls_right_functions(self, mock_lutils): mock_ws = mock.Mock() self.model.workspace = mock.Mock() mock_lutils.hyphenise.return_value = "2695-2696" workspace1 = ["2695; detector 1", "2695; detector 2"] workspace2 = ["2696; detector 1", "2696; detector 2"] for ws in workspace1: mantid.CreateSampleWorkspace(OutputWorkspace=ws) for ws in workspace2: mantid.CreateSampleWorkspace(OutputWorkspace=ws) mock_lutils.flatten_run_data = mock.Mock( return_value=[workspace1, workspace2]) self.model.add_co_load_to_group = mock.Mock() self.model.co_load_run(mock_ws) self.assertEqual(self.model.add_co_load_to_group.call_count, 1) self.assertEqual(mock_lutils.hyphenise.call_count, 1) self.assertTrue("2695-2696" in self.model.loaded_runs.keys())
def test_flatten_run_data(self): test_workspaces = [mantid.CreateSampleWorkspace(OutputWorkspace=name) for name in self.test_ws_names] workspaces = [] for i in range(0, len(test_workspaces), 2): name = str(i) mantid.GroupWorkspaces(test_workspaces[i:i + 2], OutputWorkspace=name) workspaces.append(name) self.assertEquals(lutils.flatten_run_data(workspaces), [self.test_ws_names])
def test_group_by_detector(self): output, workspaces = [], [] detectors = range(1, 5) for detector in detectors: workspace = self.var_ws_name.format(detector, self.test_run) workspaces.append(workspace) mantid.CreateSampleWorkspace(OutputWorkspace=workspace).getName() output.append("{}; Detector {}".format(self.test_run, detector)) self.assertEquals(lutils.group_by_detector(self.test_run, workspaces), output)
def test_subtract_summed_runs_throw_on_tof_mismatch(self): # Create a sample workspace which will have mismatched TOF range sample_ws = mantid.CreateSampleWorkspace() ws_file_name = "100" # Load POL100 # This should throw as the TOF ranges do not match with assertRaisesRegex(self, ValueError, "specified for this file do not have matching binning. Do the "): common.subtract_summed_runs(ws_to_correct=sample_ws, instrument=ISISPowderMockInst(), empty_sample_ws_string=ws_file_name) mantid.DeleteWorkspace(sample_ws)
def test_extract_ws_spectra(self): number_of_expected_banks = 5 ws_to_split = mantid.CreateSampleWorkspace(XMin=0, XMax=2, BankPixelWidth=1, NumBanks=number_of_expected_banks) input_name = ws_to_split.name() extracted_banks = common.extract_ws_spectra(ws_to_split=ws_to_split) self.assertEqual(len(extracted_banks), number_of_expected_banks) for i, ws in enumerate(extracted_banks): expected_name = input_name + '-' + str(i + 1) self.assertEqual(expected_name, ws.name())
def test_sample_is_set_correctly(self): sample_details = SampleDetails(height=4.0, radius=0.25, center=[0., 0., 0.], shape="cylinder") sample_details.set_material(chemical_formula="V") ws = mantid.CreateSampleWorkspace(Function='Flat background', NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1) ws = absorb_corrections.run_cylinder_absorb_corrections(ws_to_correct=ws, multiple_scattering=False, sample_details_obj=sample_details, is_vanadium=True) self.assertAlmostEqual(ws.dataY(0)[2], 1.16864808, delta=1e-8) self.assertAlmostEqual(ws.dataY(0)[5], 1.16872761, delta=1e-8) self.assertAlmostEqual(ws.dataY(0)[9], 1.16883365, delta=1e-8)
def setUp(self): self.test_path = r"test\path\to\ral012345.rooth2020.dat" self.bad_path = r"test\path\to\ral012345.rooth2042" self.test_run = 5 self.var_ws_name = "{}_Delayed_{}" self.test_ws_name = self.var_ws_name.format(1, self.test_run) self.test_ws_names = [ self.var_ws_name.format( i, self.test_run) for i in range( 1, 9)] self.test_workspaces = [mantid.CreateSampleWorkspace( OutputWorkspace=name) for name in self.test_ws_names]
def test_EventWorkspace_with_pulse_times(): import mantid.simpleapi as sapi small_event_ws = sapi.CreateSampleWorkspace(WorkspaceType='Event', NumBanks=1, NumEvents=10) d = scn.mantid.convert_EventWorkspace_to_data_array(small_event_ws, load_pulse_times=True) assert d.data.values[0].coords['pulse_time'].dtype == sc.DType.datetime64 assert sc.identical( d.data.values[0].coords['pulse_time']['event', 0], sc.scalar(value=small_event_ws.getSpectrum(0).getPulseTimes() [0].to_datetime64()))
def test_merge_workspaces(self): expected_output, workspaces = [], [] detectors = range(1, 5) for detector in detectors: workspace = self.var_ws_name.format(detector, self.test_run) workspaces.append(workspace) mantid.CreateSampleWorkspace(OutputWorkspace=workspace) expected_output.append("{}; Detector {}".format(self.test_run, detector)) self.assertEquals(lutils.merge_workspaces(self.test_run, workspaces), sorted(expected_output)) # check call works with empty workspace list self.assertEqual(lutils.merge_workspaces(self.test_run, []), sorted(expected_output))
def test_EventWorkspace_no_y_unit(self): import mantid.simpleapi as mantid tiny_event_ws = mantid.CreateSampleWorkspace(WorkspaceType='Event', NumBanks=1, NumEvents=1) d = scn.mantid.convert_EventWorkspace_to_data_array( tiny_event_ws, load_pulse_times=False) self.assertEqual(d.data.bins.constituents['data'].unit, sc.units.counts) tiny_event_ws.setYUnit('') d = scn.mantid.convert_EventWorkspace_to_data_array( tiny_event_ws, load_pulse_times=False) self.assertEqual(d.data.bins.constituents['data'].unit, sc.units.one)
def test_crop_banks_using_crop_list(self): bank_list = [] cropping_value = (0, 1000 ) # Crop to 0-1000 microseconds for unit tests cropping_value_list = [] expected_number_of_bins = cropping_value[-1] - cropping_value[0] for i in range(0, 3): out_name = "crop_banks_in_tof-" + str(i) cropping_value_list.append(cropping_value) bank_list.append( mantid.CreateSampleWorkspace(OutputWorkspace=out_name, XMin=0, XMax=1100, BinWidth=1)) # Check a list of WS and single cropping value is detected with self.assertRaisesRegex( ValueError, "The cropping values were not in a list or tuple type"): common.crop_banks_using_crop_list(bank_list=bank_list, crop_values_list=1000) # Check a list of cropping values and a single workspace is detected with self.assertRaisesRegex(RuntimeError, "Attempting to use list based cropping"): common.crop_banks_using_crop_list( bank_list=bank_list[0], crop_values_list=cropping_value_list) # What about a mismatch between the number of cropping values and workspaces with self.assertRaisesRegex( RuntimeError, "The number of TOF cropping values does not match"): common.crop_banks_using_crop_list( bank_list=bank_list[1:], crop_values_list=cropping_value_list) # Check we can crop a single workspace from the list cropped_single_ws_list = common.crop_banks_using_crop_list( bank_list=[bank_list[0]], crop_values_list=[cropping_value]) self.assertEqual(cropped_single_ws_list[0].blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(Workspace=cropped_single_ws_list[0]) # Check we can crop a whole list cropped_ws_list = common.crop_banks_using_crop_list( bank_list=bank_list[1:], crop_values_list=cropping_value_list[1:]) for ws in cropped_ws_list[1:]: self.assertEqual(ws.blocksize(), expected_number_of_bins) mantid.DeleteWorkspace(Workspace=ws)
def geom_file(): import mantid.simpleapi as sapi # 100 output positions (10 by 10) ws = sapi.CreateSampleWorkspace(NumBanks=1, BankPixelWidth=10, PixelSpacing=0.01, StoreInADS=False) file_name = "example_geometry.nxs" geom_path = os.path.join(tempfile.gettempdir(), file_name) sapi.SaveNexusGeometry(ws, geom_path) assert os.path.isfile(geom_path) # sanity check yield geom_path try: os.remove(geom_path) except Exception: pass
def test_spline_workspaces(self): ws_list = [] for i in range(1, 4): out_name = "test_spline_vanadium-" + str(i) ws_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, NumBanks=1, BankPixelWidth=1, XMax=100, BinWidth=1)) splined_list = common.spline_workspaces(focused_vanadium_spectra=ws_list, num_splines=10) for ws in splined_list: self.assertAlmostEqual(ws.dataY(0)[25], 0.28576649, delta=1e-8) self.assertAlmostEqual(ws.dataY(0)[50], 0.37745918, delta=1e-8) self.assertAlmostEqual(ws.dataY(0)[75], 0.28133096, delta=1e-8) for input_ws, splined_ws in zip(ws_list, splined_list): mantid.DeleteWorkspace(input_ws) mantid.DeleteWorkspace(splined_ws)
def test_sample_workspace(self): # numpy 1.7 (on rhel7) doesn't have np.full xmins = np.array([2500.] * 200) xmins[11] = 3100. xmaxs = np.array([5500.] * 200) xmaxs[12] = 4700. ws = api.CreateSampleWorkspace() cropped = api.CropWorkspaceRagged(ws, XMin=xmins, XMax=xmaxs) self.assertEqual(cropped.getNumberHistograms(), 200) for i in range(cropped.getNumberHistograms()): if i == 11: self.assertEqual(cropped.readX(i).size, 12) elif i == 12: self.assertEqual(cropped.readX(i).size, 11) else: self.assertEqual(cropped.readX(i).size, 15)
def test_subtract_summed_runs_throw_on_tof_mismatch(self): # Create a sample workspace which will have mismatched TOF range sample_ws = mantid.CreateSampleWorkspace() mantid.AddSampleLog(Workspace=sample_ws, LogName='gd_prtn_chrg', LogText="10.0", LogType='Number') ws_file_name = "POL100" # Load POL100 empty_ws = mantid.Load(ws_file_name) # This should throw as the TOF ranges do not match with self.assertRaisesRegex( ValueError, "specified for this file do not have matching binning. Do the " ): common.subtract_summed_runs(ws_to_correct=sample_ws, empty_sample=empty_ws) mantid.DeleteWorkspace(sample_ws)
def test_rebin_bin_boundary_defaults(self): ws = mantid.CreateSampleWorkspace(OutputWorkspace='test_rebin_bin_boundary_default', Function='Flat background', NumBanks=1, BankPixelWidth=1, XMax=10, BinWidth=1) new_bin_width = 0.5 # Originally had bins at 1 unit each. So binning of 0.5 should give us 2n bins back original_number_bins = ws.getNumberBins() original_first_x_val = ws.readX(0)[0] original_last_x_val = ws.readX(0)[-1] expected_bins = original_number_bins * 2 ws = common.rebin_workspace(workspace=ws, new_bin_width=new_bin_width) self.assertEqual(ws.getNumberBins(), expected_bins) # Check bin boundaries were preserved self.assertEqual(ws.readX(0)[0], original_first_x_val) self.assertEqual(ws.readX(0)[-1], original_last_x_val) mantid.DeleteWorkspace(ws)