def readHeaderADSC(self, _strImageFileName):
        """
        This method reads the header from an ADSC image and returns a dictionary.
        Ideally this method should be a part of another (exec) plugin.
        """
        pyFile = None
        dictionary = None
        try:
            pyFile = open(_strImageFileName, "r")
        except:
            EDVerbose.warning("**** EDPluginExecReadImageHeaderADSCv10.readHeaderADSC: couldn't open file: " + _strImageFileName)

        if (pyFile != None):
            EDVerbose.DEBUG("EDPluginExecReadImageHeaderADSCv10.readHeaderADSC: Reading header from image " + _strImageFileName)
            pyFile.seek(0, 0)
            strLine = pyFile.readline()
            if strLine[0] == "{":
                dictionary = {}
                strLine = pyFile.readline()
                while strLine[0] != "}" :
                    listSplit = strLine.split("=")
                    strKeyword = listSplit[0]
                    listSplitValue = listSplit[1].split(";")
                    strValue = listSplitValue[0]
                    dictionary[strKeyword] = strValue
                    strLine = pyFile.readline()
            pyFile.close()

        return dictionary
예제 #2
0
    def postProcess(self, _edObject=None):
        """
        Calls the parent preProcess method
        Checks that the installed 3rd party software is in the list of
        compatible versions
        """
        EDPluginExec.postProcess(self)
        EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.postProcess")

        # Tests the compatibles executable versions
        listCompatibleVersions = self.getListOfCompatibleVersions()

        if(len(listCompatibleVersions) != 0):

            bFound = False
            for compatibleVersion in listCompatibleVersions:
                bFound = self.findStringInLog(compatibleVersion)
                if(bFound == True):
                    break

            if(bFound == False):
                strErrorMessage = "Plugin not compatible with %s, compatible versions are: %s" % \
                                  (self.getStringVersion(),
                                   self.getCompatibleVersionsStringLine())
                EDVerbose.warning(strErrorMessage)
                self.addWarningMessage(strErrorMessage)
예제 #3
0
    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlKappaStrategyv2_0.configure")
        pluginConfiguration = self.getConfiguration()

        if pluginConfiguration != None:
            strSymopHome = EDConfiguration.getStringParamValue(
                pluginConfiguration, self.strCONF_SYMOP_HOME)
            if (strSymopHome == None):
                strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % (
                    'EDPluginControlKappaStrategyv2_0.configure',
                    self.strCONF_SYMOP_HOME, self.getPluginName())
                EDVerbose.warning(strWarningMessage)
                self.addWarningMessage(strWarningMessage)
            else:
                strSymopHomeNorm = os.path.normpath(strSymopHome)
                self.setSymopHome(strSymopHomeNorm)

            strSymopHome = EDConfiguration.getStringParamValue(
                pluginConfiguration, "KAPPA")
            if (strSymopHome == None or strSymopHome != "ON"):
                #self.strPluginStrategyName = "EDPluginControlStrategyv10"
                #self.strPluginStrategyName = "EDPluginControlStrategyv2_0"
                self.KappaStrategy = 0
            else:
                self.KappaStrategy = 1
예제 #4
0
파일: EDUtilsPath.py 프로젝트: kif/edna
 def getEdnaUserTempFolder(cls):
     """
     Returns the name of a temporary folder that is unique for a given user.
     """
     if cls._EDNA_USERTEMPFOLDER is None:
         if os.environ.has_key("EDNA_USERTEMPFOLDER"):
             cls._EDNA_USERTEMPFOLDER = os.environ["EDNA_USERTEMPFOLDER"]
             if not os.path.exists(cls._EDNA_USERTEMPFOLDER):
                 EDVerbose.warning(
                     "EDNA_USERTEMPFOLDER environment variable is set to %s put the directory does not exist!"
                     % cls._EDNA_USERTEMPFOLDER)
                 cls._EDNA_USERTEMPFOLDER = None
             elif (not os.access(cls._EDNA_USERTEMPFOLDER, os.W_OK)):
                 EDVerbose.warning(
                     "EDNA_USERTEMPFOLDER environment variable is set to %s put the directory cannot be accessed!"
                     % cls._EDNA_USERTEMPFOLDER)
                 cls._EDNA_USERTEMPFOLDER = None
         if cls._EDNA_USERTEMPFOLDER is None:
             strEdnaTempFileDir = tempfile.gettempdir()
             try:
                 # Working on Windows and Linux:
                 strUserName = getpass.getuser()
             except Exception:
                 # Working on MacOS:
                 strUserName = os.getlogin()
             bIsOk = False
             # Check that we have write access to this directory:
             if os.access(strEdnaTempFileDir, os.W_OK) and os.access(
                     strEdnaTempFileDir, os.X_OK):
                 cls._EDNA_USERTEMPFOLDER = os.path.join(
                     strEdnaTempFileDir, "edna-%s" % strUserName)
                 # Check that we have write access to this directory:
                 if not os.path.exists(cls._EDNA_USERTEMPFOLDER):
                     try:
                         os.mkdir(cls._EDNA_USERTEMPFOLDER)
                     except Exception:
                         EDVerbose.WARNING(
                             "Error when trying to create the directory %s"
                             % cls._EDNA_USERTEMPFOLDER)
                 if os.access(cls._EDNA_USERTEMPFOLDER,
                              os.W_OK) and os.access(
                                  cls._EDNA_USERTEMPFOLDER, os.X_OK):
                     bIsOk = True
             if not bIsOk:
                 # We cannot use the edna-<user name> folder...
                 EDVerbose.WARNING(
                     "EDUtilsFile.getEdnaUserTempFolder: cannot access user temporary directory %s"
                     % cls._EDNA_USERTEMPFOLDER)
                 # Create temporary directory
                 cls._EDNA_USERTEMPFOLDER = tempfile.mkdtemp(prefix="edna-")
                 EDVerbose.WARNING(
                     "Created temporary directory for this session: %s" %
                     cls._EDNA_USERTEMPFOLDER)
                 EDVerbose.WARNING(
                     "If you would like to continue to use this directory for future sessions"
                 )
                 EDVerbose.WARNING(
                     "please set then environment variable EDNA_USERTEMPFOLDER to %s"
                     % cls._EDNA_USERTEMPFOLDER)
     return cls._EDNA_USERTEMPFOLDER
예제 #5
0
    def postProcess(self, _edObject=None):
        """
        Calls the parent preProcess method
        Checks that the installed 3rd party software is in the list of
        compatible versions
        """
        EDPluginExec.postProcess(self)
        EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.postProcess")

        # Tests the compatibles executable versions
        listCompatibleVersions = self.getListOfCompatibleVersions()

        if (len(listCompatibleVersions) != 0):

            bFound = False
            for compatibleVersion in listCompatibleVersions:
                bFound = self.findStringInLog(compatibleVersion)
                if (bFound == True):
                    break

            if (bFound == False):
                strErrorMessage = "Plugin not compatible with %s, compatible versions are: %s" % \
                                  (self.getStringVersion(),
                                   self.getCompatibleVersionsStringLine())
                EDVerbose.warning(strErrorMessage)
                self.addWarningMessage(strErrorMessage)
    def postProcess(self, _edObject=None):
        EDPluginExecProcessScript.postProcess(self)

        strRaddoseError = self.readProcessErrorLogFile()
        if((strRaddoseError is not None) and (strRaddoseError != "")):
            errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginRaddosev10.postProcess', 'EDPluginRaddosev10', strRaddoseError)
            EDVerbose.error(errorMessage)
            self.addErrorMessage(errorMessage)
            raise RuntimeError, errorMessage

        resultDict = self.analyseScriptLogFileName(os.path.join(self.getWorkingDirectory(), self.getScriptLogFileName()))

        strSolvent = self.__dictResults[ EDPluginRaddosev10.__strSOLVENT ]

        # ugly workaround while waiting for RADDOSE XML output file
        strAbsorbedDose = None
        for strAbsorbedDoseKeyword in EDPluginRaddosev10.__listABSORBED_DOSE:
            strAbsorbedDose = self.__dictResults[ strAbsorbedDoseKeyword ]
            if (strAbsorbedDose is not None):
                break

        if(strSolvent is None):
            errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginRaddosev10.postProcess', "Raddose", "No Result for Keyword [" + EDPluginRaddosev10.__strSOLVENT + "] see: " + self.getScriptLogFileName())
            EDVerbose.error(errorMessage)
            self.addErrorMessage(errorMessage)
            raise RuntimeError, errorMessage

        if(strAbsorbedDose is None):
            errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginRaddosev10.postProcess', "Raddose", "No Result for Keyword [" + strAbsorbedDoseKeyword + "] see: " + self.getScriptLogFileName())
            EDVerbose.error(errorMessage)
            self.addErrorMessage(errorMessage)
            raise RuntimeError, errorMessage


        self.__fSolvent = float(strSolvent)
        if(self.__fSolvent < EDPluginRaddosev10.__iMIN_SOLVENT_PERCENTAGE or self.__fSolvent > EDPluginRaddosev10.__iMAX_SOLVENT_PERCENTAGE):
            warningMessage = "Inconsistent solvent percentage value: %.1f" % self.__fSolvent
            EDVerbose.warning(warningMessage)
            self.addWarningMessage(warningMessage)

        iNumberOfImages = self.getDataInput().getNumberOfImages().getValue()
        fExposureTimePerImageInSec = self.getDataInput().getBeamExposureTime().getValue()
        fTotalExposureTime = iNumberOfImages * fExposureTimePerImageInSec
        fAbsorbedDoseSpeed = float(strAbsorbedDose) / fTotalExposureTime
        xsDataAbsorbedDoseRate = XSDataAbsorbedDoseRate(fAbsorbedDoseSpeed)

        xsDataAbsorbedDose = XSDataDouble(float(strAbsorbedDose))

        self.__fTimeToReachHendersonLimit = EDPluginRaddosev10.__fHENDERSON_LIMIT / fAbsorbedDoseSpeed

        xsDataRaddosev10Output = XSDataRaddoseOutput()
        xsDataRaddosev10Output.setAbsorbedDose(xsDataAbsorbedDose)
        xsDataRaddosev10Output.setAbsorbedDoseRate(xsDataAbsorbedDoseRate)
        xsDataRaddosev10Output.setTimeToReachHendersonLimit(XSDataTime(self.__fTimeToReachHendersonLimit))

        xsDataFilePathToLog = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), self.getScriptLogFileName())))
        xsDataRaddosev10Output.setPathToLogFile(xsDataFilePathToLog)

        self.setDataOutput(xsDataRaddosev10Output)
예제 #7
0
파일: EDUtilsPath.py 프로젝트: gbourgh/edna
 def setEdnaTestDataPath(cls, value):
     """
     This class method initializes the path to the test data (probably unused)
     """
     cls._EDNA_TESTDATA = os.path.abspath(value)
     if not os.path.isdir(cls._EDNA_TESTDATA):
         EDVerbose.warning("EDNA_TESTDATA environment variable is set to %s put the directory does not exist!" % cls._EDNA_TESTDATA)
         cls._EDNA_TESTDATA = None
예제 #8
0
 def configure(self):
     EDPluginControl.configure(self)
     EDVerbose.DEBUG("EDPluginControlStrategyv1_2.configure")
     strSymopHome = self.config.get(self._strCONF_SYMOP_HOME)
     if strSymopHome is None:
         strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlStrategyv1_2.configure', self._strCONF_SYMOP_HOME, self.getPluginName())
         EDVerbose.warning(strWarningMessage)
         self.addWarningMessage(strWarningMessage)
     else:
         self.setSymopHome(strSymopHome)
예제 #9
0
파일: EDUtilsPath.py 프로젝트: kif/edna
 def setEdnaTestDataPath(cls, value):
     """
     This class method initializes the path to the test data (probably unused)
     """
     cls._EDNA_TESTDATA = os.path.abspath(value)
     if not os.path.isdir(cls._EDNA_TESTDATA):
         EDVerbose.warning(
             "EDNA_TESTDATA environment variable is set to %s put the directory does not exist!"
             % cls._EDNA_TESTDATA)
         cls._EDNA_TESTDATA = None
예제 #10
0
 def configure(self):
     EDPluginControl.configure(self)
     EDVerbose.DEBUG("EDPluginControlStrategyv1_2.configure")
     strSymopHome = self.config.get(self._strCONF_SYMOP_HOME)
     if strSymopHome is None:
         strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlStrategyv1_2.configure', self._strCONF_SYMOP_HOME, self.getPluginName())
         EDVerbose.warning(strWarningMessage)
         self.addWarningMessage(strWarningMessage)
     else:
         self.setSymopHome(strSymopHome)
예제 #11
0
 def setConfiguration(_edConfiguration):
     """
     """
     EDVerbose.DEBUG("EDApplication.setConfiguration")
     EDApplication.synchronizeOn()
     if (_edConfiguration == None):
         EDVerbose.warning("EDApplication.setConfiguration: Configuration is None!")
     else:
         EDApplication.__edConfiguration = _edConfiguration
     EDApplication.synchronizeOff()
