Esempio n. 1
0
def convertToRST(algName, tempDir, convertedDir, version):

    #Set input name and change working directory
    inputN = algName+'.txt'
    outputN = algName+'.rst'        
    
    cwd = os.getcwd()
    os.chdir(tempDir)
    args = ['pandoc', '-f', 'mediawiki', '-t', 'rst', inputN, '-o', outputN]
    #run pandoc and wait for output
    obj = subprocess.Popen(args)    
    obj.wait()  

    os.chdir(cwd)

    #move completed rst file into completed folder for tidyness
    mvFile = tempDir+algName+'.rst'

    destname = None
    if AlgorithmFactory.exists(algName):
        destname = convertedDir + "/algorithms/" + algName + "-v" + str(version) + ".rst"
    elif AlgorithmFactory.exists(algName[:-1]):
        destname = convertedDir + "/algorithms/" + algName[:-1] + "-v" + str(version) + ".rst"
    elif algName in FUNC_NAMES:
        destname = convertedDir + "/functions/" + algName + ".rst"
    elif "USAGE" in algName:
        destname = convertedDir + algName + ".rst"
    else:
        unknowns_file = open("unknowns.txt", 'a')
        unknowns_file.write("Unknown object type %s\n" % algName)
        unknowns_file.close()
        return

    shutil.move(mvFile, destname)
Esempio n. 2
0
def create(algName, convertedDir):
    #read the rst content in
    with open (convertedDir+algName+'.rst', 'r') as rstFile:
        rst=rstFile.read()
    
    #remove extra whitespace and newlines from the end of the documentation
    rst = rst.rstrip()
    template_dir = os.path.dirname(__file__)

    if AlgorithmFactory.exists(algName):
        template_file = os.path.join(template_dir,'algorithm_template.rst')
    elif AlgorithmFactory.exists(algName[:-3]):
        template_file = os.path.join(template_dir,'algorithm_template.rst')
    elif algName in FUNC_NAMES:
        template_file = os.path.join(template_dir,'function_template.rst')
    elif "USAGE" in algName:
        raise RuntimeError("Usage section rst encountered in directive insertion: %s" % algName)
    else:
        raise RuntimeError("Unknown object in directive insertion: %s" % algName)

    with open (template_file, 'r') as templateFile:
        template=templateFile.read()

    built = template.replace('[TITLE]', "="*len(algName) + "\n" + algName + "\n" + "="*len(algName) + "\n")
    built = built.replace('[DOCUMENTATION]', rst)
    
    builtFile = open(convertedDir+algName+'.rst', 'w')
    builtFile.write(built)
 def test_getDescriptors(self):
     from mantid import AlgorithmFactory
     descriptors = AlgorithmFactory.getDescriptors(True)
     self.assertGreater(len(descriptors), 0)
     d = descriptors[0]
     self.assertFalse(isinstance(d, AlgorithmDescriptorMock))
     self.assertTrue(hasattr(d, 'name'))
     self.assertTrue(hasattr(d, 'alias'))
     self.assertTrue(hasattr(d, 'category'))
     self.assertTrue(hasattr(d, 'version'))
