Пример #1
0
    def addReflections(self, file, points):
        "add reflection points from a set in the 'points' argument for a file in the argument"
        if file in self.addedReflections:
            self.addedReflections[file].update(points)
        else:
            self.addedReflections[file] = points

        if file in self.reflections:
            self.reflections[file].update(points)
        else:
            if file in self.pairedfiles:
                cm = m.CL(file, self.pairedfiles[file])
            else:
                cm = m.CL(file, "auto")
            reflections = cm.findReflections(results = "indices")
            self.reflections[file] = set(reflections[0]) | set(reflections[1]) | points
Пример #2
0
    def processFun(self):
        "processes chosen files and saves the results in the save-to file"
        # files to be processed
        self.filesToProcess = [file for file in self.fileStorage if \
                               self.optionFrame.processFile(file)]

        # checking for mistakes
        try:
            self.processCheck()
        except Exception as e:
            self.bell()
            self.status.set(e)
            return                   

        # progressWindow
        if len(self.filesToProcess) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self, len(self.filesToProcess))     

        # initializations
        output = self.saveToFrame.saveToVar.get()
        if not os.path.splitext(output)[1]:
            output = output + optionGet("DefProcessOutputFileType", ".txt", "str", True)
        if not os.path.dirname(output):
            output = os.path.join(optionGet("ResultDirectory", os.getcwd(), "str", True), output)
        startTime = float(self.timeFrame.startTimeVar.get())
        time = float(self.timeFrame.timeVar.get())
        separator = optionGet("ResultSeparator", ",", "str", True)
        batchTime = self.selectedBatchTime if self.useBatchTimeVar.get() else None
        self.someProblem = False
        developer = optionGet("Developer", False, 'bool', True)

        # selected methods          
        methods = OrderedDict()
        parameters = m.parameters
        for name, par in parameters.items():
            if eval("self.parametersF.%sVar.get()" % (name.replace(" ", ""))):
                options = {name: optionGet(*option[0]) for name, option in par.options.items()}
                if not self.useBatchTimeVar.get():
                    methods[name] = [methodcaller(par.method, startTime = startTime,
                                                  time = time, **options)]
                elif name not in parameters.noBatch:
                    methods[name] = [methodcaller(par.method, startTime = times[0],
                                                  time = times[1], **options)
                                     for times in batchTime]
                else:
                    methods[name] = [methodcaller(par.method, **options)]

        # log
        self.log = Log(methods, startTime, time, self.filesToProcess, self.fileStorage,
                       self.optionFrame.removeReflectionsWhere.get(), output,
                       batchTime = batchTime)
                    
        # results header
        if self.useBatchTimeVar.get():
            results = ["File"]
            for method in methods:
                if method in parameters.noBatch:
                    results.append(method)
                else:
                    results.extend([method + " ({}-{})".format(start, end) for
                                    start, end in self.selectedBatchTime])
            results = separator.join(results)
        else:
            results = separator.join(["File"] + [method for method in methods])
        if self.optionFrame.saveTags.get():
            results += separator + "Tag"
        if self.optionFrame.saveComments.get():
            results += separator + "Comment"
        
        # computing of results
        for file in self.filesToProcess:
            # loading of cm object
            if methods:
                try:
                    if file in self.fileStorage.pairedfiles:
                        cm = m.CL(file, self.fileStorage.pairedfiles[file])
                    else:
                        cm = m.CL(file, "auto")

                    if self.optionFrame.removeReflections(file):
                        cm.removeReflections(points = self.fileStorage.reflections.get(file,
                                                                                            None))
                except Exception as e:
                    if developer:
                        print(e)   
                    filename = returnName(filename = file, allFiles =
                                          self.fileStorage.arenafiles) 
                    results += "\n" + filename + "{}NA".format(separator) * len(methods)
                    self.log.failedToLoad.append(file)
                    self.someProblem = True
                    continue
                                
            result = []

            for name, funcs in methods.items():
                for func in funcs:                        
                    try:
                        #if method[2] == "custom":
                            #exec("from Stuff.Parameters import {}".format(method[5]))               
                        result.append(func(cm))
                    except Exception as e:
                        if developer:
                            print(e)   
                        result.append("NA")
                        self.log.methodProblems[name].append(file)
                        self.someProblem = True

            result = separator.join(map(str, result))
            if methods:
                result = separator + result               
            filename = returnName(filename = file, allFiles = self.fileStorage.arenafiles)      
            results += "\n" + filename + result
            
            # tag inclusion in results
            if self.optionFrame.saveTags.get(): 
                if file in self.fileStorage.tagged:
                    results += separator + "1"
                else:
                    results += separator + "0"

            # comment inclusion in results
            if self.optionFrame.saveComments.get():
                results += separator + self.fileStorage.comments[file]
                    
            # progress window update
            if len(self.filesToProcess) > 1:
                if self.stoppedProcessing:
                    writeResults(output, results)
                    self.log.stopped = file
                    self.log.writeLog()
                    self.status.set("Processing stopped")
                    return
                else:
                    self.progressWindow.addOne()

        # results and log writing, ending of processing
        writeResults(output, results)
        self.log.writeLog()
        self._setStatusEndProgressWindow()

        if self.someProblem:
            ProcessingProblemDialog(self, self.log.filename, output)
        elif self.optionFrame.showResults.get():
            os.startfile(output)   
Пример #3
0
 def _initializeCM(self, file):
     "initializes self.cm"
     if file in self.fileStorage.pairedfiles:
         self.cm = m.CL(file, self.fileStorage.pairedfiles[file])
     else:
         self.cm = m.CL(file, "auto")
Пример #4
0
    def controlFun(self):
        "processes selected files, clears report, shows results in a report"

        # progressbar
        if len(self.fileStorage) > 1:
            self.stoppedProcessing = False
            self.progressWindow = ProgressWindow(self,
                                                 len(self.fileStorage),
                                                 text="controlled")

        # initialization
        controls = self.controlFrame.controlsGet()  # selected controls
        self.controlReport.clear()  # clears report
        self.controlReport.addControls(
            controls)  # adds selected controls to ControlReport

        self.problemOccured = False
        # processing
        for file in self.fileStorage:
            tag = "x" if file in self.fileStorage.tagged else " "
            try:
                if file in self.fileStorage.pairedfiles:
                    cm = m.CL(file, self.fileStorage.pairedfiles[file])
                else:
                    cm = m.CL(file, "auto")
            except Exception:
                self.problemOccured = True
                for control in controls:
                    self.controlReport.addFile(
                        (control[0],
                         [file, "Failed to load!", "Problem", 9999999, tag]))
            else:
                for control in controls:
                    try:
                        assessment = self.assessImportance(cm=cm,
                                                           control=control,
                                                           file=file)
                        assessment[1].append(tag)
                    except Exception:
                        self.problemOccured = True
                        assessment = (control[0], [
                            file, "Failed to compute!", "Problem", 9999998, tag
                        ])
                    self.controlReport.addFile(assessment)

            if len(self.fileStorage) > 1:
                if self.stoppedProcessing:
                    return
                else:
                    self.progressWindow.addOne()

        self.controlReport.updateTree()

        # progressbar and status
        if len(self.fileStorage) > 1:
            self.progressWindow.destroy()
            if self.problemOccured:
                self.status.set("Files were not processed successfully!")
                self.bell()
            else:
                self.status.set("Files were processed successfully.")
        else:
            if self.problemOccured:
                self.status.set("File was not processed successfully!")
                self.bell()
            else:
                self.status.set("File was processed successfully.")