예제 #12
0
 def doFailureActionRaddose(self, _edPlugin=None):
     """
     retrieve the potential warning messages
     retrieve the potential error messages
     """
     EDVerbose.DEBUG("EDPluginControlStrategyv1_2.doFailureActionRaddose")
     self.retrieveFailureMessages(_edPlugin, "EDPluginControlStrategyv1_2.doFailureActionRaddose")
     strWarningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % ('EDPluginControlStrategyv1_2.doFailureActionRaddose', self._strPluginRaddoseName, "Raddose failure")
     EDVerbose.warning(strWarningMessage)
     self.addWarningMessage(strWarningMessage)
     self.executeBest(self)
 def doFailureActionAlignment(self, _edPlugin):
     """
     retrieve the potential warning messages
     retrieve the potential error messages
     """
     EDVerbose.DEBUG("EDPluginControlKappaReorientationStrategyv2_0.doFailureActionAlignment")
     self.retrieveFailureMessages(_edPlugin, "EDPluginControlKappaReorientationStrategyv2_0.doFailureActionAlignment")
     strWarningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % ('EDPluginControlKappaReorientationStrategyv2_0.doFailureActionAlignment', self.strPluginAlignmentName, "STACAlignment failure")
     EDVerbose.warning(strWarningMessage)
     self.addWarningMessage(strWarningMessage)
     self.executeSimpleStrategy(_edPlugin)
예제 #14
0
    def preProcess(self):
        """
        Creates the application working directory (log dir)
        Initializes the configuration
        retrieves the plugin xml data to be passed to the plugin
        """
        EDVerbose.DEBUG("EDApplication.preProcess")
        self.processCommandline()
        if (not self.__bIsFailure):
            # Check that the plugin can be located
            strPluginLocation = EDFactoryPluginStatic.getFactoryPlugin().getModuleLocation(self.__strPluginName)
            if (strPluginLocation is None):
                EDVerbose.error("Plugin  %s cannot be loaded!" % self.__strPluginName)
                self.__bIsFailure = True
            # Check that the input file can be read
            if (self.getDataInputFilePath() is not None) and (not os.path.exists(self.__strDataInputFilePath)):
                EDVerbose.error("Input XML file not found : %s" % self.__strDataInputFilePath)
                self.__bIsFailure = True
            # Check that the output file can be created
            if (self.__strDataOutputFilePath is not None):
                strOutputDirectory = os.path.dirname(self.__strDataOutputFilePath)
                if (strOutputDirectory is None or strOutputDirectory == ""):
                    strOutputDirectory = os.getcwd()
                    self.__strDataOutputFilePath = os.path.join(strOutputDirectory, self.__strDataOutputFilePath)
                if (not os.access(strOutputDirectory, os.W_OK)):
                    EDVerbose.error("Output directory not writable: %s" % strOutputDirectory)
                    self.__bIsFailure = True
                elif (os.path.exists(self.__strDataOutputFilePath)):
                    if (not os.access(self.__strDataOutputFilePath, os.W_OK)):
                        EDVerbose.error("Output file not writable: %s" % self.__strDataOutputFilePath)
                        self.__bIsFailure = True
        if (not self.__bIsFailure):
            EDVerbose.DEBUG("EDApplication.PLUGIN_PARAM_LABEL: " + EDApplication.PLUGIN_PARAM_LABEL)

            # Load the configuration file
            if(self.__strConfigurationFileName is None):
                self.__strConfigurationHome = EDApplication.getConfigurationHome(self.__strPluginName)
                self.__strConfigurationFileName = os.path.abspath(os.path.join(self.__strConfigurationHome, "XSConfiguration_%s.xml" % EDUtilsPath.getEdnaSite()))
            if (os.path.exists(self.__strConfigurationFileName)):
                EDVerbose.screen("Loading Configuration file: %s" % self.__strConfigurationFileName)
                edConfiguration = EDConfiguration(self.__strConfigurationFileName)
                self.setConfiguration(edConfiguration)
                self.loadConfiguration()
                EDVerbose.DEBUG("EDApplication.preProcess: Checking... Number of plugins...: %d" % EDApplication.__edConfiguration.getPluginListSize())
                pyDictionary = {}
                pyDictionary[ "${EDNA_HOME}" ] = EDUtilsPath.getEdnaHome()
                if self.getDataInputFilePath() is not None:
                    self.__strXMLData = EDUtilsFile.readFileAndParseVariables(self.getDataInputFilePath(), pyDictionary)
            else:
                EDVerbose.warning("Cannot find configuration file: %s" % self.__strConfigurationFileName)
            # Create the application working directory    
            if(self.__strWorkingDir is None):
                self.__strWorkingDir = self.__strApplicationInstanceName
            self.createApplicationWorkingDirectory()
예제 #15
0
 def doFailureActionRaddose(self, _edPlugin):
     """
     retrieve the potential warning messages
     retrieve the potential error messages
     """
     EDVerbose.DEBUG("EDPluginControlStrategyv10.doFailureActionRaddose")
     self.retrieveFailureMessages(_edPlugin, "EDPluginControlStrategyv10.doFailureActionRaddose")
     warningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % ('EDPluginControlStrategyv10.doFailureActionRaddose', self.__strPluginRaddoseName, "Raddose failure")
     EDVerbose.warning(warningMessage)
     self.addWarningMessage(warningMessage)
     self.executeBest(self)
예제 #16
0
 def getEdnaUserTempFolder(cls):
     """
     Returns the name of a temporary folder that is unique for a given user.
     """
     if cls._EDNA_USERTEMPFOLDER is None:
         if os.environ.has_key("EDNA_USERTEMPFOLDER"):
             cls._EDNA_USERTEMPFOLDER = os.environ["EDNA_USERTEMPFOLDER"]
             if not os.path.exists(cls._EDNA_USERTEMPFOLDER):
                 EDVerbose.warning(
                     "EDNA_USERTEMPFOLDER environment variable is set to %s put the directory does not exist!"
                     % cls._EDNA_USERTEMPFOLDER
                 )
                 cls._EDNA_USERTEMPFOLDER = None
             elif not os.access(cls._EDNA_USERTEMPFOLDER, os.W_OK):
                 EDVerbose.warning(
                     "EDNA_USERTEMPFOLDER environment variable is set to %s put the directory cannot be accessed!"
                     % cls._EDNA_USERTEMPFOLDER
                 )
                 cls._EDNA_USERTEMPFOLDER = None
         if cls._EDNA_USERTEMPFOLDER is None:
             strEdnaTempFileDir = tempfile.gettempdir()
             try:
                 # Working on Windows and Linux:
                 strUserName = getpass.getuser()
             except Exception:
                 # Working on MacOS:
                 strUserName = os.getlogin()
             bIsOk = False
             # Check that we have write access to this directory:
             if os.access(strEdnaTempFileDir, os.W_OK) and os.access(strEdnaTempFileDir, os.X_OK):
                 cls._EDNA_USERTEMPFOLDER = os.path.join(strEdnaTempFileDir, "edna-%s" % strUserName)
                 # Check that we have write access to this directory:
                 if not os.path.exists(cls._EDNA_USERTEMPFOLDER):
                     try:
                         os.mkdir(cls._EDNA_USERTEMPFOLDER)
                     except Exception:
                         EDVerbose.WARNING("Error when trying to create the directory %s" % cls._EDNA_USERTEMPFOLDER)
                 if os.access(cls._EDNA_USERTEMPFOLDER, os.W_OK) and os.access(cls._EDNA_USERTEMPFOLDER, os.X_OK):
                     bIsOk = True
             if not bIsOk:
                 # We cannot use the edna-<user name> folder...
                 EDVerbose.WARNING(
                     "EDUtilsFile.getEdnaUserTempFolder: cannot access user temporary directory %s"
                     % cls._EDNA_USERTEMPFOLDER
                 )
                 # Create temporary directory
                 cls._EDNA_USERTEMPFOLDER = tempfile.mkdtemp(prefix="edna-")
                 EDVerbose.WARNING("Created temporary directory for this session: %s" % cls._EDNA_USERTEMPFOLDER)
                 EDVerbose.WARNING("If you would like to continue to use this directory for future sessions")
                 EDVerbose.WARNING(
                     "please set then environment variable EDNA_USERTEMPFOLDER to %s" % cls._EDNA_USERTEMPFOLDER
                 )
     return cls._EDNA_USERTEMPFOLDER
예제 #17
0
 def getPluginConfiguration(self, _strConfigurationFileName):
     """
     Returns the plugin configuration from a configuration file
     """
     xsPluginItem = None
     edConfiguration = EDConfiguration(_strConfigurationFileName)
     if(edConfiguration != None):
         xsPluginItem = edConfiguration.getXSConfigurationItem(self.getPluginName())
         if(xsPluginItem == None):
             EDVerbose.warning("EDTestCasePluginUnit.getPluginConfiguration: Could not get configuration plugin item for: " + self.getPluginName())
     else:
         EDVerbose.warning("EDTestCasePluginUnit.getPluginConfiguration: Could not load Configuration: " + _strConfigurationFileName)
     return xsPluginItem
예제 #18
0
 def getEdnaSite(cls):
     """
     Returns the EDNA_SITE variable from environment
     """
     # EDNA Site
     if(cls._EDNA_SITE == None):
         cls._EDNA_SITE = os.environ.get("EDNA_SITE")
         if(cls._EDNA_SITE is None):
             EDVerbose.warning("EDUtilsPath.getEdnaSite: EDNA_SITE not set, using EDNA_SITE='default'")
             cls._EDNA_SITE = "default"
         else:
             EDVerbose.DEBUG("EDUtilsPath.getEdnaSite: EDNA_SITE is set: %s" % cls._EDNA_SITE)
     return cls._EDNA_SITE
예제 #19
0
    def preProcess(self):
        """
        Creates the application working directory (log dir)
        Initializes the configuration
        retrieves the plugin xml data to be passed to the plugin
        """
        EDVerbose.DEBUG("EDApplication.preProcess")
        self.processCommandline()
        if (not self._bIsFailure):
            # Check that the plugin can be located
            strPluginLocation = EDFactoryPluginStatic.getFactoryPlugin().getModuleLocation(self._strPluginName)
            if (strPluginLocation is None):
                EDVerbose.error("Plugin  %s cannot be loaded!" % self._strPluginName)
                self._bIsFailure = True
            # Check that the input file can be read
            if (self.getDataInputFilePath() is not None) and (not os.path.exists(self._strDataInputFilePath)):
                EDVerbose.error("Input XML file not found : %s" % self._strDataInputFilePath)
                self._bIsFailure = True
            # Check that the output file can be created
            if (self._strDataOutputFilePath is not None):
                strOutputDirectory = os.path.dirname(self._strDataOutputFilePath)
                if (strOutputDirectory is None or strOutputDirectory == ""):
                    strOutputDirectory = os.getcwd()
                    self._strDataOutputFilePath = os.path.join(strOutputDirectory, self._strDataOutputFilePath)
                if (not os.access(strOutputDirectory, os.W_OK)):
                    EDVerbose.error("Output directory not writable: %s" % strOutputDirectory)
                    self._bIsFailure = True
                elif (os.path.exists(self._strDataOutputFilePath)):
                    if (not os.access(self._strDataOutputFilePath, os.W_OK)):
                        EDVerbose.error("Output file not writable: %s" % self._strDataOutputFilePath)
                        self._bIsFailure = True
        if (not self._bIsFailure):
            EDVerbose.DEBUG("EDApplication.PLUGIN_PARAM_LABEL: " + EDApplication.PLUGIN_PARAM_LABEL)

            if self._strConfigurationFileName is not None:
                # Load the configuration file
                if (os.path.exists(self._strConfigurationFileName)):
                    EDVerbose.screen("Loading Configuration file: %s" % self._strConfigurationFileName)
                    EDConfigurationStatic.addConfigurationFile(self._strConfigurationFileName, _bReplace=True)
                else:
                    EDVerbose.warning("Cannot find configuration file: %s" % self._strConfigurationFileName)
            pyDictionary = {}
            pyDictionary[ "${EDNA_HOME}" ] = EDUtilsPath.getEdnaHome()
            if self.getDataInputFilePath() is not None:
                self._strXMLData = EDUtilsFile.readFileAndParseVariables(self.getDataInputFilePath(), pyDictionary)
            # Create the application working directory    
            if(self._strWorkingDir is None):
                self._strWorkingDir = self._strApplicationInstanceName
            self.createApplicationWorkingDirectory()
 def configure(self):
     EDPluginExecProcessScript.configure(self)
     EDVerbose.DEBUG("EDPluginControlLabelitv10.configure")
     xsPluginItem = self.getConfiguration()
     if (xsPluginItem == None):
         EDVerbose.warning("EDPluginControlLabelitv10.configure: No Labelit plugin item defined.")
         xsPluginItem = XSPluginItem()
     strPathToLabelitSetpathScript = EDConfiguration.getStringParamValue(xsPluginItem, self.strCONF_PATH_TO_LABELIT_SETPATH_SCRIPT)
     if(strPathToLabelitSetpathScript == None):
         errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginControlLabelitv10.configure', self.getClassName(), "Configuration parameter missing: " + self.strCONF_PATH_TO_LABELIT_SETPATH_SCRIPT)
         EDVerbose.error(errorMessage)
         self.addErrorMessage(errorMessage)
         raise RuntimeError, errorMessage
     else:
         self.setPathToLabelitSetpathScript(strPathToLabelitSetpathScript)