Esempio n. 4
0
    def get_algorithm_data(self):
        """
        Prepare the algorithm description data for displaying in the view.
        :return: A tuple of two elements. The first is a list of all algorithm names.
            The second is a tree of nested dicts where keys either category names
            or self.algorithm_key. Values of the category names are sub-trees
            and those of self.algorithm_key have dicts mapping algorithm names
            to lists of their versions. For example (as yaml):

                Arithmetic:
                  Errors:
                    _:
                      PoissonErrors: [1]
                      SetUncertainties: [1]
                      SignalOverError: [1]
                  FFT:
                    _:
                      ExtractFFTSpectrum: [1]
                      FFT: [1]
                      FFTDerivative: [1]
                      FFTSmooth: [1, 2]
                  _:
                    CrossCorrelate: [1]
                    Divide: [1]
                    Exponential: [1]
                    GeneralisedSecondDifference: [1]

            Here self.algorithm_key == '_'

        """
        descriptors = AlgorithmFactory.getDescriptors(self.include_hidden)
        algorithm_names = []
        data = {}
        for descriptor in descriptors:
            # descriptor is a class with data fields: name, alias, category, version
            if descriptor.name not in algorithm_names:
                algorithm_names.append(descriptor.name)
            categories = descriptor.category.split('\\')
            # Create nested dictionaries in which the key is a category and the value
            # is a similar dictionary with sub-categories as keys
            d = data
            for cat in categories:
                if cat not in d:
                    d[cat] = {}
                d = d[cat]
            # Entry with key == '' contains a dict with algorithm names as keys
            # The values are lists of version numbers
            if self.algorithm_key not in d:
                d[self.algorithm_key] = {}
            d = d[self.algorithm_key]
            if descriptor.name not in d:
                d[descriptor.name] = []
            d[descriptor.name].append(descriptor.version)
        return algorithm_names, data
Esempio n. 5
0
    ties = []
    kwargs = {}
    num_spectra = mtd[input_ws].getNumberHistograms()
    for i in range(0, num_spectra):
        multi += comp
        kwargs['WorkspaceIndex_' + str(i)] = i

        if i > 0:
            kwargs['InputWorkspace_' + str(i)] = input_ws

            # tie beta for every spectrum
            for stretched_index in stretched_indices:
                ties.append('f{0}.f{1}.Stretching=f0.f{1}.Stretching'.format(i, stretched_index))

    ties = ','.join(ties)
    multi += 'ties=(' + ties + ')'

    return multi, kwargs


def _find_indices_of_stretched_exponentials(composite):
    indices = []

    for index in range(0, len(composite)):
        if composite.getFunction(index).name() == "StretchExp":
            indices.append(index)
    return indices


AlgorithmFactory.subscribe(IqtFitMultiple)
Esempio n. 6
0
            'fit_type': self._fit_type,
            'intensities_constrained': self._intensities_constrained,
            'beta_constrained': False
        }

        copy_log_alg = self.createChildAlgorithm("CopyLogs")
        copy_log_alg.setProperty("InputWorkspace", self._input_ws)
        copy_log_alg.setProperty("OutputWorkspace", self._fit_group_name)
        copy_log_alg.execute()
        copy_log_alg.setProperty("InputWorkspace", self._input_ws)
        copy_log_alg.setProperty("OutputWorkspace", self._result_ws.getName())
        copy_log_alg.execute()

        log_names = [item for item in sample_logs]
        log_values = [sample_logs[item] for item in sample_logs]

        add_sample_log_multi = self.createChildAlgorithm(
            "AddSampleLogMultiple")
        add_sample_log_multi.setProperty("Workspace",
                                         self._result_ws.getName())
        add_sample_log_multi.setProperty("LogNames", log_names)
        add_sample_log_multi.setProperty("LogValues", log_values)
        add_sample_log_multi.execute()
        add_sample_log_multi.setProperty("Workspace", self._fit_group_name)
        add_sample_log_multi.setProperty("LogNames", log_names)
        add_sample_log_multi.setProperty("LogValues", log_values)
        add_sample_log_multi.execute()


