Пример #1
0
    def correct(self, workspaces, parent_alg):
        """
        For LOQ we want to apply a different instrument definition for the transmission runs.

        :param workspaces: a dictionary of data types, e.g. SampleScatter vs. a workspace
        :param parent_alg: a handle to the parent algorithm
        """
        # Get the transmission and the direct workspaces and apply the correction to them
        workspace_which_require_transmission_correction = []
        for data_type, _ in list(workspaces.items()):
            if is_transmission_type(data_type):
                workspace_which_require_transmission_correction.append(workspaces[data_type])

        # We want to apply a different instrument for the transmission runs

        for workspace in workspace_which_require_transmission_correction:
            assert len(workspace) == 1
            workspace = workspace[0]
            instrument = workspace.getInstrument()
            has_m4 = instrument.getComponentByName("monitor4")
            if has_m4 is None:
                trans_definition_file = os.path.join(config.getString('instrumentDefinition.directory'),
                                                     'LOQ_trans_Definition.xml')
            else:
                trans_definition_file = os.path.join(config.getString('instrumentDefinition.directory'),
                                                     'LOQ_trans_Definition_M4.xml')
            # Done
            instrument_name = "LoadInstrument"
            instrument_options = {"Workspace": workspace,
                                  "Filename": trans_definition_file,
                                  "RewriteSpectraMap": False}
            instrument_alg = create_child_algorithm(parent_alg, instrument_name, **instrument_options)
            instrument_alg.execute()
Пример #2
0
    def correct(self, workspaces, parent_alg):
        """
        For LOQ we want to apply a different instrument definition for the transmission runs.

        :param workspaces: a dictionary of data types, e.g. SampleScatter vs. a workspace
        :param parent_alg: a handle to the parent algorithm
        """
        # Get the transmission and the direct workspaces and apply the correction to them
        workspace_which_require_transmission_correction = []
        for data_type, _ in list(workspaces.items()):
            if is_transmission_type(data_type):
                workspace_which_require_transmission_correction.append(workspaces[data_type])

        # We want to apply a different instrument for the transmission runs

        for workspace in workspace_which_require_transmission_correction:
            assert len(workspace) == 1
            workspace = workspace[0]
            instrument = workspace.getInstrument()
            has_m4 = instrument.getComponentByName("monitor4")
            if has_m4 is None:
                trans_definition_file = os.path.join(config.getString('instrumentDefinition.directory'),
                                                     'LOQ_trans_Definition.xml')
            else:
                trans_definition_file = os.path.join(config.getString('instrumentDefinition.directory'),
                                                     'LOQ_trans_Definition_M4.xml')
            # Done
            instrument_name = "LoadInstrument"
            instrument_options = {"Workspace": workspace,
                                  "Filename": trans_definition_file,
                                  "RewriteSpectraMap": False}
            instrument_alg = create_child_algorithm(parent_alg, instrument_name, **instrument_options)
            instrument_alg.execute()
Пример #3
0
    def test_service_acts_like_dictionary(self):
        dictcall = config.get("property_not_found")
        self.assertEqual(dictcall, "")

        test_prop = "projectRecovery.secondsBetween"
        self.assertTrue(config.hasProperty(test_prop))
        dictcall = config[test_prop]
        fncall = config.getString(test_prop)

        # Use brackets to retrieve a value
        dictcall = config[test_prop]
        self.assertEqual(dictcall, fncall)
        self.assertNotEqual(config[test_prop], "")

        # Use "get" to retrieve a value or a default
        dictcall = config.get(test_prop, "other")
        self.assertEqual(dictcall, fncall)
        dictcall = config.get("property_not_found", "default_alternative")
        self.assertEqual(dictcall, "default_alternative")

        old_value = fncall
        config.setString(test_prop, "1")
        self.assertEqual(config.getString(test_prop), "1")
        config[test_prop] = "2"
        self.assertEqual(config.getString(test_prop), "2")

        config.setString(test_prop, old_value)
Пример #4
0
    def test_service_acts_like_dictionary(self):
        test_prop = "algorithms.retained"
        self.assertTrue(config.hasProperty(test_prop))
        dictcall = config[test_prop]
        fncall = config.getString(test_prop)
        self.assertEquals(dictcall, fncall)
        self.assertNotEqual(config[test_prop], "")

        old_value = fncall
        config.setString(test_prop, "1")
        self.assertEquals(config.getString(test_prop), "1")
        config[test_prop] = "2"
        self.assertEquals(config.getString(test_prop), "2")

        config.setString(test_prop, old_value)
Пример #5
0
    def test_service_acts_like_dictionary(self):
        test_prop = "projectRecovery.secondsBetween"
        self.assertTrue(config.hasProperty(test_prop))
        dictcall = config[test_prop]
        fncall = config.getString(test_prop)
        self.assertEqual(dictcall, fncall)
        self.assertNotEqual(config[test_prop], "")

        old_value = fncall
        config.setString(test_prop, "1")
        self.assertEqual(config.getString(test_prop), "1")
        config[test_prop] = "2"
        self.assertEqual(config.getString(test_prop), "2")

        config.setString(test_prop, old_value)