예제 #21
0
    def preProcess(self, _edObject=None):
        """
        Preprocess of the plugin: 
        check parameters and extract from EDNA format into something more simple & pythonic
        """
        EDPluginExec.preProcess(self)
        EDVerbose.DEBUG("EDPluginPyarchThumbnailv10.preProcess")
        sdi = self.getDataInput()
        if sdi.getInputImagePath() is not None:
            self.inputFilename = sdi.getInputImagePath().getPath().getValue()
            if not os.path.isfile(self.inputFilename):
                EDVerbose.ERROR(
                    "The input file provided is not a valid file: " +
                    self.inputFilename)
                raise "Not a valid file " + self.inputFilename

            # Output path
            strImageNameWithoutExt = os.path.basename(
                os.path.splitext(self.inputFilename)[0])
            strImageDirname = os.path.dirname(self.inputFilename)
            strOutputDirname = self.createPyarchFilePath(strImageDirname)
            # Check that output pyarch path exists and is writeable:
            bIsOk = False
            if strOutputDirname:
                if not os.path.exists(strOutputDirname):
                    # Try to create the directory
                    try:
                        os.makedirs(strOutputDirname)
                        bIsOk = True
                    except BaseException, e:
                        EDVerbose.WARNING("Couldn't create the directory %s" %
                                          strOutputDirname)
                elif os.access(strOutputDirname, os.W_OK):
                    bIsOk = True
            if not bIsOk:
                EDVerbose.warning("Cannot write to pyarch directory: %s" %
                                  strOutputDirname)
                strOutputDirname = tempfile.mkdtemp(
                    "", "EDPluginPyarchThumbnailv10_", "/tmp")
                EDVerbose.warning("Writing thumbnail images to: %s" %
                                  strOutputDirname)

            self.strOutputPath = os.path.join(strOutputDirname,
                                              strImageNameWithoutExt + ".jpeg")
            self.strOutputPathThumb = os.path.join(
                strOutputDirname, strImageNameWithoutExt + ".thumb.jpeg")
예제 #22
0
 def newFile(self, filename="test", size=(0, 0), metadata={}):
     """this is a method to create a new empty file
     @param filename: name of the file to create, the size and the extension will be added.
     @type  filename: string
     @type size: 2-tuple of integers  
     @param size: the size of the image to create
     """
     if len(size) != 2:
         EDVerbose.error("Error in the size of the size-tuple")
         raise Exception("Error in the size of the size-tuple")
     if size[0] < 0:
         EDVerbose.error("Error in the X part of the size tuple")
         raise Exception("Error in the X part of the size tuple")
     if size[1] < 0:
         EDVerbose.error("Error in the Y part of the size tuple")
         raise Exception("Error in the Y part of the size tuple")
     emptyNParray = numpy.zeros(size, dtype="float32")
     self.data[filename] = emptyNParray
     self.headers[filename] = metadata
     self.size[filename] = size
     fullFilename = "%sSize%ix%i.edf" % ((filename, ) + size)
     if os.path.isfile(fullFilename):
         EDVerbose.warning("Warning, I am going to overwrite the file %s " %
                           fullFilename)
         self.synchronizeOn()
         try:
             self.edf[filename] = EdfFile(fullFilename)
             self.data[filename] = self.edf[filename].GetData(0)
             self.headers[filename] = self.edf[filename].GetHeader(0)
         except Exception:
             EDVerbose.error("[ERROR] in reading file %s" % filename)
         self.synchronizeOff()
         if self.data[filename].shape != size:
             self.data[filename] = emptyNParray
             self.headers[filename] = metadata
     else:
         self.synchronizeOn()
         try:
             self.edf[filename] = EdfFile(fullFilename)
             self.edf[filename].WriteImage(self.headers[filename],
                                           self.data[filename],
                                           Append=0)
         except Exception:
             EDVerbose.error("[ERROR] in opening and creating file %s" %
                             filename)
         self.synchronizeOff()
 def configure(self):
     """
     Configures the plugin from the configuration file with the following parameters
      - Excpected image size
     """
     EDPluginControl.configure(self)
     EDVerbose.DEBUG("EDPluginControlDiffractionCTv1_2.configure")
     xsPluginItem = self.getConfiguration()
     if (xsPluginItem == None):
         EDVerbose.warning("EDPluginControlDiffractionCTv1_2.configure: No plugin item defined.")
         xsPluginItem = XSPluginItem()
     strImageSize = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginControlDiffractionCTv1_2.CONF_INPUT_IMAGE_SIZE)
     if(strImageSize == None):
         EDVerbose.WARNING("EDPluginControlDiffractionCTv1_2.configure: No configuration parameter found for: %s, using default value: %s " % (\
                      EDPluginControlDiffractionCTv1_2.CONF_INPUT_IMAGE_SIZE, self.iImageSize))
     else:
         self.iImageSize = int(strImageSize)
 def configure(self):
     EDPluginExecProcessScript.configure(self)
     EDVerbose.DEBUG("EDPluginLabelitv1_1.configure")
     xsPluginItem = self.getConfiguration()
     if (xsPluginItem == None):
         EDVerbose.warning("EDPluginLabelitv1_1.configure: No Labelit plugin item defined.")
         xsPluginItem = XSPluginItem()
     strPathToLabelitSetpathScript = EDConfiguration.getStringParamValue(xsPluginItem, \
                                                                         EDPluginLabelitv1_1.CONF_PATH_TO_LABELIT_SETPATH_SCRIPT)
     if(strPathToLabelitSetpathScript == None):
         strErrorMessage = "EDPluginLabelitv1_1.configure : Configuration parameter missing: " + \
                             EDPluginLabelitv1_1.CONF_PATH_TO_LABELIT_SETPATH_SCRIPT
         EDVerbose.error(strErrorMessage)
         self.addErrorMessage(strErrorMessage)
         self.setFailure()
     else:
         self.setPathToLabelitSetpathScript(strPathToLabelitSetpathScript)
예제 #25
0
파일: EDUtilsPath.py 프로젝트: kif/edna
 def getEdnaSite(cls):
     """
     Returns the EDNA_SITE variable from environment
     """
     # EDNA Site
     if (cls._EDNA_SITE == None):
         cls._EDNA_SITE = os.environ.get("EDNA_SITE")
         if (cls._EDNA_SITE is None):
             EDVerbose.warning(
                 "EDUtilsPath.getEdnaSite: EDNA_SITE not set, using EDNA_SITE='default'"
             )
             cls._EDNA_SITE = "default"
         else:
             EDVerbose.DEBUG(
                 "EDUtilsPath.getEdnaSite: EDNA_SITE is set: %s" %
                 cls._EDNA_SITE)
     return cls._EDNA_SITE
예제 #26
0
    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlStrategyv1_2.configure")
        pluginConfiguration = self.getConfiguration()

        if(pluginConfiguration == None):
            strWarningMessage = EDMessage.WARNING_NO_PLUGIN_CONFIGURATION_ITEM_FOUND_02 % ('EDPluginControlStrategyv1_2.configure', self.getPluginName())
            EDVerbose.warning(strWarningMessage)
            self.addWarningMessage(strWarningMessage)
        else:
            strSymopHome = self.getStringConfigurationParameterValue(self._strCONF_SYMOP_HOME)
            if(strSymopHome == None):
                strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlStrategyv1_2.configure', self._strCONF_SYMOP_HOME, self.getPluginName())
                EDVerbose.warning(strWarningMessage)
                self.addWarningMessage(strWarningMessage)
            else:
                self.setSymopHome(strSymopHome)
예제 #27
0
 def getPluginConfiguration(self, _strConfigurationFileName):
     """
     Returns the plugin configuration from a configuration file
     """
     xsPluginItem = None
     edConfiguration = EDConfiguration(_strConfigurationFileName)
     if (edConfiguration != None):
         xsPluginItem = edConfiguration.getXSConfigurationItem(
             self.getPluginName())
         if (xsPluginItem == None):
             EDVerbose.warning(
                 "EDTestCasePluginUnit.getPluginConfiguration: Could not get configuration plugin item for: "
                 + self.getPluginName())
     else:
         EDVerbose.warning(
             "EDTestCasePluginUnit.getPluginConfiguration: Could not load Configuration: "
             + _strConfigurationFileName)
     return xsPluginItem
예제 #28
0
 def getDataInput(self, _strDataInputKey=None):
     """
     Returns the Plugin Input Data for a particular key.
     If the key is not provided a default key is used.
     """
     oValue = None
     strDataInputKey = _strDataInputKey
     if (strDataInputKey is None):
         strDataInputKey = self.getDefaultInputDataKey()
     if (strDataInputKey in self.__dictXMLDataInput.keys()):
         oValue = self.__dictXMLDataInput[ strDataInputKey ]
     else:
         strErrorMessage = self.getPluginName() + ".getDataInput, no input data defined for key: " + strDataInputKey
         EDVerbose.warning(strErrorMessage)
         self.addWarningMessage(strErrorMessage)
     if isinstance(oValue, (str, unicode)):
         oValue = self.xsDataXmlToObject(oValue)
     return oValue
예제 #29
0
 def doFailureActionAlignment(self, _edPlugin):
     """
     retrieve the potential warning messages
     retrieve the potential error messages
     """
     EDVerbose.DEBUG(
         "EDPluginControlKappaReorientationStrategyv2_0.doFailureActionAlignment"
     )
     self.retrieveFailureMessages(
         _edPlugin,
         "EDPluginControlKappaReorientationStrategyv2_0.doFailureActionAlignment"
     )
     strWarningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % (
         'EDPluginControlKappaReorientationStrategyv2_0.doFailureActionAlignment',
         self.strPluginAlignmentName, "STACAlignment failure")
     EDVerbose.warning(strWarningMessage)
     self.addWarningMessage(strWarningMessage)
     self.executeSimpleStrategy(_edPlugin)
예제 #30
0
    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlKappaStrategyv2_0.configure")
        strSymopHome = self.config.get(self.strCONF_SYMOP_HOME)
        if strSymopHome is None:
            strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlKappaStrategyv2_0.configure', self.strCONF_SYMOP_HOME, self.getPluginName())
            EDVerbose.warning(strWarningMessage)
            self.addWarningMessage(strWarningMessage)
        else:
            strSymopHomeNorm = os.path.normpath(strSymopHome)
            self.setSymopHome(strSymopHomeNorm)

        bKappaOn = self.config.get("KAPPA")
        if bKappaOn:
            #self.strPluginStrategyName = "EDPluginControlStrategyv10"
            #self.strPluginStrategyName = "EDPluginControlStrategyv2_0"
            self.KappaStrategy = 1
        else:
            self.KappaStrategy = 0
예제 #31
0
    def configure(self):
        """
        """
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlStrategyv10.configure")
        pluginConfiguration = self.getConfiguration()

        if(pluginConfiguration == None):
            warningMessage = EDMessage.WARNING_NO_PLUGIN_CONFIGURATION_ITEM_FOUND_02 % ('EDPluginControlStrategyv10.configure', self.getPluginName())
            EDVerbose.DEBUG(warningMessage)
        else:
            strSymopHome = EDConfiguration.getStringParamValue(pluginConfiguration, self.__strCONF_SYMOP_HOME)
            if(strSymopHome == None):
                warningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlStrategyv10.configure', self.__strCONF_SYMOP_HOME, self.getPluginName())
                EDVerbose.warning(warningMessage)
                self.addWarningMessage(warningMessage)
            else:
                strSymopHomeNorm = os.path.normpath(strSymopHome)
                self.setSymopHome(strSymopHomeNorm)
예제 #32
0
    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlKappaStrategyv2_0.configure")
        strSymopHome = self.config.get(self.strCONF_SYMOP_HOME)
        if strSymopHome is None:
            strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlKappaStrategyv2_0.configure', self.strCONF_SYMOP_HOME, self.getPluginName())
            EDVerbose.warning(strWarningMessage)
            self.addWarningMessage(strWarningMessage)
        else:
            strSymopHomeNorm = os.path.normpath(strSymopHome)
            self.setSymopHome(strSymopHomeNorm)

        bKappaOn = self.config.get("KAPPA")
        if bKappaOn:
            #self.strPluginStrategyName = "EDPluginControlStrategyv10"
            #self.strPluginStrategyName = "EDPluginControlStrategyv2_0"
            self.KappaStrategy = 1
        else:
            self.KappaStrategy = 0
예제 #33
0
 def newFile(self, filename="test", size=(0, 0), metadata={}):
     """this is a method to create a new empty file
     @param filename: name of the file to create, the size and the extension will be added.
     @type  filename: string
     @type size: 2-tuple of integers  
     @param size: the size of the image to create
     """
     if len(size) != 2 :
         EDVerbose.error("Error in the size of the size-tuple")
         raise Exception("Error in the size of the size-tuple")
     if size[0] < 0 :
         EDVerbose.error("Error in the X part of the size tuple")
         raise Exception("Error in the X part of the size tuple")
     if size[1] < 0 :
         EDVerbose.error("Error in the Y part of the size tuple")
         raise Exception("Error in the Y part of the size tuple")
     emptyNParray = numpy.zeros(size, dtype="float32")
     self.data[ filename ] = emptyNParray
     self.headers [ filename ] = metadata
     self.size [ filename ] = size
     fullFilename = "%sSize%ix%i.edf" % ((filename,) + size)
     if os.path.isfile(fullFilename):
         EDVerbose.warning("Warning, I am going to overwrite the file %s " % fullFilename)
         self.synchronizeOn()
         try:
             self.edf [ filename ] = EdfFile(fullFilename)
             self.data[ filename ] = self.edf[ filename ].GetData(0)
             self.headers [ filename ] = self.edf[ filename ].GetHeader(0)
         except Exception:
             EDVerbose.error("[ERROR] in reading file %s" % filename)
         self.synchronizeOff()
         if self.data[ filename ].shape != size :
             self.data[ filename ] = emptyNParray
             self.headers [ filename ] = metadata
     else:
         self.synchronizeOn()
         try:
             self.edf[ filename ] = EdfFile(fullFilename)
             self.edf[ filename ].WriteImage(self.headers [ filename ] , self.data [ filename ] , Append=0)
         except Exception:
             EDVerbose.error("[ERROR] in opening and creating file %s" % filename)
         self.synchronizeOff()
예제 #34
0
    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlStrategyv1_2.configure")
        pluginConfiguration = self.getConfiguration()

        if (pluginConfiguration == None):
            strWarningMessage = EDMessage.WARNING_NO_PLUGIN_CONFIGURATION_ITEM_FOUND_02 % (
                'EDPluginControlStrategyv1_2.configure', self.getPluginName())
            EDVerbose.warning(strWarningMessage)
            self.addWarningMessage(strWarningMessage)
        else:
            strSymopHome = self.getStringConfigurationParameterValue(
                self._strCONF_SYMOP_HOME)
            if (strSymopHome == None):
                strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % (
                    'EDPluginControlStrategyv1_2.configure',
                    self._strCONF_SYMOP_HOME, self.getPluginName())
                EDVerbose.warning(strWarningMessage)
                self.addWarningMessage(strWarningMessage)
            else:
                self.setSymopHome(strSymopHome)
예제 #35
0
파일: EDUtilsPath.py 프로젝트: kif/edna
 def getEdnaPluginCachePath(cls):
     """This private method initializes the path to the plugin cache file"""
     if cls._EDNA_PLUGINCACHE is None:
         if "EDNA_PLUGINCACHE" in os.environ.keys():
             cls._EDNA_PLUGINCACHE = os.environ["EDNA_PLUGINCACHE"]
             strDirName = os.path.dirname(cls._EDNA_PLUGINCACHE)
             if os.path.exists(cls._EDNA_PLUGINCACHE) and (not os.access(
                     cls._EDNA_PLUGINCACHE, os.W_OK)):
                 EDVerbose.warning(
                     "EDNA_PLUGINCACHE environment variable is set to %s but the file is not writeable!"
                     % cls._EDNA_PLUGINCACHE)
                 cls._EDNA_PLUGINCACHE = None
             elif not os.path.exists(strDirName):
                 EDVerbose.warning(
                     "EDNA_PLUGINCACHE environment variable is set to %s put the parent directory does not exist!"
                     % cls._EDNA_PLUGINCACHE)
                 cls._EDNA_PLUGINCACHE = None
             elif not os.access(strDirName, os.W_OK):
                 EDVerbose.warning(
                     "EDNA_PLUGINCACHE environment variable is set to %s put the parent directory cannot be accessed!"
                     % cls._EDNA_PLUGINCACHE)
                 cls._EDNA_PLUGINCACHE = None
         if cls._EDNA_PLUGINCACHE is None:
             strTempFileDir = EDUtilsPath.getEdnaUserTempFolder()
             # We create a hash of the path in order to be able to reference several different EDNA_HOME
             # caches in the same directory
             strCacheFileName = hashlib.sha1(
                 os.getenv('EDNA_HOME')).hexdigest() + ".xml"
             cls._EDNA_PLUGINCACHE = os.path.abspath(
                 os.path.join(strTempFileDir, strCacheFileName))
         EDVerbose.DEBUG("EDFactoryPlugin: Path to plugin cache: %s" %
                         cls._EDNA_PLUGINCACHE)
     return cls._EDNA_PLUGINCACHE
예제 #36
0
 def getEdnaPluginCachePath(cls):
     """This private method initializes the path to the plugin cache file"""
     if cls._EDNA_PLUGINCACHE is None:
         if "EDNA_PLUGINCACHE" in os.environ.keys():
             cls._EDNA_PLUGINCACHE = os.environ["EDNA_PLUGINCACHE"]
             strDirName = os.path.dirname(cls._EDNA_PLUGINCACHE)
             if os.path.exists(cls._EDNA_PLUGINCACHE) and (not os.access(cls._EDNA_PLUGINCACHE, os.W_OK)):
                 EDVerbose.warning(
                     "EDNA_PLUGINCACHE environment variable is set to %s but the file is not writeable!"
                     % cls._EDNA_PLUGINCACHE
                 )
                 cls._EDNA_PLUGINCACHE = None
             elif not os.path.exists(strDirName):
                 EDVerbose.warning(
                     "EDNA_PLUGINCACHE environment variable is set to %s put the parent directory does not exist!"
                     % cls._EDNA_PLUGINCACHE
                 )
                 cls._EDNA_PLUGINCACHE = None
             elif not os.access(strDirName, os.W_OK):
                 EDVerbose.warning(
                     "EDNA_PLUGINCACHE environment variable is set to %s put the parent directory cannot be accessed!"
                     % cls._EDNA_PLUGINCACHE
                 )
                 cls._EDNA_PLUGINCACHE = None
         if cls._EDNA_PLUGINCACHE is None:
             strTempFileDir = EDUtilsPath.getEdnaUserTempFolder()
             # We create a hash of the path in order to be able to reference several different EDNA_HOME
             # caches in the same directory
             strCacheFileName = hashlib.sha1(os.getenv("EDNA_HOME")).hexdigest() + ".xml"
             cls._EDNA_PLUGINCACHE = os.path.abspath(os.path.join(strTempFileDir, strCacheFileName))
         EDVerbose.DEBUG("EDFactoryPlugin: Path to plugin cache: %s" % cls._EDNA_PLUGINCACHE)
     return cls._EDNA_PLUGINCACHE
 def configure(self):
     """
     Configures the plugin with executable from configuration file
     """
     EDPluginExec.configure(self)
     EDVerbose.DEBUG("EDPluginExecProcess.configure")
     xsPluginItem = self.getConfiguration()
     if (xsPluginItem == None):
         EDVerbose.warning("EDPluginExecProcess.configure: No plugin item defined.")
         xsPluginItem = XSPluginItem()
     strExecutable = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcess.CONF_EXEC_PROCESS_EXECUTABLE)
     if(strExecutable == None):
         EDVerbose.DEBUG("EDPluginExecProcess.configure: No configuration parameter found for: %s , using default value: %s"\
                         % (EDPluginExecProcess.CONF_EXEC_PROCESS_EXECUTABLE, self.getExecutable()))
     else:
         self.setExecutable(strExecutable)
     # The execProcessTimeOut is deprecated, see bug #563
     strTimeOut = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcess.CONF_EXEC_PROCESS_TIME_OUT)
     if strTimeOut is not None:
         EDVerbose.WARNING("Use of %s in plugin configuration is deprecated" % EDPluginExecProcess.CONF_EXEC_PROCESS_TIME_OUT)
         EDVerbose.WARNING("Please use %s instead." % EDPlugin.CONF_TIME_OUT)
         self.setTimeOut(strTimeOut)
    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlKappaStrategyv2_0.configure")
        pluginConfiguration = self.getConfiguration()

        if pluginConfiguration != None:
            strSymopHome = EDConfiguration.getStringParamValue(pluginConfiguration, self.strCONF_SYMOP_HOME)
            if(strSymopHome == None):
                strWarningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % ('EDPluginControlKappaStrategyv2_0.configure', self.strCONF_SYMOP_HOME, self.getPluginName())
                EDVerbose.warning(strWarningMessage)
                self.addWarningMessage(strWarningMessage)
            else:
                strSymopHomeNorm = os.path.normpath(strSymopHome)
                self.setSymopHome(strSymopHomeNorm)

            strSymopHome = EDConfiguration.getStringParamValue(pluginConfiguration, "KAPPA")
            if(strSymopHome == None or strSymopHome != "ON"):
                #self.strPluginStrategyName = "EDPluginControlStrategyv10"
                #self.strPluginStrategyName = "EDPluginControlStrategyv2_0"
                self.KappaStrategy = 0
            else:
                self.KappaStrategy = 1
 def getImageFileNameFromTemplate(self, _strTemplate, _iImageNumber):
     bHashFound = False
     bFinished = False
     iFirstHash = None
     iNoHashes = 0
     strImageFileName = None
     try:
         for iIndex, pyChar in enumerate(_strTemplate):
             if ((not bHashFound) and (not bFinished)):
                 if (pyChar == "#"):
                     iFirstHash = iIndex
                     bHashFound = True
             else:
                 if ((pyChar != "#") and (not bFinished)):
                     bFinished = True
             if (bHashFound and (not bFinished)):
                 iNoHashes += 1
         strImageFileName = _strTemplate[ 0:iFirstHash ] + str(_iImageNumber).rjust(iNoHashes, "0")
     except:
         EDVerbose.warning("EDPluginMOSFLMGeneratePredictionv10: Couldn't transform template %s to file name" % _strTemplate)
         strImageFileName = None
     return strImageFileName
예제 #40
0
    def configure(self):
        """
        """
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlStrategyv10.configure")
        pluginConfiguration = self.getConfiguration()

        if (pluginConfiguration == None):
            warningMessage = EDMessage.WARNING_NO_PLUGIN_CONFIGURATION_ITEM_FOUND_02 % (
                'EDPluginControlStrategyv10.configure', self.getPluginName())
            EDVerbose.DEBUG(warningMessage)
        else:
            strSymopHome = EDConfiguration.getStringParamValue(
                pluginConfiguration, self.__strCONF_SYMOP_HOME)
            if (strSymopHome == None):
                warningMessage = EDMessage.WARNING_NO_PARAM_CONFIGURATION_ITEM_FOUND_03 % (
                    'EDPluginControlStrategyv10.configure',
                    self.__strCONF_SYMOP_HOME, self.getPluginName())
                EDVerbose.warning(warningMessage)
                self.addWarningMessage(warningMessage)
            else:
                strSymopHomeNorm = os.path.normpath(strSymopHome)
                self.setSymopHome(strSymopHomeNorm)
예제 #41
0
    def preProcess(self, _edObject=None):
        """
        Preprocess of the plugin: 
        check parameters and extract from EDNA format into something more simple & pythonic
        """
        EDPluginExec.preProcess(self)
        EDVerbose.DEBUG("EDPluginPyarchThumbnailv10.preProcess")
        sdi = self.getDataInput()
        if sdi.getInputImagePath() is not None:
            self.inputFilename = sdi.getInputImagePath().getPath().getValue()
            if not os.path.isfile(self.inputFilename):
                EDVerbose.ERROR("The input file provided is not a valid file: " + self.inputFilename)
                raise "Not a valid file " + self.inputFilename

            # Output path
            strImageNameWithoutExt = os.path.basename(os.path.splitext(self.inputFilename)[0])
            strImageDirname = os.path.dirname(self.inputFilename)
            strOutputDirname = self.createPyarchFilePath(strImageDirname)
            # Check that output pyarch path exists and is writeable:
            bIsOk = False
            if strOutputDirname:
                if not os.path.exists(strOutputDirname):
                    # Try to create the directory
                    try:
                        os.makedirs(strOutputDirname)
                        bIsOk = True
                    except BaseException, e:
                        EDVerbose.WARNING("Couldn't create the directory %s" % strOutputDirname)
                elif os.access(strOutputDirname, os.W_OK):
                    bIsOk = True
            if not bIsOk:
                EDVerbose.warning("Cannot write to pyarch directory: %s" % strOutputDirname)
                strOutputDirname = tempfile.mkdtemp("", "EDPluginPyarchThumbnailv10_", "/tmp")
                EDVerbose.warning("Writing thumbnail images to: %s" % strOutputDirname)

            self.strOutputPath = os.path.join(strOutputDirname, strImageNameWithoutExt + ".jpeg")
            self.strOutputPathThumb = os.path.join(strOutputDirname, strImageNameWithoutExt + ".thumb.jpeg")
예제 #42
0
파일: EDUtilsPath.py 프로젝트: gbourgh/edna
 def setEdnaTestDataImagesPath(cls, value):
     """
     This class method initializes the path to the test images downloaded from internet
     """
     cls._EDNA_TESTIMAGES = os.path.abspath(value)
     if os.path.exists(cls._EDNA_TESTIMAGES) and (not os.access(cls._EDNA_TESTIMAGES, os.W_OK)):
         EDVerbose.warning("EDNA_TESTIMAGES environment variable is set to %s but the file is not writeable!" % cls._EDNA_TESTIMAGES)
         cls._EDNA_TESTIMAGES = None
     elif not os.path.exists(cls._EDNA_TESTIMAGES):
         EDVerbose.warning("EDNA_TESTIMAGES environment variable is set to %s put the directory does not exist!" % cls._EDNA_TESTIMAGES)
         cls._EDNA_TESTIMAGES = None
     elif not os.access(cls._EDNA_TESTIMAGES, os.W_OK):
         EDVerbose.warning("EDNA_TESTIMAGES environment variable is set to %s put the directory cannot be accessed!" % cls._EDNA_TESTIMAGES)
         cls._EDNA_TESTIMAGES = None
예제 #43
0
파일: EDUtilsPath.py 프로젝트: kif/edna
 def setEdnaTestDataImagesPath(cls, value):
     """
     This class method initializes the path to the test images downloaded from internet
     """
     cls._EDNA_TESTIMAGES = os.path.abspath(value)
     if os.path.exists(cls._EDNA_TESTIMAGES) and (not os.access(
             cls._EDNA_TESTIMAGES, os.W_OK)):
         EDVerbose.warning(
             "EDNA_TESTIMAGES environment variable is set to %s but the file is not writeable!"
             % cls._EDNA_TESTIMAGES)
         cls._EDNA_TESTIMAGES = None
     elif not os.path.exists(cls._EDNA_TESTIMAGES):
         EDVerbose.warning(
             "EDNA_TESTIMAGES environment variable is set to %s put the directory does not exist!"
             % cls._EDNA_TESTIMAGES)
         cls._EDNA_TESTIMAGES = None
     elif not os.access(cls._EDNA_TESTIMAGES, os.W_OK):
         EDVerbose.warning(
             "EDNA_TESTIMAGES environment variable is set to %s put the directory cannot be accessed!"
             % cls._EDNA_TESTIMAGES)
         cls._EDNA_TESTIMAGES = None
 def createDNAFileDirectory(self, _strDNAFileDirectoryPath):
     """
     Create a "DNA-files" directory - if possible.
     """
     bSuccess = False
     if (_strDNAFileDirectoryPath is not None):
         if (os.path.exists(_strDNAFileDirectoryPath)):
             EDVerbose.warning("Removing existing DNA files directory: %s" % _strDNAFileDirectoryPath)
             if (os.access(_strDNAFileDirectoryPath, os.W_OK)):
                 shutil.rmtree(_strDNAFileDirectoryPath)
             else:
                 EDVerbose.warning("Cannot remove existing DNA files directory!")
         if (_strDNAFileDirectoryPath is not None):
             # Check if directory one level up is writeable
             strDNAFileBaseDirectory = os.path.split(_strDNAFileDirectoryPath)[0]
             if (os.access(strDNAFileBaseDirectory, os.W_OK)):
                 EDVerbose.DEBUG("Creating DNA files directory: %s" % _strDNAFileDirectoryPath)
                 os.mkdir(_strDNAFileDirectoryPath)
                 bSuccess = True
             else:
                 EDVerbose.warning("Cannot create DNA files directory: %s" % _strDNAFileDirectoryPath)
     return bSuccess
 def createDNAFileDirectory(self, _strDNAFileDirectoryPath):
     """
     Create a "DNA-files" directory - if possible.
     """
     bSuccess = False
     if (_strDNAFileDirectoryPath is not None):
         if (os.path.exists(_strDNAFileDirectoryPath)):
             EDVerbose.warning("Removing existing DNA files directory: %s" % _strDNAFileDirectoryPath)
             if (os.access(_strDNAFileDirectoryPath, os.W_OK)):
                 shutil.rmtree(_strDNAFileDirectoryPath)
             else:
                 EDVerbose.warning("Cannot remove existing DNA files directory!")
         if (_strDNAFileDirectoryPath is not None):
             # Check if directory one level up is writeable
             strDNAFileBaseDirectory = os.path.split(_strDNAFileDirectoryPath)[0]
             if (os.access(strDNAFileBaseDirectory, os.W_OK)):
                 EDVerbose.DEBUG("Creating DNA files directory: %s" % _strDNAFileDirectoryPath)
                 os.mkdir(_strDNAFileDirectoryPath)
                 bSuccess = True
             else:
                 EDVerbose.warning("Cannot create DNA files directory: %s" % _strDNAFileDirectoryPath)
     return bSuccess
예제 #46
0
    def configure(self):
        """
        Configures the plugin from the configuration file with the following
        parameters
         - The shell that will execute the script
         - Script executor
         - Script executable to be invoked
         - Path to CCP4 setup file if required
         - The 3rd party executable installed version
        """
        EDPluginExec.configure(self)
        EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.configure")
        xsPluginItem = self.getConfiguration()
        if (xsPluginItem == None):
            EDVerbose.warning(
                "EDPluginExecProcessXIA2CORE.configure: No plugin item defined.")
            xsPluginItem = XSPluginItem()

        if (self.getExecutable() is None):
            strExecutable = EDConfiguration.getStringParamValue(
                xsPluginItem,
                EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE)
            if(strExecutable == None):
                strErrorMessage = "Configuration parameter missing: " + \
                                  EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                if (EDVerbose.isVerboseDebug()):
                    raise RuntimeError, strErrorMessage
            else:
                # Check that the executable file exists
                if (os.path.exists(strExecutable) == False):
                    strErrorMessage = "Cannot find configured " + EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_EXECUTABLE + " : " + strExecutable
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    self.setFailure()
                    if (EDVerbose.isVerboseDebug()):
                        raise RuntimeError, strErrorMessage
                else:
                    self.setExecutable(strExecutable)

        if (self.getConfigXIA2COREType() is None):
            strXIA2COREType = EDConfiguration.getStringParamValue(
                xsPluginItem,
                EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_XIA2CORE_TYPE)
            if(strXIA2COREType == None):
                strErrorMessage = "Configuration parameter not set: " + \
                                  EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_XIA2CORE_TYPE
                EDVerbose.DEBUG(strErrorMessage)
            else:
                # FIXME test that this is a legal name
                self.__strConfigXIA2COREType = strXIA2COREType

        strVersion = EDConfiguration.getStringParamValue(xsPluginItem, EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_VERSION_STRING)
        if(strVersion == None):
            EDVerbose.DEBUG("EDPluginExecProcessXIA2CORE.configure: No configuration parameter found for: " + \
                            EDPluginExecProcessXIA2CORE.CONF_EXEC_PROCESS_VERSION_STRING + ", NO default value!")
        else:
            self.setStringVersion(strVersion)
        if (self.__strLogFileName == None):
            self.setLogFileName(self.getBaseName() + ".log")
        if (self.__strErrorLogFileName == None):
            self.setErrorLogFileName(self.getBaseName() + ".err")

        if self.__strExecutable is None:
            EDVerbose.ERROR("Executable not defined in configuration file")
            # shall we raise an exception?

        self.__strPathToHostNamePidFile = os.path.join(self.getWorkingDirectory(), os.path.basename(self.__strExecutable) + "_hostNamePid.txt")

        return
예제 #47
0
    def process(self, _edObject=None):
        """
        This is the main method of the plugin, it does the job, not the EDNA name conversions which were done in the preprocess. 
        """

        EDPluginExec.process(self)
        EDVerbose.DEBUG("EDPluginExecThumbnailv10.process")

        #        try:
        #        except Exception:
        #        edfImage = EDF(self.inputFilename)
        #        self.npaImage = edfImage.GetData(0)

        #        Read the image using FABIO
        isRGB = False
        pilOutputImage = None
        if self.inputFilename is not None:
            try:
                fabioImage = openimage(self.inputFilename)
                self.npaImage = fabioImage.data
            except Exception:
                pilInputImage = Image.open(self.inputFilename)
                x, y = pilInputImage.size
                ImageFile.MAXBLOCK = x * y
                if pilInputImage.mode == "1":
                    self.npaImage = numpy.asarray(pilInputImage).astype(
                        "uint8")
                    isRGB = False
                elif pilInputImage.mode == "F":
                    self.npaImage = numpy.asarray(pilInputImage)
                    isRGB = False
                elif pilInputImage.mode == "L":
                    self.npaImage = numpy.asarray(pilInputImage)
                    isRGB = False
                elif pilInputImage.mode == "P":
                    self.npaImage = numpy.asarray(pilInputImage.convert("RGB"))
                    isRGB = True
                elif pilInputImage.mode == "RGB":
                    self.npaImage = numpy.asarray(pilInputImage)
                    isRGB = True
                elif pilInputImage.mode == "CMJK":
                    self.npaImage = numpy.asarray(pilInputImage.convert("RGB"))
                    isRGB = True

        dtype = self.npaImage.dtype
        NPAImageFloat = None

        # crop border
        if len(self.cropBorders) > 0:

            if len(self.cropBorders) == 1:
                crop0 = self.cropBorders[0]
                crop1 = self.cropBorders[0]
            else:
                crop0 = self.cropBorders[0]
                crop1 = self.cropBorders[1]
            if isRGB:
                self.npaImage = self.npaImage[crop0:-crop0, crop1:crop1, :]
            else:
                self.npaImage = self.npaImage[crop0:-crop0, crop1:crop1]

# Set maxima and minima
        if (self.minLevelUnit is not None) or (self.maxLevelUnit is not None):
            sortedArray = self.npaImage.flatten()
            sortedArray.sort()

        if self.minLevel is not None:
            self.normalize = True
            if isRGB:
                EDVerbose.warning(
                    "It is not allowed  to set Min with RGB data")
            else:
                if self.minLevelUnit in ["%", "percent"]:
                    self.minLevel = sortedArray[int(
                        round(float(self.minLevel) * sortedArray.size /
                              100.0))]
                if isinstance(self.npaImage[0, 0], int):
                    self.npaImage = numpy.maximum(
                        self.npaImage,
                        int(self.minLevel) * numpy.ones_like(self.npaImage))
                else:
                    self.npaImage = numpy.maximum(
                        self.npaImage,
                        self.minLevel * numpy.ones_like(self.npaImage))

        if self.maxLevel is not None:
            self.normalize = True
            if isRGB:
                EDVerbose.warning(
                    "It is not allowed  to set Max with RGB data")
            else:
                if self.maxLevelUnit in ["%", "percent"]:
                    self.maxLevel = sortedArray[int(
                        round(float(self.maxLevel) * sortedArray.size /
                              100.0))]
                if isinstance(self.npaImage[0, 0], int):
                    self.npaImage = numpy.minimum(
                        self.npaImage,
                        int(self.maxLevel) * numpy.ones_like(self.npaImage))
                else:
                    self.npaImage = numpy.minimum(
                        self.npaImage,
                        self.maxLevel * numpy.ones_like(self.npaImage))

# Scipy filters come here:
        if len(self.gaussianBlur) > 0:
            if len(self.gaussianBlur) == 1:
                kernel = (self.gaussianBlur[0], self.gaussianBlur[0])
            else:
                kernel = (self.gaussianBlur[0], self.gaussianBlur[1])
            if isRGB:
                kernel = (kernel[0], kernel[1], 0)
            self.npaImage = scipy.ndimage.gaussian_filter(
                self.npaImage, kernel)

        if len(self.dilatation) > 0:
            if len(self.dilatation) == 1:
                kernel = (self.dilatation[0], self.dilatation[0])
            else:
                kernel = (self.dilatation[0], self.dilatation[1])
            if isRGB:
                kernel = (kernel[0], kernel[1], 0)
            self.npaImage = scipy.ndimage.morphology.grey_dilation(
                self.npaImage, kernel)

#Normalization ; equalization
        if (self.normalize is True) or (self.equalize is True):
            if isRGB is True:
                self.npaImage = numpy.asarray(
                    ImageOps.equalize(Image.fromarray(self.npaImage)))
            else:
                EDVerbose.DEBUG("EDPluginExecThumbnailv10: Normalization")
                vmin = self.npaImage.min()
                vmax = self.npaImage.max()
                NPAImageFloat = (self.npaImage.astype(numpy.float32) -
                                 float(vmin)) / (float(vmax) - float(vmin))
                if (self.equalize == True):
                    nbr_bins = 64
                    NPAImageFloatFlat = NPAImageFloat.flatten()
                    imhist, bins = numpy.histogram(
                        NPAImageFloatFlat, nbr_bins,
                        normed=True)  #get image histogram
                    cdf = imhist.cumsum()  #cumulative distribution function
                    ncdf = cdf / cdf[
                        -1]  #normalized cumulative distribution function
                    #                    print ncdf
                    NPAImageFloat2Flat = numpy.interp(NPAImageFloatFlat, bins,
                                                      [0] + ncdf.tolist())
                    NPAImageFloat = NPAImageFloat2Flat.reshape(
                        NPAImageFloat.shape)
                    EDVerbose.DEBUG("Equalize: min= %f, max= %f" %
                                    (NPAImageFloat.min(), NPAImageFloat.max()))

#Gamma and logarithm scale
        if ((self.log is True) or (self.gamma != 1)) and (
                NPAImageFloat is None):  # then we need the array in float
            if dtype == numpy.uint8:
                NPAImageFloat = self.npaImage.astype(numpy.float32) / 255.0
            elif dtype == numpy.uint16:
                NPAImageFloat = self.npaImage.astype(numpy.float32) / 65535.0
            else:
                NPAImageFloat = self.npaImage.astype(numpy.float32)

        if self.log is True:
            NPAImageFloat = numpy.log(1 - NPAImageFloat.min() + NPAImageFloat)
            vmin = NPAImageFloat.min()
            vmax = NPAImageFloat.max()
            NPAImageFloat = (NPAImageFloat - vmin) / (vmax - vmin)

        if self.gamma != 1:
            if dtype not in [numpy.uint8, numpy.uint16]:
                vmin = NPAImageFloat.min()
                vmax = NPAImageFloat.max()
                NPAImageFloat = (NPAImageFloat - vmin) / (vmax - vmin)
            NPAImageInt = (255.0 * (NPAImageFloat**self.gamma)).astype("uint8")

        else:  #if (self.gamma == 1):
            if NPAImageFloat is None:
                if dtype == numpy.uint8:
                    NPAImageInt = self.npaImage
                elif dtype == numpy.uint16:
                    NPAImageInt = (self.npaImage / 256).astype(numpy.uint8)
                else:  #for float or a signed integer
                    vmin = self.npaImage.min()
                    vmax = self.npaImage.max()
                    NPAImageInt = (
                        (self.npaImage.astype(numpy.float32) - vmin) /
                        (vmax - vmin) * 255.0).astype(numpy.uint8)
            else:
                vmin = NPAImageFloat.min()
                vmax = NPAImageFloat.max()
                EDVerbose.DEBUG(
                    "EDPluginExecThumbnailv10:   NPAImageFloat => NPAImageInt min=%s max =%s"
                    % (vmin, vmax))
                NPAImageInt = ((NPAImageFloat - vmin) * 255.0 /
                               (vmax - vmin)).astype(numpy.uint8)
#COnversion back to PIL mode
        if isRGB is True:
            pilOutputImage = Image.fromarray(NPAImageInt, 'RGB')
        else:
            pilOutputImage = Image.fromarray(NPAImageInt, 'L')

        if (self.autocontrast is not None):
            pilOutputImage = ImageOps.autocontrast(pilOutputImage,
                                                   self.autocontrast)

        if (self.width is not None) or (self.height is not None):
            if (self.width > 0) and (self.height > 0):
                if self.keepRatio is True:
                    #                    PIL takes care of the ratio
                    pilOutputImage.thumbnail((self.width, self.height),
                                             Image.ANTIALIAS)
                else:
                    pilOutputImage = pilOutputImage.resize(
                        (self.width, self.height), Image.ANTIALIAS)
            else:
                if self.width is None:
                    pilOutputImage.thumbnail((self.height, self.height),
                                             Image.ANTIALIAS)
                elif self.height is None:
                    pilOutputImage.thumbnail((self.width, self.width),
                                             Image.ANTIALIAS)

        if self.invert == True:
            pilOutputImage = ImageOps.invert(pilOutputImage)
        if self.colorize == True:
            pilOutputImage.putpalette(EDPluginExecThumbnailv10.getPalette())
            pilOutputImage = pilOutputImage.convert("RGB")

        self.synchronizeOn()
        if self.format == "jpg":
            self.width, self.height = pilOutputImage.size
            if self.width * self.height > ImageFile.MAXBLOCK:
                ImageFile.MAXBLOCK = self.width * self.height
            try:
                pilOutputImage.save(self.output,
                                    "JPEG",
                                    quality=85,
                                    optimize=True)
            except TypeError:
                pilOutputImage.save(self.output)
        else:
            pilOutputImage.save(self.output)
        self.synchronizeOff()
예제 #48
0
        sys.exit(1)
    for strPath in listPaths:
        EDVerbose.screen("Starting EDNA AutoProc -> ISPyB for file %s" %
                         strPath)
        xsDataInputStoreAutoProc = XSDataInputStoreAutoProc()
        strXMLAutoProcContainer = EDUtilsFile.readFile(strPath)
        xsDataAutoProcContainer = AutoProcContainer.parseString(
            strXMLAutoProcContainer)
        if xsDataAutoProcContainer is None:
            EDVerbose.WARNING("Couldn't parse file %s" % strPath)
        else:
            if xsDataAutoProcContainer.AutoProcProgramContainer.AutoProcProgram.processingStatus == "True":
                xsDataAutoProcContainer.AutoProcProgramContainer.AutoProcProgram.processingStatus = "SUCCESS"
            xsDataInputStoreAutoProc.setAutoProcContainer(
                xsDataAutoProcContainer)
            edPluginISPyBStoreAutoProc = EDFactoryPluginStatic.loadPlugin(
                "EDPluginISPyBStoreAutoProcv1_4")
            edPluginISPyBStoreAutoProc.setDataInput(xsDataInputStoreAutoProc)
            edPluginISPyBStoreAutoProc.executeSynchronous()
            if edPluginISPyBStoreAutoProc.isFailure():
                EDVerbose.ERROR("XML data not stored in ISPyB")
            else:
                xsDataResultISPyBStoreAutoProc = edPluginISPyBStoreAutoProc.dataOutput
                EDVerbose.screen("XML data sucessfully stored in ISPyB")
                if xsDataResultISPyBStoreAutoProc.autoProcScalingId is not None:
                    EDVerbose.screen(
                        "autoProcScalingId: %d" %
                        xsDataResultISPyBStoreAutoProc.autoProcScalingId.value)
                else:
                    EDVerbose.warning("No autoProcScalingId in results!")
예제 #49
0
    def readHeaderMarccd(self, _strFileName):
        """
        Returns an dictionary with the contents of a MAR CCD image header.
        """
        #
        #  Created by Krister Larsson on 08/11/5.
        #  Modified by Olof Svensson 20090401
        #
        strUint32 = 'I'
        strChar = 's'
        #strInt16 = 'H'
        strInt32 = 'i'

        iMAXIMAGES = 9

        pyListHeader = [
            #File/header format parameters (256bytes)
            [strUint32, 'header_type'],
            [strChar, 'header_name', 16],
            [strUint32, 'header_major_version'],
            [strUint32, 'header_minor_version'],
            [strUint32, 'header_byte_order'],
            [strUint32, 'data_byte_order'],
            [strUint32, 'header_size'],
            [strUint32, 'frame_type'],
            [strUint32, 'magic_number'],
            [strUint32, 'compression_type'],
            [strUint32, 'compression1'],
            [strUint32, 'compression2'],
            [strUint32, 'compression3'],
            [strUint32, 'compression4'],
            [strUint32, 'compression5'],
            [strUint32, 'compression6'],
            [strUint32, 'nheaders'],
            [strUint32, 'nfast'],
            [strUint32, 'nslow'],
            [strUint32, 'depth'],
            [strUint32, 'record_length'],
            [strUint32, 'signif_bits'],
            [strUint32, 'data_type'],
            [strUint32, 'saturated_value'],
            [strUint32, 'sequence'],
            [strUint32, 'nimages'],
            [strUint32, 'origin'],
            [strUint32, 'orientation'],
            [strUint32, 'view_direction'],
            [strUint32, 'overflow_direction'],
            [strUint32, 'over_8_bits'],
            [strUint32, 'over_16_bits'],
            [strUint32, 'multiplexed'],
            [strUint32, 'nfastimages'],
            [strUint32, 'nslowimages'],
            [strUint32, 'darkcurrent_applied'],
            [strUint32, 'bias_applied'],
            [strUint32, 'flatfield_applied'],
            [strUint32, 'distortion_applied'],
            [strUint32, 'original_header_type'],
            [strUint32, 'file_saved'],
            [strUint32, 'n_valid_pixels'],
            [strUint32, 'defectmap_applied'],
            [strUint32, 'subimage_nfast'],
            [strUint32, 'subimage_nslow'],
            [strUint32, 'subimage_origin_fast'],
            [strUint32, 'subimage_origin_slow'],
            [strUint32, 'readout_pattern'],
            [strUint32, 'saturation_level'],
            [strUint32, 'orientation_code'],
            [strUint32, 'frameshift_multiplexed'],
            [strUint32, 'precsan_nfast'],
            [strUint32, 'prescan_nslow'],
            [strUint32, 'postscan_nfast'],
            [strUint32, 'postscan_nslow'],
            [strUint32, 'prepost_trimmed'],
            [strChar, 'reserve1', 20],
            #Data statistics (128 bytes)
            [strUint32, 'total_counts', 2],
            [strUint32, 'special_counts1', 2],
            [strUint32, 'special_counts2', 2],
            [strUint32, 'min'],
            [strUint32, 'max'],
            [strUint32, 'mean'],
            [strUint32, 'rms'],
            [strUint32, 'n_zeros'],
            [strUint32, 'n_saturated'],
            [strUint32, 'stats_uptodate'],
            [strUint32, 'pixel_noise', iMAXIMAGES],
            [strChar, 'reserve2', (19 - iMAXIMAGES) * 4],

            #More statistics (256 bytes)
            #[uint16,'percentile',128],
            #Percentile is substituted by Sample changer info
            [strChar, 'barcode', 16],
            [strUint32, 'barcode_angle'],
            [strUint32, 'barcode_status'],
            [strChar, 'reserve2a', 232],
            #Goniostat parameters (128 bytes)
            [strInt32, 'xtal_to_detector'],
            [strInt32, 'beam_x'],
            [strInt32, 'beam_y'],
            [strInt32, 'integration_time'],
            [strInt32, 'exposure_time'],
            [strInt32, 'readout_time'],
            [strInt32, 'nreads'],
            [strInt32, 'start_twotheta'],
            [strInt32, 'start_omega'],
            [strInt32, 'start_chi'],
            [strInt32, 'start_kappa'],
            [strInt32, 'start_phi'],
            [strInt32, 'start_delta'],
            [strInt32, 'start_gamma'],
            [strInt32, 'start_xtal_to_detector'],
            [strInt32, 'end_twotheta'],
            [strInt32, 'end_omega'],
            [strInt32, 'end_chi'],
            [strInt32, 'end_kappa'],
            [strInt32, 'end_phi'],
            [strInt32, 'end_delta'],
            [strInt32, 'end_gamma'],
            [strInt32, 'end_xtal_to_detector'],
            [strInt32, 'rotation_axis'],
            [strInt32, 'rotation_range'],
            [strInt32, 'detector_rotx'],
            [strInt32, 'detector_roty'],
            [strInt32, 'detector_rotz'],
            [strInt32, 'total_dose'],
            [strChar, 'reserve3', 12],
            #Detector parameters (128 bytes)
            [strInt32, 'detector_type'],
            [strInt32, 'pixelsize_x'],
            [strInt32, 'pixelsize_y'],
            [strInt32, 'mean_bias'],
            [strInt32, 'photons_per_100adu'],
            [strInt32, 'measured_bias', iMAXIMAGES],
            [strInt32, 'measured_temperature', iMAXIMAGES],
            [strInt32, 'measured_pressure', iMAXIMAGES],
            #X-ray source and optics parameters (128 bytes)
            [strInt32, 'source_type'],
            [strInt32, 'source_dx'],
            [strInt32, 'source_dy'],
            [strInt32, 'source_wavelength'],
            [strInt32, 'source_power'],
            [strInt32, 'source_voltage'],
            [strInt32, 'source_current'],
            [strInt32, 'source_bias'],
            [strInt32, 'source_polarization_x'],
            [strInt32, 'source_polarization_y'],
            [strInt32, 'source_intensity_0'],
            [strInt32, 'source_intensity_1'],
            [strChar, 'reserve_source', 8],
            [strInt32, 'optics_type'],
            [strInt32, 'optics_dx'],
            [strInt32, 'optics_dy'],
            [strInt32, 'optics_wavelength'],
            [strInt32, 'optics_dispersion'],
            [strInt32, 'optics_crossfire_x'],
            [strInt32, 'optics_crossfire_y'],
            [strInt32, 'optics_angle'],
            [strInt32, 'optics_polarization_x'],
            [strInt32, 'optics_polarization_y'],
            [strChar, 'reserve_optics', 16],
            [strChar, 'reserve5', 16],
            #File parameters
            [strChar, 'filetitle', 128],
            [strChar, 'filepath', 128],
            [strChar, 'filename', 64],
            [strChar, 'acquire_timestamp', 32],
            [strChar, 'header_timestamp', 32],
            [strChar, 'save_timestamp', 32],
            [strChar, 'file_comment', 512],
            [strChar, 'reserve6', 96],
            [strChar, 'dataset_comments', 512],
            [strChar, 'user_data', 512]
        ]

        pyFile = None
        dictMarccd = None
        try:
            pyFile = open(_strFileName, "rb")
        except:
            EDVerbose.warning(
                "EDPluginExecReadImageHeaderMARCCDv10.readHeaderMarccd: couldn't open file: "
                + _strFileName)
        if (pyFile is not None):
            EDVerbose.DEBUG(
                "EDPluginExecReadImageHeaderMARCCDv10.readHeaderMarccd: Reading header from image "
                + _strFileName)
            dictMarccd = {}
            #Move to marccd part of header
            pyFile.seek(1024)
            for pyListRow in pyListHeader:
                if len(pyListRow) == 3:
                    strFormat = str(pyListRow[2]) + str(pyListRow[0])
                else:
                    strFormat = pyListRow[0]
                strKeyword = pyListRow[1]
                iReadSize = struct.calcsize(strFormat)
                pyRawData = pyFile.read(iReadSize)
                strValue = struct.unpack(strFormat, pyRawData)
                if len(strValue) == 1:
                    strValue = strValue[0]
                if pyListRow[0] == strChar:
                    strValue = strValue.strip('\x00')
                dictMarccd[strKeyword] = strValue
            pyFile.close()

        return dictMarccd
예제 #50
0
    def getXSDataInputBest(self, _xsDataInputStrategy):
        xsDataBeam = _xsDataInputStrategy.getExperimentalCondition().getBeam()
        xsDataSample = _xsDataInputStrategy.getSample()
        xsDataDetector = _xsDataInputStrategy.getExperimentalCondition(
        ).getDetector()
        xsDataGoniostat = _xsDataInputStrategy.getExperimentalCondition(
        ).getGoniostat()
        xsDataDiffractionPlan = _xsDataInputStrategy.getDiffractionPlan()
        xsDataStringBestFileContentDat = _xsDataInputStrategy.getBestFileContentDat(
        )
        xsDataStringBestFileContentPar = _xsDataInputStrategy.getBestFileContentPar(
        )
        xsDataFileXdsBackgroundImage = _xsDataInputStrategy.getXdsBackgroundImage(
        )
        listXSDataStringBestFileContentHKL = _xsDataInputStrategy.getBestFileContentHKL(
        )
        xsDataInputBest = XSDataInputBest()

        # Sample
        xsDataAbsorbedDose = None
        xsDataSusceptibility = None

        # Could be None if sample has not been set
        # It could be not None in case Raddose has calculated an absorbed dose with default sample values
        if (xsDataSample is not None):
            xsDataAbsorbedDose = xsDataSample.getAbsorbedDoseRate()
            xsDataSusceptibility = xsDataSample.getSusceptibility()
            # crystalShape
            # Default value is 1 (We assume that Xtal is smaller than beam)
            if xsDataSample.size is not None and xsDataSample.omegaMin is not None:
                xsDataInputBest.crystalSize = XSDataSize().parseString(
                    xsDataSample.size.marshal())
                xsDataInputBest.omegaMin = xsDataSample.omegaMin
            else:
                xsDataDoubleCrystalShape = xsDataSample.getShape()
                if (xsDataDoubleCrystalShape is None):
                    if (xsDataSample.getSize() is
                            None) or (xsDataBeam.getSize() is None):
                        xsDataDoubleCrystalShape = XSDataDouble(1)
                    else:
                        fCrystalSizeY = xsDataSample.getSize().getY().getValue(
                        )
                        fCrystalSizeZ = xsDataSample.getSize().getZ().getValue(
                        )
                        fDiagonal = math.sqrt(fCrystalSizeY**2 +
                                              fCrystalSizeZ**2)
                        fBeamSizeY = xsDataBeam.getSize().getY().getValue()
                        fCrystalShape = None
                        if fBeamSizeY > fDiagonal:
                            fCrystalShape = 1.0
                        else:
                            fCrystalShape = int(
                                10 * fDiagonal / fBeamSizeY) / 10.0
                        xsDataDoubleCrystalShape = XSDataDouble(fCrystalShape)
                xsDataInputBest.setCrystalShape(xsDataDoubleCrystalShape)
            # Radiation damage model parameters
            xsDataInputBest.setRadiationDamageModelBeta(
                xsDataSample.getRadiationDamageModelBeta())
            xsDataInputBest.setRadiationDamageModelGamma(
                xsDataSample.getRadiationDamageModelGamma())

        # Could be None if Raddose failed to calculate the absorbed dose
        if (xsDataAbsorbedDose is not None):
            xsDataInputBest.setCrystalAbsorbedDoseRate(
                xsDataSample.getAbsorbedDoseRate())

        xsDataInputBest.setCrystalSusceptibility(xsDataSusceptibility)

        # Detector
        xsDataInputBest.setDetectorType(xsDataDetector.getType())

        # Minimum exposure time per image
        xsDataTimeMinExposureTimePerImage = None
        if xsDataBeam:
            xsDataTimeMinExposureTimePerImage = xsDataBeam.getMinExposureTimePerImage(
            )
        if xsDataTimeMinExposureTimePerImage == None:
            xsDataTimeMinExposureTimePerImage = xsDataDiffractionPlan.getMinExposureTimePerImage(
            )
        xsDataInputBest.setBeamMinExposureTime(
            xsDataTimeMinExposureTimePerImage)

        # Max rotation speed
        xsDataAngularSpeedMax = None
        if xsDataGoniostat:
            xsDataAngularSpeedMax = xsDataGoniostat.getMaxOscillationSpeed()
        if xsDataDiffractionPlan and xsDataAngularSpeedMax == None:
            xsDataAngularSpeedMax = xsDataDiffractionPlan.getGoniostatMaxOscillationSpeed(
            )
        xsDataInputBest.setGoniostatMaxRotationSpeed(xsDataAngularSpeedMax)

        # Min rotation width
        xsDataAngleMin = None
        if xsDataGoniostat:
            xsDataAngleMin = xsDataGoniostat.getMinOscillationWidth()
        if xsDataDiffractionPlan and xsDataAngleMin == None:
            xsDataAngleMin = xsDataDiffractionPlan.getGoniostatMinOscillationWidth(
            )
        xsDataInputBest.setGoniostatMinRotationWidth(xsDataAngleMin)

        # Other beam parameters
        if xsDataBeam:
            xsDataInputBest.setBeamExposureTime(xsDataBeam.getExposureTime())
            if xsDataBeam.getTransmission():
                # Fix for bug 741: if the transmission is zero don't set it and warn the user
                fTransmission = xsDataBeam.getTransmission().getValue()
                if (abs(fTransmission) < 0.1):
                    EDVerbose.warning(
                        "Input transmission to BEST ignored because it is zero or close to zero: %f"
                        % fTransmission)
                else:
                    xsDataInputBest.setTransmission(
                        xsDataBeam.getTransmission())
            if xsDataBeam.getApertureSize():
                xsDataInputBest.setApertureSize(xsDataBeam.getApertureSize())
            if xsDataBeam.size:
                xsDataInputBest.setBeamSize(xsDataBeam.size)
            if xsDataBeam.flux:
                xsDataInputBest.setBeamFlux(xsDataBeam.flux)

        # Other diffraction plan parameters
        if xsDataDiffractionPlan:
            xsDataInputBest.setAimedResolution(
                xsDataDiffractionPlan.getAimedResolution())
            xsDataInputBest.setAimedRedundancy(
                xsDataDiffractionPlan.getAimedMultiplicity())
            xsDataInputBest.setAimedCompleteness(
                xsDataDiffractionPlan.getAimedCompleteness())
            xsDataInputBest.setAimedIOverSigma(
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution())
            xsDataInputBest.setBeamMaxExposureTime(
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection())
            xsDataInputBest.setComplexity(
                xsDataDiffractionPlan.getComplexity())
            xsDataInputBest.setAnomalousData(
                xsDataDiffractionPlan.getAnomalousData())
            xsDataInputBest.setStrategyOption(
                xsDataDiffractionPlan.getStrategyOption())
            xsDataInputBest.setMinTransmission(
                xsDataDiffractionPlan.getMinTransmission())
            xsDataInputBest.setNumberOfCrystalPositions(
                xsDataDiffractionPlan.getNumberOfPositions())
            xsDataInputBest.setDetectorDistanceMin(
                xsDataDiffractionPlan.getDetectorDistanceMin())
            xsDataInputBest.setDetectorDistanceMax(
                xsDataDiffractionPlan.getDetectorDistanceMax())
            xsDataInputBest.setUserDefinedRotationStart(
                xsDataDiffractionPlan.getUserDefinedRotationStart())
            xsDataInputBest.setUserDefinedRotationRange(
                xsDataDiffractionPlan.getUserDefinedRotationRange())
            xsDataInputBest.doseLimit = xsDataDiffractionPlan.doseLimit
            xsDataInputBest.rFriedel = xsDataDiffractionPlan.rFriedel

        # Best Files
        xsDataInputBest.setBestFileContentDat(xsDataStringBestFileContentDat)
        xsDataInputBest.setBestFileContentPar(xsDataStringBestFileContentPar)
        xsDataInputBest.setBestFileContentHKL(
            listXSDataStringBestFileContentHKL)
        xsDataInputBest.setXdsBackgroundImage(xsDataFileXdsBackgroundImage)

        return xsDataInputBest