AlgorithmFactory.subscribe(IqtFitSequential)
Esempio n. 7
0
        self.declareProperty(name="TimeMax", defaultValue=0.2, validator=FloatMandatoryValidator(),
                             doc="Multiplicative scale factor")
        self.declareProperty(name='Plot', defaultValue='None', validator=StringListValidator(['None', 'Intensity', 'Tau', 'Beta', 'All']),
                             doc='Switch Plot Off/On')

    def PyExec(self):
        from IndirectDataAnalysis import furyfitMult

        workdir = config['defaultsave.directory']
        inType = self.getProperty('InputType').value
        prefix = self.getProperty('Instrument').value
        ana = self.getProperty('Analyser').value
        RunNumb = self.getProperty('RunNumber').value
        xMax = self.getProperty('TimeMax').value
        filename = prefix + str(RunNumb) + '_' + ana
        plotOp = self.getProperty('Plot').value
        inWS = filename + '_iqt'
        if inType == 'File':
            spath = os.path.join(workdir, inWS + '.nxs')  # path name for sample nxs file
            logger.notice('Input from File : ' + spath)
            LoadNexusProcessed(Filename=spath, OutputWorkspace=inWS)
        else:
            logger.notice('Input from Workspace : ' + inWS)
        CropWorkspace(InputWorkspace=inWS, OutputWorkspace=inWS, XMin=0.0, XMax=xMax)
        function = 'name=LinearBackground,A0=0.02,A1=0,ties=(A1=0);'
        function +=     'name=UserFunction,Formula=Intensity*exp(-(x/Tau)^Beta),Intensity=0.98,Tau=0.02,Beta=0.8'

        furyfitMult(inWS, function, 'SSSS', 0.0, 0.2, False, plotOp, True)

AlgorithmFactory.subscribe(FuryFitMultiple)
Esempio n. 8
0
        """
        Copy the sample logs from the input workspace and add them to the output workspaces
        """

        sample_logs = {'start_x': self._start_x, 'end_x': self._end_x, 'fit_type': self._fit_type,
                       'intensities_constrained': self._intensities_constrained, 'beta_constrained': False}

        copy_log_alg = self.createChildAlgorithm("CopyLogs", enableLogging=False)
        copy_log_alg.setProperty("InputWorkspace", self._input_ws)
        copy_log_alg.setProperty("OutputWorkspace", self._fit_group_name)
        copy_log_alg.execute()
        copy_log_alg.setProperty("InputWorkspace", self._input_ws)
        copy_log_alg.setProperty("OutputWorkspace", self._result_ws.name())
        copy_log_alg.execute()

        log_names = [item for item in sample_logs]
        log_values = [sample_logs[item] for item in sample_logs]

        add_sample_log_multi = self.createChildAlgorithm("AddSampleLogMultiple", enableLogging=False)
        add_sample_log_multi.setProperty("Workspace", self._result_ws.name())
        add_sample_log_multi.setProperty("LogNames", log_names)
        add_sample_log_multi.setProperty("LogValues", log_values)
        add_sample_log_multi.execute()
        add_sample_log_multi.setProperty("Workspace", self._fit_group_name)
        add_sample_log_multi.setProperty("LogNames", log_names)
        add_sample_log_multi.setProperty("LogValues", log_values)
        add_sample_log_multi.execute()


AlgorithmFactory.subscribe(IqtFitSequential)
    def PyExec(self):
        from IndirectDataAnalysis import furyfitMult

        workdir = config['defaultsave.directory']
        inType = self.getProperty('InputType').value
        prefix = self.getProperty('Instrument').value
        ana = self.getProperty('Analyser').value
        RunNumb = self.getProperty('RunNumber').value
        xMax = self.getProperty('TimeMax').value
        filename = prefix + str(RunNumb) + '_' + ana
        plotOp = self.getProperty('Plot').value
        inWS = filename + '_iqt'
        if inType == 'File':
            spath = os.path.join(workdir, inWS +
                                 '.nxs')  # path name for sample nxs file
            logger.notice('Input from File : ' + spath)
            LoadNexusProcessed(Filename=spath, OutputWorkspace=inWS)
        else:
            logger.notice('Input from Workspace : ' + inWS)
        CropWorkspace(InputWorkspace=inWS,
                      OutputWorkspace=inWS,
                      XMin=0.0,
                      XMax=xMax)
        function = 'name=LinearBackground,A0=0.02,A1=0,ties=(A1=0);'
        function += 'name=UserFunction,Formula=Intensity*exp(-(x/Tau)^Beta),Intensity=0.98,Tau=0.02,Beta=0.8'

        furyfitMult(inWS, function, 'SSSS', 0.0, 0.2, False, plotOp, True)


AlgorithmFactory.subscribe(FuryFitMultiple)