diff --git a/scripts/Diffraction/isis_powder/polaris.py b/scripts/Diffraction/isis_powder/polaris.py index 71b9d40ab17eac5c7c00f623508af26bdf634f3c..2196abb39bae6e281bc064496e009e2c201ef73f 100644 --- a/scripts/Diffraction/isis_powder/polaris.py +++ b/scripts/Diffraction/isis_powder/polaris.py @@ -53,9 +53,12 @@ class Polaris(AbstractInst): # Generate pdf run_details = self._get_run_details(self._inst_settings.run_number) focus_file_path = self._generate_out_file_paths(run_details)["nxs_filename"] + run_details = self._get_run_details(run_number_string=self._inst_settings.run_number) pdf_output = polaris_algs.generate_ts_pdf(run_number=self._inst_settings.run_number, focus_file_path=focus_file_path, - merge_banks=self._inst_settings.merge_banks) + merge_banks=self._inst_settings.merge_banks, + q_lims=self._inst_settings.q_lims, + grouping_file_path=run_details.grouping_file_path) return pdf_output def set_sample_details(self, **kwargs): diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py index 89264ec8115398cae24930347bc77fddfb3f4dac..b1a1fa5047bde06ece31651032d9648307d73736 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py @@ -79,11 +79,41 @@ def save_unsplined_vanadium(vanadium_ws, output_path): mantid.DeleteWorkspace(converted_group) -def generate_ts_pdf(run_number, focus_file_path, merge_banks=False): +def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, instrument=None, q_lims=None, + grouping_file_path=None): focused_ws = _obtain_focused_run(run_number, focus_file_path) pdf_output = mantid.ConvertUnits(InputWorkspace=focused_ws.name(), Target="MomentumTransfer") + if merge_banks: - raise RuntimeError("Merging banks is currently not supported") + placzek_self_scattering = mantid.CalculatePlaczekSelfScattering(InputWorkspace=pdf_output) + pdf_output = mantid.Subtract(LHSWorkspace=pdf_output, RHSWorkspace=placzek_self_scattering) + + pdf_output = mantid.DiffractionFocussing(InputWorkspace=pdf_output, + GroupingFileName=grouping_file_path) + pdf_output = mantid.MatchSpectra(InputWorkspace=pdf_output, ReferenceSpectrum=1) + if type(q_lims) == str: + q_min = [] + q_max = [] + try: + with open(q_lims, 'r') as f: + line_list = [line.rstrip('\n') for line in f] + for line in line_list[:-1]: + value_list = line.split() + q_min.append(value_list[2]) + q_max.append(value_list[3]) + except IOError: + raise RuntimeError("q_lims is not valid") + elif type(q_lims) == list: + q_min = q_lims[0, :] + q_max = q_lims[1, :] + else: + raise RuntimeError("q_lims is not valid") + pdf_x_array = pdf_output.readX() + bin_width = pdf_x_array[1] - pdf_x_array[0] + pdf_output = mantid.CropWorkspaceRagged(InputWorkspace=pdf_output, XMin=q_min, XMax=q_max) + pdf_output = mantid.Rebin(InputWorkspace=pdf_output, Params=[q_min, bin_width, q_max]) + pdf_output = mantid.SumSpectra(InputWorkspace=pdf_output, WeightedSum=True) + pdf_output = mantid.PDFFourierTransform(Inputworkspace=pdf_output, InputSofQType="S(Q)", PDFType="G(r)", Filter=True) pdf_output = mantid.RebinToWorkspace(WorkspaceToRebin=pdf_output, WorkspaceToMatch=pdf_output[4], diff --git a/scripts/Diffraction/isis_powder/routines/calibrate.py b/scripts/Diffraction/isis_powder/routines/calibrate.py index 8e211edf8faf15ae673694bc78c3eee178bdb787..a5a238c9c0aa680d36ece2eb2deb85cede8e743e 100644 --- a/scripts/Diffraction/isis_powder/routines/calibrate.py +++ b/scripts/Diffraction/isis_powder/routines/calibrate.py @@ -47,28 +47,33 @@ def create_van(instrument, run_details, absorb): CalibrationFile=run_details.offset_file_path) 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) + 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) - focused_spectra = common.extract_ws_spectra(focused_vanadium) - focused_spectra = instrument._crop_van_to_expected_tof_range(focused_spectra) + if instrument._inst_settings.mode != 'PDF': + focused_vanadium = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, + GroupingFileName=run_details.grouping_file_path) - d_spacing_group, tof_group = instrument._output_focused_ws(processed_spectra=focused_spectra, - run_details=run_details) + focused_spectra = common.extract_ws_spectra(focused_vanadium) + focused_spectra = instrument._crop_van_to_expected_tof_range(focused_spectra) - _create_vanadium_splines(focused_spectra, instrument, run_details) + d_spacing_group, tof_group = instrument._output_focused_ws(processed_spectra=focused_spectra, + run_details=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()) + _create_vanadium_splines(focused_spectra, instrument, run_details) - 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) + common.keep_single_ws_unit(d_spacing_group=d_spacing_group, tof_group=tof_group, + unit_to_keep=instrument._get_unit_to_keep()) - return d_spacing_group + 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 + else: + common.remove_intermediate_workspace(corrected_van_ws) + return aligned_ws def _create_vanadium_splines(focused_spectra, instrument, run_details): diff --git a/scripts/Diffraction/isis_powder/routines/focus.py b/scripts/Diffraction/isis_powder/routines/focus.py index 8f59f2796566a0c2a7aa673b58f3ca5fa135e465..ab10416d7552cb829c021b1b550e2e71ba1fa8bf 100644 --- a/scripts/Diffraction/isis_powder/routines/focus.py +++ b/scripts/Diffraction/isis_powder/routines/focus.py @@ -65,35 +65,43 @@ def _focus_one_ws(input_workspace, run_number, instrument, perform_vanadium_norm mantid.DeleteWorkspace(solid_angle) # Focus the spectra into banks - focused_ws = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, - GroupingFileName=run_details.grouping_file_path) + if instrument._inst_settings.mode != 'PDF': + focused_ws = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, + GroupingFileName=run_details.grouping_file_path) - calibrated_spectra = _apply_vanadium_corrections(instrument=instrument, - input_workspace=focused_ws, - perform_vanadium_norm=perform_vanadium_norm, - vanadium_splines=vanadium_path) + calibrated_spectra = _apply_vanadium_corrections(instrument=instrument, + input_workspace=focused_ws, + perform_vanadium_norm=perform_vanadium_norm, + vanadium_splines=vanadium_path) - output_spectra = instrument._crop_banks_to_user_tof(calibrated_spectra) + output_spectra = instrument._crop_banks_to_user_tof(calibrated_spectra) - bin_widths = instrument._get_instrument_bin_widths() - if bin_widths: - # Reduce the bin width if required on this instrument - output_spectra = common.rebin_workspace_list(workspace_list=output_spectra, - bin_width_list=bin_widths) + bin_widths = instrument._get_instrument_bin_widths() + if bin_widths: + # Reduce the bin width if required on this instrument + output_spectra = common.rebin_workspace_list(workspace_list=output_spectra, + bin_width_list=bin_widths) - # Output - d_spacing_group, tof_group = instrument._output_focused_ws(output_spectra, run_details=run_details) + # Output + d_spacing_group, tof_group = instrument._output_focused_ws(output_spectra, run_details=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.keep_single_ws_unit(d_spacing_group=d_spacing_group, tof_group=tof_group, + unit_to_keep=instrument._get_unit_to_keep()) - # Tidy workspaces from Mantid - common.remove_intermediate_workspace(input_workspace) - common.remove_intermediate_workspace(aligned_ws) - common.remove_intermediate_workspace(focused_ws) - common.remove_intermediate_workspace(output_spectra) + # Tidy workspaces from Mantid + common.remove_intermediate_workspace(input_workspace) + common.remove_intermediate_workspace(aligned_ws) + common.remove_intermediate_workspace(focused_ws) + common.remove_intermediate_workspace(output_spectra) - return d_spacing_group + return d_spacing_group + else: + calibrated_spectra = _apply_vanadium_corrections(instrument=instrument, + input_workspace=aligned_ws, + perform_vanadium_norm=perform_vanadium_norm, + vanadium_splines=vanadium_path) + common.remove_intermediate_workspace(input_workspace) + return calibrated_spectra def _apply_vanadium_corrections(instrument, input_workspace, perform_vanadium_norm, vanadium_splines):