def test_that_sanitises_instrument_names(self): name1 = sanitise_instrument_name("LOQ_trans") self.assertEqual(name1, LOQ) name2 = sanitise_instrument_name("sans2d") self.assertEqual(name2, SANS2D) name3 = sanitise_instrument_name("__LArMOR_") self.assertEqual(name3, LARMOR) name4 = sanitise_instrument_name("OThER") self.assertEqual(name4, "OThER")
def test_that_sanitises_instrument_names(self): name1 = sanitise_instrument_name("LOQ_trans") self.assertTrue(LOQ == name1) name2 = sanitise_instrument_name("sans2d") self.assertTrue(SANS2D == name2) name3 = sanitise_instrument_name("__LArMOR_") self.assertTrue(LARMOR == name3) name4 = sanitise_instrument_name("OThER") self.assertTrue("OThER" == name4)
def apply_missing_parameters(calibration_workspace, workspace, missing_parameters, parent_alg): """ Transfers missing properties from the data workspace to the calibration workspace. :param calibration_workspace: the calibration workspace. :param workspace: the data workspace. :param missing_parameters: a list of missing parameters which exist on the data workspace but not on the calibration workspace. :param parent_alg: a handle to the parent algorithm """ instrument = workspace.getInstrument() component_name = instrument.getName() component_name = sanitise_instrument_name(component_name) set_instrument_name = "SetInstrumentParameter" set_instrument_parameter_options = {"Workspace": calibration_workspace, "ComponentName": component_name} alg = create_child_algorithm(parent_alg, set_instrument_name, **set_instrument_parameter_options) # For now only string, int and double are handled type_options = {"string": "String", "int": "Number", "double": "Number"} value_options = {"string": instrument.getStringParameter, "int": instrument.getIntParameter, "double": instrument.getNumberParameter} try: for missing_parameter in missing_parameters: parameter_type = instrument.getParameterType(missing_parameter) type_to_save = type_options[parameter_type] value = value_options[parameter_type](missing_parameter) alg.setProperty("ParameterName", missing_parameter) alg.setProperty("ParameterType", type_to_save) alg.setProperty("Value", str(value[0])) except KeyError: raise RuntimeError("SANSCalibration: An Instrument Parameter File value of unknown type" "was going to be copied. Cannot handle this currently.")
def create_mover(workspace): # Get selection run_number = workspace.getRunNumber() instrument = workspace.getInstrument() instrument_name = instrument.getName() instrument_name = sanitise_instrument_name(instrument_name) instrument_type = SANSInstrument.from_string(instrument_name) if SANSMoveLOQ.is_correct(instrument_type, run_number): mover = SANSMoveLOQ() elif SANSMoveSANS2D.is_correct(instrument_type, run_number): mover = SANSMoveSANS2D() elif SANSMoveLARMOROldStyle.is_correct(instrument_type, run_number): mover = SANSMoveLARMOROldStyle() elif SANSMoveLARMORNewStyle.is_correct(instrument_type, run_number): mover = SANSMoveLARMORNewStyle() else: mover = None NotImplementedError("SANSLoaderFactory: Other instruments are not implemented yet.") return mover
def get_idf_path_from_workspace(workspace): """ Gets the full IDF path from a workspace. It queries the workspace for the start time and instrument name. It gets the IDF path from the ExperimentInfo. :param workspace: the workspace for which we want the full IDF path. :return: the full IDF path for the instrument of the workspace. """ run = workspace.run() instrument = workspace.getInstrument() instrument_name = instrument.getName() instrument_name = sanitise_instrument_name(instrument_name) if run.hasProperty("start_time"): time = run.getProperty("start_time").value idf_path = ExperimentInfo.getInstrumentFilename(instrument_name, time) elif run.hasProperty("run_start"): time = run.getProperty("run_start").value idf_path = ExperimentInfo.getInstrumentFilename(instrument_name, time) else: idf_path = None return idf_path
def create_mover(workspace): # Get selection run_number = workspace.getRunNumber() instrument = workspace.getInstrument() instrument_name = instrument.getName() instrument_name = sanitise_instrument_name(instrument_name) instrument_type = SANSInstrument.from_string(instrument_name) if SANSMoveLOQ.is_correct(instrument_type, run_number): mover = SANSMoveLOQ() elif SANSMoveSANS2D.is_correct(instrument_type, run_number): mover = SANSMoveSANS2D() elif SANSMoveLARMOROldStyle.is_correct(instrument_type, run_number): mover = SANSMoveLARMOROldStyle() elif SANSMoveLARMORNewStyle.is_correct(instrument_type, run_number): mover = SANSMoveLARMORNewStyle() elif SANSMoveZOOM.is_correct(instrument_type, run_number): mover = SANSMoveZOOM() else: mover = None NotImplementedError("SANSLoaderFactory: Other instruments are not implemented yet.") return mover