diff --git a/scripts/Diffraction/isis_powder/abstract_inst.py b/scripts/Diffraction/isis_powder/abstract_inst.py index 57f6b5445641cd514cd3cb2bf6f1e63d619c617d..ad60cb2b4e321c49fc69750fb11e0ebf5762e360 100644 --- a/scripts/Diffraction/isis_powder/abstract_inst.py +++ b/scripts/Diffraction/isis_powder/abstract_inst.py @@ -36,7 +36,7 @@ class AbstractInst(object): def user_name(self): return self._user_name - def _create_vanadium(self, run_number_string, do_absorb_corrections=True): + def _create_vanadium(self, run_number_string, do_absorb_corrections): """ Creates a vanadium calibration - should be called by the concrete instrument :param run_number_string : The user input string for any run within the cycle @@ -49,7 +49,7 @@ class AbstractInst(object): return calibrate.create_van(instrument=self, run_details=run_details, absorb=do_absorb_corrections) - def _focus(self, run_number_string, do_van_normalisation): + def _focus(self, run_number_string, do_van_normalisation, do_absorb_corrections): """ Focuses the user specified run - should be called by the concrete instrument :param run_number_string: The run number(s) to be processed @@ -58,7 +58,7 @@ class AbstractInst(object): """ self._is_vanadium = False return focus.focus(run_number_string=run_number_string, perform_vanadium_norm=do_van_normalisation, - instrument=self) + instrument=self, absorb=do_absorb_corrections) # Mandatory overrides @@ -79,6 +79,15 @@ class AbstractInst(object): """ raise NotImplementedError("generate_input_file_name must be implemented per instrument") + def _apply_absorb_corrections(self, run_details, ws_to_correct): + """ + Generates absorption corrections to compensate for the container. The overriding instrument + should handle the difference between a vanadium workspace and regular workspace + :param ws_to_correct: A reference vanadium workspace to match the binning of or correct + :return: A workspace containing the corrections + """ + raise NotImplementedError("apply_absorb_corrections Not implemented for this instrument yet") + def _generate_output_file_name(self, run_number_string): """ Generates the filename which is used to uniquely identify and save the workspace. This should include any @@ -99,14 +108,6 @@ class AbstractInst(object): raise NotImplementedError("spline_vanadium_ws must be implemented per instrument") # Optional overrides - def _apply_absorb_corrections(self, run_details, van_ws): - """ - Generates vanadium absorption corrections to compensate for the container - :param van_ws: A reference vanadium workspace to match the binning of or correct - :return: A workspace containing the corrections - """ - raise NotImplementedError("apply_absorb_corrections Not implemented for this instrument yet") - def _attenuate_workspace(self, input_workspace): """ Applies an attenuation correction to the workspace diff --git a/scripts/Diffraction/isis_powder/gem.py b/scripts/Diffraction/isis_powder/gem.py index b73fb7cdbf5f9f09fbf230d653b831c1f1100582..a00b24932f6fdae05ddff0cf3247491dbc8d637a 100644 --- a/scripts/Diffraction/isis_powder/gem.py +++ b/scripts/Diffraction/isis_powder/gem.py @@ -2,7 +2,7 @@ from __future__ import (absolute_import, division, print_function) from isis_powder.abstract_inst import AbstractInst from isis_powder.gem_routines import gem_advanced_config, gem_algs, gem_param_mapping -from isis_powder.routines import common, instrument_settings, sample_details +from isis_powder.routines import absorb_corrections, common, instrument_settings, sample_details class Gem(AbstractInst): @@ -22,8 +22,9 @@ class Gem(AbstractInst): def focus(self, **kwargs): self._inst_settings.update_attributes(kwargs=kwargs) - return self._focus(run_number_string=self._inst_settings.run_number, - do_van_normalisation=self._inst_settings.do_van_norm) + return self._focus( + run_number_string=self._inst_settings.run_number, do_van_normalisation=self._inst_settings.do_van_norm, + do_absorb_corrections=self._inst_settings.do_absorb_corrections) def create_vanadium(self, **kwargs): self._inst_settings.update_attributes(kwargs=kwargs) @@ -62,9 +63,14 @@ class Gem(AbstractInst): def _generate_input_file_name(run_number): return _gem_generate_inst_name(run_number=run_number) - def _apply_absorb_corrections(self, run_details, van_ws): - return gem_algs.calculate_van_absorb_corrections(ws_to_correct=van_ws, - multiple_scattering=self._inst_settings.multiple_scattering) + def _apply_absorb_corrections(self, run_details, ws_to_correct): + if self._is_vanadium: + return gem_algs.calculate_van_absorb_corrections( + ws_to_correct=ws_to_correct, multiple_scattering=self._inst_settings.multiple_scattering) + else: + return absorb_corrections.run_cylinder_absorb_corrections( + ws_to_correct=ws_to_correct, multiple_scattering=self._inst_settings.multiple_scattering, + sample_details_obj=sample_details) def _crop_banks_to_user_tof(self, focused_banks): return common.crop_banks_using_crop_list(focused_banks, self._inst_settings.focused_cropping_values) diff --git a/scripts/Diffraction/isis_powder/pearl.py b/scripts/Diffraction/isis_powder/pearl.py index 947b7144b3416a6b859bf907d06860b6ee4c47fd..e10e0c7527159a5aa93b200d9fa9ddd27ddee597 100644 --- a/scripts/Diffraction/isis_powder/pearl.py +++ b/scripts/Diffraction/isis_powder/pearl.py @@ -23,7 +23,10 @@ class Pearl(AbstractInst): def focus(self, **kwargs): self._switch_long_mode_inst_settings(kwargs.get("long_mode")) self._inst_settings.update_attributes(kwargs=kwargs) + # Pearl does not have absorption corrections for a sample + do_absorb_corrections = False return self._focus(run_number_string=self._inst_settings.run_number, + do_absorb_corrections=do_absorb_corrections, do_van_normalisation=self._inst_settings.van_norm) def create_vanadium(self, **kwargs): @@ -115,13 +118,19 @@ class Pearl(AbstractInst): x_max=self._inst_settings.van_tof_cropping[-1]) return cropped_ws - def _apply_absorb_corrections(self, run_details, van_ws): - # TODO move this to an instrument param + def _apply_absorb_corrections(self, run_details, ws_to_correct): + # TODO move generating absorption corrections to an instrument param gen_absorb = False if gen_absorb: - pearl_algs.generate_vanadium_absorb_corrections(van_ws=van_ws) + pearl_algs.generate_vanadium_absorb_corrections(van_ws=ws_to_correct) - return pearl_algs.apply_vanadium_absorb_corrections(van_ws=van_ws, run_details=run_details) + if not self._is_vanadium: + # This is sample absorption corrections which is not supported on Pearl. + # We should not get here as the absorption flag shouldn't do anything whilst focusing on Pearl + raise RuntimeError("Cannot run Absorption corrections for a sample on Pearl. Please contact development " + "team.") + + return pearl_algs.apply_vanadium_absorb_corrections(van_ws=ws_to_correct, run_details=run_details) def _switch_long_mode_inst_settings(self, long_mode_on): self._inst_settings.update_attributes(advanced_config=pearl_advanced_config.get_long_mode_dict(long_mode_on), diff --git a/scripts/Diffraction/isis_powder/polaris.py b/scripts/Diffraction/isis_powder/polaris.py index abc010c734e90d1dc01f45fc113bce9de8cdc1a6..8241e0c91ab9da275eec47a02fa0f8edf1a49cb9 100644 --- a/scripts/Diffraction/isis_powder/polaris.py +++ b/scripts/Diffraction/isis_powder/polaris.py @@ -2,7 +2,7 @@ from __future__ import (absolute_import, division, print_function) import os -from isis_powder.routines import common, instrument_settings, sample_details +from isis_powder.routines import absorb_corrections, common, instrument_settings, sample_details from isis_powder.abstract_inst import AbstractInst from isis_powder.polaris_routines import polaris_advanced_config, polaris_algs, polaris_param_mapping @@ -26,7 +26,8 @@ class Polaris(AbstractInst): def focus(self, **kwargs): self._inst_settings.update_attributes(kwargs=kwargs) return self._focus(run_number_string=self._inst_settings.run_number, - do_van_normalisation=self._inst_settings.do_van_normalisation) + do_van_normalisation=self._inst_settings.do_van_normalisation, + do_absorb_corrections=self._inst_settings.do_absorb_corrections) def create_vanadium(self, **kwargs): self._inst_settings.update_attributes(kwargs=kwargs) @@ -44,9 +45,14 @@ class Polaris(AbstractInst): self._sample_details = sample_details_obj # Overrides - def _apply_absorb_corrections(self, run_details, van_ws): - return polaris_algs.calculate_van_absorb_corrections(ws_to_correct=van_ws, - multiple_scattering=self._inst_settings.multiple_scattering) + 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) + else: + return absorb_corrections.run_cylinder_absorb_corrections( + ws_to_correct=ws_to_correct, multiple_scattering=self._inst_settings.multiple_scattering, + sample_details_obj=sample_details) @staticmethod def _can_auto_gen_vanadium_cal(): diff --git a/scripts/Diffraction/isis_powder/routines/calibrate.py b/scripts/Diffraction/isis_powder/routines/calibrate.py index 2b9d0108fdfe2ae6e999450a8ae54d5b9e5a063b..96e06873fe4faed82bc202f2c2beae0562a050d2 100644 --- a/scripts/Diffraction/isis_powder/routines/calibrate.py +++ b/scripts/Diffraction/isis_powder/routines/calibrate.py @@ -21,7 +21,6 @@ def create_van(instrument, run_details, absorb): input_batching=INPUT_BATCHING.Summed) input_van_ws = input_van_ws_list[0] # As we asked for a summed ws there should only be one returned - # TODO where do we subtract empty can on GEM ? corrected_van_ws = common.subtract_summed_runs(ws_to_correct=input_van_ws, empty_sample_ws_string=run_details.empty_runs, instrument=instrument) @@ -32,7 +31,7 @@ def create_van(instrument, run_details, absorb): aligned_ws = mantid.AlignDetectors(InputWorkspace=corrected_van_ws, CalibrationFile=run_details.offset_file_path) if absorb: - aligned_ws = instrument._apply_absorb_corrections(run_details=run_details, van_ws=aligned_ws) + aligned_ws = instrument._apply_absorb_corrections(run_details=run_details, ws_to_correct=aligned_ws) focused_vanadium = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, GroupingFileName=run_details.grouping_file_path) diff --git a/scripts/Diffraction/isis_powder/routines/focus.py b/scripts/Diffraction/isis_powder/routines/focus.py index a6b2034e09e2defcae765ea028cb83b705ad9559..b7068e1ae12b018de6eadcf5b6fdbd8ff09c3208 100644 --- a/scripts/Diffraction/isis_powder/routines/focus.py +++ b/scripts/Diffraction/isis_powder/routines/focus.py @@ -8,17 +8,18 @@ import os import warnings -def focus(run_number_string, instrument, perform_vanadium_norm=True): +def focus(run_number_string, instrument, perform_vanadium_norm, absorb): input_batching = instrument._get_input_batching_mode() if input_batching == INPUT_BATCHING.Individual: - return _individual_run_focusing(instrument, perform_vanadium_norm, run_number_string) + return _individual_run_focusing(instrument=instrument, perform_vanadium_norm=perform_vanadium_norm, + run_number=run_number_string, absorb=absorb) elif input_batching == INPUT_BATCHING.Summed: return _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string) else: raise ValueError("Input batching not passed through. Please contact development team.") -def _focus_one_ws(ws, run_number, instrument, perform_vanadium_norm): +def _focus_one_ws(ws, run_number, instrument, perform_vanadium_norm, absorb): run_details = instrument._get_run_details(run_number_string=run_number) if perform_vanadium_norm: _test_splined_vanadium_exists(instrument, run_details) @@ -32,6 +33,10 @@ def _focus_one_ws(ws, run_number, instrument, perform_vanadium_norm): empty_sample_ws_string=run_details.sample_empty, scale_factor=instrument._inst_settings.sample_empty_scale) + # Correct for absorption / multiple scattering if required + if absorb: + input_workspace = instrument._apply_absorb_corrections(run_details=run_details, ws_to_correct=input_workspace) + # Crop to largest acceptable TOF range input_workspace = instrument._crop_raw_to_expected_tof_range(ws_to_crop=input_workspace) @@ -77,13 +82,13 @@ def _apply_vanadium_corrections(instrument, run_number, input_workspace, perform return processed_spectra -def _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string): +def _batched_run_focusing(instrument, perform_vanadium_norm, run_number_string, absorb): read_ws_list = common.load_current_normalised_ws_list(run_number_string=run_number_string, instrument=instrument) output = None for ws in read_ws_list: output = _focus_one_ws(ws=ws, run_number=run_number_string, instrument=instrument, - perform_vanadium_norm=perform_vanadium_norm) + perform_vanadium_norm=perform_vanadium_norm, absorb=absorb) return output @@ -98,13 +103,13 @@ def _divide_by_vanadium_splines(spectra_list, spline_file_path): return output_list -def _individual_run_focusing(instrument, perform_vanadium_norm, run_number): +def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb): # Load and process one by one run_numbers = common.generate_run_numbers(run_number_string=run_number) output = None for run in run_numbers: ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument) - output = _focus_one_ws(ws=ws[0], run_number=run, instrument=instrument, + output = _focus_one_ws(ws=ws[0], run_number=run, instrument=instrument, absorb=absorb, perform_vanadium_norm=perform_vanadium_norm) return output