diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py b/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py index 700e1adf191a1f8c9614be7b4c6ceda928c10c7c..3e4bba06b542c30dd095951e8c2cd5723e549d00 100644 --- a/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py +++ b/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py @@ -3,7 +3,7 @@ from __future__ import (absolute_import, division, print_function) import os import mantid.simpleapi as mantid -from isis_powder.routines import common, RunDetails, yaml_parser +from isis_powder.routines import absorb_corrections, common, RunDetails, yaml_parser from isis_powder.gem_routines import gem_advanced_config @@ -12,24 +12,8 @@ def calculate_absorb_corrections(ws_to_correct, multiple_scattering): mantid.MaskDetectors(ws_to_correct, SpectraList=list(range(0, 101))) absorb_dict = gem_advanced_config.absorption_correction_params - - height_key = "cylinder_sample_height" - radius_key = "cylinder_sample_radius" - pos_key = "cylinder_position" - formula_key = "chemical_formula" - - e_msg = "The following key was not found in the advanced configuration for sample correction:\n" - - height = common.dictionary_key_helper(dictionary=absorb_dict, key=height_key, exception_msg=e_msg + height_key) - radius = common.dictionary_key_helper(dictionary=absorb_dict, key=radius_key, exception_msg=e_msg + radius_key) - pos = common.dictionary_key_helper(dictionary=absorb_dict, key=pos_key, exception_msg=e_msg + pos_key) - - formula = common.dictionary_key_helper(dictionary=absorb_dict, key=formula_key, exception_msg=e_msg + formula_key) - - ws_to_correct = common.calculate__cylinder_absorb_corrections( - ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, - c_height=height, c_radius=radius, c_pos=pos, chemical_formula=formula) - + ws_to_correct = absorb_corrections.run_cylinder_absorb_corrections( + ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, config_dict=absorb_dict) return ws_to_correct diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py index 3bc222428b0dc73c8fa216af803aa58bd274947b..5610edae2dd52d73c73bc677c89ed5c9a90dfff4 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py @@ -3,7 +3,7 @@ from __future__ import (absolute_import, division, print_function) import mantid.simpleapi as mantid import os -from isis_powder.routines import common, yaml_parser +from isis_powder.routines import absorb_corrections, common, yaml_parser from isis_powder.routines.RunDetails import RunDetails from isis_powder.polaris_routines import polaris_advanced_config @@ -12,24 +12,8 @@ def calculate_absorb_corrections(ws_to_correct, multiple_scattering): mantid.MaskDetectors(ws_to_correct, SpectraList=list(range(0, 55))) absorb_dict = polaris_advanced_config.absorption_correction_params - - height_key = "cylinder_sample_height" - radius_key = "cylinder_sample_radius" - pos_key = "cylinder_position" - formula_key = "chemical_formula" - - e_msg = "The following key was not found in the advanced configuration for sample correction:\n" - - height = common.dictionary_key_helper(dictionary=absorb_dict, key=height_key, exception_msg=e_msg + height_key) - radius = common.dictionary_key_helper(dictionary=absorb_dict, key=radius_key, exception_msg=e_msg + radius_key) - pos = common.dictionary_key_helper(dictionary=absorb_dict, key=pos_key, exception_msg=e_msg + pos_key) - - formula = common.dictionary_key_helper(dictionary=absorb_dict, key=formula_key, exception_msg=e_msg + formula_key) - - ws_to_correct = common.calculate__cylinder_absorb_corrections( - ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, - c_height=height, c_radius=radius, c_pos=pos, chemical_formula=formula) - + ws_to_correct = absorb_corrections.run_cylinder_absorb_corrections( + ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, config_dict=absorb_dict) return ws_to_correct diff --git a/scripts/Diffraction/isis_powder/routines/absorb_corrections.py b/scripts/Diffraction/isis_powder/routines/absorb_corrections.py new file mode 100644 index 0000000000000000000000000000000000000000..4a9933e04827a45333acec99920026d0b78fa1f5 --- /dev/null +++ b/scripts/Diffraction/isis_powder/routines/absorb_corrections.py @@ -0,0 +1,68 @@ +from __future__ import (absolute_import, division, print_function) + +import mantid.simpleapi as mantid + +from isis_powder.routines import common + + +def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, config_dict): + """ + Sets a cylindrical sample from the user specified config dictionary and performs Mayers + sample correction on the workspace. The config dictionary must be for a cylinder and contain + the keys "cylinder_sample_height", "cylinder_sample_radius", "cylinder_position" and + "chemical_formula". If any of these keys are not found an exception is raise informing + the user that the key was not in the advanced configuration file. + Additionally it checks the value of multiple_scattering to determine whether to take + into account the effects of multiple scattering. + :param ws_to_correct: The workspace to perform Mayers sample correction on + :param multiple_scattering: Boolean of whether to account for the effects of multiple scattering + :param config_dict: A dictionary containing the required keys to set a cylinder sample + :return: The corrected workspace + """ + height_key = "cylinder_sample_height" + radius_key = "cylinder_sample_radius" + pos_key = "cylinder_position" + formula_key = "chemical_formula" + + e_msg = "The following key was not found in the advanced configuration for sample correction:\n" + + height = common.dictionary_key_helper(dictionary=config_dict, key=height_key, exception_msg=e_msg + height_key) + radius = common.dictionary_key_helper(dictionary=config_dict, key=radius_key, exception_msg=e_msg + radius_key) + pos = common.dictionary_key_helper(dictionary=config_dict, key=pos_key, exception_msg=e_msg + pos_key) + + formula = common.dictionary_key_helper(dictionary=config_dict, key=formula_key, exception_msg=e_msg + formula_key) + + ws_to_correct = _calculate__cylinder_absorb_corrections( + ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, + c_height=height, c_radius=radius, c_pos=pos, chemical_formula=formula) + + return ws_to_correct + + +def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, + c_height, c_radius, c_pos, chemical_formula): + """ + Calculates vanadium absorption corrections for the specified workspace. The workspace + should have any monitor spectra masked before being passed into this method. Additionally + it takes details of the sample container and sets the sample geometry to a cylinder with + the specified geometry. This function uses Mayers Sample Correction to perform the corrections. + :param ws_to_correct: The workspace to apply the sample corrections to + :param multiple_scattering: True if the effects of multiple scattering should be accounted for, else False + :param c_height: The height of the cylinder as a float + :param c_radius: The radius of the cylinder as a float + :param c_pos: The position as a list of three float values + :param chemical_formula: The chemical formula of the container - usually set to 'V' for Vanadium + :return: The workspace with corrections applied + """ + geometry_json = {'Shape': 'Cylinder', 'Height': c_height, + 'Radius': c_radius, 'Center': c_pos} + material_json = {'ChemicalFormula': chemical_formula} + + mantid.SetSample(InputWorkspace=ws_to_correct, Geometry=geometry_json, Material=material_json) + + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="TOF") + ws_to_correct = mantid.MayersSampleCorrection(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, + MultipleScattering=multiple_scattering) + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="dSpacing") + + return ws_to_correct diff --git a/scripts/Diffraction/isis_powder/routines/calibrate.py b/scripts/Diffraction/isis_powder/routines/calibrate.py index 58e5d913b9384c1174dfa7ed5714a4a2dc7316df..77077021941fbfd8b32d1db075265dc3076f1c05 100644 --- a/scripts/Diffraction/isis_powder/routines/calibrate.py +++ b/scripts/Diffraction/isis_powder/routines/calibrate.py @@ -21,7 +21,8 @@ def create_van(instrument, run_details, absorb): aligned_ws = mantid.AlignDetectors(InputWorkspace=corrected_van_ws, CalibrationFile=run_details.offset_file_path) - + import pydevd + pydevd.settrace('localhost', port=51205, stdoutToServer=True, stderrToServer=True) if absorb: aligned_ws = _apply_absorb_corrections(instrument=instrument, run_details=run_details, van_ws=aligned_ws) diff --git a/scripts/Diffraction/isis_powder/routines/common.py b/scripts/Diffraction/isis_powder/routines/common.py index dc62b788c2a1d4bdf68fdf3671edd906d705594c..a17717929843e9b60d0b4613deca9de9ac5cf77d 100644 --- a/scripts/Diffraction/isis_powder/routines/common.py +++ b/scripts/Diffraction/isis_powder/routines/common.py @@ -5,35 +5,6 @@ import mantid.simpleapi as mantid from isis_powder.routines.common_enums import InputBatchingEnum -def calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, - c_height, c_radius, c_pos, chemical_formula): - """ - Calculates vanadium absorption corrections for the specified workspace. The workspace - should have any monitor spectra masked before being passed into this method. Additionally - it takes details of the sample container and sets the sample geometry to a cylinder with - the specified geometry. This function uses Mayers Sample Correction to perform the corrections. - :param ws_to_correct: The workspace to apply the sample corrections to - :param multiple_scattering: True if the effects of multiple scattering should be accounted for, else False - :param c_height: The height of the cylinder as a float - :param c_radius: The radius of the cylinder as a float - :param c_pos: The position as a list of three float values - :param chemical_formula: The chemical formula of the container - usually set to 'V' for Vanadium - :return: The workspace with corrections applied - """ - geometry_json = {'Shape': 'Cylinder', 'Height': c_height, - 'Radius': c_radius, 'Center': c_pos} - material_json = {'ChemicalFormula': chemical_formula} - - mantid.SetSample(InputWorkspace=ws_to_correct, Geometry=geometry_json, Material=material_json) - - ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="TOF") - ws_to_correct = mantid.MayersSampleCorrection(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, - MultipleScattering=multiple_scattering) - ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, Target="dSpacing") - - return ws_to_correct - - def cal_map_dictionary_key_helper(dictionary, key, append_to_error_message=None): """ Provides a light wrapper around the dictionary key helper which provides a generic error