diff --git a/scripts/Diffraction/isis_powder/polaris.py b/scripts/Diffraction/isis_powder/polaris.py index 4a93ffe71cd91fe617bb6c85e544c4c04e1f628e..6c5d91bc62b54a37f6e2c68cce2ad4f41a9815a9 100644 --- a/scripts/Diffraction/isis_powder/polaris.py +++ b/scripts/Diffraction/isis_powder/polaris.py @@ -46,11 +46,12 @@ class Polaris(AbstractInst): def _apply_absorb_corrections(self, run_details, ws_to_correct): if self._is_vanadium: return polaris_algs.calculate_van_absorb_corrections( - ws_to_correct=ws_to_correct, multiple_scattering=self._inst_settings.multiple_scattering) + ws_to_correct=ws_to_correct, multiple_scattering=self._inst_settings.multiple_scattering, + is_vanadium=self._is_vanadium) else: return absorb_corrections.run_cylinder_absorb_corrections( ws_to_correct=ws_to_correct, multiple_scattering=self._inst_settings.multiple_scattering, - sample_details_obj=self._sample_details) + sample_details_obj=self._sample_details, is_vanadium=self._is_vanadium) @staticmethod def _can_auto_gen_vanadium_cal(): diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py index 463ad022e689d379068898463ba8171e391eb363..923d2085f25234082631f8a5f61c20dfd1b7e881 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py @@ -8,13 +8,14 @@ from isis_powder.routines.run_details import create_run_details_object, \ from isis_powder.polaris_routines import polaris_advanced_config -def calculate_van_absorb_corrections(ws_to_correct, multiple_scattering): +def calculate_van_absorb_corrections(ws_to_correct, multiple_scattering, is_vanadium): mantid.MaskDetectors(ws_to_correct, SpectraList=list(range(1, 55))) absorb_dict = polaris_advanced_config.absorption_correction_params sample_details_obj = absorb_corrections.create_vanadium_sample_details_obj(config_dict=absorb_dict) ws_to_correct = absorb_corrections.run_cylinder_absorb_corrections( - ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, sample_details_obj=sample_details_obj) + ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, sample_details_obj=sample_details_obj, + is_vanadium=is_vanadium) return ws_to_correct diff --git a/scripts/Diffraction/isis_powder/routines/absorb_corrections.py b/scripts/Diffraction/isis_powder/routines/absorb_corrections.py index fcfb677301eeae1054a3d6fdd8608c3b1de81ece..811196ed4e7a1906d9e86b8983f62220338c9ee9 100644 --- a/scripts/Diffraction/isis_powder/routines/absorb_corrections.py +++ b/scripts/Diffraction/isis_powder/routines/absorb_corrections.py @@ -31,7 +31,7 @@ def create_vanadium_sample_details_obj(config_dict): return vanadium_sample_details -def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, sample_details_obj): +def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, sample_details_obj, is_vanadium): """ Sets a cylindrical sample from the user specified config dictionary and performs Mayers sample correction on the workspace. The SampleDetails object defines the sample, material @@ -40,6 +40,7 @@ def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, sample_d :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 sample_details_obj: The object containing the sample details + :param is_vanadium: Whether the sample is a vanadium :return: The corrected workspace """ @@ -56,12 +57,11 @@ def run_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, sample_d ws_to_correct = _calculate__cylinder_absorb_corrections( ws_to_correct=ws_to_correct, multiple_scattering=multiple_scattering, - sample_details_obj=sample_details_obj) - + sample_details_obj=sample_details_obj, is_vanadium=is_vanadium) return ws_to_correct -def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, sample_details_obj): +def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, sample_details_obj, is_vanadium): """ Calculates vanadium absorption corrections for the specified workspace. The workspace should have any monitor spectra masked before being passed into this method. Additionally @@ -71,9 +71,18 @@ def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, :param multiple_scattering: True if the effects of multiple scattering should be accounted for, else False :param sample_details_obj: The SampleDetails object in a checked state which describes the sample to ensure a none elemental formula has associated number density + :param is_vanadium: Whether the sample is a vanadium :return: The workspace with corrections applied """ + _setup_sample_for_cylinder_absorb_corrections(ws_to_correct=ws_to_correct, + sample_details_obj=sample_details_obj) + ws_to_correct = _do_cylinder_absorb_corrections(ws_to_correct=ws_to_correct, + multiple_scattering=multiple_scattering, + is_vanadium=is_vanadium, sample_details=sample_details_obj) + return ws_to_correct + +def _setup_sample_for_cylinder_absorb_corrections(ws_to_correct, sample_details_obj): geometry_json = {'Shape': 'Cylinder', 'Height': sample_details_obj.height, 'Radius': sample_details_obj.radius, 'Center': sample_details_obj.center} @@ -89,17 +98,37 @@ def _calculate__cylinder_absorb_corrections(ws_to_correct, multiple_scattering, mantid.SetSample(InputWorkspace=ws_to_correct, Geometry=geometry_json, Material=material_json) + +def _do_cylinder_absorb_corrections(ws_to_correct, multiple_scattering, is_vanadium, sample_details): previous_units = ws_to_correct.getAxis(0).getUnit().unitID() ws_units = common_enums.WORKSPACE_UNITS - # Mayers Sample correction must be completed in TOF, convert if needed. Then back to original units afterwards - if previous_units != ws_units.tof: - ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, - Target=ws_units.tof) - ws_to_correct = mantid.MayersSampleCorrection(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, - MultipleScattering=multiple_scattering) - if previous_units != ws_units.tof: - ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, OutputWorkspace=ws_to_correct, - Target=previous_units) - - return ws_to_correct + if is_vanadium: + # Mayers Sample correction must be completed in TOF, convert if needed. Then back to original units afterwards + if previous_units != ws_units.tof: + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, Target=ws_units.tof) + ws_to_correct = mantid.MayersSampleCorrection(InputWorkspace=ws_to_correct, + MultipleScattering=multiple_scattering) + if previous_units != ws_units.tof: + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, Target=previous_units) + return ws_to_correct + + else: # Sample is not vanadium + # Cylinder Absorption correction must be in units of wavelength, convert if needed, then back afterwards + if previous_units != ws_units.wavelength: + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, Target=ws_units.wavelength, + OutputWorkspace=ws_to_correct) + + attenuation_factors_ws = mantid.CloneWorkspace(InputWorkspace=ws_to_correct) + attenuation_factors_ws = mantid.CylinderAbsorption(InputWorkspace=attenuation_factors_ws, + CylinderSampleHeight=sample_details.height, + CylinderSampleRadius=sample_details.radius) + ws_to_correct = mantid.Divide(LHSWorkspace=ws_to_correct, RHSWorkspace=attenuation_factors_ws, + OutputWorkspace=ws_to_correct) + common.remove_intermediate_workspace(attenuation_factors_ws) + + if previous_units != ws_units.wavelength: + ws_to_correct = mantid.ConvertUnits(InputWorkspace=ws_to_correct, Target=previous_units, + OutputWorkspace=ws_to_correct) + + return ws_to_correct diff --git a/scripts/Diffraction/isis_powder/routines/common_enums.py b/scripts/Diffraction/isis_powder/routines/common_enums.py index 1d11a1f7f303869b07b5a792fa9bc3cd5b668272..8b8aa2a43defc08887fb39c5efb48e13a5645ec7 100644 --- a/scripts/Diffraction/isis_powder/routines/common_enums.py +++ b/scripts/Diffraction/isis_powder/routines/common_enums.py @@ -13,3 +13,4 @@ class WORKSPACE_UNITS(object): enum_friendly_name = "workspace units" d_spacing = "dSpacing" tof = "TOF" + wavelength = "Wavelength" diff --git a/scripts/Diffraction/isis_powder/routines/focus.py b/scripts/Diffraction/isis_powder/routines/focus.py index 71b3098f619124009bb03ba73b57128b5c232db5..a9ed960326caae4b604499523213aa4cb3a8383f 100644 --- a/scripts/Diffraction/isis_powder/routines/focus.py +++ b/scripts/Diffraction/isis_powder/routines/focus.py @@ -42,7 +42,7 @@ def _focus_one_ws(ws, run_number, instrument, perform_vanadium_norm, absorb): # Correct for absorption / multiple scattering if required if absorb: - input_workspace = instrument._apply_absorb_corrections(run_details=run_details, ws_to_correct=input_workspace) + aligned_ws = instrument._apply_absorb_corrections(run_details=run_details, ws_to_correct=aligned_ws) # Focus the spectra into banks focused_ws = mantid.DiffractionFocussing(InputWorkspace=aligned_ws,