Пример #6
0
    def test_service_acts_like_dictionary(self):
        test_prop = "algorithms.retained"
        self.assertTrue(config.hasProperty(test_prop))
        dictcall = config[test_prop]
        fncall = config.getString(test_prop)
        self.assertEquals(dictcall, fncall)
        self.assertNotEqual(config[test_prop], "")

        old_value = fncall
        config.setString(test_prop, "1")
        self.assertEquals(config.getString(test_prop), "1")
        config[test_prop] =  "2"
        self.assertEquals(config.getString(test_prop), "2")

        config.setString(test_prop, old_value)
Пример #7
0
 def _load_empty_instrument(self):
     """Returns an empty workspace for the instrument.
     Raises: 
         * ValueError if no instrument is selected.
         * RuntimeError if there is a problem with the IDF.
     """
     if self._instrument_name is None:
         raise ValueError('No instrument selected.')
     self._workspace_instrument = '__empty_' + self._instrument_name
     if not mtd.doesExist(self._workspace_instrument):
         idf_dir = config.getString('instrumentDefinition.directory')
         idf = idf_dir + self._instrument_name + '_Definition.xml'
         try:
             LoadEmptyInstrument(Filename=idf,OutputWorkspace= self._workspace_instrument)
         except RuntimeError:
             raise ValueError('Invalid IDF')
     return mtd[self._workspace_instrument]
    def _create_test_wavelength_adjustment_file(file_name):
        test_file = ("  Tue 24-MAR-2015 00:02 Workspace: directbeam_new_hist\n"
                     "\n"
                     "  6    0    0    0    1  6    0\n"
                     "         0         0         0         0\n"
                     " 3 (F12.5,2E16.6)\n"
                     "     1.00000    5.000000e-01    5.000000e-01\n"
                     "     3.00000    5.000000e-01    5.000000e-01\n"
                     "     5.00000    5.000000e-01    5.000000e-01\n"
                     "     7.00000    5.000000e-01    5.000000e-01\n"
                     "     9.00000    5.000000e-01    5.000000e-01\n"
                     "    11.00000    5.000000e-01    5.000000e-01\n")

        full_file_path = os.path.join(config.getString('defaultsave.directory'), file_name)
        if os.path.exists(full_file_path):
            os.remove(full_file_path)

        with open(full_file_path, 'w') as f:
            f.write(test_file)
        return full_file_path
Пример #9
0
    def run(self, sample):
        """
        Run the export algorithms on a sample. For each export algorithm, the
        function will try to validate the criteria (using _validCriteria()) on
        the output workspace that corresponds to the sample. If the criteria are
        valid, the export will be run on all workspaces whose name contains the
        sample name.

        Args:
            sample (DrillSample): sample to be exported
        """
        exportPath = config.getString("defaultsave.directory")
        if not exportPath:
            logger.warning("Default save directory is not defined. Please "
                           "specify one in the data directories dialog to "
                           "enable exports.")
            return
        workspaceName = sample.getOutputName()

        try:
            outputWs = mtd[workspaceName]
            if isinstance(outputWs, WorkspaceGroup):
                names = outputWs.getNames()
                outputWs = names[0]
            else:
                outputWs = workspaceName
        except:
            return

        tasks = list()
        for algo,active in self._exportAlgorithms.items():
            if not active:
                continue
            if not self._validCriteria(outputWs, algo):
                logger.notice("Export of sample {} with {} was skipped "
                              "because workspaces are not compatible."
                              .format(outputWs, algo))
                continue

            for wsName in mtd.getObjectNames(contain=workspaceName):
                if isinstance(mtd[wsName], WorkspaceGroup):
                    continue

                filename = os.path.join(
                        exportPath,
                        wsName + RundexSettings.EXPORT_ALGO_EXTENSION[algo])
                name = wsName + ":" + filename
                if wsName not in self._exports:
                    self._exports[wsName] = set()
                self._exports[wsName].add(filename)
                kwargs = {}
                if 'Ascii' in algo:
                    log_list = mtd[wsName].getInstrument().getStringParameter('log_list_to_save')
                    if log_list:
                        log_list = log_list[0].split(',')
                        kwargs['LogList'] = [log.strip() for log in log_list] # removes white spaces
                    if 'Reflectometry' in algo:
                        kwargs['WriteHeader'] = True
                        kwargs['FileExtension'] = 'custom'
                    else:
                        kwargs['WriteXError'] = True
                task = DrillTask(name, algo, InputWorkspace=wsName,
                                 FileName=filename, **kwargs)
                task.addSuccessCallback(lambda wsName=wsName, filename=filename:
                                        self._onTaskSuccess(wsName, filename))
                task.addErrorCallback(lambda msg, wsName=wsName,
                                             filename=filename:
                                      self._onTaskError(wsName, filename, msg))
                tasks.append(task)

        self._pool.addProcesses(tasks)