Skip to content
Snippets Groups Projects
Unverified Commit 29a60969 authored by Martyn Gigg's avatar Martyn Gigg Committed by GitHub
Browse files

Merge pull request #21303 from mantidproject/21294_base_case_for_total_scattering

Total Scattering :: Add most basic form of total scattering workflow
parents 7f64c29e 495a9c44
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,34 @@ class FocusTest(stresstesting.MantidStressTest): ...@@ -95,6 +95,34 @@ class FocusTest(stresstesting.MantidStressTest):
mantid.mtd.clear() mantid.mtd.clear()
class TotalScatteringTest(stresstesting.MantidStressTest):
pdf_output = None
def runTest(self):
# Load Focused ws
mantid.LoadNexus(Filename="ISIS_Powder-POLARIS98533_FocusSempty.nxs", OutputWorkspace='98533-Results-TOF-Grp')
self.pdf_output = run_total_scattering('98533', False)
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 51
expected_peak_values = [0.0187231,
0.0583586,
0.2241280,
0.2752230,
1.0252800]
for index, ws in enumerate(self.pdf_output):
self.assertAlmostEqual(ws.dataY(0)[51], expected_peak_values[index], places=3)
def run_total_scattering(run_number, merge_banks):
pdf_inst_obj = setup_inst_object(mode="PDF")
return pdf_inst_obj.create_total_scattering_pdf(run_number=run_number,
merge_banks=merge_banks)
def _gen_required_files(): def _gen_required_files():
required_run_numbers = ["98531", "98532", # create_van : PDF mode required_run_numbers = ["98531", "98532", # create_van : PDF mode
"98533"] # File to focus (Si) "98533"] # File to focus (Si)
......
...@@ -53,6 +53,11 @@ Single Crystal Diffraction ...@@ -53,6 +53,11 @@ Single Crystal Diffraction
- :ref:`FindUBUsingLatticeParameters <algm-FindUBUsingLatticeParameters>` now has option to specify number of iterations to refine UB. - :ref:`FindUBUsingLatticeParameters <algm-FindUBUsingLatticeParameters>` now has option to specify number of iterations to refine UB.
Total Scattering
----------------
- A basic analysis for total scattering method ``create_total_scattering_pdf`` has been added to POLARIS. More information can be found on the POLARIS reference page.
Imaging Imaging
------- -------
......
...@@ -161,8 +161,44 @@ Example ...@@ -161,8 +161,44 @@ Example
polaris_example.set_sample(sample=sample_obj) polaris_example.set_sample(sample=sample_obj)
.. _create_total_scattering_pdf_polaris-isis-powder-ref:
create_total_scattering_pdf
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. warning:: Total scattering support is not yet fully implemented.
Any results obtaining from using the below routine in its current
state should not be considered accurate or complete.
The *create_total_scattering_pdf* method allows a user to create a Pair Distribution Function (PDF)
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.
This function requires the run_number you wish to analyse. The focused file for this run number must
either be loaded in Mantid with the naming format given by the *focus* method:
*<run number>-Results-<TOF/D>-Grp*
for example:
12345-Results-TOF-Grp
Or the focused file must be in the output directory of the POLARIS instrument.
Example
=======
.. code-block:: python
polaris_example.create_total_scattering_pdf(run_number='12345',
merge_banks=False)
.. _calibration_mapping_polaris-isis-powder-ref: .. _calibration_mapping_polaris-isis-powder-ref:
Calibration Mapping File Calibration Mapping File
------------------------- -------------------------
The calibration mapping file holds the mapping between The calibration mapping file holds the mapping between
......
...@@ -42,6 +42,16 @@ class Polaris(AbstractInst): ...@@ -42,6 +42,16 @@ class Polaris(AbstractInst):
output_path=run_details.unsplined_vanadium_file_path) output_path=run_details.unsplined_vanadium_file_path)
return vanadium_d return vanadium_d
def create_total_scattering_pdf(self, **kwargs):
self._inst_settings.update_attributes(kwargs=kwargs)
# 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"]
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)
return pdf_output
def set_sample_details(self, **kwargs): def set_sample_details(self, **kwargs):
self._switch_mode_specific_inst_settings(kwargs.get("mode")) self._switch_mode_specific_inst_settings(kwargs.get("mode"))
kwarg_name = "sample" kwarg_name = "sample"
......
...@@ -76,6 +76,44 @@ def save_unsplined_vanadium(vanadium_ws, output_path): ...@@ -76,6 +76,44 @@ def save_unsplined_vanadium(vanadium_ws, output_path):
mantid.DeleteWorkspace(converted_group) mantid.DeleteWorkspace(converted_group)
def generate_ts_pdf(run_number, focus_file_path, merge_banks=False):
focused_ws = _obtain_focused_run(run_number, focus_file_path)
pdf_output = mantid.ConvertUnits(InputWorkspace=focused_ws.getName(), Target="MomentumTransfer")
if merge_banks:
raise RuntimeError("Merging banks is currently not supported")
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],
PreserveEvents=True)
return pdf_output
def _obtain_focused_run(run_number, focus_file_path):
"""
Searches for the focused workspace to use (based on user specified run number) in the ADS and then the output
directory.
If unsuccessful, a ValueError exception is thrown.
:param run_number: The run number to search for.
:param focus_file_path: The expected file path for the focused file.
:return: The focused workspace.
"""
# Try the ADS first to avoid undesired loading
if mantid.mtd.doesExist('%s-Results-TOF-Grp' % run_number):
focused_ws = mantid.mtd['%s-Results-TOF-Grp' % run_number]
elif mantid.mtd.doesExist('%s-Results-D-Grp' % run_number):
focused_ws = mantid.mtd['%s-Results-D-Grp' % run_number]
else:
# Check output directory
print('No loaded focused files found. Searching in output directory...')
try:
focused_ws = mantid.LoadNexus(Filename=focus_file_path, OutputWorkspace='focused_ws').OutputWorkspace
except ValueError:
raise ValueError("Could not find focused file for run number:%s\n"
"Please ensure a focused file has been produced and is located in the output directory."
% run_number)
return focused_ws
def _apply_bragg_peaks_masking(workspaces_to_mask, mask_list): def _apply_bragg_peaks_masking(workspaces_to_mask, mask_list):
output_workspaces = list(workspaces_to_mask) output_workspaces = list(workspaces_to_mask)
......
...@@ -18,6 +18,7 @@ attr_mapping = \ ...@@ -18,6 +18,7 @@ attr_mapping = \
ParamMapEntry(ext_name="focused_bin_widths", int_name="focused_bin_widths"), ParamMapEntry(ext_name="focused_bin_widths", int_name="focused_bin_widths"),
ParamMapEntry(ext_name="grouping_file_name", int_name="grouping_file_name"), ParamMapEntry(ext_name="grouping_file_name", int_name="grouping_file_name"),
ParamMapEntry(ext_name="input_mode", int_name="input_mode", enum_class=INPUT_BATCHING), ParamMapEntry(ext_name="input_mode", int_name="input_mode", enum_class=INPUT_BATCHING),
ParamMapEntry(ext_name="merge_banks", int_name="merge_banks"),
ParamMapEntry(ext_name="mode", int_name="mode", enum_class=POLARIS_CHOPPER_MODES), ParamMapEntry(ext_name="mode", int_name="mode", enum_class=POLARIS_CHOPPER_MODES),
ParamMapEntry(ext_name="multiple_scattering", int_name="multiple_scattering"), ParamMapEntry(ext_name="multiple_scattering", int_name="multiple_scattering"),
ParamMapEntry(ext_name="raw_data_cropping_values", int_name="raw_data_crop_values"), ParamMapEntry(ext_name="raw_data_cropping_values", int_name="raw_data_crop_values"),
......
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