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

Clean function for performing a fourier filter to PDF

This commit cleans and fixes many bugs in the fouriet filter function in polaris_algs as well as making the filter params passable into the create_total_scattering_pdf.
It also cleans up the polaris paramiter map so that some of the inputs are optional so the defaults can be used.

re: 27773
parent b6b693a2
No related branches found
No related tags found
No related merge requests found
......@@ -50,11 +50,7 @@ class Polaris(AbstractInst):
return vanadium_d
def create_total_scattering_pdf(self, **kwargs):
if 'q_lims' not in kwargs:
kwargs['q_lims'] = None
if 'output_binning' not in kwargs:
kwargs['output_binning'] = None
if 'pdf_type' not in kwargs or not kwargs['pdf_type'] in ['G(r)', 'g(r)', 'RDF(r)']:
if 'pdf_type' not in kwargs or kwargs['pdf_type'] not in ['G(r)', 'g(r)', 'RDF(r)']:
kwargs['pdf_type'] = 'G(r)'
logger.warning('PDF type not specified or is invalid, defaulting to G(r)')
self._inst_settings.update_attributes(kwargs=kwargs)
......@@ -69,7 +65,8 @@ class Polaris(AbstractInst):
cal_file_name=cal_file_name,
sample_details=self._sample_details,
output_binning=self._inst_settings.output_binning,
pdf_type=self._inst_settings.pdf_type)
pdf_type=self._inst_settings.pdf_type,
freq_params=self._inst_settings.freq_params)
return pdf_output
def set_sample_details(self, **kwargs):
......
......@@ -82,7 +82,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, output_binning=None, pdf_type="G(r)"):
sample_details=None, output_binning=None, pdf_type="G(r)", freq_params=None):
focused_ws = _obtain_focused_run(run_number, focus_file_path)
focused_ws = mantid.ConvertUnits(InputWorkspace=focused_ws, Target="MomentumTransfer", EMode='Elastic')
......@@ -107,12 +107,14 @@ def generate_ts_pdf(run_number, focus_file_path, merge_banks=False, q_lims=None,
if merge_banks:
q_min, q_max = _load_qlims(q_lims)
mantid.MatchAndMergeWorkspaces(InputWorkspaces=focused_ws, OutputWorkspace="merged_ws", XMin=q_min, XMax=q_max,
CalculateScale=False)
fast_fourier_filter("merged_ws", 5.0, 15.0)
merged_ws = mantid.MatchAndMergeWorkspaces(InputWorkspaces=focused_ws, XMin=q_min, XMax=q_max,
CalculateScale=False)
fast_fourier_filter(merged_ws, freq_params)
pdf_output = mantid.PDFFourierTransform(Inputworkspace="merged_ws", InputSofQType="S(Q)-1", PDFType=pdf_type,
Filter=True)
else:
for ws in focused_ws:
fast_fourier_filter(ws, freq_params)
pdf_output = mantid.PDFFourierTransform(Inputworkspace='focused_ws', InputSofQType="S(Q)-1",
PDFType=pdf_type, Filter=True)
pdf_output = mantid.RebinToWorkspace(WorkspaceToRebin=pdf_output, WorkspaceToMatch=pdf_output[4],
......@@ -189,15 +191,16 @@ def _determine_chopper_mode(ws):
raise ValueError("Chopper frequency not in log data. Please specify a chopper mode")
def fast_fourier_filter(input_ws, lower_boundary=None, upper_boundary=None):
def fast_fourier_filter(input_ws, freq_params=None):
if not freq_params:
return
# This is a simple fourier filter using the FFTSmooth to get a WS with only the low radius components, then
# subtracting that from the merged WS
x_range = ADS.retrieve(input_ws).dataX(0)
if lower_boundary:
lower_index = round(2 * np.pi / (lower_boundary * 2 * (x_range[1] - x_range[0])))
tmp = mantid.FFTSmooth(InputWorkspace=input_ws, Filter="Zeroing", Params=str(lower_index))
mantid.Minus(LHSWorkspace=input_ws, RHSWorkspace=tmp, OutputWorkspace=input_ws)
if upper_boundary:
upper_index = round(2 * np.pi / (upper_boundary * 2 * (x_range[1] - x_range[0])))
mantid.FFTSmooth(InputWorkspace=input_ws, OutputWorkspace=input_ws, Filter="Zeroing", Params=str(upper_index))
x_range = input_ws.dataX(0)
lower_index = round(2 * np.pi / (freq_params[0] * 2 * (x_range[1] - x_range[0])))
tmp = mantid.FFTSmooth(InputWorkspace=input_ws, Filter="Zeroing", Params=str(lower_index), StoreInADS=False, IgnoreXBins=True)
mantid.Minus(LHSWorkspace=input_ws, RHSWorkspace=tmp, OutputWorkspace=input_ws)
if len(freq_params) > 1:
upper_index = round(2 * np.pi / (freq_params[1] * 2 * (x_range[1] - x_range[0])))
mantid.FFTSmooth(InputWorkspace=input_ws, OutputWorkspace=input_ws, Filter="Zeroing", Params=str(upper_index), IgnoreXBins=True)
......@@ -22,21 +22,22 @@ attr_mapping = [
ParamMapEntry(ext_name="first_cycle_run_no", int_name="run_in_range"),
ParamMapEntry(ext_name="focused_cropping_values", int_name="focused_cropping_values"),
ParamMapEntry(ext_name="focused_bin_widths", int_name="focused_bin_widths"),
ParamMapEntry(ext_name="freq_params", int_name="freq_params", optional=True),
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="merge_banks", int_name="merge_banks"),
ParamMapEntry(ext_name="merge_banks", int_name="merge_banks", optional=True),
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="q_lims", int_name="q_lims", optional=True),
ParamMapEntry(ext_name="raw_data_cropping_values", int_name="raw_data_crop_values"),
ParamMapEntry(ext_name="run_number", int_name="run_number"),
ParamMapEntry(ext_name="sample_empty", int_name="sample_empty", optional=True),
ParamMapEntry(ext_name="sample_empty_scale", int_name="sample_empty_scale"),
ParamMapEntry(ext_name="suffix", int_name="suffix", optional=True),
ParamMapEntry(ext_name="spline_coefficient", int_name="spline_coeff"),
ParamMapEntry(ext_name="output_binning", int_name="output_binning"),
ParamMapEntry(ext_name="output_binning", int_name="output_binning", optional=True),
ParamMapEntry(ext_name="output_directory", int_name="output_dir"),
ParamMapEntry(ext_name="user_name", int_name="user_name"),
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