Skip to content
Snippets Groups Projects
Commit c7a4b57d authored by Harriet Brown's avatar Harriet Brown
Browse files

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
parent 9eab6479
No related merge requests found
......@@ -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():
......
......@@ -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
......
......@@ -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
......
......@@ -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):
......
......@@ -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')
......
......@@ -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"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment