Exemple #1
0
    def loadModuleDictionaryFromDisk(self, _strPath):
        """
        Loads the cache from disk.

        @param _strPath: Path to the module dictionary XML file
        @type _strPath: python string
        """
        #strPath = None
        strEdnaHome = EDUtilsPath.EDNA_HOME
        self.__dictModuleLocation = {}
        try:
            xsDataDictionaryPlugin = XSDataDictionary.parseFile(_strPath)
            for xsDataKeyValuePair in xsDataDictionaryPlugin.getKeyValuePair():
                strModuleName = xsDataKeyValuePair.getKey().getValue()
                strModuleLocationRelative = xsDataKeyValuePair.getValue(
                ).getValue()
                strModuleLocationAbsolute = os.path.abspath(
                    os.path.join(strEdnaHome, strModuleLocationRelative))
                if not os.path.exists(strModuleLocationAbsolute):
                    raise BaseException(
                        "Path loaded from disk does not exist: %s" %
                        strModuleLocationAbsolute)
                self.__dictModuleLocation[
                    strModuleName] = strModuleLocationAbsolute
        except BaseException, oExcpetionType:
            self.warning("Error when reading module cache from disk: %s" %
                         str(oExcpetionType))
            self.warning("Forcing reload of module locations.")
            self.__searchRootDirectories()
            self.saveModuleDictionaryToDisk(_strPath)
    def loadModuleDictionaryFromDisk(self, _strPath):
        """
        Loads the cache from disk.

        @param _strPath: Path to the module dictionary XML file
        @type _strPath: python string
        """
        #strPath = None
        strEdnaHome = EDUtilsPath.EDNA_HOME
        self.__dictModuleLocation = {}
        try:
            xsDataDictionaryPlugin = XSDataDictionary.parseFile(_strPath)
            for xsDataKeyValuePair in xsDataDictionaryPlugin.getKeyValuePair():
                strModuleName = xsDataKeyValuePair.getKey().getValue()
                strModuleLocationRelative = xsDataKeyValuePair.getValue().getValue()
                strModuleLocationAbsolute = os.path.abspath(os.path.join(strEdnaHome, strModuleLocationRelative))
                if not os.path.exists(strModuleLocationAbsolute):
                    self.warning("Path loaded from disk does not exist: %s" % strModuleLocationAbsolute)
                else:
                    self.__dictModuleLocation[ strModuleName ] = strModuleLocationAbsolute
        except Exception as oExcpetionType:
            self.warning("Error when reading module cache from disk: %s" % str(oExcpetionType))
            self.warning("Forcing reload of module locations.")
            self.__searchRootDirectories()
            self.saveModuleDictionaryToDisk(_strPath)
Exemple #3
0
    def saveModuleDictionaryToDisk(self, _strPath):
        """
        This method saves the module dictionary to disk in form of XML.
        This method should be private but is kept public in order to be unit tested.

        @param _strPath: Path to the module dictionary XML file
        @type _strPath: python string
        """
        xsDataDictionaryPlugin = XSDataDictionary()
        strEdnaHome = EDUtilsPath.EDNA_HOME
        for strModule in self.__dictModuleLocation:
            xsDataKeyValuePair = XSDataKeyValuePair()
            xsDataKeyValuePair.setKey(XSDataString(strModule))
            strModuleLocation = self.__dictModuleLocation[strModule]
            # Remove the path up to $EDNA_HOME
            strModuleLocationStripped = strModuleLocation.replace(
                strEdnaHome, "")
            if (strModuleLocationStripped.startswith("/")
                    or strModuleLocationStripped.startswith("\\")):
                strModuleLocationStripped = strModuleLocationStripped[1:]
            xsDataKeyValuePair.setValue(
                XSDataString(strModuleLocationStripped))
            xsDataDictionaryPlugin.addKeyValuePair(xsDataKeyValuePair)
        try:
            xsDataDictionaryPlugin.exportToFile(_strPath)
        except Exception:
            self.warning("The module cache could not be written to disk.")
    def saveModuleDictionaryToDisk(self, _strPath):
        """
        This method saves the module dictionary to disk in form of XML.
        This method should be private but is kept public in order to be unit tested.

        @param _strPath: Path to the module dictionary XML file
        @type _strPath: python string
        """
        xsDataDictionaryPlugin = XSDataDictionary()
        strEdnaHome = EDUtilsPath.EDNA_HOME
        for strModule in self.__dictModuleLocation:
            xsDataKeyValuePair = XSDataKeyValuePair()
            xsDataKeyValuePair.setKey(XSDataString(strModule))
            strModuleLocation = self.__dictModuleLocation[ strModule ]
            # Remove the path up to $EDNA_HOME
            strModuleLocationStripped = strModuleLocation.replace(strEdnaHome, "")
            if (strModuleLocationStripped.startswith("/") or  strModuleLocationStripped.startswith("\\")):
                strModuleLocationStripped = strModuleLocationStripped[1:]
            xsDataKeyValuePair.setValue(XSDataString(strModuleLocationStripped))
            xsDataDictionaryPlugin.addKeyValuePair(xsDataKeyValuePair)
        try:
            xsDataDictionaryPlugin.exportToFile(_strPath)
        except:
            self.warning("The module cache could not be written to disk.")
    def createOutputFileDictionary(self, _xsDataResultCharacterisation, _strPathToLogFileDirectory=None):
        """
        This method creates an XSDataDictionary containing the name and locations of the 
        characterisation output files.
        """
        xsDataDictionaryLogFile = XSDataDictionary()
        # Start with the prediction images
        xsDataIndexingResult = _xsDataResultCharacterisation.getIndexingResult()
        if xsDataIndexingResult is not None:
            xsDataGeneratePredictionResult = xsDataIndexingResult.getPredictionResult()
            if xsDataGeneratePredictionResult is not None:
                listXSDataImagePrediction = xsDataGeneratePredictionResult.getPredictionImage()
                for xsDataImagePrediction in listXSDataImagePrediction:
                    xsDataKeyValuePair = XSDataKeyValuePair()
                    iPredictionImageNumber = xsDataImagePrediction.getNumber().getValue()
                    xsDataStringKey = XSDataString("predictionImage_%d" % iPredictionImageNumber)
                    xsDataStringValue = None
                    strPredictionImagePath = xsDataImagePrediction.getPath().getValue()
                    if (_strPathToLogFileDirectory is not None):
                        strPredictionImageFileName = EDUtilsFile.getBaseName(strPredictionImagePath)
                        strNewPredictionImagePath = os.path.join(_strPathToLogFileDirectory, strPredictionImageFileName)
                        EDUtilsFile.copyFile(strPredictionImagePath, strNewPredictionImagePath)
                        xsDataStringValue = XSDataString(strNewPredictionImagePath)
                    else:
                        xsDataStringValue = XSDataString(strPredictionImageFileName)
                    xsDataKeyValuePair.setKey(xsDataStringKey)
                    xsDataKeyValuePair.setValue(xsDataStringValue)
                    xsDataDictionaryLogFile.addKeyValuePair(xsDataKeyValuePair)
        # Best log file
        strPathToBESTLogFile = None
        strPathToExecutiveSummary = None
        if _xsDataResultCharacterisation.getStrategyResult() is not None:
            if _xsDataResultCharacterisation.getStrategyResult().getBestLogFile() != None:
                strPathToBESTLogFile = _xsDataResultCharacterisation.getStrategyResult().getBestLogFile().getPath().getValue()
            if strPathToBESTLogFile is not None:
                xsDataStringKey = XSDataString("logFileBest")
                xsDataStringValue = None
                if (_strPathToLogFileDirectory is not None):
                    strNewBestLogPath = os.path.join(_strPathToLogFileDirectory, "best.log")
                    EDUtilsFile.copyFile(strPathToBESTLogFile, strNewBestLogPath)
                    xsDataStringValue = XSDataString(strNewBestLogPath)
                else:
                    xsDataStringValue = XSDataString(strPathToBESTLogFile)
                xsDataKeyValuePair = XSDataKeyValuePair()
                xsDataKeyValuePair.setKey(xsDataStringKey)
                xsDataKeyValuePair.setValue(xsDataStringValue)
                xsDataDictionaryLogFile.addKeyValuePair(xsDataKeyValuePair)
            if (strPathToExecutiveSummary is not None):
                xsDataStringKey = XSDataString("executiveSummary")
                xsDataStringValue = None
                if (_strPathToLogFileDirectory is not None):
                    strExecutiveSummaryFileName = EDUtilsFile.getBaseName(strPathToExecutiveSummary)
                    strNewExecutiveSummaryPath = os.path.join(_strPathToLogFileDirectory, strExecutiveSummaryFileName)
                    EDUtilsFile.copyFile(strPathToExecutiveSummary, strNewExecutiveSummaryPath)
                    xsDataStringValue = XSDataString(strNewExecutiveSummaryPath)
                    # Copy also the executive summary file to "dna_log.txt"...
                    strNewExecutiveSummaryPath = os.path.join(_strPathToLogFileDirectory, "dna_log.txt")
                    EDUtilsFile.copyFile(strPathToExecutiveSummary, strNewExecutiveSummaryPath)
                else:
                    xsDataStringValue = XSDataString(strPathToExecutiveSummary)
                xsDataKeyValuePair = XSDataKeyValuePair()
                xsDataKeyValuePair.setKey(xsDataStringKey)
                xsDataKeyValuePair.setValue(xsDataStringValue)
                xsDataDictionaryLogFile.addKeyValuePair(xsDataKeyValuePair)

        return xsDataDictionaryLogFile
Exemple #6
0
    def createOutputFileDictionary(self,
                                   _xsDataResultCharacterisation,
                                   _strPathToLogFileDirectory=None):
        """
        This method creates an XSDataDictionary containing the name and locations of the 
        characterisation output files.
        """
        xsDataDictionaryLogFile = XSDataDictionary()
        # Start with the prediction images
        xsDataIndexingResult = _xsDataResultCharacterisation.getIndexingResult(
        )
        xsDataGeneratePredictionResult = xsDataIndexingResult.getPredictionResult(
        )
        listXSDataImagePrediction = xsDataGeneratePredictionResult.getPredictionImage(
        )
        for xsDataImagePrediction in listXSDataImagePrediction:
            xsDataKeyValuePair = XSDataKeyValuePair()
            iPredictionImageNumber = xsDataImagePrediction.getNumber(
            ).getValue()
            xsDataStringKey = XSDataString("predictionImage_%d" %
                                           iPredictionImageNumber)
            xsDataStringValue = None
            strPredictionImagePath = xsDataImagePrediction.getPath().getValue()
            if (_strPathToLogFileDirectory is not None):
                strPredictionImageFileName = EDUtilsFile.getBaseName(
                    strPredictionImagePath)
                strNewPredictionImagePath = os.path.join(
                    _strPathToLogFileDirectory, strPredictionImageFileName)
                EDUtilsFile.copyFile(strPredictionImagePath,
                                     strNewPredictionImagePath)
                xsDataStringValue = XSDataString(strNewPredictionImagePath)
            else:
                xsDataStringValue = XSDataString(strPredictionImageFileName)
            xsDataKeyValuePair.setKey(xsDataStringKey)
            xsDataKeyValuePair.setValue(xsDataStringValue)
            xsDataDictionaryLogFile.addKeyValuePair(xsDataKeyValuePair)
        # Best log file
        strPathToBESTLogFile = None
        strPathToExecutiveSummary = None
        if _xsDataResultCharacterisation.getStrategyResult().getBestLogFile(
        ) != None:
            strPathToBESTLogFile = _xsDataResultCharacterisation.getStrategyResult(
            ).getBestLogFile().getPath().getValue()
        if strPathToBESTLogFile is not None:
            xsDataStringKey = XSDataString("logFileBest")
            xsDataStringValue = None
            if (_strPathToLogFileDirectory is not None):
                strNewBestLogPath = os.path.join(_strPathToLogFileDirectory,
                                                 "best.log")
                EDUtilsFile.copyFile(strPathToBESTLogFile, strNewBestLogPath)
                xsDataStringValue = XSDataString(strNewBestLogPath)
            else:
                xsDataStringValue = XSDataString(strPathToBESTLogFile)
            xsDataKeyValuePair = XSDataKeyValuePair()
            xsDataKeyValuePair.setKey(xsDataStringKey)
            xsDataKeyValuePair.setValue(xsDataStringValue)
            xsDataDictionaryLogFile.addKeyValuePair(xsDataKeyValuePair)
        if (strPathToExecutiveSummary is not None):
            xsDataStringKey = XSDataString("executiveSummary")
            xsDataStringValue = None
            if (_strPathToLogFileDirectory is not None):
                strExecutiveSummaryFileName = EDUtilsFile.getBaseName(
                    strPathToExecutiveSummary)
                strNewExecutiveSummaryPath = os.path.join(
                    _strPathToLogFileDirectory, strExecutiveSummaryFileName)
                EDUtilsFile.copyFile(strPathToExecutiveSummary,
                                     strNewExecutiveSummaryPath)
                xsDataStringValue = XSDataString(strNewExecutiveSummaryPath)
                # Copy also the executive summary file to "dna_log.txt"...
                strNewExecutiveSummaryPath = os.path.join(
                    _strPathToLogFileDirectory, "dna_log.txt")
                EDUtilsFile.copyFile(strPathToExecutiveSummary,
                                     strNewExecutiveSummaryPath)
            else:
                xsDataStringValue = XSDataString(strPathToExecutiveSummary)
            xsDataKeyValuePair = XSDataKeyValuePair()
            xsDataKeyValuePair.setKey(xsDataStringKey)
            xsDataKeyValuePair.setValue(xsDataStringValue)
            xsDataDictionaryLogFile.addKeyValuePair(xsDataKeyValuePair)

        return xsDataDictionaryLogFile
Exemple #7
0
    def doSuccessExecNormalize(self, _edPlugin=None):
        with self.locked():
            self.DEBUG(
                "EDPluginControlFullFieldXASv1_0.doSuccessExecNormalize")
            self.retrieveSuccessMessages(
                _edPlugin,
                "EDPluginControlFullFieldXASv1_0.doSuccessExecNormalize")
            self.xsdAlignStack.setMeasureOffset(self.xsdMeasureOffset)
            output = _edPlugin.dataOutput.output
            self.xsdAlignStack.images = [output]
            data = EDUtilsArray.getArray(output)
            data.shape = -1

            self.xsdAlignStack.index = [XSDataInteger(self.index)]
            self.xsdAlignStack.frameReference = XSDataInteger(self.reference)
            self.xsdAlignStack.HDF5File = self.dataInput.getHDF5File()
            self.xsdAlignStack.internalHDF5Path = self.internalHDF5Path

            internalHDF5Path = self.internalHDF5Path.value
            if not internalHDF5Path.startswith("/"):
                internalHDF5Path = "/" + internalHDF5Path
            keyValuePair1 = XSDataKeyValuePair(key=XSDataString("axes"),
                                               value=XSDataString(
                                                   self.DSenergy))
            keyValuePair2 = XSDataKeyValuePair(key=XSDataString("long_name"),
                                               value=XSDataString(self.TITLE))
            keyValuePair3 = XSDataKeyValuePair(
                key=XSDataString("interpretation"),
                value=XSDataString("image"))
            keyValuePair4 = XSDataKeyValuePair(key=XSDataString("signal"),
                                               value=XSDataString("1"))

            xsAttrDataset = XSDataHDF5Attributes(
                h5path=XSDataString(
                    posixpath.join(internalHDF5Path, self.DSstack)),
                metadata=XSDataDictionary([
                    XSDataKeyValuePair(key=XSDataString(k),
                                       value=XSDataString(v))
                    for k, v in self.dataAttr.items()
                ]))

            #            NXdata is treated in this file not in HDF5 plugins
            #            xsAttrNXdata = XSDataHDF5Attributes(h5path=XSDataString(posixpath.join(internalHDF5Path, "NXdata")), \
            #                            metadata=XSDataDictionary([XSDataKeyValuePair(key=XSDataString(k), value=XSDataString(v)) for k, v in self.NXdataAttr.items()]))

            xsAttrEntry = XSDataHDF5Attributes(
                h5path=XSDataString(internalHDF5Path),
                metadata=XSDataDictionary([
                    XSDataKeyValuePair(key=XSDataString(k),
                                       value=XSDataString(v))
                    for k, v in self.NXentryAttr.items()
                ]))

            self.xsdAlignStack.extraAttributes = [xsAttrDataset, xsAttrEntry]

            ########################################################################
            # Selecte the mean of last centile
            ########################################################################
            data.sort()
            fMaxSignal = data[int(0.99 * len(data)):].mean()
            self.makeHDF5MaxIntStructure(fMaxSignal)