예제 #51
0
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     EDVerbose.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess")
     # Check that the input image exists and is of the expected type
     strPathToDiffractionImage = self.getDataInput().getDiffractionImage().getPath().getValue()
     strImageFileNameExtension = os.path.splitext(strPathToDiffractionImage)[1]
     if not strImageFileNameExtension in [".img", ".marccd", ".mccd", ".cbf"]:
         print strImageFileNameExtension
         EDVerbose.error("Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage)
         self.setFailure()
     else:
         # Load the waitFile plugin
         xsDataInputWaitFile = XSDataInputWaitFile()
         xsDataInputWaitFile.setExpectedSize(XSDataInteger(self.__iExpectedSize))
         xsDataInputWaitFile.setExpectedFile(self.getDataInput().getDiffractionImage())
         if self.getDataInput().getWaitForFileTimeOut():
             xsDataInputWaitFile.setTimeOut(self.getDataInput().getWaitForFileTimeOut())
         self.__edPluginWaitFile = EDPluginWaitFile()
         self.__edPluginWaitFile.setDataInput(xsDataInputWaitFile)
         # Load the execution plugin
         self.__edPluginExecThumbnail = self.loadPlugin(self.__strExecThumbnailPluginName)
         xsDataInputExecThumbnail = XSDataInputExecThumbnail()
         xsDataInputExecThumbnail.setInputImagePath(self.getDataInput().getDiffractionImage())
         xsDataInputExecThumbnail.setLevelsInvert(XSDataBoolean(True))
         xsDataInputExecThumbnail.setLevelsMin(XSDataDoubleWithUnit(0.0))
         xsDataDoubleWithUnitLevelsMax = XSDataDoubleWithUnit(99.95)
         xsDataDoubleWithUnitLevelsMax.setUnit(XSDataString("%"))
         xsDataInputExecThumbnail.setLevelsMax(xsDataDoubleWithUnitLevelsMax)
         xsDataInputExecThumbnail.setFilterDilatation([XSDataInteger(4)])
         xsDataInputExecThumbnail.setLevelsColorize(XSDataBoolean(False))
         xsDataInputExecThumbnail.setThumbHeight(XSDataInteger(1024))
         xsDataInputExecThumbnail.setThumbWidth(XSDataInteger(1024))
         xsDataInputExecThumbnail.setKeepRatio(XSDataBoolean(False))
         # Output path
         strImageNameWithoutExt = os.path.basename(os.path.splitext(strPathToDiffractionImage)[0])
         strImageDirname = os.path.dirname(strPathToDiffractionImage)
         if self.getDataInput().getForcedOutputDirectory():
             strForcedOutputDirectory = self.getDataInput().getForcedOutputDirectory().getPath().getValue()
             if not os.access(strForcedOutputDirectory, os.W_OK):
                 EDVerbose.error("Cannot write to forced output directory : %s" % strForcedOutputDirectory)
                 self.setFailure()
             else:
                 self.strOutputPathWithoutExtension = os.path.join(strForcedOutputDirectory, strImageNameWithoutExt)
         else:
             # Try to store in the ESRF pyarch directory
             strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath(strImageDirname)
             # Check that output pyarch path exists and is writeable:
             bIsOk = False
             if strOutputDirname:
                 if not os.path.exists(strOutputDirname):
                     # Try to create the directory
                     try:
                         os.makedirs(strOutputDirname)
                         bIsOk = True
                     except BaseException, e:
                         EDVerbose.WARNING("Couldn't create the directory %s" % strOutputDirname)
                 elif os.access(strOutputDirname, os.W_OK):
                     bIsOk = True
             if not bIsOk:
                 EDVerbose.warning("Cannot write to pyarch directory: %s" % strOutputDirname)
                 strOutputDirname = tempfile.mkdtemp("", "EDPluginPyarchThumbnailv10_", "/tmp")
                 EDVerbose.warning("Writing thumbnail images to: %s" % strOutputDirname)
             self.strOutputPathWithoutExtension = os.path.join(strOutputDirname, strImageNameWithoutExt)
         self.strOutputPath = os.path.join(self.strOutputPathWithoutExtension + ".jpeg")
         xsDataInputExecThumbnail.setOutputPath(XSDataFile(XSDataString(self.strOutputPath)))
         self.__edPluginExecThumbnail.setDataInput(xsDataInputExecThumbnail)
예제 #52
0
    def set(self, value=0, filename="test.edf", position=(0, 0)):
        """
        This is the set method that will first ensure that the data are available 
        #then set a lock on it and finally #No more 
        write the data 
        #before unlocking. #No more  
        @param: value value of the pixel to set
        @type value: probably float but can be any figure
        @param filename: name of the file to be processed
        @type filename: string
        @param position: the position of the pixel to modify 
        @type position: 2-tuple of integers  
        
        """
        if not isinstance(value, float):
            EDVerbose.error("ERROR The value %s is not a float" % value)
            raise Exception("ERROR The value %s is not a float" % value)
        if not (isinstance(filename, str) or isinstance(filename, unicode)):
            EDVerbose.error("ERROR The filename variable %s is not a string " %
                            filename)
            raise Exception("ERROR The filename variable %s is not a string " %
                            filename)
        if not isinstance(position, tuple):
            EDVerbose.error("ERROR The position variable %s is not a tuple " %
                            position)
            raise Exception("ERROR The position variable %s is not a tuple " %
                            position)
        if len(position) != 2:
            EDVerbose.error("ERROR in the size of the position-tuple")
            raise Exception("ERROR in the size of the position-tuple")
        if position[0] < 0:
            EDVerbose.error("ERROR in the X part of the position-tuple")
            raise Exception("ERROR in the X part of the position-tuple")
        if position[1] < 0:
            EDVerbose.error("ERROR in the Y part of the position-tuple")
            raise Exception("ERROR in the Y part of the position-tuple")
        if not self.data.has_key(filename):
            EDVerbose.warning(
                "ERROR, the destination image  %s is not in the list of images tracked : %s"
                % (filename, self.data.keys()))
            pystrDirname, pystrFilename = os.path.split(filename)
            fileInDir = []
            for onefile in os.listdir(pystrDirname):
                if onefile.find("%sSize" % pystrFilename) == 0:
                    if onefile[-4:].lower() == ".edf":
                        XxY = onefile.split("Size")[-1][:-4]
                        try:
                            size = tuple(
                                [int(i) for i in tuple(XxY.split("x"))])
                        except Exception:
                            size = None
                        if size:
                            fileInDir.append(onefile)

            if len(fileInDir) > 1:
                EDVerbose.warning(
                    "ERROR, for %s, I found too many images corresponding to what you are looking for : %s"
                    % (filename, fileInDir))
                raise Exception(
                    "ERROR, I found too many images corresponding to what you are looking for : %s"
                    % (filename, fileInDir))
            elif len(fileInDir) == 1:
                EDVerbose.warning(
                    "WARNING, As The file %s exists, I will try to read it. The expected size is %s"
                    % (filename, size))
                self.size[filename] = size
                fullFilename = "%sSize%ix%i.edf" % ((filename, ) + size)
                self.headers[filename] = {}
                self.data[filename] = numpy.zeros(size, dtype="float32")
                self.synchronizeOn()
                try:
                    self.edf[filename] = EdfFile(fullFilename)
                    self.headers[filename] = self.edf[filename].GetHeader(0)
                    self.data[filename] = self.edf[filename].GetData(0)
                except Exception:
                    EDVerbose.warning(
                        "ERROR in reading file %s: Reintializing it" %
                        filename)
                    self.edf[filename] = EdfFile(fullFilename)
                    self.data[filename] = numpy.zeros(size, dtype="float32")
                    self.headers[filename] = {}
                self.synchronizeOff()

                if self.data[filename].shape != size:
                    self.data[filename] = numpy.zeros(size, dtype="float32")
                    self.headers[filename] = {}
            else:
                EDVerbose.error(
                    "ERROR, the destination image  %s is not in the list of images tracked : %s"
                    % (filename, self.data.keys()))
                raise Exception(
                    "ERROR, the destination image  %s is not in the list of images tracked : %s"
                    % (filename, self.data.keys()))

        if position[0] > self.data[filename].shape[0]:
            EDVerbose.error(
                "ERROR in the X part of the position-tuple: too large %i > %i"
                % (position[0], npArray.shape[0]))
            raise Exception(
                "ERROR in the X part of the position-tuple: too large %i > %i"
                % (position[0], npArray.shape[0]))
        if position[1] > self.data[filename].shape[1]:
            EDVerbose.error(
                "ERROR in the Y part of the position-tuple: too large %i > %i"
                % (position[1], npArray.shape[1]))
            raise Exception(
                "ERROR in the Y part of the position-tuple: too large %i > %i"
                % (position[1], npArray.shape[1]))
        self.data[filename][position[0], position[1]] = value
        self.synchronizeOn()
        try:
            self.edf[filename].WriteImage(self.headers[filename],
                                          self.data[filename],
                                          Append=0)
        except Exception:
            EDVerbose.error("ERROR in writing image %s at position %s" %
                            (filename, position))
        self.synchronizeOff()
예제 #53
0
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlStrategyv10.preProcess...")
        self.__edPluginRaddose = None

        xsDataSampleCrystalMM = self.getDataInput().getSample()

        if(xsDataSampleCrystalMM is None):
            self.__xsDataSampleCopy = XSDataSampleCrystalMM()

        else:
            strXmlStringDataSample = xsDataSampleCrystalMM.marshal()
            self.__xsDataSampleCopy = XSDataSampleCrystalMM.parseString(strXmlStringDataSample)

        xsDataCrystal = self.getDataInput().getCrystalRefined()
        if(xsDataCrystal is not None):
            self.__xsDataSampleCopy.setCrystal(xsDataCrystal)

        # Raddose is enabled only if the beam flux is set
        if(self.getDataInput().getExperimentalCondition().getBeam().getFlux() is None):
            warningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % ('EDPluginControlStrategyv10.preProcess', self.__strPluginRaddoseName, "Beam Flux not set")
            EDVerbose.warning(warningMessage)
            self.addWarningMessage(warningMessage)

        else:
            self.__edPluginRaddose = self.loadPlugin(self.__strPluginRaddoseName)

            if (self.__edPluginRaddose is not None):
                EDVerbose.DEBUG("EDPluginControlStrategyv10.preProcess: " + self.__strPluginRaddoseName + " Found... setting Data Input")

                strFileSymop = os.path.join(self.getSymopHome(), "symop.lib")

                xsDataStringSpaceGroup = self.getDataInput().getDiffractionPlan().getForcedSpaceGroup()
                # Space Group has been forced
                # Prepare chemical composition calculation with the forced Space Group (Space Group Name)
                if(xsDataStringSpaceGroup is not None):
                    strSpaceGroup = xsDataStringSpaceGroup.getValue()
                    EDVerbose.DEBUG("EDPluginControlStrategyv10.preProcess: Forced Space Group Found: " + strSpaceGroup)
                    try:
                        strNumOperators = EDUtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupName(strSpaceGroup, strFileSymop)
                    except Exception, detail:
                        errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginControlStrategyv10.preProcess', "Problem to calculate Number of symmetry operators", detail)
                        EDVerbose.error(errorMessage)
                        self.addErrorMessage(errorMessage)
                        raise RuntimeError, errorMessage
                # Space Group has NOT been forced
                else:
                    xsDataStringSpaceGroup = self.__xsDataSampleCopy.getCrystal().getSpaceGroup().getName()
                    if (xsDataStringSpaceGroup is not None):
                        # Prepare chemical composition calculation with the Space Group calculated by indexing (Space Group Name)
                        strSpaceGroupName = self.__xsDataSampleCopy.getCrystal().getSpaceGroup().getName().getValue()
                        EDVerbose.DEBUG("EDPluginControlStrategyv10.preProcess: Space Group IT Name found by indexing: " + strSpaceGroupName)
                        try:
                            strNumOperators = EDUtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupName(strSpaceGroupName, strFileSymop)
                        except Exception, detail:
                            errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginControlStrategyv10.preProcess', "Problem to calculate Number of symmetry operators", detail)
                            EDVerbose.error(errorMessage)
                            self.addErrorMessage(errorMessage)
                            raise RuntimeError, errorMessage
                    else:
                        # Prepare chemical composition calculation with the Space Group calculated by indexing (Space Group IT number)
                        strSpaceGroupITNumber = str(self.__xsDataSampleCopy.getCrystal().getSpaceGroup().getITNumber().getValue())
예제 #54
0
                    xsDataUpdatedChemicalComposition = self.updateChemicalComposition(xsDataChemicalComposition)
                    self.__xsDataSampleCopy.setChemicalComposition(xsDataUpdatedChemicalComposition)

                # create Data Input for Raddose
                from EDHandlerXSDataRaddosev10 import EDHandlerXSDataRaddosev10
                self.__edHandlerXSDataRaddose = EDHandlerXSDataRaddosev10()
                xsDataBeam = self.getDataInput().getExperimentalCondition().getBeam()

                xsDataRaddoseInput = None

                try:
                    xsDataRaddoseInput = self.__edHandlerXSDataRaddose.getXSDataRaddoseInput(xsDataBeam, self.__xsDataSampleCopy, iNumOperators)

                except Exception, detail:
                    warningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % ('EDPluginControlStrategyv10.preProcess', self.__strPluginRaddoseName, self.__edHandlerXSDataRaddose.getClassName() + ": " + str(detail))
                    EDVerbose.warning(warningMessage)
                    self.addWarningMessage(warningMessage)

                if(xsDataRaddoseInput is not None):
                    self.__edPluginRaddose.setDataInput(xsDataRaddoseInput)
                    self.__edPluginRaddose.setBaseDirectory(self.getWorkingDirectory())
                    self.__edPluginRaddose.setBaseName(self.__strPluginRaddoseName)

                    # More checks?
#                    try:
#                        self.__edPluginRaddose.setDataInput( xsDataRaddoseInput )
#                        self.__edPluginRaddose.setBaseDirectory( self.getWorkingDirectory() )
#                        self.__edPluginRaddose.setBaseName( self.__strPluginRaddoseName )
#                        
#                    except Exception, detail:
#                        warningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % ('EDPluginControlStrategyv10.preProcess', self.__strPluginRaddoseName, str( detail ) )
예제 #55
0
                    xsDataBeam = self.getDataInput().getExperimentalCondition(
                    ).getBeam()

                    xsDataRaddoseInput = None

                    try:
                        xsDataRaddoseInput = self.__edHandlerXSDataRaddose.getXSDataRaddoseInput(
                            xsDataBeam, self.__xsDataSampleCopy, iNumOperators)

                    except Exception, detail:
                        pyStrWarningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % (
                            'EDPluginControlStrategyv1_1.preProcess',
                            self.__strPluginRaddoseName,
                            self.__edHandlerXSDataRaddose.getClassName() +
                            ": " + detail)
                        EDVerbose.warning(pyStrWarningMessage)
                        self.addWarningMessage(pyStrWarningMessage)

                    if (xsDataRaddoseInput is not None):
                        self.__edPluginRaddose.setDataInput(xsDataRaddoseInput)
                        self.__edPluginRaddose.setBaseDirectory(
                            self.getWorkingDirectory())
                        self.__edPluginRaddose.setBaseName(
                            self.__strPluginRaddoseName)

                        # More checks?

    #                    try:
    #                        self.__edPluginRaddose.setDataInput( xsDataRaddoseInput )
    #                        self.__edPluginRaddose.setBaseDirectory( self.getWorkingDirectory() )
    #                        self.__edPluginRaddose.setBaseName( self.__strPluginRaddoseName )
예제 #56
0
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlStrategyv1_1.preProcess...")
        self.__edPluginRaddose = None

        xsDataSampleCrystalMM = self.getDataInput().getSample()

        if (xsDataSampleCrystalMM is None):
            self.__xsDataSampleCopy = XSDataSampleCrystalMM()

        else:
            strXmlStringDataSample = xsDataSampleCrystalMM.marshal()
            self.__xsDataSampleCopy = XSDataSampleCrystalMM.parseString(
                strXmlStringDataSample)

        xsDataCrystal = self.getDataInput().getCrystalRefined()
        if (xsDataCrystal is not None):
            self.__xsDataSampleCopy.setCrystal(xsDataCrystal)

        # Raddose is enabled only if the beam flux is set
        if (self.getDataInput().getExperimentalCondition().getBeam().getFlux()
                is None):
            pyStrWarningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % (
                'EDPluginControlStrategyv1_1.preProcess',
                self.__strPluginRaddoseName, "Beam Flux not set")
            EDVerbose.warning(pyStrWarningMessage)
            self.addWarningMessage(pyStrWarningMessage)

        else:
            self.__edPluginRaddose = self.loadPlugin(
                self.__strPluginRaddoseName)

            if (self.__edPluginRaddose is not None):
                EDVerbose.DEBUG("EDPluginControlStrategyv1_1.preProcess: " +
                                self.__strPluginRaddoseName +
                                " Found... setting Data Input")

                strFileSymop = os.path.join(self.getSymopHome(), "symop.lib")

                xsDataStringSpaceGroup = self.getDataInput(
                ).getDiffractionPlan().getForcedSpaceGroup()
                # Space Group has been forced
                # Prepare chemical composition calculation with the forced Space Group (Space Group Name)
                strNumOperators = None
                strSpaceGroup = None
                if (xsDataStringSpaceGroup is not None):
                    strSpaceGroup = xsDataStringSpaceGroup.getValue().upper()
                    EDVerbose.DEBUG(
                        "EDPluginControlStrategyv1_1.preProcess: Forced Space Group Found: "
                        + strSpaceGroup)
                    try:
                        strNumOperators = EDUtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupName(
                            strSpaceGroup, strFileSymop)
                    except Exception, detail:
                        pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                            'EDPluginControlStrategyv1_1.preProcess',
                            "Problem to calculate Number of symmetry operators",
                            detail)
                        EDVerbose.error(pyStrErrorMessage)
                        self.addErrorMessage(pyStrErrorMessage)
                        self.setFailure()
                # Space Group has NOT been forced
                else:
                    xsDataStringSpaceGroup = self.__xsDataSampleCopy.getCrystal(
                    ).getSpaceGroup().getName()
                    if (xsDataStringSpaceGroup is not None):
                        # Prepare chemical composition calculation with the Space Group calculated by indexing (Space Group Name)
                        strSpaceGroupName = self.__xsDataSampleCopy.getCrystal(
                        ).getSpaceGroup().getName().getValue()
                        EDVerbose.DEBUG(
                            "EDPluginControlStrategyv1_1.preProcess: Space Group IT Name found by indexing: "
                            + strSpaceGroupName)
                        try:
                            strNumOperators = EDUtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupName(
                                strSpaceGroupName, strFileSymop)
                        except Exception, detail:
                            pyStrErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                                'EDPluginControlStrategyv1_1.preProcess',
                                "Problem to calculate Number of symmetry operators",
                                detail)
                            EDVerbose.error(pyStrErrorMessage)
                            self.addErrorMessage(pyStrErrorMessage)
                            self.setFailure()
                    else:
                        # Prepare chemical composition calculation with the Space Group calculated by indexing (Space Group IT number)
                        iSpaceGroupITNumber = self.__xsDataSampleCopy.getCrystal(
예제 #57
0
                xsDataBeam = self.getDataInput().getExperimentalCondition(
                ).getBeam()

                xsDataRaddoseInput = None

                try:
                    xsDataRaddoseInput = self.__edHandlerXSDataRaddose.getXSDataRaddoseInput(
                        xsDataBeam, self.__xsDataSampleCopy, iNumOperators)

                except Exception, detail:
                    warningMessage = EDMessage.WARNING_CANNOT_USE_PLUGIN_03 % (
                        'EDPluginControlStrategyv10.preProcess',
                        self.__strPluginRaddoseName,
                        self.__edHandlerXSDataRaddose.getClassName() + ": " +
                        str(detail))
                    EDVerbose.warning(warningMessage)
                    self.addWarningMessage(warningMessage)

                if (xsDataRaddoseInput is not None):
                    self.__edPluginRaddose.setDataInput(xsDataRaddoseInput)
                    self.__edPluginRaddose.setBaseDirectory(
                        self.getWorkingDirectory())
                    self.__edPluginRaddose.setBaseName(
                        self.__strPluginRaddoseName)

                    # More checks?
#                    try:
#                        self.__edPluginRaddose.setDataInput( xsDataRaddoseInput )
#                        self.__edPluginRaddose.setBaseDirectory( self.getWorkingDirectory() )
#                        self.__edPluginRaddose.setBaseName( self.__strPluginRaddoseName )
#