diff --git a/scripts/Diffraction/isis_powder/abstract_inst.py b/scripts/Diffraction/isis_powder/abstract_inst.py index 09b5302aa20c976cae48baaf9ac654a176c777a8..320c8a876cc3f02b6aacdd0c9265515d56c91cd1 100644 --- a/scripts/Diffraction/isis_powder/abstract_inst.py +++ b/scripts/Diffraction/isis_powder/abstract_inst.py @@ -34,7 +34,7 @@ class AbstractInst(object): def user_name(self): return self._user_name - def _create_vanadium(self, run_details, do_absorb_corrections=True, gen_absorb_correction=False): + def _create_vanadium(self, run_details, do_absorb_corrections=True): """ Creates a vanadium calibration - should be called by the concrete instrument :param vanadium_runs: The vanadium run or run in range (depending on instrument) to process @@ -44,7 +44,7 @@ class AbstractInst(object): :return: d_spacing focused vanadium group """ return calibrate.create_van(instrument=self, run_details=run_details, - absorb=do_absorb_corrections, gen_absorb=gen_absorb_correction) + absorb=do_absorb_corrections) def _focus(self, run_number_string, do_van_normalisation): """ @@ -95,7 +95,7 @@ class AbstractInst(object): raise NotImplementedError("spline_vanadium_ws must be implemented per instrument") # Optional overrides - def _apply_absorb_corrections(self, run_details, van_ws, gen_absorb=False): + 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 diff --git a/scripts/Diffraction/isis_powder/gem.py b/scripts/Diffraction/isis_powder/gem.py index 6dc674a3a58ffad1c3ca52086e6a1f4942920960..0fbecd54cbbf735ab1941b4382224f63e1f0fb99 100644 --- a/scripts/Diffraction/isis_powder/gem.py +++ b/scripts/Diffraction/isis_powder/gem.py @@ -1,10 +1,8 @@ from __future__ import (absolute_import, division, print_function) -import mantid.simpleapi as mantid - from isis_powder.abstract_inst import AbstractInst -from isis_powder.gem_routines import gem_advanced_config, gem_param_mapping -from isis_powder.routines import InstrumentSettings, RunDetails, yaml_parser +from isis_powder.gem_routines import gem_advanced_config, gem_algs, gem_param_mapping +from isis_powder.routines import InstrumentSettings, yaml_parser class Gem(AbstractInst): @@ -12,7 +10,7 @@ class Gem(AbstractInst): basic_config_dict = yaml_parser.open_yaml_file_as_dictionary(kwargs.get("config_file", None)) self._inst_settings = InstrumentSettings.InstrumentSettings( - attr_mapping=gem_param_mapping.attr_mapping, adv_conf_dict=gem_advanced_config, + attr_mapping=gem_param_mapping.attr_mapping, adv_conf_dict=gem_advanced_config.get_all_adv_variables(), kwargs=kwargs, basic_conf_dict=basic_config_dict) super(Gem, self).__init__(user_name=self._inst_settings.user_name, @@ -21,7 +19,6 @@ class Gem(AbstractInst): self._cached_run_details = None self._cached_run_number = None - raise NotImplementedError() def focus(self, **kwargs): self._inst_settings.update_attributes(kwargs=kwargs) @@ -34,13 +31,12 @@ class Gem(AbstractInst): run_details = self._get_run_details(run_number_string=self._inst_settings.run_in_range) # Set the run and vanadium run equal run_details.run_number = run_details.vanadium_run_numbers - # TODO remove gen absorb_corrections param if we remove it on POLARIS + return self._create_vanadium(run_details=run_details, - do_absorb_corrections=self._inst_settings.do_absorb_corrections, - gen_absorb_correction=None) + do_absorb_corrections=self._inst_settings.do_absorb_corrections) def _get_run_details(self, run_number_string): - raise NotImplementedError() + return gem_algs.get_run_details(run_number_string=run_number_string, inst_settings=self._inst_settings) def _generate_auto_vanadium_calibration(self, run_details): raise NotImplementedError() @@ -52,7 +48,7 @@ class Gem(AbstractInst): def _generate_input_file_name(run_number): raise NotImplementedError() - def _apply_absorb_corrections(self, run_details, van_ws, gen_absorb=False): + def _apply_absorb_corrections(self, run_details, van_ws): raise NotImplementedError() def _spline_vanadium_ws(self, focused_vanadium_banks): diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py b/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py index 5ca40f49ef22f5877498841526d8f1bcbc3502a7..db9e8bbedbcffd042af2eec234c1ea988f5f1a21 100644 --- a/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py +++ b/scripts/Diffraction/isis_powder/gem_routines/gem_algs.py @@ -1 +1,38 @@ -from __future__ import (absolute_import, division, print_function) \ No newline at end of file +from __future__ import (absolute_import, division, print_function) + +import os + +from isis_powder.routines import common, RunDetails, yaml_parser + + +def get_run_details(run_number_string, inst_settings): + run_number = common.generate_run_numbers(run_number_string=run_number_string) + if isinstance(run_number, list): + run_number = run_number[0] + + # Get calibration mapping file + cycle_map = yaml_parser.get_run_dictionary(run_number_string=run_number_string, + file_path=inst_settings.cal_mapping_path) + label = cycle_map["label"] + offset_file_name = cycle_map["offset_file_name"] + empty_runs = cycle_map["empty_run_numbers"] + vanadium_runs = cycle_map["vanadium_run_numbers"] + + # For GEM the grouping and offset file are identical + calibration_folder = os.path.normpath(os.path.expanduser(inst_settings.calibration_dir)) + label_calibration_folder = os.path.join(calibration_folder, label) + + offset_file_path = os.path.join(label_calibration_folder, offset_file_name) + + # TODO generate splined vanadium name from common + + run_details = RunDetails.RunDetails(run_number=run_number) + run_details.empty_runs = empty_runs, + run_details.user_input_run_number = run_number_string + run_details.label = label + run_details.vanadium_run_numbers = vanadium_runs + + run_details.grouping_file_path = offset_file_path + run_details.offset_file_path = offset_file_path + + return run_details diff --git a/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py b/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py index 9721ec1a97e65405e256720d2180b0849ec8523d..e8d965dd642c613d9593db8ea7e02a80d3cfdced 100644 --- a/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py +++ b/scripts/Diffraction/isis_powder/gem_routines/gem_param_mapping.py @@ -2,6 +2,7 @@ from __future__ import (absolute_import, division, print_function) # Maps friendly user name -> script name attr_mapping = [("calibration_directory", "calibration_dir"), + ("calibration_mapping_file", "cal_mapping_path"), ("config_file", "config_file"), ("output_directory", "output_dir"), ("run_in_range", "run_in_range"), diff --git a/scripts/Diffraction/isis_powder/pearl.py b/scripts/Diffraction/isis_powder/pearl.py index 69255747f08431f78d95efb42ddad3bf6226dd65..87370343e88cc123641f775f34cd8ebfab8a4527 100644 --- a/scripts/Diffraction/isis_powder/pearl.py +++ b/scripts/Diffraction/isis_powder/pearl.py @@ -121,7 +121,9 @@ class Pearl(AbstractInst): x_max=self._inst_settings.van_tof_cropping[-1]) return cropped_ws - def _apply_absorb_corrections(self, run_details, van_ws, gen_absorb=False): + def _apply_absorb_corrections(self, run_details, van_ws): + # TODO move this to an instrument param + gen_absorb = False if gen_absorb: pearl_algs.generate_vanadium_absorb_corrections(van_ws=van_ws) diff --git a/scripts/Diffraction/isis_powder/pearl_routines/pearl_algs.py b/scripts/Diffraction/isis_powder/pearl_routines/pearl_algs.py index 43443ca52767142bb60087469e10e68e66766e8e..2f12d2ddf00bbb0e72bcdf9fd75df4cf6a14307f 100644 --- a/scripts/Diffraction/isis_powder/pearl_routines/pearl_algs.py +++ b/scripts/Diffraction/isis_powder/pearl_routines/pearl_algs.py @@ -102,7 +102,7 @@ def get_run_details(run_number_string, inst_settings): run_details = RunDetails(run_number=first_run_number) run_details.user_input_run_number = run_number_string - run_details.calibration_file_path = calibration_file_path + run_details.offset_file_path = calibration_file_path run_details.grouping_file_path = grouping_file_path run_details.empty_runs = empty_run_numbers run_details.label = label diff --git a/scripts/Diffraction/isis_powder/polaris.py b/scripts/Diffraction/isis_powder/polaris.py index f4ccbeda19717fa136421278382266ef1490416f..f242f0823e09871f7c5a28309d5e2fdb6d0d5879 100644 --- a/scripts/Diffraction/isis_powder/polaris.py +++ b/scripts/Diffraction/isis_powder/polaris.py @@ -37,14 +37,12 @@ class Polaris(AbstractInst): run_details = self._get_run_details(run_number_string=int(self._inst_settings.run_in_range)) run_details.run_number = run_details.vanadium_run_numbers - # TODO POLARIS doesn't need this flag to gen abs. corrections does PEARL? return self._create_vanadium(run_details=run_details, - do_absorb_corrections=self._inst_settings.do_absorb_corrections, - gen_absorb_correction=None) + do_absorb_corrections=self._inst_settings.do_absorb_corrections) # Overrides - def _apply_absorb_corrections(self, run_details, van_ws, gen_absorb=False): + def _apply_absorb_corrections(self, run_details, van_ws): return polaris_algs.calculate_absorb_corrections(ws_to_correct=van_ws, multiple_scattering=self._inst_settings.multiple_scattering) diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py index ead35de5b755758a9bc0b732fc2ef89fc0029bf5..206153af981da657cf7773ce8a7e5c324f06efb4 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py @@ -2,11 +2,11 @@ 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.RunDetails import RunDetails from isis_powder.polaris_routines import polaris_advanced_config - def calculate_absorb_corrections(ws_to_correct, multiple_scattering): mantid.MaskDetectors(ws_to_correct, SpectraList=list(range(0, 55))) @@ -46,7 +46,7 @@ def get_run_details(run_number_string, inst_settings): grouping_full_path = os.path.join(grouping_full_path, inst_settings.grouping_file_name) in_calib_dir = os.path.join(inst_settings.calibration_dir, label) - calibration_full_path = os.path.join(in_calib_dir, offset_file_name) + offsets_file_full_path = os.path.join(in_calib_dir, offset_file_name) # Generate the name of the splined file we will either be loading or saving splined_vanadium_name = _generate_splined_van_filename(chopper_on=inst_settings.chopper_on, vanadium_run_string=vanadium_runs, @@ -59,7 +59,7 @@ def get_run_details(run_number_string, inst_settings): run_details.vanadium_run_numbers = vanadium_runs run_details.label = label - run_details.calibration_file_path = calibration_full_path + run_details.offset_file_path = offsets_file_full_path run_details.grouping_file_path = grouping_full_path run_details.splined_vanadium_file_path = splined_vanadium diff --git a/scripts/Diffraction/isis_powder/routines/RunDetails.py b/scripts/Diffraction/isis_powder/routines/RunDetails.py index 9d6a5f9265901925d8be5f8778d87d35ca3baace..b03e87ba945cb334eba7da417341362b99f84748 100644 --- a/scripts/Diffraction/isis_powder/routines/RunDetails.py +++ b/scripts/Diffraction/isis_powder/routines/RunDetails.py @@ -14,7 +14,7 @@ class RunDetails(object): self.empty_runs = None self.label = None - self.calibration_file_path = None + self.offset_file_path = None self.grouping_file_path = None self.splined_vanadium_file_path = None diff --git a/scripts/Diffraction/isis_powder/routines/calibrate.py b/scripts/Diffraction/isis_powder/routines/calibrate.py index 3ba7d6d5cf766508732b571e356c74fa916c4c16..f86f3facffc802fa2ff1b7be6ab9f0924969d018 100644 --- a/scripts/Diffraction/isis_powder/routines/calibrate.py +++ b/scripts/Diffraction/isis_powder/routines/calibrate.py @@ -6,7 +6,7 @@ import isis_powder.routines.common as common from isis_powder.routines.common_enums import InputBatchingEnum -def create_van(instrument, run_details, absorb, gen_absorb): +def create_van(instrument, run_details, absorb): van = run_details.vanadium_run_numbers run_details = instrument._get_run_details(run_number_string=van) # Always sum a range of inputs as its a vanadium run over multiple captures @@ -24,7 +24,7 @@ def create_van(instrument, run_details, absorb, gen_absorb): if absorb: aligned_ws = _apply_absorb_corrections(instrument=instrument, run_details=run_details, - van_ws=aligned_ws, gen_absorb=gen_absorb) + van_ws=aligned_ws) focused_vanadium = mantid.DiffractionFocussing(InputWorkspace=aligned_ws, GroupingFileName=run_details.grouping_file_path) @@ -55,8 +55,8 @@ def _create_vanadium_splines(focused_spectra, instrument, run_details): mantid.GroupWorkspaces(InputWorkspaces=splined_ws_list, OutputWorkspace="Van_spline_data") -def _apply_absorb_corrections(instrument, run_details, van_ws, gen_absorb): - absorb_ws = instrument._apply_absorb_corrections(run_details, van_ws, gen_absorb=gen_absorb) +def _apply_absorb_corrections(instrument, run_details, van_ws): + absorb_ws = instrument._apply_absorb_corrections(run_details=run_details, van_ws=van_ws) return absorb_ws diff --git a/scripts/Diffraction/isis_powder/routines/yaml_parser.py b/scripts/Diffraction/isis_powder/routines/yaml_parser.py index 476fadbe00c0747648196464ea2d14784dc914fc..54e058d57aa3e50f069c1e1da822996d87c8df6d 100644 --- a/scripts/Diffraction/isis_powder/routines/yaml_parser.py +++ b/scripts/Diffraction/isis_powder/routines/yaml_parser.py @@ -12,7 +12,7 @@ def get_run_dictionary(run_number_string, file_path): run_number_string = run_number_list[0] config_file = open_yaml_file_as_dictionary(file_path) - yaml_sanity.calibration_file_sanity_check(config_file) + yaml_sanity.calibration_file_sanity_check(config_file, file_path) run_key = _find_dictionary_key(dict_to_search=config_file, run_number=run_number_string) if not run_key: @@ -49,10 +49,15 @@ def _find_dictionary_key(dict_to_search, run_number): if is_run_range_key_unbounded(key): # Have an unbounded run don't generate numbers split_key = str(key).split('-') lower_key_bound = int(split_key[-2]) - if run_number > lower_key_bound: + if run_number >= lower_key_bound: return key else: - generated_runs = common.generate_run_numbers(run_number_string=key) + try: + generated_runs = common.generate_run_numbers(run_number_string=key) + except RuntimeError: + raise ValueError("Could not parse '" + str(key) + "'\n" + "This should be a range of runs in this cycle in the mapping file." + " Please check your indentation if this should be within a cycle.") if run_number in generated_runs: return key diff --git a/scripts/Diffraction/isis_powder/routines/yaml_sanity.py b/scripts/Diffraction/isis_powder/routines/yaml_sanity.py index 4d945b71ae6a19361aecfe3d5dbb9e8faff5780c..8227aecce194a2ffaa8f72f9f0299680d5d18699 100644 --- a/scripts/Diffraction/isis_powder/routines/yaml_sanity.py +++ b/scripts/Diffraction/isis_powder/routines/yaml_sanity.py @@ -1,7 +1,11 @@ from __future__ import (absolute_import, division, print_function) -def calibration_file_sanity_check(yaml_dict): +def calibration_file_sanity_check(yaml_dict, file_path): + # Check that the dictionary has data + if not yaml_dict: + raise ValueError("YAML dictionary appear to be empty at:\n" + str(file_path)) + # Check that we only have one unbounded range at maximum unbound_key_exists = _does_single_unbound_key_exist(yaml_dict) if unbound_key_exists: