From c7a4b57d17954cf916fa3490b8cb2e0f0548ca37 Mon Sep 17 00:00:00 2001 From: Harriet Brown <harriet.brown@stfc.ac.uk> Date: Mon, 6 Jan 2020 13:59:20 +0000 Subject: [PATCH] Add option to set PDF type on polaris create_total_scattering_pdf This commit add the option for the user to set the PDF output type on the polaris create_total_scattering_pdf function. They can use any of the types available through PDFFourierTransform (G(r), g(r), RDF(r)), if none given it will default to G(r). Re #27607 --- .../tests/analysis/ISIS_PowderPolarisTest.py | 23 +++++++++++++++++-- docs/source/release/v4.3.0/diffraction.rst | 1 + .../techniques/ISISPowder-Polaris-v1.rst | 9 ++++---- scripts/Diffraction/isis_powder/polaris.py | 6 ++++- .../polaris_routines/polaris_algs.py | 6 ++--- .../polaris_routines/polaris_param_mapping.py | 1 + 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py b/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py index 75ca0e0c026..cd78da964cb 100644 --- a/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py +++ b/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py @@ -193,11 +193,30 @@ class TotalScatteringMergedTest(systemtesting.MantidSystemTest): self.assertAlmostEqual(self.pdf_output.dataY(0)[37], 0.7376667, places=3) -def run_total_scattering(run_number, merge_banks, q_lims=None): +class TotalScatteringPdfTypeTest(systemtesting.MantidSystemTest): + + pdf_output = None + + def runTest(self): + setup_mantid_paths() + # Load Focused ws + mantid.LoadNexus(Filename=total_scattering_input_file, OutputWorkspace='98533-Results-TOF-Grp') + q_lims = np.array([2.5, 3, 4, 6, 7, 3.5, 5, 7, 11, 40]).reshape((2, 5)) + self.pdf_output = run_total_scattering('98533', True, q_lims=q_lims, pdf_type="g(r)") + + def validate(self): + # Whilst total scattering is in development, the validation will avoid using reference files as they will have + # to be updated very frequently. In the meantime, the expected peak in the PDF at ~3.9 Angstrom will be checked. + # After rebin this is at X index 37 + self.assertAlmostEqual(self.pdf_output.dataY(0)[37], 1.0152123, places=3) + + +def run_total_scattering(run_number, merge_banks, q_lims=None, pdf_type="G(r)"): pdf_inst_obj = setup_inst_object(mode="PDF") return pdf_inst_obj.create_total_scattering_pdf(run_number=run_number, merge_banks=merge_banks, - q_lims=q_lims) + q_lims=q_lims, + pdf_type=pdf_type) def _gen_required_files(): diff --git a/docs/source/release/v4.3.0/diffraction.rst b/docs/source/release/v4.3.0/diffraction.rst index 04f25c089a7..7f6623e2a35 100644 --- a/docs/source/release/v4.3.0/diffraction.rst +++ b/docs/source/release/v4.3.0/diffraction.rst @@ -18,6 +18,7 @@ Powder Diffraction - The create_total_scattering_pdf merging banks now matches spectra to the spectrum with the largest x range. - The create_total_scattering_pdf merging banks no longer matches spectra with scale, it now only matches with offset. +- The polaris create_total_scattering_pdf function can now accept a `pdf_type` argument to set the pdf_output type. - :ref:`HRPDSlabCanAbsorption <algm-HRPDSlabCanAbsorption-v1>` now accepts any thickness parameter and not those in a specified list. Engineering Diffraction diff --git a/docs/source/techniques/ISISPowder-Polaris-v1.rst b/docs/source/techniques/ISISPowder-Polaris-v1.rst index 9db04cec5a8..5c530a6fc50 100644 --- a/docs/source/techniques/ISISPowder-Polaris-v1.rst +++ b/docs/source/techniques/ISISPowder-Polaris-v1.rst @@ -168,10 +168,11 @@ The *create_total_scattering_pdf* method allows a user to create a Pair Distribu from focused POLARIS data, with a view performing further total scattering analysis. With no merging criteria specified, *merge_banks=False* a PDF will be generated for each bank within -the focused_workspace. If run with *merge_banks=True* a PDF will be generated based on the wighted -sum of the detector banks performed using supplied Q limits *q_lims=q_limits*, Q_limits can be in the -form of a numpy array with shape (2, x) where x is the number rof detectors, or a string containing the -directory of an appropriately formatted `.lim` file. +the focused_workspace. The type of PDF output can be set with the kayword argument `pdf_type`, with the +option of `G(r)`, `g(r)`, `RDF(r)` (defaults to `G(r)`). If run with *merge_banks=True* a PDF will be +generated based on the wighted sum of the detector banks performed using supplied Q limits +*q_lims=q_limits*, Q_limits can be in the form of a numpy array with shape (2, x) where x is the number +of detectors, or a string containing the directory of an appropriately formatted `.lim` file. This function applies the placzek self scattering correction from :ref:CalculatePlaczekSelfScattering <algm-CalculatePlaczekSelfScattering> before calculating the PDF diff --git a/scripts/Diffraction/isis_powder/polaris.py b/scripts/Diffraction/isis_powder/polaris.py index 89b7c365a5a..5f1f76451d8 100644 --- a/scripts/Diffraction/isis_powder/polaris.py +++ b/scripts/Diffraction/isis_powder/polaris.py @@ -51,6 +51,9 @@ class Polaris(AbstractInst): def create_total_scattering_pdf(self, **kwargs): if 'q_lims' not in kwargs: kwargs['q_lims'] = None + if 'pdf_type' not in kwargs or not kwargs['pdf_type'] in ['G(r)', 'g(r)', 'RDF(r)']: + kwargs['pdf_type'] = 'G(r)' + print('PDF type not specified or is invalid, defaulting to G(r)') self._inst_settings.update_attributes(kwargs=kwargs) # Generate pdf run_details = self._get_run_details(self._inst_settings.run_number) @@ -61,7 +64,8 @@ class Polaris(AbstractInst): merge_banks=self._inst_settings.merge_banks, q_lims=self._inst_settings.q_lims, cal_file_name=cal_file_name, - sample_details=self._sample_details) + sample_details=self._sample_details, + pdf_type=self._inst_settings.pdf_type) 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 8cf5287de59..6990ef53e71 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py @@ -80,7 +80,7 @@ def save_unsplined_vanadium(vanadium_ws, output_path): def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None, cal_file_name=None, - sample_details=None): + sample_details=None, pdf_type="G(r)"): focused_ws = _obtain_focused_run(run_number, focus_file_path) focused_ws = mantid.ConvertUnits(InputWorkspace=focused_ws, Target="MomentumTransfer", EMode='Elastic') @@ -107,11 +107,11 @@ def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None, q_min, q_max = _load_qlims(q_lims) merged_ws = mantid.MatchAndMergeWorkspaces(InputWorkspaces=focused_ws, XMin=q_min, XMax=q_max, CalculateScale=False) - pdf_output = mantid.PDFFourierTransform(Inputworkspace=merged_ws, InputSofQType="S(Q)-1", PDFType="G(r)", + pdf_output = mantid.PDFFourierTransform(Inputworkspace=merged_ws, InputSofQType="S(Q)-1", PDFType=pdf_type, Filter=True) else: pdf_output = mantid.PDFFourierTransform(Inputworkspace='focused_ws', InputSofQType="S(Q)-1", - PDFType="G(r)", Filter=True) + PDFType=pdf_type, Filter=True) pdf_output = mantid.RebinToWorkspace(WorkspaceToRebin=pdf_output, WorkspaceToMatch=pdf_output[4], PreserveEvents=True) common.remove_intermediate_workspace('self_scattering_correction') diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py index 911791606e0..7313731c246 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_param_mapping.py @@ -28,6 +28,7 @@ attr_mapping = [ ParamMapEntry(ext_name="mode", int_name="mode", enum_class=POLARIS_CHOPPER_MODES, optional=True), ParamMapEntry(ext_name="multiple_scattering", int_name="multiple_scattering", optional=True), + ParamMapEntry(ext_name="pdf_type", int_name="pdf_type"), ParamMapEntry(ext_name="q_lims", int_name="q_lims"), ParamMapEntry(ext_name="raw_data_cropping_values", int_name="raw_data_crop_values"), ParamMapEntry(ext_name="run_number", int_name="run_number"), -- GitLab