def test_load_current_normalised_ws_respects_ext(self): run_number = "102" file_ext_one = ".s1" file_ext_two = ".s2" bin_index = 5 result_ext_one = 1.25270032 result_ext_two = 1.15126361 # Check that it respects the ext flag - try the first extension of this name returned_ws_one = common.load_current_normalised_ws_list( instrument=ISISPowderMockInst(file_ext=file_ext_one), run_number_string=run_number) # Have to store result and delete the ws as they share the same name so will overwrite result_ws_one = returned_ws_one[0].readY(0)[bin_index] mantid.DeleteWorkspace(returned_ws_one[0]) returned_ws_two = common.load_current_normalised_ws_list( instrument=ISISPowderMockInst(file_ext=file_ext_two), run_number_string=run_number) result_ws_two = returned_ws_two[0].readY(0)[bin_index] mantid.DeleteWorkspace(returned_ws_two[0]) # Ensure it loaded two different workspaces self.assertAlmostEqual(result_ws_one, result_ext_one) # If this next line fails it means it loaded the .s1 file INSTEAD of the .s2 file self.assertAlmostEqual(result_ws_two, result_ext_two) self.assertNotAlmostEqual(result_ext_one, result_ext_two)
def test_load_current_normalised_ws_respects_ext(self): run_number = "102" file_ext_one = ".s1" file_ext_two = ".s2" bin_index = 5 result_ext_one = 1.25270032 result_ext_two = 1.15126361 # Check that it respects the ext flag - try the first extension of this name returned_ws_one = common.load_current_normalised_ws_list(instrument=ISISPowderMockInst(file_ext=file_ext_one), run_number_string=run_number) # Have to store result and delete the ws as they share the same name so will overwrite result_ws_one = returned_ws_one[0].readY(0)[bin_index] mantid.DeleteWorkspace(returned_ws_one[0]) returned_ws_two = common.load_current_normalised_ws_list(instrument=ISISPowderMockInst(file_ext=file_ext_two), run_number_string=run_number) result_ws_two = returned_ws_two[0].readY(0)[bin_index] mantid.DeleteWorkspace(returned_ws_two[0]) # Ensure it loaded two different workspaces self.assertAlmostEqual(result_ws_one, result_ext_one) # If this next line fails it means it loaded the .s1 file INSTEAD of the .s2 file self.assertAlmostEqual(result_ws_two, result_ext_two) self.assertNotAlmostEqual(result_ext_one, result_ext_two)
def test_load_current_normalised_workspace(self): run_number_single = 100 run_number_range = "100-101" bin_index = 8 first_run_bin_value = 0.59706224 second_run_bin_value = 1.48682782 # Check it handles a single workspace correctly single_workspace = common.load_current_normalised_ws_list( run_number_string=run_number_single, instrument=ISISPowderMockInst()) # Get the only workspace in the list, ask for the 0th spectrum and the value at the 200th bin self.assertTrue(isinstance(single_workspace, list)) self.assertEqual(len(single_workspace), 1) self.assertAlmostEqual(single_workspace[0].readY(0)[bin_index], first_run_bin_value) mantid.DeleteWorkspace(single_workspace[0]) # Does it return multiple workspaces when instructed multiple_ws = common.load_current_normalised_ws_list( run_number_string=run_number_range, instrument=ISISPowderMockInst(), input_batching=common_enums.INPUT_BATCHING.Individual) self.assertTrue(isinstance(multiple_ws, list)) self.assertEqual(len(multiple_ws), 2) # Check the bins haven't been summed self.assertAlmostEqual(multiple_ws[0].readY(0)[bin_index], first_run_bin_value) self.assertAlmostEqual(multiple_ws[1].readY(0)[bin_index], second_run_bin_value) for ws in multiple_ws: mantid.DeleteWorkspace(ws) # Does it sum workspaces when instructed summed_ws = common.load_current_normalised_ws_list( run_number_string=run_number_range, instrument=ISISPowderMockInst(), input_batching=common_enums.INPUT_BATCHING.Summed) self.assertTrue(isinstance(summed_ws, list)) self.assertEqual(len(summed_ws), 1) # Check bins have been summed self.assertAlmostEqual(summed_ws[0].readY(0)[bin_index], (first_run_bin_value + second_run_bin_value)) mantid.DeleteWorkspace(summed_ws[0])
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb, sample_details): # Load and process one by one run_numbers = common.generate_run_numbers(run_number_string=run_number) run_details = instrument._get_run_details(run_number_string=run_number) vanadium_splines = None van = "van_{}".format(run_details.vanadium_run_numbers) if perform_vanadium_norm: if van not in mantid.mtd: vanadium_splines = mantid.LoadNexus( Filename=run_details.splined_vanadium_file_path, OutputWorkspace=van) else: vanadium_splines = mantid.mtd[van] output = None for run in run_numbers: ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument) output = _focus_one_ws(input_workspace=ws[0], run_number=run, instrument=instrument, absorb=absorb, perform_vanadium_norm=perform_vanadium_norm, sample_details=sample_details, vanadium_path=vanadium_splines) return output
def create_calibration(calibration_runs, instrument, offset_file_name, grouping_file_name, calibration_dir, rebin_1_params, rebin_2_params, cross_correlate_params, get_det_offset_params): """ Create a calibration file from (usually) a ceria run :param calibration_runs: Run number(s) for this run :param instrument: The GEM instrument object :param offset_file_name: Name of the file to write detector offset information to :param grouping_file_name: Name of grouping calibration file :param calibration_dir: Path to directory containing calibration information :param rebin_1_params: Parameters for the first rebin step (as a string in the usual format) :param rebin_2_params: Parameters for the second rebin step (as a string in the usual format) :param cross_correlate_params: Parameters for CrossCorrelate (as a dictionary PropertyName: PropertyValue) :param get_det_offset_params: Parameters for GetDetectorOffsets (as a dictionary PropertyName: PropertyValue) """ input_ws_list = common.load_current_normalised_ws_list( run_number_string=calibration_runs, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_ws = input_ws_list[0] focused = _calibration_processing(calibration_dir, calibration_runs, cross_correlate_params, get_det_offset_params, grouping_file_name, input_ws, instrument, offset_file_name, rebin_1_params, rebin_2_params) return focused
def _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string, absorb, sample_details): read_ws_list = common.load_current_normalised_ws_list( run_number_string=run_number_string, instrument=instrument) run_details = instrument._get_run_details( run_number_string=run_number_string) vanadium_splines = None van = "van_{}".format(run_details.vanadium_run_numbers) if perform_vanadium_norm: if van not in mantid.mtd: vanadium_splines = mantid.LoadNexus( Filename=run_details.splined_vanadium_file_path, OutputWorkspace=van) else: vanadium_splines = mantid.mtd[van] output = None for ws in read_ws_list: output = _focus_one_ws(input_workspace=ws, run_number=run_number_string, instrument=instrument, perform_vanadium_norm=perform_vanadium_norm, absorb=absorb, sample_details=sample_details, vanadium_path=vanadium_splines) if instrument.get_instrument_prefix( ) == "PEARL" and vanadium_splines is not None: mantid.DeleteWorkspace(vanadium_splines.OutputWorkspace) return output
def create_van(instrument, run_details, absorb): """ Creates a splined vanadium run for the following instrument. Requires the run_details for the vanadium workspace we will process and whether to apply absorption corrections. :param instrument: The instrument object that will be used to supply various instrument specific methods :param run_details: The run details associated with this vanadium run :param absorb: Boolean flag whether to apply absorption corrections :return: Processed workspace group in dSpacing (but not splined) """ van = run_details.vanadium_run_numbers # Always sum a range of inputs as its a vanadium run over multiple captures input_van_ws_list = common.load_current_normalised_ws_list( run_number_string=van, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_van_ws = input_van_ws_list[ 0] # As we asked for a summed ws there should only be one returned corrected_van_ws = common.subtract_summed_runs( ws_to_correct=input_van_ws, empty_sample_ws_string=run_details.empty_runs, instrument=instrument) # Crop the tail end of the data on PEARL if they are not capturing slow neutrons corrected_van_ws = instrument._crop_raw_to_expected_tof_range( ws_to_crop=corrected_van_ws) if absorb: corrected_van_ws = instrument._apply_absorb_corrections( run_details=run_details, ws_to_correct=corrected_van_ws) aligned_ws = mantid.AlignDetectors( InputWorkspace=corrected_van_ws, CalibrationFile=run_details.offset_file_path) focused_vanadium = mantid.DiffractionFocussing( InputWorkspace=aligned_ws, GroupingFileName=run_details.grouping_file_path) focused_spectra = common.extract_ws_spectra(focused_vanadium) focused_spectra = instrument._crop_van_to_expected_tof_range( focused_spectra) d_spacing_group, tof_group = instrument._output_focused_ws( processed_spectra=focused_spectra, run_details=run_details, output_mode="mods") _create_vanadium_splines(focused_spectra, instrument, run_details) common.keep_single_ws_unit(d_spacing_group=d_spacing_group, tof_group=tof_group, unit_to_keep=instrument._get_unit_to_keep()) common.remove_intermediate_workspace(corrected_van_ws) common.remove_intermediate_workspace(aligned_ws) common.remove_intermediate_workspace(focused_vanadium) common.remove_intermediate_workspace(focused_spectra) return d_spacing_group
def create_calibration(calibration_runs, instrument, offset_file_name, grouping_file_name, calibration_dir, rebin_1_params, rebin_2_params, cross_correlate_params, get_det_offset_params): """ Create a calibration file from (usually) a ceria run :param calibration_runs: Run number(s) for this run :param instrument: The PEARL instrument object :param offset_file_name: Name of the file to write detector offset information to :param grouping_file_name: Name of grouping calibration file :param calibration_dir: Path to directory containing calibration information :param rebin_1_params: Parameters for the first rebin step (as a string in the usual format) :param rebin_2_params: Parameters for the second rebin step (as a string in the usual format) :param cross_correlate_params: Parameters for CrossCorrelate (as a dictionary PropertyName: PropertyValue) :param get_det_offset_params: Parameters for GetDetectorOffsets (as a dictionary PropertyName: PropertyValue) """ input_ws_list = common.load_current_normalised_ws_list( run_number_string=calibration_runs, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_ws = input_ws_list[0] calibration_ws = mantid.Rebin(InputWorkspace=input_ws, Params=rebin_1_params) if calibration_ws.getAxis( 0).getUnit().unitID() != WORKSPACE_UNITS.d_spacing: calibration_ws = mantid.ConvertUnits(InputWorkspace=calibration_ws, Target="dSpacing") rebinned = mantid.Rebin(InputWorkspace=calibration_ws, Params=rebin_2_params) cross_correlated = mantid.CrossCorrelate(InputWorkspace=rebinned, **cross_correlate_params) offset_file = os.path.join(calibration_dir, offset_file_name) # Offsets workspace must be referenced as string so it can be deleted, as simpleapi doesn't recognise it as a ws offsets_ws_name = "offsets" mantid.GetDetectorOffsets(InputWorkspace=cross_correlated, GroupingFileName=offset_file, OutputWorkspace=offsets_ws_name, **get_det_offset_params) rebinned_tof = mantid.ConvertUnits(InputWorkspace=rebinned, Target="TOF") aligned = mantid.AlignDetectors(InputWorkspace=rebinned_tof, CalibrationFile=offset_file) grouping_file = os.path.join(calibration_dir, grouping_file_name) focused = mantid.DiffractionFocussing( InputWorkspace=aligned, GroupingFileName=grouping_file, OutputWorkspace=instrument._generate_output_file_name(calibration_runs) + "_grouped") common.remove_intermediate_workspace([ calibration_ws, rebinned, cross_correlated, rebinned_tof, aligned, offsets_ws_name ]) return focused
def _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string, absorb, sample_details): read_ws_list = common.load_current_normalised_ws_list(run_number_string=run_number_string, instrument=instrument) output = None for ws in read_ws_list: output = _focus_one_ws(input_workspace=ws, run_number=run_number_string, instrument=instrument, perform_vanadium_norm=perform_vanadium_norm, absorb=absorb, sample_details=sample_details) return output
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb, sample_details): # Load and process one by one run_numbers = common.generate_run_numbers(run_number_string=run_number) output = None for run in run_numbers: ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument) output = _focus_one_ws(input_workspace=ws[0], run_number=run, instrument=instrument, absorb=absorb, perform_vanadium_norm=perform_vanadium_norm, sample_details=sample_details) return output
def test_load_current_normalised_workspace(self): run_number_single = 100 run_number_range = "100-101" bin_index = 8 first_run_bin_value = 0.59706224 second_run_bin_value = 1.48682782 # Check it handles a single workspace correctly single_workspace = common.load_current_normalised_ws_list(run_number_string=run_number_single, instrument=ISISPowderMockInst()) # Get the only workspace in the list, ask for the 0th spectrum and the value at the 200th bin self.assertTrue(isinstance(single_workspace, list)) self.assertEqual(len(single_workspace), 1) self.assertAlmostEqual(single_workspace[0].readY(0)[bin_index], first_run_bin_value) mantid.DeleteWorkspace(single_workspace[0]) # Does it return multiple workspaces when instructed multiple_ws = common.load_current_normalised_ws_list( run_number_string=run_number_range, instrument=ISISPowderMockInst(), input_batching=common_enums.INPUT_BATCHING.Individual) self.assertTrue(isinstance(multiple_ws, list)) self.assertEqual(len(multiple_ws), 2) # Check the bins haven't been summed self.assertAlmostEqual(multiple_ws[0].readY(0)[bin_index], first_run_bin_value) self.assertAlmostEqual(multiple_ws[1].readY(0)[bin_index], second_run_bin_value) for ws in multiple_ws: mantid.DeleteWorkspace(ws) # Does it sum workspaces when instructed summed_ws = common.load_current_normalised_ws_list( run_number_string=run_number_range, instrument=ISISPowderMockInst(), input_batching=common_enums.INPUT_BATCHING.Summed) self.assertTrue(isinstance(summed_ws, list)) self.assertEqual(len(summed_ws), 1) # Check bins have been summed self.assertAlmostEqual(summed_ws[0].readY(0)[bin_index], (first_run_bin_value + second_run_bin_value)) mantid.DeleteWorkspace(summed_ws[0])
def create_van(instrument, run_details, absorb): """ Creates a splined vanadium run for the following instrument. Requires the run_details for the vanadium workspace we will process and whether to apply absorption corrections. :param instrument: The instrument object that will be used to supply various instrument specific methods :param run_details: The run details associated with this vanadium run :param absorb: Boolean flag whether to apply absorption corrections :return: Processed workspace group in dSpacing (but not splined) """ van = run_details.vanadium_run_numbers # Always sum a range of inputs as its a vanadium run over multiple captures input_van_ws_list = common.load_current_normalised_ws_list(run_number_string=van, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_van_ws = input_van_ws_list[0] # As we asked for a summed ws there should only be one returned corrected_van_ws = common.subtract_summed_runs(ws_to_correct=input_van_ws, empty_sample_ws_string=run_details.empty_runs, instrument=instrument) # Crop the tail end of the data on PEARL if they are not capturing slow neutrons corrected_van_ws = instrument._crop_raw_to_expected_tof_range(ws_to_crop=corrected_van_ws) if absorb: corrected_van_ws = instrument._apply_absorb_corrections(run_details=run_details, ws_to_correct=corrected_van_ws) else: # Assume that create_van only uses Vanadium runs mantid.SetSampleMaterial(InputWorkspace=corrected_van_ws, ChemicalFormula='V') aligned_ws = mantid.AlignDetectors(InputWorkspace=corrected_van_ws, CalibrationFile=run_details.offset_file_path) focused_vanadium = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, GroupingFileName=run_details.grouping_file_path) focused_spectra = common.extract_ws_spectra(focused_vanadium) focused_spectra = instrument._crop_van_to_expected_tof_range(focused_spectra) d_spacing_group, tof_group = instrument._output_focused_ws(processed_spectra=focused_spectra, run_details=run_details) _create_vanadium_splines(focused_spectra, instrument, run_details) common.keep_single_ws_unit(d_spacing_group=d_spacing_group, tof_group=tof_group, unit_to_keep=instrument._get_unit_to_keep()) common.remove_intermediate_workspace(corrected_van_ws) common.remove_intermediate_workspace(aligned_ws) common.remove_intermediate_workspace(focused_vanadium) common.remove_intermediate_workspace(focused_spectra) return d_spacing_group
def create_calibration(calibration_runs, instrument, offset_file_name, grouping_file_name, calibration_dir, rebin_1_params, rebin_2_params, cross_correlate_params, get_det_offset_params): """ Create a calibration file from (usually) a ceria run :param calibration_runs: Run number(s) for this run :param instrument: The PEARL instrument object :param offset_file_name: Name of the file to write detector offset information to :param grouping_file_name: Name of grouping calibration file :param calibration_dir: Path to directory containing calibration information :param rebin_1_params: Parameters for the first rebin step (as a string in the usual format) :param rebin_2_params: Parameters for the second rebin step (as a string in the usual format) :param cross_correlate_params: Parameters for CrossCorrelate (as a dictionary PropertyName: PropertyValue) :param get_det_offset_params: Parameters for GetDetectorOffsets (as a dictionary PropertyName: PropertyValue) """ input_ws_list = common.load_current_normalised_ws_list(run_number_string=calibration_runs, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_ws = input_ws_list[0] calibration_ws = mantid.Rebin(InputWorkspace=input_ws, Params=rebin_1_params) if calibration_ws.getAxis(0).getUnit().unitID() != WORKSPACE_UNITS.d_spacing: calibration_ws = mantid.ConvertUnits(InputWorkspace=calibration_ws, Target="dSpacing") rebinned = mantid.Rebin(InputWorkspace=calibration_ws, Params=rebin_2_params) cross_correlated = mantid.CrossCorrelate(InputWorkspace=rebinned, **cross_correlate_params) offset_file = os.path.join(calibration_dir, offset_file_name) # Offsets workspace must be referenced as string so it can be deleted, as simpleapi doesn't recognise it as a ws offsets_ws_name = "offsets" mantid.GetDetectorOffsets(InputWorkspace=cross_correlated, GroupingFileName=offset_file, OutputWorkspace=offsets_ws_name, **get_det_offset_params) rebinned_tof = mantid.ConvertUnits(InputWorkspace=rebinned, Target="TOF") aligned = mantid.AlignDetectors(InputWorkspace=rebinned_tof, CalibrationFile=offset_file) grouping_file = os.path.join(calibration_dir, grouping_file_name) focused = mantid.DiffractionFocussing(InputWorkspace=aligned, GroupingFileName=grouping_file, OutputWorkspace=instrument._generate_output_file_name(calibration_runs) + "_grouped") common.remove_intermediate_workspace([calibration_ws, rebinned, cross_correlated, rebinned_tof, aligned, offsets_ws_name]) return focused
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb, sample_details): # Load and process one by one run_numbers = common.generate_run_numbers(run_number_string=run_number) run_details = instrument._get_run_details(run_number_string=run_number) vanadium_splines = None van = "van_{}".format(run_details.vanadium_run_numbers) if perform_vanadium_norm: if van not in mantid.mtd: vanadium_splines = mantid.LoadNexus(Filename=run_details.splined_vanadium_file_path, OutputWorkspace=van) else: vanadium_splines = mantid.mtd[van] output = None for run in run_numbers: ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument) output = _focus_one_ws(input_workspace=ws[0], run_number=run, instrument=instrument, absorb=absorb, perform_vanadium_norm=perform_vanadium_norm, sample_details=sample_details, vanadium_path=vanadium_splines) return output
def _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string, absorb, sample_details): read_ws_list = common.load_current_normalised_ws_list(run_number_string=run_number_string, instrument=instrument) run_details = instrument._get_run_details(run_number_string=run_number_string) vanadium_splines = None van = "van_{}".format(run_details.vanadium_run_numbers) if perform_vanadium_norm: if van not in mantid.mtd: vanadium_splines = mantid.LoadNexus(Filename=run_details.splined_vanadium_file_path, OutputWorkspace=van) else: vanadium_splines = mantid.mtd[van] output = None for ws in read_ws_list: output = _focus_one_ws(input_workspace=ws, run_number=run_number_string, instrument=instrument, perform_vanadium_norm=perform_vanadium_norm, absorb=absorb, sample_details=sample_details, vanadium_path=vanadium_splines) if instrument.get_instrument_prefix() == "PEARL" and vanadium_splines is not None : mantid.DeleteWorkspace(vanadium_splines.OutputWorkspace) return output
def _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string, absorb, sample_details): read_ws_list = common.load_current_normalised_ws_list( run_number_string=run_number_string, instrument=instrument) run_details = instrument._get_run_details( run_number_string=run_number_string) vanadium_splines = None if perform_vanadium_norm: vanadium_splines = mantid.LoadNexus( Filename=run_details.splined_vanadium_file_path) output = None for ws in read_ws_list: output = _focus_one_ws(input_workspace=ws, run_number=run_number_string, instrument=instrument, perform_vanadium_norm=perform_vanadium_norm, absorb=absorb, sample_details=sample_details, vanadium_path=vanadium_splines) return output
def adjust_calibration(calibration_runs, instrument, offset_file_name, grouping_file_name, calibration_dir, rebin_1_params, rebin_2_params, cross_correlate_params, get_det_offset_params, original_cal): """ Create a calibration file from (usually) a ceria run :param calibration_runs: Run number(s) for this run :param instrument: The GEM instrument object :param offset_file_name: Name of the file to write detector offset information to :param grouping_file_name: Name of grouping calibration file :param calibration_dir: Path to directory containing calibration information :param rebin_1_params: Parameters for the first rebin step (as a string in the usual format) :param rebin_2_params: Parameters for the second rebin step (as a string in the usual format) :param cross_correlate_params: Parameters for CrossCorrelate (as a dictionary PropertyName: PropertyValue) :param get_det_offset_params: Parameters for GetDetectorOffsets (as a dictionary PropertyName: PropertyValue) :param original_cal: path to calibration file to adjust """ input_ws_list = common.load_current_normalised_ws_list( run_number_string=calibration_runs, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_ws = input_ws_list[0] mantid.ApplyDiffCal(InstrumentWorkspace=input_ws, CalibrationFile=original_cal) input_ws = mantid.ConvertUnits(InputWorkspace=input_ws, Target="dSpacing") mantid.ApplyDiffCal(InstrumentWorkspace=input_ws, ClearCalibration=True) offset_file = os.path.join(calibration_dir, offset_file_name) focused = _calibration_processing(calibration_dir, calibration_runs, cross_correlate_params, get_det_offset_params, grouping_file_name, input_ws, instrument, offset_file, rebin_1_params, rebin_2_params) _adjust_cal_file(original_cal, offset_file) return focused
def create_calibration(self, calibration_runs, offset_file_name, grouping_file_name): input_ws_list = common.load_current_normalised_ws_list( run_number_string=calibration_runs, instrument=self, input_batching=INPUT_BATCHING.Summed) input_ws = input_ws_list[0] run_details = self._get_run_details(calibration_runs) if run_details.instrument_version == "new" or run_details.instrument_version == "new2": input_ws = mantid.Rebin(InputWorkspace=input_ws, Params="100,-0.0006,19950") d_spacing_cal = mantid.ConvertUnits(InputWorkspace=input_ws, Target="dSpacing") d_spacing_cal = mantid.Rebin(InputWorkspace=d_spacing_cal, Params="1.8,0.002,2.1") if run_details.instrument_version == "new2": cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal, ReferenceSpectra=20, WorkspaceIndexMin=9, WorkspaceIndexMax=1063, XMin=1.8, XMax=2.1) elif run_details.instrument_version == "new": cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal, ReferenceSpectra=20, WorkspaceIndexMin=9, WorkspaceIndexMax=943, XMin=1.8, XMax=2.1) else: cross_cor_ws = mantid.CrossCorrelate(InputWorkspace=d_spacing_cal, ReferenceSpectra=500, WorkspaceIndexMin=1, WorkspaceIndexMax=1440, XMin=1.8, XMax=2.1) if self._old_api_uses_full_paths: # Workaround for old API setting full paths grouping_file_path = grouping_file_name offset_file_path = offset_file_name else: offset_file_path = os.path.join(self.calibration_dir, offset_file_name) grouping_file_path = os.path.join(self.calibration_dir, grouping_file_name) # Ceo Cell refined to 5.4102(3) so 220 is 1.912795 offset_output_path = mantid.GetDetectorOffsets( InputWorkspace=cross_cor_ws, Step=0.002, DReference=1.912795, XMin=-200, XMax=200, GroupingFileName=offset_file_path) del offset_output_path # This isn't used so delete it to keep linters happy aligned_ws = mantid.AlignDetectors(InputWorkspace=input_ws, CalibrationFile=offset_file_path) cal_grouped_ws = mantid.DiffractionFocussing( InputWorkspace=aligned_ws, GroupingFileName=grouping_file_path) common.remove_intermediate_workspace(d_spacing_cal) common.remove_intermediate_workspace(cross_cor_ws) common.remove_intermediate_workspace(aligned_ws) common.remove_intermediate_workspace(cal_grouped_ws)
def create_van(instrument, run_details, absorb): """ Creates a splined vanadium run for the following instrument. Requires the run_details for the vanadium workspace we will process and whether to apply absorption corrections. :param instrument: The instrument object that will be used to supply various instrument specific methods :param run_details: The run details associated with this vanadium run :param absorb: Boolean flag whether to apply absorption corrections :return: Processed workspace group in dSpacing (but not splined) """ van = run_details.vanadium_run_numbers # Always sum a range of inputs as its a vanadium run over multiple captures input_van_ws_list = common.load_current_normalised_ws_list( run_number_string=van, instrument=instrument, input_batching=INPUT_BATCHING.Summed) input_van_ws = input_van_ws_list[ 0] # As we asked for a summed ws there should only be one returned instrument.create_solid_angle_corrections(input_van_ws, run_details) if not (run_details.empty_runs is None): summed_empty = common.generate_summed_runs( empty_sample_ws_string=run_details.empty_runs, instrument=instrument) mantid.SaveNexus(Filename=run_details.summed_empty_file_path, InputWorkspace=summed_empty) corrected_van_ws = common.subtract_summed_runs( ws_to_correct=input_van_ws, empty_sample=summed_empty) # Crop the tail end of the data on PEARL if they are not capturing slow neutrons corrected_van_ws = instrument._crop_raw_to_expected_tof_range( ws_to_crop=corrected_van_ws) if absorb: corrected_van_ws = instrument._apply_absorb_corrections( run_details=run_details, ws_to_correct=corrected_van_ws) else: # Assume that create_van only uses Vanadium runs mantid.SetSampleMaterial(InputWorkspace=corrected_van_ws, ChemicalFormula='V') mantid.ApplyDiffCal(InstrumentWorkspace=corrected_van_ws, CalibrationFile=run_details.offset_file_path) aligned_ws = mantid.ConvertUnits(InputWorkspace=corrected_van_ws, Target="dSpacing") solid_angle = instrument.get_solid_angle_corrections( run_details.run_number, run_details) if solid_angle: aligned_ws = mantid.Divide(LHSWorkspace=aligned_ws, RHSWorkspace=solid_angle) mantid.DeleteWorkspace(solid_angle) focused_vanadium = mantid.DiffractionFocussing( InputWorkspace=aligned_ws, GroupingFileName=run_details.grouping_file_path) # convert back to TOF based on engineered detector positions mantid.ApplyDiffCal(InstrumentWorkspace=focused_vanadium, ClearCalibration=True) focused_spectra = common.extract_ws_spectra(focused_vanadium) focused_spectra = instrument._crop_van_to_expected_tof_range( focused_spectra) d_spacing_group, tof_group = instrument._output_focused_ws( processed_spectra=focused_spectra, run_details=run_details) _create_vanadium_splines(focused_spectra, instrument, run_details) common.keep_single_ws_unit(d_spacing_group=d_spacing_group, tof_group=tof_group, unit_to_keep=instrument._get_unit_to_keep()) common.remove_intermediate_workspace(corrected_van_ws) common.remove_intermediate_workspace(aligned_ws) common.remove_intermediate_workspace(focused_vanadium) common.remove_intermediate_workspace(focused_spectra) return d_spacing_group
def do_silicon_calibration(self, runs_to_process, cal_file_name, grouping_file_name): # TODO fix all of this as the script is too limited to be useful create_si_ws = common.load_current_normalised_ws_list( run_number_string=runs_to_process, instrument=self) cycle_details = self._get_label_information(runs_to_process) instrument_version = cycle_details["instrument_version"] if instrument_version == "new" or instrument_version == "new2": create_si_ws = mantid.Rebin(InputWorkspace=create_si_ws, Params="100,-0.0006,19950") create_si_d_spacing_ws = mantid.ConvertUnits(InputWorkspace=create_si_ws, Target="dSpacing") if instrument_version == "new2": create_si_d_spacing_rebin_ws = mantid.Rebin( InputWorkspace=create_si_d_spacing_ws, Params="1.71,0.002,2.1") create_si_cross_corr_ws = mantid.CrossCorrelate( InputWorkspace=create_si_d_spacing_rebin_ws, ReferenceSpectra=20, WorkspaceIndexMin=9, WorkspaceIndexMax=1063, XMin=1.71, XMax=2.1) elif instrument_version == "new": create_si_d_spacing_rebin_ws = mantid.Rebin( InputWorkspace=create_si_d_spacing_ws, Params="1.85,0.002,2.05") create_si_cross_corr_ws = mantid.CrossCorrelate( InputWorkspace=create_si_d_spacing_rebin_ws, ReferenceSpectra=20, WorkspaceIndexMin=9, WorkspaceIndexMax=943, XMin=1.85, XMax=2.05) elif instrument_version == "old": create_si_d_spacing_rebin_ws = mantid.Rebin( InputWorkspace=create_si_d_spacing_ws, Params="3,0.002,3.2") create_si_cross_corr_ws = mantid.CrossCorrelate( InputWorkspace=create_si_d_spacing_rebin_ws, ReferenceSpectra=500, WorkspaceIndexMin=1, WorkspaceIndexMax=1440, XMin=3, XMax=3.2) else: raise NotImplementedError( "The instrument version is not supported for creating a silicon calibration" ) common.remove_intermediate_workspace(create_si_d_spacing_ws) common.remove_intermediate_workspace(create_si_d_spacing_rebin_ws) calibration_output_path = self.calibration_dir + cal_file_name create_si_offsets_ws = mantid.GetDetectorOffsets( InputWorkspace=create_si_cross_corr_ws, Step=0.002, DReference=1.920127251, XMin=-200, XMax=200, GroupingFileName=calibration_output_path) create_si_aligned_ws = mantid.AlignDetectors( InputWorkspace=create_si_ws, CalibrationFile=calibration_output_path) grouping_output_path = self.calibration_dir + grouping_file_name create_si_grouped_ws = mantid.DiffractionFocussing( InputWorkspace=create_si_aligned_ws, GroupingFileName=grouping_output_path) del create_si_offsets_ws, create_si_grouped_ws