Skip to content
Snippets Groups Projects
Unverified Commit ac112db0 authored by Nick Draper's avatar Nick Draper Committed by GitHub
Browse files

Merge pull request #28447 from mantidproject/28415_replace_polaris_pdf_output_binning_with_deltaR

Replace polaris output rebinning with delta_r and delta_q
parents 3ff7f159 58aef6f1
No related branches found
No related tags found
No related merge requests found
...@@ -191,7 +191,7 @@ class TotalScatteringMergedTest(systemtesting.MantidSystemTest): ...@@ -191,7 +191,7 @@ class TotalScatteringMergedTest(systemtesting.MantidSystemTest):
self.assertAlmostEqual(self.pdf_output.dataY(0)[37], 0.7376667, places=3) self.assertAlmostEqual(self.pdf_output.dataY(0)[37], 0.7376667, places=3)
class TotalScatteringRebinTest(systemtesting.MantidSystemTest): class TotalScatteringPDFRebinTest(systemtesting.MantidSystemTest):
pdf_output = None pdf_output = None
...@@ -200,13 +200,31 @@ class TotalScatteringRebinTest(systemtesting.MantidSystemTest): ...@@ -200,13 +200,31 @@ class TotalScatteringRebinTest(systemtesting.MantidSystemTest):
# Load Focused ws # Load Focused ws
mantid.LoadNexus(Filename=total_scattering_input_file, OutputWorkspace='98533-Results-TOF-Grp') 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)) 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, output_binning=[0.07856, 0.07856, 10]) self.pdf_output = run_total_scattering('98533', True, q_lims=q_lims, delta_r=0.1)
def validate(self): def validate(self):
# Whilst total scattering is in development, the validation will avoid using reference files as they will have # 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 rebin test will be done by testing the histogram size in # to be updated very frequently. In the meantime, the rebin test will be done by testing the histogram size in
# a truncated WS # a truncated WS
self.assertAlmostEqual(self.pdf_output.dataX(0).size, 128, places=3) self.assertAlmostEqual(self.pdf_output.dataX(0).size, 201, places=3)
class TotalScatteringMergedRebinTest(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, delta_q=0.1)
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 rebin test will be done by testing the histogram size in
# a truncated WS
self.assertAlmostEqual(self.pdf_output.dataX(0).size, 197, places=3)
class TotalScatteringPdfTypeTest(systemtesting.MantidSystemTest): class TotalScatteringPdfTypeTest(systemtesting.MantidSystemTest):
...@@ -245,12 +263,14 @@ class TotalScatteringFilterTest(systemtesting.MantidSystemTest): ...@@ -245,12 +263,14 @@ class TotalScatteringFilterTest(systemtesting.MantidSystemTest):
self.assertAlmostEqual(self.pdf_output.dataY(0)[37], 0.6068334, places=3) self.assertAlmostEqual(self.pdf_output.dataY(0)[37], 0.6068334, places=3)
def run_total_scattering(run_number, merge_banks, q_lims=None, output_binning=None, pdf_type="G(r)", freq_params=None): def run_total_scattering(run_number, merge_banks, q_lims=None, delta_q=None, delta_r=None, pdf_type="G(r)",
freq_params=None):
pdf_inst_obj = setup_inst_object(mode="PDF") pdf_inst_obj = setup_inst_object(mode="PDF")
return pdf_inst_obj.create_total_scattering_pdf(run_number=run_number, return pdf_inst_obj.create_total_scattering_pdf(run_number=run_number,
merge_banks=merge_banks, merge_banks=merge_banks,
q_lims=q_lims, q_lims=q_lims,
output_binning=output_binning, delta_q=delta_q,
delta_r=delta_r,
pdf_type=pdf_type, pdf_type=pdf_type,
freq_params=freq_params) freq_params=freq_params)
......
...@@ -13,6 +13,8 @@ Powder Diffraction ...@@ -13,6 +13,8 @@ Powder Diffraction
------------------ ------------------
- Polaris.create_total_scattering_pdf output workspaces now have the run number in the names. - Polaris.create_total_scattering_pdf output workspaces now have the run number in the names.
- Polaris.create_total_scattering_pdf no longer takes `output_binning` as a parameter, instead binning of the output pdf can be controlled with `delta_r`
- Polaris.create_total_scattering_pdf can rebin the Q space workspace before calculating the PDF by being given an input `delta_q`
Engineering Diffraction Engineering Diffraction
----------------------- -----------------------
......
...@@ -190,7 +190,8 @@ The output PDF can be customized with the following parameters: ...@@ -190,7 +190,8 @@ The output PDF can be customized with the following parameters:
with shape (2, x) where x is the number of detectors, or a string containing the directory with shape (2, x) where x is the number of detectors, or a string containing the directory
of an appropriately formatted `.lim` file. By default or specifically called with `merge_banks=False` of an appropriately formatted `.lim` file. By default or specifically called with `merge_banks=False`
a PDF will be generated for each bank within the focused_workspace. a PDF will be generated for each bank within the focused_workspace.
- By calling with `output_binning` which will rebin the output PDF as with the rebin algorithm. - By calling with `delta_q` which will calculate the PDF after rebinning the Q workspace to have bin width `delta_r`.
- By calling with `delta_r` which will calculate the PDF with bin width of `delta_q`.
- By calling with `freq_params` a fourier filter will be performed on the focused signal removing any - By calling with `freq_params` a fourier filter will be performed on the focused signal removing any
components from atomic distances outside of the parameters. The parameters must be given as list: components from atomic distances outside of the parameters. The parameters must be given as list:
[lower], or [lower, upper]. [lower], or [lower, upper].
......
...@@ -63,7 +63,8 @@ class Polaris(AbstractInst): ...@@ -63,7 +63,8 @@ class Polaris(AbstractInst):
q_lims=self._inst_settings.q_lims, q_lims=self._inst_settings.q_lims,
cal_file_name=cal_file_name, cal_file_name=cal_file_name,
sample_details=self._sample_details, sample_details=self._sample_details,
output_binning=self._inst_settings.output_binning, delta_r=self._inst_settings.delta_r,
delta_q=self._inst_settings.delta_q,
pdf_type=self._inst_settings.pdf_type, pdf_type=self._inst_settings.pdf_type,
freq_params=self._inst_settings.freq_params) freq_params=self._inst_settings.freq_params)
return pdf_output return pdf_output
......
...@@ -80,7 +80,7 @@ def save_unsplined_vanadium(vanadium_ws, output_path): ...@@ -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, def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None, cal_file_name=None,
sample_details=None, output_binning=None, pdf_type="G(r)", freq_params=None): sample_details=None, delta_r=None, delta_q=None, pdf_type="G(r)", freq_params=None):
focused_ws = _obtain_focused_run(run_number, focus_file_path) focused_ws = _obtain_focused_run(run_number, focus_file_path)
focused_ws = mantid.ConvertUnits(InputWorkspace=focused_ws, Target="MomentumTransfer", EMode='Elastic') focused_ws = mantid.ConvertUnits(InputWorkspace=focused_ws, Target="MomentumTransfer", EMode='Elastic')
...@@ -102,27 +102,23 @@ def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None, ...@@ -102,27 +102,23 @@ def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None,
self_scattering_correction = mantid.RebinToWorkspace(WorkspaceToRebin=self_scattering_correction, self_scattering_correction = mantid.RebinToWorkspace(WorkspaceToRebin=self_scattering_correction,
WorkspaceToMatch=focused_ws) WorkspaceToMatch=focused_ws)
focused_ws = mantid.Subtract(LHSWorkspace=focused_ws, RHSWorkspace=self_scattering_correction) focused_ws = mantid.Subtract(LHSWorkspace=focused_ws, RHSWorkspace=self_scattering_correction)
if delta_q:
focused_ws = mantid.Rebin(InputWorkspace=focused_ws, Params=delta_q)
if merge_banks: if merge_banks:
q_min, q_max = _load_qlims(q_lims) q_min, q_max = _load_qlims(q_lims)
merged_ws = mantid.MatchAndMergeWorkspaces(InputWorkspaces=focused_ws, XMin=q_min, XMax=q_max, merged_ws = mantid.MatchAndMergeWorkspaces(InputWorkspaces=focused_ws, XMin=q_min, XMax=q_max,
CalculateScale=False) CalculateScale=False)
fast_fourier_filter(merged_ws, freq_params) fast_fourier_filter(merged_ws, freq_params)
pdf_output = mantid.PDFFourierTransform(Inputworkspace="merged_ws", InputSofQType="S(Q)-1", PDFType=pdf_type, pdf_output = mantid.PDFFourierTransform(Inputworkspace="merged_ws", InputSofQType="S(Q)-1", PDFType=pdf_type,
Filter=True) Filter=True, DeltaR=delta_r)
else: else:
for ws in focused_ws: for ws in focused_ws:
fast_fourier_filter(ws, freq_params) fast_fourier_filter(ws, freq_params)
pdf_output = mantid.PDFFourierTransform(Inputworkspace='focused_ws', InputSofQType="S(Q)-1", pdf_output = mantid.PDFFourierTransform(Inputworkspace='focused_ws', InputSofQType="S(Q)-1", PDFType=pdf_type,
PDFType=pdf_type, Filter=True) Filter=True, DeltaR=delta_r)
pdf_output = mantid.RebinToWorkspace(WorkspaceToRebin=pdf_output, WorkspaceToMatch=pdf_output[4], pdf_output = mantid.RebinToWorkspace(WorkspaceToRebin=pdf_output, WorkspaceToMatch=pdf_output[4],
PreserveEvents=True) PreserveEvents=True)
common.remove_intermediate_workspace('self_scattering_correction') common.remove_intermediate_workspace('self_scattering_correction')
if output_binning is not None:
try:
pdf_output = mantid.Rebin(InputWorkspace=pdf_output, Params=output_binning)
except RuntimeError:
return pdf_output
# Rename output ws # Rename output ws
if 'merged_ws' in locals(): if 'merged_ws' in locals():
mantid.RenameWorkspace(InputWorkspace=merged_ws, OutputWorkspace=run_number + '_merged_Q') mantid.RenameWorkspace(InputWorkspace=merged_ws, OutputWorkspace=run_number + '_merged_Q')
......
...@@ -14,6 +14,8 @@ attr_mapping = [ ...@@ -14,6 +14,8 @@ attr_mapping = [
ParamMapEntry(ext_name="calibration_directory", int_name="calibration_dir"), ParamMapEntry(ext_name="calibration_directory", int_name="calibration_dir"),
ParamMapEntry(ext_name="calibration_mapping_file", int_name="cal_mapping_path"), ParamMapEntry(ext_name="calibration_mapping_file", int_name="cal_mapping_path"),
ParamMapEntry(ext_name="config_file", int_name="config_file"), ParamMapEntry(ext_name="config_file", int_name="config_file"),
ParamMapEntry(ext_name="delta_r", int_name="delta_r", optional=True),
ParamMapEntry(ext_name="delta_q", int_name="delta_q", optional=True),
ParamMapEntry(ext_name="do_absorb_corrections", int_name="do_absorb_corrections"), ParamMapEntry(ext_name="do_absorb_corrections", int_name="do_absorb_corrections"),
ParamMapEntry(ext_name="do_van_normalisation", int_name="do_van_normalisation"), ParamMapEntry(ext_name="do_van_normalisation", int_name="do_van_normalisation"),
ParamMapEntry(ext_name="file_ext", int_name="file_extension", optional=True), ParamMapEntry(ext_name="file_ext", int_name="file_extension", optional=True),
...@@ -35,7 +37,6 @@ attr_mapping = [ ...@@ -35,7 +37,6 @@ attr_mapping = [
ParamMapEntry(ext_name="sample_empty_scale", int_name="sample_empty_scale"), ParamMapEntry(ext_name="sample_empty_scale", int_name="sample_empty_scale"),
ParamMapEntry(ext_name="suffix", int_name="suffix", optional=True), ParamMapEntry(ext_name="suffix", int_name="suffix", optional=True),
ParamMapEntry(ext_name="spline_coefficient", int_name="spline_coeff"), ParamMapEntry(ext_name="spline_coefficient", int_name="spline_coeff"),
ParamMapEntry(ext_name="output_binning", int_name="output_binning", optional=True),
ParamMapEntry(ext_name="output_directory", int_name="output_dir"), ParamMapEntry(ext_name="output_directory", int_name="output_dir"),
ParamMapEntry(ext_name="user_name", int_name="user_name"), ParamMapEntry(ext_name="user_name", int_name="user_name"),
ParamMapEntry(ext_name="vanadium_cropping_values", int_name="van_crop_values"), ParamMapEntry(ext_name="vanadium_cropping_values", int_name="van_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