Skip to content
Snippets Groups Projects
Commit 92c1e56d authored by David Fairbrother's avatar David Fairbrother
Browse files

Re #18108 Read from basic setup config file

parent 77c66308
No related branches found
No related tags found
No related merge requests found
......@@ -65,9 +65,6 @@ class Pearl(AbstractInst):
def _get_lambda_range(self):
return self._lambda_lower, self._lambda_upper
# Methods #
def get_run_details(self, run_number):
# TODO once we migrate this to another format (i.e. not the if/elif/else) implement cached val
cycle_dict = self._get_cycle_factory_dict(run_number=run_number)
......@@ -77,6 +74,7 @@ class Pearl(AbstractInst):
run_details.instrument_version = cycle_dict["instrument_version"]
return run_details
@staticmethod
def _get_cycle_factory_dict(self, run_number):
# TODO remove this when we move to combining CAL/RUN factories
run_input = ""
......
......@@ -6,8 +6,7 @@ import mantid.simpleapi as mantid
import isis_powder.routines.common as common
from isis_powder.abstract_inst import AbstractInst
from isis_powder.polaris_routines import polaris_algs, polaris_output
from isis_powder.routines.RunDetails import RunDetails
from isis_powder.polaris_routines import polaris_algs, polaris_config_parser, polaris_output
class Polaris(AbstractInst):
......@@ -15,17 +14,20 @@ class Polaris(AbstractInst):
_masking_file_name = "VanaPeaks.dat"
_number_of_banks = 5
def __init__(self, user_name, chopper_on, apply_solid_angle=True,
calibration_dir=None, output_dir=None, **kwargs):
def __init__(self, chopper_on, config_file=None, **kwargs):
_set_kwargs_from_basic_config_file(config_path=config_file, kwargs=kwargs)
# Have to pass in everything through named types until abstract_inst takes kwargs
super(Polaris, self).__init__(user_name=kwargs["user_name"], calibration_dir=kwargs["calibration_directory"],
output_dir=kwargs["output_directory"], kwargs=kwargs)
super(Polaris, self).__init__(user_name=user_name, calibration_dir=calibration_dir,
output_dir=output_dir, kwargs=kwargs)
self._chopper_on = chopper_on
self._apply_solid_angle = apply_solid_angle
self._apply_solid_angle = kwargs["apply_solid_angle"]
self._spline_coeff = 100
# Caches the last dictionary to avoid us having to keep parsing the YAML
# Hold the last dictionary later to avoid us having to keep parsing the YAML
self._run_details_last_run_number = None
self._run_details_cached_obj = None
......@@ -42,11 +44,11 @@ class Polaris(AbstractInst):
do_absorb_corrections=do_absorb_corrections,
gen_absorb_correction=gen_absorb_correction)
# Abstract implementation
def get_default_group_names(self):
return self._calibration_grouping_names
# Abstract implementation
def get_run_details(self, run_number):
if self._run_details_last_run_number == run_number:
return self._run_details_cached_obj
......@@ -132,3 +134,32 @@ class Polaris(AbstractInst):
output_paths=output_paths, run_number=run_details.run_number)
return d_spacing_group, tof_group
def _set_kwargs_from_basic_config_file(config_path, kwargs):
if config_path:
basic_config_dict = polaris_config_parser.get_basic_config(file_path=config_path)
else:
# Create an empty dictionary so we still get error checking below and nicer error messages
basic_config_dict = {}
# Set any unset properties:
key = "user_name"
_set_from_config_kwargs_helper(config_dictionary=basic_config_dict, kwargs=kwargs, key=key)
key = "calibration_directory"
_set_from_config_kwargs_helper(config_dictionary=basic_config_dict, kwargs=kwargs, key=key)
key = "output_directory"
_set_from_config_kwargs_helper(config_dictionary=basic_config_dict, kwargs=kwargs, key=key)
key = "apply_solid_angle"
_set_from_config_kwargs_helper(config_dictionary=basic_config_dict, kwargs=kwargs, key=key)
def _set_from_config_kwargs_helper(config_dictionary, kwargs, key):
error_first = "Setting with name: '"
error_last = "' was not passed in the call or set in the basic config."
kwarg_value = kwargs.get(key, None)
if not kwarg_value:
# Only try to parse it if it wasn't passed
value = common.dictionary_key_helper(dictionary=config_dictionary, key=key, throws=True,
exception_msg=(error_first + key + error_last))
kwargs[key] = value
# Basic setup
user_name : "Mantid"
apply_solid_angle : "True"
calibration_directory : ""
output_directory : ""
advanced_config_file : "Not Set"
\ No newline at end of file
from __future__ import (absolute_import, division, print_function)
import os
import yaml
import isis_powder.routines.common
......
# NOTE: All of the data below is TEST data - it is not representitive of any actual cycles/data values used
# NOTE: All of the data below is TEST data -
# it is not representative of any actual cycles/data values used
78334-82415:
offset_file_name : "offsets_2011_cycle111b.cal"
......@@ -24,7 +25,7 @@
empty_run_numbers : "93106"
95600-95614:
95600-95614,97000:
# Calibration run
offset_file_name : "offsets_2011_cycle111b.cal"
label : "16_4"
......@@ -35,3 +36,13 @@
vanadium_run_numbers : "95603-95607,95613-95614"
empty_run_numbers : "78339"
exceptions:
1234:
offset_file_name : "offsets_2011_cycle111b.cal"
label : "16_4"
chopper_on:
vanadium_run_numbers : "95603-95607,95613-95614"
empty_run_numbers : "78339"
chopper_off:
vanadium_run_numbers : "95603-95607,95613-95614"
empty_run_numbers : "78339"
from __future__ import (absolute_import, division, print_function)
import yaml
import os
def get_basic_config(file_path):
# At the moment we just return it without additional processing
return _open_yaml_file(file_path=file_path)
def _open_yaml_file(file_path):
if not os.path.isfile(file_path):
raise ValueError("File not found at: " + str(file_path))
read_config = None
with open(file_path, 'r') as yaml_stream:
try:
read_config = yaml.load(yaml_stream)
except yaml.YAMLError as exception:
raise ValueError("Failed to parse YAML. Exception was:\n" + str(exception))
return read_config
......@@ -16,6 +16,20 @@ def create_calibration_by_names(calibration_runs, startup_objects, grouping_file
out_grouping_file_name=grouping_file_name, instrument=startup_objects)
def dictionary_key_helper(dictionary, key, throws=True, exception_msg=None):
if key in dictionary:
return dictionary[key]
elif not throws:
return None
elif exception_msg:
# Print user specified message
raise KeyError(exception_msg)
else:
# Raise default python key error:
this_throws = dictionary[key]
return this_throws # Never gets this far just makes linters happy
def extract_bank_spectra(ws_to_split, num_banks):
spectra_bank_list = []
for i in range(0, num_banks):
......@@ -51,10 +65,8 @@ def get_monitor_ws(ws_to_process, run_number_string, instrument):
def load_current_normalised_ws(run_number_string, instrument):
read_in_ws = _load_raw_files(run_number_string=run_number_string, instrument=instrument)
run_information = instrument.get_run_details(run_number=run_number_string)
read_in_ws = _load_raw_files(run_number_string=run_number_string, instrument=instrument)
read_ws = instrument.normalise_ws(ws_to_correct=read_in_ws, run_details=run_information)
output_name = "read_ws_output-" + str(g_ads_workaround["read_ws"])
......
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