def postProcess(self, _edObject=None):
        """
        Calls the parent preProcess method
        Checks that the installed 3rd party software is in the list of compatible versions
        """
        EDPluginExecProcess.postProcess(self)
        EDVerbose.DEBUG("EDPluginExecProcessScript.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.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                if (EDVerbose.isVerboseDebug()):
                    raise RuntimeError, strErrorMessage
 def postProcess(self, _edObject=None):
     """
     Parses the labelit.screen log file and the generated MOSFLM script
     """
     EDPluginExecProcessScript.postProcess(self, _edObject)
     EDVerbose.DEBUG("EDPluginLabelitv10.postProcess...")
     strLabelitLog = self.readProcessLogFile()
     if (strLabelitLog is None):
         errorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginLabelitv10.postProcess", self.getClassName(), "Could not read the Labelit log file")
         EDVerbose.error(errorMessage)
         self.addErrorMessage(errorMessage)
     else:
         xsDataLabelitScreenOutput = self.parseLabelitScreenOutput(strLabelitLog)
         xsDataIntegerSelectedSolutionNumber = xsDataLabelitScreenOutput.getSelectedSolutionNumber()
         if (xsDataIntegerSelectedSolutionNumber is None):
             errorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginLabelitv10.postProcess", self.getClassName(), "No selected solution")
             EDVerbose.error(errorMessage)
             self.addErrorMessage(errorMessage)
         else:
             strLabelitMosflmScriptsOutput = self.readProcessFile(self.generateMosflmScriptName(xsDataIntegerSelectedSolutionNumber.getValue()))
             xsDataLabelitMosflmScriptsOutput = self.parseMosflmScriptsOutput(strLabelitMosflmScriptsOutput)
             xsDataResultLabelit = XSDataResultLabelit()
             xsDataResultLabelit.setLabelitScreenOutput(xsDataLabelitScreenOutput)
             xsDataResultLabelit.setLabelitMosflmScriptsOutput(xsDataLabelitMosflmScriptsOutput)
             self.setDataOutput(xsDataResultLabelit)
Exemplo n.º 3
0
 def compareTwoValues(self, _value1, _value2, _dTolerance=0.000001):
     """
     This method compares two values which can be of type double, integer or string.
     The types of the two values two be compared must be identical.
     If the value is of type double, an optional tolerance can be passed as an
     argument to the method. If both values are None the methods returns True.
     """
     bReturnValue = False
     if (_value1 is None):
         if (_value2 is None):
             bReturnValue = True
     elif (type (_value1) != type(_value2)):
         strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginSubWedgeMergev1_1.compareTwoValues', self.getClassName(), "Types of values different : value1=%r, value2=%r" % (type(_value1), type(_value2)))
         EDVerbose.error(strErrorMessage)
         self.addErrorMessage(strErrorMessage)
         raise Exception, strErrorMessage
     elif (type(_value1) == type(0.1)):
         if (abs(_value1 - _value2) < _dTolerance):
             bReturnValue = True
     elif (type(_value1) == type(1)):
         if (_value1 == _value2):
             bReturnValue = True
     elif type(_value1) == type("aaa") or type(_value1) == type(u'unicode'):
         if _value1 == _value2:
             bReturnValue = True
     else:
         strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginSubWedgeMergev1_1.compareTwoValues', self.getClassName(), "Unknown value type : %r for value %r" % (type(_value1), _value1))
         EDVerbose.error(strErrorMessage)
         self.addErrorMessage(strErrorMessage)
         raise Exception, strErrorMessage
     return bReturnValue
Exemplo n.º 4
0
    def preProcess(self, _edObject=None):
        """
        Loads the ISPyB execution plugin and prepares the input data
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlISPyBv1_4.preProcess...")

        if (self.hasDataInput("shortComments")):
            self.strShortComments = self.getDataInput("shortComments")[0].getValue()
        if (self.hasDataInput("comments")):
            self.strComments = self.getDataInput("comments")[0].getValue()
        if (self.hasDataInput("statusMessage")):
            self.strStatusMessage = self.getDataInput("statusMessage")[0].getValue()

        self.edPluginExecISPyB = self.loadPlugin(self.edStringPluginExecISPyBName)
        try:
            xsDataInputISPyBStoreScreening = EDHandlerXSDataISPyBv1_4.generateXSDataInputISPyBStoreScreening(self.getDataInput(), 
                                                                                                             self.strStatusMessage, \
                                                                                                             self.strShortComments, \
                                                                                                             self.strComments)
        except Exception, error:
            raise
            # This exception handling needs to be rethought, see bug #43.
            errorMessage = "EDPluginControlISPyBv1_4.preProcess: Unexpected error in ISPyB handler: %r" % error
            EDVerbose.error(errorMessage)
            self.addErrorMessage(errorMessage)
            raise RuntimeError, errorMessage
 def doSuccessEvaluationIndexingMOSFLM(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexingMOSFLM")
     self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexing")
     # Retrieve status messages (if any)
     if self.__edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageImageQualityIndicators"):
         self.addStatusMessage(self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageImageQualityIndicators")[0].getValue())
     if self.__edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageIndexing"):
         self.addStatusMessage("MOSFLM: " + self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageIndexing")[0].getValue())
     # Check if indexing was successful
     bIndexWithLabelit = False
     bIndexingSuccess = self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingSuccess")[0].getValue()
     if bIndexingSuccess:
         xsDataIndexingResult = self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingResult")[0]
         self.__xsDataIndexingResultMOSFLM = xsDataIndexingResult
         # Check if space group is P1 - if yes run Labelit indexing
         xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution()
         xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
         xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
         strSpaceGroupName = xsDataSpaceGroup.getName().getValue().upper()
         # Check if MOSFLM has indexed in P1
         if strSpaceGroupName == "P1":
             # Check if the user maybe asked for P1!
             bIndexWithLabelit = True
             if self.__xsDataCollection.getDiffractionPlan() is not None:
                 if self.__xsDataCollection.getDiffractionPlan().getForcedSpaceGroup() is not None:
                     if self.__xsDataCollection.getDiffractionPlan().getForcedSpaceGroup().getValue().upper() == "P1":
                         EDVerbose.screen("P1 space forced by diffraction plan")
                         bIndexWithLabelit = False
         if bIndexWithLabelit:
             EDVerbose.screen("P1 space group choosed - reindexing with Labelit")
         else:
             EDVerbose.screen("MOSFLM indexing successful!")
             if self.__edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
                 self.__strCharacterisationShortSummary += self.__edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
             # Generate prediction images
             xsDataCollection = self.__xsDataResultCharacterisation.getDataCollection()
             self.__xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
             xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
             xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
             xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(xsDataIndexingResult.getSelectedSolution().marshal()))
             self.__edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
             # Start the generation of prediction images - we synchronize in the post-process
             self.__edPluginControlGeneratePrediction.execute()
             # Then start the integration of the reference images
             self.indexingToIntegration()
     else:
         EDVerbose.screen("Indexing with MOSFLM failed!")
         bIndexWithLabelit = True
     if bIndexWithLabelit:
         # Execute Labelit indexing
         EDVerbose.screen("Now trying to index with Labelit - please be patient...")
         xsDataIndexingInput = XSDataIndexingInput()
         xsDataSubWedgeList = self.__xsDataCollection.getSubWedge()
         xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()
         xsDataIndexingInput.setDataCollection(self.__xsDataCollection)
         xsDataIndexingInput.setExperimentalCondition(xsDataExperimentalCondition)
         if self.__xsDataCrystal != None:
             xsDataIndexingInput.setCrystal(self.__xsDataCrystal)
         self.__edPluginControlIndexingLabelit.setDataInput(xsDataIndexingInput)
         self.__edPluginControlIndexingLabelit.executeSynchronous()
 def generateIndicatorsShortSummary(self, _edPlugin):
     """
     Generates a very short summary of the image quality indicator processing
     """
     strIndicatorsShortSummary = ""
     if _edPlugin.hasDataOutput():
         for xsDataQualityIndicators in _edPlugin.getDataOutput().getImageQualityIndicators():
             strImageName = os.path.basename(xsDataQualityIndicators.getImage().getPath().getValue())
             strIndicatorsShortSummary += "ImageQualityIndicators: %s: " % strImageName
             iNoGoodBraggCandidates = xsDataQualityIndicators.getGoodBraggCandidates().getValue()
             strIndicatorsShortSummary += "good bragg %d, " % iNoGoodBraggCandidates
             fResMethod1 = xsDataQualityIndicators.getMethod1Res().getValue()
             strIndicatorsShortSummary += "r1 %.1f [A], " % fResMethod1
             if xsDataQualityIndicators.getMethod2Res() is not None:
                 fResMethod2 = xsDataQualityIndicators.getMethod2Res().getValue()
                 strIndicatorsShortSummary += "r2 %.1f [A], " % fResMethod2
             if xsDataQualityIndicators.getMaxUnitCell() is not None:
                 fMaxCell = xsDataQualityIndicators.getMaxUnitCell().getValue()
                 strIndicatorsShortSummary += "max cell %.1f [A], " % fMaxCell
             iIceRings = xsDataQualityIndicators.getIceRings().getValue()
             strIndicatorsShortSummary += "ice rings %d" % iIceRings
             if xsDataQualityIndicators.getTotalIntegratedSignal() is not None:
                 fTotalIntegratedSignal = xsDataQualityIndicators.getTotalIntegratedSignal().getValue()
                 strIndicatorsShortSummary += ", total integrated signal %.0f\n" % fTotalIntegratedSignal
         for strLine in strIndicatorsShortSummary.split("\n"):
             EDVerbose.screen(strLine)
         self.setDataOutput(XSDataString(strIndicatorsShortSummary), "indicatorsShortSummary")
Exemplo n.º 7
0
 def existPath(cls, _strPath):
     """
     Checks if a folder exists.
     Deprecated: please use 'os.path.exists' instead
     """
     EDVerbose.log("EDUtilsPath.existPath is deprecated, please use 'os.path.exists' instead")
     return exists(_strPath)
    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
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

################################################################################
# Compare XSDataResults
################################################################################

        strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile())
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsProcessOneFilev1_0.parseString(strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "XSDataResult output are the same", _strExcluded="bioSaxs")


################################################################################
# Compare Ascii HEADER files
################################################################################
        asciiObt = os.linesep.join([i.strip() for i in  open(xsDataResultObtained.integratedCurve.path.value) if i.startswith("#") and "Raster" not in i])
        asciiRef = os.linesep.join([i.strip() for i in  open(os.path.join(self.getTestsDataImagesHome(), "bioSaxsProcessIntegrated1_2.dat")) if i.startswith("#") and "Raster" not in i])

        EDAssert.strAlmostEqual(asciiObt, asciiRef, _strComment="ascii header files are the same", _fRelError=0.1, _strExcluded=os.environ["USER"])

        dataObt = numpy.loadtxt(xsDataResultObtained.integratedCurve.path.value)
        dataRef = numpy.loadtxt(os.path.join(self.getTestsDataImagesHome(), "bioSaxsProcessIntegrated1_2.dat"))
        EDAssert.curveSimilar((dataObt[:, 0], dataObt[:, 1]), (dataRef[:, 0], dataRef[:, 1]), "data are the same", 0.6)
        EDAssert.curveSimilar((dataObt[:, 0], dataObt[:, 2]), (dataRef[:, 0], dataRef[:, 2]), "errors are the same", 0.6)


        EDVerbose.screen("Execution time for %s: %.3fs" % (plugin.getClassName(), plugin.getRunTime()))
Exemplo n.º 10
0
 def getCwd(cls):
     """
     Returns the current directory.
     Deprecated: please use 'os.getcwd' instead
     """
     EDVerbose.log("EDUtilsPath.getCwd is deprecated, please use 'os.getcwd' instead")
     return os.getcwd()
Exemplo n.º 11
0
 def getAbsolutePath(cls, _strPath):
     """
     Returns the absolute path.
     Deprecated: please use 'os.path.abspath' instead
     """
     EDVerbose.log("EDUtilsPath.getAbsolutePath is deprecated, please use 'os.path.abspath' instead")
     return abspath(_strPath)
 def setPluginInput(self, _edPlugin):
     
     _edPlugin.setDataInput(XSDataInputXAFSDataBatchProcessing())
     
     xsDataInputSpline = XSDataInputSpline()
     if (self.__fRbkg):
         xsDataInputSpline.setRbkg(XSDataFloat(self.__fRbkg))
     _edPlugin.getDataInput().setSplineDataInput(xsDataInputSpline)
     
     xsDataInputFFTF = XSDataInputFFTF()
     if (self.__fftfKmin):
         xsDataInputFFTF.setKmin(XSDataFloat(self.__fftfKmin))
     if (self.__fftfKmax):
         xsDataInputFFTF.setKmax(XSDataFloat(self.__fftfKmax))
     if (self.__fftfDk):
         xsDataInputFFTF.setDk(XSDataFloat(self.__fftfDk))
     if (self.__fftfKweight):
         xsDataInputFFTF.setKweight(XSDataFloat(self.__fftfKweight))
     _edPlugin.getDataInput().setFftfDataInput(xsDataInputFFTF)
     
     if (not self.__strDatasetFileNames is None):
         try:
             if (self.__strNxsEnergy and self.__strNxsLnI0It):
                 _edPlugin.readXAFSNexusFiles(self.__strDatasetFileNames, self.__strNxsEnergy, self.__strNxsLnI0It, self.__strNxsScanIndex)
         except Exception:
             errorMessage = EDMessage.ERROR_CANNOT_READ_FILE_02 % ("EDApplicationXAFSBatchProcessing.setPluginInput", self.__strDatasetFileNames)
             EDVerbose.error(errorMessage)
             raise RuntimeError, errorMessage
def functionXMLout(_strXMLin, _strXMLout):
    """
    This is an example of XMLout function ... it prints only the name of the file created
    @param _srXMLin: The XML string used to launch the job
    @type _strXMLin: python string with the input XML
    @param _strXMLout: The XML string retrieved  job
    @type _strXMLout: python string with the output XML    
    @return: None     
    """
    xsDataInputInterface = XSDataInputInterface.parseString(_strXMLin)
    strImagePath = xsDataInputInterface.getImagePath()[0].getPath().getValue()
    EDVerbose.screen("Successful processing of image %s" % strImagePath)
    strResultText = os.path.dirname(strImagePath) + " " + os.path.basename(strImagePath) + " "
    xsDataResultInterface = XSDataResultInterface.parseString(_strXMLout)
    xsDataResultCharacterisation = xsDataResultInterface.getResultCharacterisation()
    # 
    xsDataIndexingResult = xsDataResultCharacterisation.getIndexingResult()
    #strResultText = _strDirectoryVisit + " " + strFileName + " "
    if (xsDataIndexingResult is None):
        strResultText += "Indexing failed"
    else:
        xsDataSelectedSolution = xsDataIndexingResult.getSelectedSolution()
        fMosaicityEstimation = xsDataSelectedSolution.getCrystal().getMosaicity().getValue()
        strResultText += "Mosaicity: %.2f " % fMosaicityEstimation
        xsDataStrategyResult = xsDataResultCharacterisation.getStrategyResult()
        if (xsDataStrategyResult is None):
            strResultText += "No strategy result"
        else:
            xsDataCollectionPlan = xsDataStrategyResult.getCollectionPlan()[0]
            xsDataStrategySummary = xsDataCollectionPlan.getStrategySummary()
            fRankingResolution = xsDataStrategySummary.getRankingResolution().getValue()
            strResultText += "Resolution: %.2f" % fRankingResolution
    writeToResultFile(strResultText)
Exemplo n.º 14
0
 def createDataInputCharacterisationFromDataFiles(self, _pyListXSDataFile):
     """
     This method takes as input a list of paths to XML data files. It parses
     these files and create a single XSDataInputCharacterisation object.
     """
     EDVerbose.DEBUG("EDPluginControlCCP4iv1_1.createDataInputCharacterisationFromDataFiles")
     xsDataInputCharacterisation = None
     for xsDataInputFile in _pyListXSDataFile:
         try:
             pyStrInputFileContent = EDUtilsFile.readFile(xsDataInputFile.getPath().getValue())
             xsDataInputCharacterisationCurrent = XSDataInputCharacterisation.parseString(pyStrInputFileContent)
         except Exception, detail:
             errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginControlCCP4iv1_1.preProcess', 'EDPluginControlCCP4iv1_1', detail)
             EDVerbose.error(errorMessage)
             self.addErrorMessage(errorMessage)
             raise RuntimeError, errorMessage
         if (xsDataInputCharacterisationCurrent is None):
             errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginControlCCP4iv1_1.preProcess', 'EDPluginControlCCP4iv1_1', "None data collection")
             EDVerbose.error(errorMessage)
             self.addErrorMessage(errorMessage)
             raise RuntimeError, errorMessage
         else:
             # Instantiate the xsDataInputCharacterisation object if it's not already done.  
             if (xsDataInputCharacterisation is None):
                 xsDataInputCharacterisation = XSDataInputCharacterisation()
             xsDataInputCharacterisation.setDataCollection(xsDataInputCharacterisationCurrent.getDataCollection())
    def configure(self):
        """
        Gets the dbserver parameters from the config file and stores them in class member attributes.
        """
        EDPluginExec.configure(self)
        pluginConfiguration = self.getConfiguration()

        if(pluginConfiguration == None):
            EDVerbose.DEBUG("*** EDPluginISPyBv1_2.configure: pluginConfiguration is None, using default settings")
        else:
            EDVerbose.DEBUG("*** EDPluginISPyBv1_2.configure: pluginConfiguration found, using settings from there")
            strDbserverHost = EDConfiguration.getStringParamValue(pluginConfiguration, "dbserverHost")
            if(strDbserverHost == None):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2.configure", self.getClassName(), \
                                                                     "Configuration parameter missing: dbserverHost")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage
            else:
                self.setDbserverHost(strDbserverHost)

            strDbserverPort = EDConfiguration.getStringParamValue(pluginConfiguration, "dbserverPort")
            if(strDbserverPort == None):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2.configure", self.getClassName(), \
                                                                     "Configuration parameter missing: dbserverPort")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage
            else:
                self.setDbserverPort(int (strDbserverPort))
Exemplo n.º 16
0
    def executePluginSynchronous(self, _edPlugin):
        """
        This method is used to start executable plugins in pipeline synchronously.
        """
        _edControlSlotSUCCESS = EDSlot()
        _edControlSlotFAILURE = EDSlot()

        map(_edControlSlotSUCCESS.connect, _edPlugin.getSlotSUCCESS().getListMethod())
        map(_edControlSlotFAILURE.connect, _edPlugin.getSlotFAILURE().getListMethod())

        _edPlugin.getSlotSUCCESS().emptyListMethod()
        _edPlugin.getSlotFAILURE().emptyListMethod()

        _edPlugin.executeSynchronous()

        if (not _edPlugin.isFailure()):
            EDVerbose.DEBUG("EDControlPlugin.executeSynchronous slotSUCCESS")
            # Check that something doesn't go wrong in the success method!
            try:
                _edControlSlotSUCCESS.call(_edPlugin)

            except Exception:
                EDVerbose.DEBUG("EDControlPlugin.executeSynchronous: ERROR in slotSUCCESS!")
                EDVerbose.writeErrorTrace()
                _edPlugin.setFailure()

        if (_edPlugin.isFailure()):
            EDVerbose.DEBUG("EDControlPlugin.executeSynchronous slotFAILURE")
            # Check that something doesn't go wrong in the success method!
            try:
                _edControlSlotFAILURE.call(_edPlugin)

            except Exception:
                EDVerbose.DEBUG("EDControlPlugin.executeSynchronous: ERROR in slotFAILURE!")
                EDVerbose.writeErrorTrace()
Exemplo n.º 17
0
 def buildInput(self, _edObject=None):
     """
     This method creates an XSDataInputCharacterisation object depending on the input:
     - If dataFile input is provided, uses the "createDataInputCharacterisationFromDataFiles" to retrieve the data collection.
     - If dataSet input is provided, uses the "createDataInputCharacterisationFromDataSets" method to retrieve the data collection.
     After having retrieved an initial XSDataInputCharacterisation object, it then uses the method "updateDataInputCharacterisation" for
     updating certain parameters.
     """
     EDVerbose.DEBUG("EDPluginControlCCP4iv1_1.buildInput...")
     xsDataInputCCP4i = self.getDataInput()
     pyListXSDataFile = xsDataInputCCP4i.getDataFile()
     if(len(pyListXSDataFile) > 0):
         # Ok, we got data files - assemble these to an XSDataInputCharacterisation object.
         xsDataInputCharacterisation = self.createDataInputCharacterisationFromDataFiles(pyListXSDataFile)
     else:
         # No data file input - check for image files:
         pyListXSDataCCP4iDataSet = xsDataInputCCP4i.getDataSet()
         if (pyListXSDataCCP4iDataSet is None):
             pyStrErrorMessage = "No input data!"
             errorMessage = EDMessage.ERROR_EXECUTION_03 % ('EDPluginControlCCP4iv1_1.buildInput', 'EDPluginControlCCP4iv1_1', pyStrErrorMessage)
             EDVerbose.error(errorMessage)
             self.addErrorMessage(errorMessage)
             raise RuntimeError, errorMessage
         else:
             xsDataInputCharacterisation = self.createDataInputCharacterisationFromDataSets(pyListXSDataCCP4iDataSet)
     # Update the data collection with other parameters
     if (xsDataInputCharacterisation is None):
         strError = "EDPluginControlCCP4iv1_1.buildInput: failed when building input."
         EDVerbose.ERROR(strError)
         self.addErrorMessage(strError)
         self.setFailure()
     else:
         self.updateDataInputCharacterisation(xsDataInputCharacterisation)
     return xsDataInputCharacterisation
Exemplo n.º 18
0
 def processCommandLineHelp(self):
     EDVerbose.DEBUG("EDApplication.processCommandLineHelp")
     if (self.__edCommandLine.existCommand(EDApplication.HELP_LABEL_1)
         or self.__edCommandLine.existCommand(EDApplication.HELP_LABEL_2)):
         EDVerbose.setVerboseOn()
         self.usage()
         self.__bIsFailure = True
Exemplo n.º 19
0
 def processCommandLineVersion(self):
     EDVerbose.DEBUG("EDApplication.processCommandLineVersion")
     if (self.__edCommandLine.existCommand(EDApplication.VERSION_PARAM_LABEL_1) or
         self.__edCommandLine.existCommand(EDApplication.VERSION_PARAM_LABEL_2)):
         EDVerbose.setVerboseOn()
         EDVerbose.screen("%s version %s" % (self.__strName, self.__strVersion))
         self.__bIsFailure = True
def functionXMLin(_strFilename):
    """Here we create the XML string to be passed to the EDNA plugin from the input strFilename
    This can / should be modified by the final user
    
    @param _strFilename: full path of the input file
    @type _strFilename: python string representing the path
    @return: string  
    """
    EDVerbose.screen("Starting processing of image %s" % (_strFilename))
    # First check if the filename end with .img or .mccd:
    strXML = None
    if _strFilename.endswith(".img") or _strFilename.endswith(".mccd") or _strFilename.endswith(".cbf"):
        xsDataInputGridScreening = XSDataInputGridScreening()
        xsDataDiffractionPlan = XSDataDiffractionPlan()
        xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(
            XSDataTime(EDParallelExecuteGridScreening.fMaxExposureTime)
        )
        xsDataInputGridScreening.setDiffractionPlan(xsDataDiffractionPlan)
        xsDataFile = XSDataFile()
        xsDataFile.setPath(XSDataString(_strFilename))
        xsDataInputGridScreening.setImageFile(xsDataFile)
        if EDParallelExecuteGridScreening.bOnlyImageQualityIndicators:
            xsDataInputGridScreening.setDoOnlyImageQualityIndicators(XSDataBoolean(True))
        if EDParallelExecuteGridScreening.bStoreInISPyB:
            xsDataInputGridScreening.setStoreImageQualityIndicatorsInISPyB(XSDataBoolean(True))
        if EDParallelExecuteGridScreening.bDoOnlyIntegrationWithXMLOutput:
            xsDataInputGridScreening.setDoOnlyIntegrationWithXMLOutput(XSDataBoolean(True))
        strXML = xsDataInputGridScreening.marshal()
    else:
        EDVerbose.screen("File name not ending with .img or .mccd - ignored : %s" % _strFilename)
    return strXML
Exemplo n.º 21
0
 def setDataInput(self, _oDataInput, _strDataInputKey=None):
     """
     Sets the plugin input data.
     _oDataInput could be either an String XML or an XSData object.
     """
     EDVerbose.DEBUG("EDPluginWrapperForJobScheduler.setDataInput")
     strDataInputKey = _strDataInputKey
     if (strDataInputKey is None):
         strDataInputKey = self.getDefaultInputDataKey()
     # Allow for None input
     if (_oDataInput is None):
         EDVerbose.DEBUG("EDPlugin.setDataInput: Data input is None")
         self.__dictXMLDataInput[ strDataInputKey ] = []
     else:
         # Check the type
         strXMLDataInput = None
         if isinstance(_oDataInput, (str, unicode)):
             EDVerbose.DEBUG("EDPlugin.setDataInput: Input Data is string ")
             strXMLDataInput = _oDataInput
         else:
             try:
                 strXMLDataInput = _oDataInput.marshal()
             except BaseException, e:
                 strErrorMessage = "ERROR: EDPluginWrapperForJobScheduler.setDataInput, cannot marshal data input object"
                 EDVerbose.error(strErrorMessage)
                 self.addErrorMessage(strErrorMessage)
                 raise RuntimeError, strErrorMessage
         # Add the object to a list if its key is not the default key
         if (strDataInputKey != self.getDefaultInputDataKey()) :
             # Check if there's already a list stored
             if (not strDataInputKey in self.__dictXMLDataInput.keys()):
                 self.__dictXMLDataInput[ strDataInputKey ] = []
             self.__dictXMLDataInput[ strDataInputKey ].append(strXMLDataInput)
         else:
             self.__dictXMLDataInput[ strDataInputKey ] = strXMLDataInput
Exemplo n.º 22
0
 def showData(cls):
     EDVerbose.screen("*"*20 + "EDPluginControlAlignStackv1_0" + "*" * 20)
     EDVerbose.screen("Reference Frame: %s" % cls.__iRefFrame)
     if len(cls.__dictRelShift) < len(cls.__dictAbsShift):
         mydict = cls.__dictAbsShift.copy()
     else:
         mydict = cls.__dictRelShift.copy()
     lstTxt = []
     for i in mydict:
         txt = "Frame %4i:\t" % i
         rela = cls.__dictRelShift.get(i)
         abso = cls.__dictAbsShift.get(i)
         if rela:
             txt += "relative: (%.3f, %.3f)\t" % rela
         else:
             txt += "relative: %12s\t" % rela
         if abso:
             txt += "absolute:  (%.3f, %.3f)" % abso
         else:
             txt += "absolute:  %12s" % abso
         lstTxt.append(txt)
     EDVerbose.screen(os.linesep.join(lstTxt))
     items = EDPluginAccumulatorv1_0.getItems()
     items.sort()
     EDVerbose.screen("Items in the accumulator: %s" % (items))
     querylist = [" "] + [ str(i) for i in EDPluginAccumulatorv1_0.getQueries().keys()]
     EDVerbose.screen("Queries in the accumulator: " + os.linesep.join(querylist))
    def testExecute(self):
        """
        """
        plugin = self.getPlugin()
        plugin.__class__.dictHPLC = {}
        self.run()

################################################################################
# Compare XSDataResults
################################################################################

        strExpectedOutput = self.readAndParseFile (self.getReferenceDataOutputFile())
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsHPLCv1_0.parseString(strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(), xsDataResultObtained.marshal(), "XSDataResult output are the same", _strExcluded="bioSaxs")


################################################################################
# Compare Ascii files
################################################################################
        asciiObt = os.linesep.join([i.strip() for i in  open(xsDataResultObtained.integratedCurve.path.value) if "Raster" not in i])
        asciiRef = os.linesep.join([i.strip() for i in  open(os.path.join(self.getTestsDataImagesHome(), "bioSaxsProcessIntegrated1_2.dat")) if "Raster" not in i])

        EDAssert.strAlmostEqual(asciiRef, asciiObt, _strComment="3 column ascii files are the same", _fRelError=0.1, _strExcluded=os.environ["USER"])
        EDVerbose.screen("Execution time for %s: %.3fs" % (plugin.getClassName(), plugin.getRunTime()))
Exemplo n.º 24
0
    def flush(self):
        """
        This method calls the functXMLin a few times with a flush=True argument or without arguments and finishes the work 
        """
        bFinished = False
        while not bFinished:
            xml = None

            try:
                xml = self.__functXMLin(None, flush=True)
            except TypeError:
                try:
                    xml = self.__functXMLin("", flush=True)
                except TypeError:
                    try:
                        xml = self.__functXMLin("")
                    except TypeError:
                        try:
                            xml = self.__functXMLin("")
                        except TypeError:
                            xml = None
        if (xml is None) or (xml == ""):
            bFinished = True
        else:
            EDVerbose.screen ("Flushing data ...")
            self.start(xml)
Exemplo n.º 25
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)
Exemplo n.º 26
0
    def start(self, _strXmlInput):
        """
        Launch EDNA with the given XML stream
        @param _strXmlInput:  XML to be passed to the plugin
        @type  _strXmlInput: python string representing the XML data structure
        """
        if (_strXmlInput is None) or (_strXmlInput == "") :
            return
        #This is a trick to work-around bug #463:
        #  Run the fist thread alone (delay the second, third, ...)
        #    semaphore._Semaphore__value is the current value of the value, unfortunatly it is a protected value without getter 
        #    I need the value of the semaphore to guess if the current call is the first or not.
        #    Nota semaphore are decreased in value from self.__iNbThreads to 0. When Zero, the semaphore is blocking.
        # Them all other, limited by the semaphore.

        if self.__bIsFirstExecute:
            sys.stdout.write("Waiting for first thread to initialize ....")
            while EDUtilsParallel.getNbRunning() > 0:
                time.sleep(0.5)
                sys.stdout.write(".")
        EDUtilsParallel.semaphoreNbThreadsAcquire()

        edPlugin = EDParallelExecute.__edFactoryPlugin.loadPlugin(self.__strPluginName)

        if (edPlugin is not None):

            edPlugin.setDataInput(_strXmlInput)
            edPlugin.connectSUCCESS(self.successPluginExecution)
            edPlugin.connectFAILURE(self.failurePluginExecution)
            edPlugin.execute()
            #edPlugin.executeSynchronous()
        else:
            EDUtilsParallel.semaphoreNbThreadsRelease()
            self.__bIsFirstExecute = False
            EDVerbose.screen("ERROR! Plugin not found : " + self.__strPluginName)
Exemplo n.º 27
0
    def runEdnaFunction(self, _listNewFiles, _bIncludeSubdirs=False):
        """
        This method is the launcher for new files found by watch_directories ; it is also called directly in offline mode.
        
        @param  _listNewFiles: list of files newly created in the directory.
        @type   _listNewFiles: python list of strings.
        @param  _bIncludeSubdirs: should we include sub-directories ? yes for offline and no for online.
        @type   _bIncludeSubdirs: boolean
        """
        dictListFiles = {}
        for oneFile in _listNewFiles:
            if os.path.isfile(oneFile):
                if self.__bQuit == True:
                    return
                base = list(os.path.splitext(oneFile)[0])
                base.reverse()
                for i in xrange(len(base)):
                    if not base[i].isdigit():
                        break
                base = base[i:]
                base.reverse()
                base = "".join(base)

                if base in dictListFiles:
                    dictListFiles[base].append(oneFile)
                else:
                    dictListFiles[base] = [oneFile]
        for key in dictListFiles:
            EDVerbose.screen ("Processing %s: %s" % (key, dictListFiles[key]))
            self.start(self.__functXMLin(dictListFiles[key]))
    def sendEmail(self, _strSubject, _strMessage):
        """Sends an email to the EDNA contact person (if configured)."""

        EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: Subject = %s" % _strSubject)
        EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: Message:")
        EDVerbose.DEBUG(_strMessage)
        if self.__strEDNAContactEmail == None:
            EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: No email address configured!")
        elif not EDUtilsPath.getEdnaSite().startswith("ESRF"):
            EDVerbose.DEBUG("EDPluginControlInterfaceToMXCuBEv1_2.sendEmail: Not executed at the ESRF! EDNA_SITE=%s" % EDUtilsPath.getEdnaSite())
        else:
            try:
                EDVerbose.DEBUG("Sending message to %s." % self.__strEDNAContactEmail)
                EDVerbose.DEBUG("Message: %s" % _strMessage)
                strMessage = """
EDNA_HOME = %s
EDNA_SITE = %s
PLUGIN_NAME = %s
working_dir = %s
%s

""" % (EDUtilsPath.getEdnaHome(), EDUtilsPath.getEdnaSite(), self.getPluginName(), self.getWorkingDirectory(), _strMessage)
                strEmailMsg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s" % (self.__strEDNAEmailSender, \
                                                                                self.__strEDNAContactEmail, \
                                                                                _strSubject, strMessage))
                server = smtplib.SMTP("localhost")
                server.sendmail(self.__strEDNAEmailSender, self.__strEDNAContactEmail, strEmailMsg)
                server.quit()
            except:
                EDVerbose.DEBUG("Error when sending email message!")
                EDVerbose.writeErrorTrace()
Exemplo n.º 29
0
    def preProcess(self, _edObject=None):
        """
        Loads the ISPyB execution plugin and prepares the input data
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlISPyBv1_1.preProcess...")

        if (self.hasDataInput("shortComments")):
            self.__strShortComments = self.getDataInput("shortComments")[0].getValue()
        if (self.hasDataInput("comments")):
            self.__strComments = self.getDataInput("comments")[0].getValue()
        if (self.hasDataInput("statusMessage")):
            self.__strStatusMessage = self.getDataInput("statusMessage")[0].getValue()

        self.m_edPluginExecISPyB = self.loadPlugin(self.m_edStringPluginExecISPyBName)
        from EDHandlerXSDataISPyBv1_2 import EDHandlerXSDataISPyBv1_2
        xsDataInputISPyB = None
        xsDataISPyBImage = None
        try:
            xsDataISPyBScreening = EDHandlerXSDataISPyBv1_2.generateXSDataISPyBScreening(self.getDataInput(), self.__strShortComments, self.__strComments)
            xsDataISPyBScreeningInput = EDHandlerXSDataISPyBv1_2.generateXSDataISPyBScreeningInput(self.getDataInput())
            xsDataISPyBScreeningOutputContainer = EDHandlerXSDataISPyBv1_2.generateXSDataISPyBScreeningOutputContainer(self.getDataInput(), self.__strStatusMessage)
            if (xsDataISPyBScreening.getDataCollectionId() is None):
                xsDataISPyBImage = EDHandlerXSDataISPyBv1_2.generateXSDataISPyBImage(self.getDataInput())

        except Exception, error:
            # This exception handling needs to be rethought, see bug #43.
            errorMessage = EDMessage.ERROR_DATA_HANDLER_02 % ("EDPluginControlISPyBv1_1.preProcess: Unexpected error in ISPyB handler: ", error)
            EDVerbose.error(errorMessage)
            self.addErrorMessage(errorMessage)
            raise RuntimeError, errorMessage
Exemplo n.º 30
0
    def parse(self):
        """
        parse options from command line
        """
        parser = optparse.OptionParser()
        parser.add_option("-V", "--version", dest="version", action="store_true",
                          help="print version of the program and quit", metavar="FILE", default=False)
        parser.add_option("-v", "--verbose",
                          action="store_true", dest="debug", default=False,
                          help="switch to debug/verbose mode")
        parser.add_option("-m", "--mask", dest="mask",
                      help="file containing the mask (for image reconstruction)", default=None)
        parser.add_option("-M", "--mode", dest="mode",
                      help="Mode can be online/offline/all", default="offline")
        parser.add_option("-o", "--out", dest="output",
                      help="file for log", default=None)
        parser.add_option("-w", "--wavelength", dest="wavelength", type="float",
                      help="wavelength of the X-Ray beam in Angstrom", default=None)
        parser.add_option("-e", "--energy", dest="energy", type="float",
                      help="energy of the X-Ray beam in keV (hc=%skeV.A)" % self.hc, default=None)
        parser.add_option("-t", "--template", dest="template", type="str",
                      help="template XML file", default=None)
        parser.add_option("-n", "--nbcpu", dest="nbcpu", type="int",
                      help="template XML file", default=self.nbcpu)


        (options, args) = parser.parse_args()

        # Analyse aruments and options
        if options.version:
            print("BioSaxs Azimuthal integration version %s" % __version__)
            sys.exit(0)
        if options.debug:
            EDVerbose.setVerboseDebugOn()
            self.debug = True
        if options.output:
            EDVerbose.setLogFileName(options.output)
        if options.mask and os.path.isfile(options.mask):
            self.maskfile = options.mask
        if options.template and os.path.isfile(options.template):
            self.xml = open(options.template).read()
        if options.wavelength:
            self.wavelength = 1e-10 * options.wavelength
        elif options.energy:
            self.wavelength = 1e-10 * self.hc / options.energy
        if options.mode=="offline":
            self.mode = "offline"
            self.newerOnly = False
        elif options.mode=="online":
            self.mode = "dirwarch"
            self.newerOnly = True
        elif options.mode=="dirwatch":
            self.mode = "dirwarch"
            self.newerOnly = False
        self.cpu_sem = Semaphore(options.nbcpu)
        self.nbcpu = options.nbcpu
        self.dataFiles = [f for f in args if os.path.isfile(f)]
        if not self.dataFiles:
            raise RuntimeError("Please provide datafiles or read the --help")
Exemplo n.º 31
0
numpyPath = os.path.join(os.environ["EDNA_HOME"], "libraries",
                         "20090405-Numpy-1.3", architecture)
scipyPath = os.path.join(os.environ["EDNA_HOME"], "libraries",
                         "20090711-SciPy-0.7.1", architecture)

Image = EDFactoryPluginStatic.preImport("Image", imagingPath)
numpy = EDFactoryPluginStatic.preImport("numpy", numpyPath)
scipy = EDFactoryPluginStatic.preImport("scipy", scipyPath)
fabio = EDFactoryPluginStatic.preImport("fabio", fabioPath)

try:
    from fabio.edfimage import edfimage
    import scipy.ndimage
except Exception:
    EDVerbose.ERROR("Error in loading numpy, Scipy, PIL or Fabio,\n\
    Please re-run the test suite for EDTestSuitePluginExecShift \
    to ensure that all modules are compiled for you computer as they don't seem to be installed"
                    )


class EDPluginExecStitchOffsetedImagev1_0(EDPluginExec):
    """
    plugin that shifts a set of images and merge them togeather.
    """
    def __init__(self):
        """
        """
        EDPluginExec.__init__(self)
        self.setXSDataInputClass(XSDataInputStitchOffsetedImage)
        self._lImages = []  #list of ndarrays
        self._fDummy = 0
        self._lDummies = [
Exemplo n.º 32
0
modulePath = os.path.join(os.environ["EDNA_HOME"], "libraries", "SciPy-0.8.0",
                          EDUtilsPlatform.architecture)
moduleVersion = "0.7.0"

oModule = EDFactoryPluginStatic.preImport(moduleName)
if not oModule:
    oModule = EDFactoryPluginStatic.preImport(moduleName, modulePath)
    if oModule is None:
        installLibrary(modulePath)
        oModule = EDFactoryPluginStatic.preImport(moduleName, modulePath)
try:
    version = oModule.version.version
except AttributeError:
    version = "0.0.0"

if version.split(".") < moduleVersion.split("."):
    EDVerbose.screen("Wrong %s library:  %s " % (moduleName, version))
    EDFactoryPluginStatic.unImport(moduleName)
    oModule = EDFactoryPluginStatic.preImport(
        moduleName,
        modulePath,
        moduleVersion,
        _strMethodVersion="version.version")

if oModule is None:
    EDVerbose.ERROR("Unable to download, compile or install module %s" %
                    moduleName)
else:
    EDVerbose.screen("Version of %s: %s from %s" %
                     (moduleName, oModule.version.version, oModule.__file__))
Exemplo n.º 33
0
 def process(self, _edObject=None):
     EDPluginControl.process(self)
     EDVerbose.DEBUG("*** EDPluginControlDCTReadHeaderv1_0.process")
     self.m_edPluginEDFReadHeader.connectSUCCESS(self.doSuccessExecTemplate)
     self.m_edPluginEDFReadHeader.connectFAILURE(self.doFailureExecTemplate)
     self.m_edPluginEDFReadHeader.executeSynchronous()
Exemplo n.º 34
0
 def doFailureExecBzip2(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlDevelopRawv1_0.doFailureExecBzip2")
     self.retrieveFailureMessages(
         _edPlugin, "EDPluginControlDevelopRawv1_0.doFailureExecBzip2")
     self.setFailure()
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

        ################################################################################
        # Compare XSDataResults
        ################################################################################

        strExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        #        strObtainedOutput = self.readAndParseFile (self.m_edObtainedOutputDataFile)
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsNormalizev1_0.parseString(
            strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(),
                                xsDataResultObtained.marshal(),
                                "XSDataResult output are the same",
                                _strExcluded="bioSaxs")

        ################################################################################
        # Compare Log Files
        ################################################################################

        outputData = ""
        for oneLine in open(xsDataResultObtained.getLogFile().getPath().value,
                            "rb").readlines():
            oneline = oneLine.lower()
            if oneline.startswith("first"): outputData += oneLine
            if oneline.startswith("last"): outputData += oneLine
            if oneline.startswith("increment"): outputData += oneLine
            if oneline.startswith("factor"): outputData += oneLine
            if oneline.startswith("constant"): outputData += oneLine

        referenceData = ""
        for oneLine in open(
                os.path.join(self.getTestsDataImagesHome(),
                             "bioSaxsNormalized.log"), "rb").readlines():
            oneline = oneLine.lower()
            if oneline.startswith("first"): referenceData += oneLine
            elif oneline.startswith("last"): referenceData += oneLine
            elif oneline.startswith("increment"): referenceData += oneLine
            elif oneline.startswith("factor"): referenceData += oneLine
            elif oneline.startswith("constant"): referenceData += oneLine

        EDAssert.strAlmostEqual(referenceData,
                                outputData,
                                _strComment="LogFiles are the same",
                                _fAbsError=0.1)

        ################################################################################
        # Compare dictionary
        ################################################################################
        edfRef = EdfFile.EdfFile(
            xsDataResultObtained.normalizedImage.getPath().value)
        edfObt = EdfFile.EdfFile(
            os.path.join(self.getTestsDataImagesHome(),
                         "bioSaxsNormalized.edf"))

        ########################################################################
        # Deprected plugin => deprected test
        ########################################################################
        #        headerRef = edfRef.GetHeader(0)
        #        headerObt = edfObt.GetHeader(0)
        #        keysRef = headerRef.keys()
        #        keysObt = headerObt.keys()
        #        keysRef.sort()
        #        keysObt.sort()
        #        for key in ["HeaderID", "Image", 'EDF_BinarySize', "EDF_DataBlockID", "EDF_HeaderSize", "filename", "RasterOrientation", "time_of_day" ]:
        #            if key in keysObt: keysObt.remove(key)
        #            if key in keysRef: keysRef.remove(key)
        #        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dict")
        #        for key in keysRef:
        #            if not key.startswith("History"):
        #                EDAssert.strAlmostEqual(headerRef[key], headerObt[key], _strComment="header value %s are the same" % key, _strExcluded="bioSaxs")

        ################################################################################
        # Compare images
        ################################################################################

        outputData = edfRef.GetData(0)
        referenceData = edfObt.GetData(0)
        EDAssert.arraySimilar(outputData,
                              referenceData,
                              _fAbsMaxDelta=0.1,
                              _fScaledMaxDelta=0.05,
                              _strComment="Images-data are the same")

        outputData = edfRef.GetData(1)
        referenceData = edfObt.GetData(1)
        EDAssert.arraySimilar(outputData,
                              referenceData,
                              _fAbsMaxDelta=0.1,
                              _fScaledMaxDelta=0.05,
                              _strComment="Images-ESD are the same")
    def testExecute(self):
        """
        """
        self.run()

        # Checks that there are no error messages

        plugin = self.getPlugin()

        edStringExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        edStringObtainedOutput = self.readAndParseFile(
            self.m_edObtainedOutputDataFile)
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultExecVideo.parseString(
            edStringExpectedOutput)
        xsDataResultObtained = XSDataResultExecVideo.parseString(
            edStringObtainedOutput)

        EDAssert.strAlmostEqual(xsDataResultReference.marshal(),
                                xsDataResultObtained.marshal(),
                                "XSDataResult output are the same")

        ################################################################################
        # Identification of the video by its size
        ################################################################################

        edStringExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        xsDataResultReference = XSDataResultExecVideo.parseString(
            edStringExpectedOutput)
        outputFileName = xsDataResultReference.getVideoPath().getPath(
        ).getValue()
        outputVideoSize = os.stat(outputFileName)[6]

        referenceFileName = os.path.join(self.getPluginTestsDataHome(),
                                         os.path.basename(outputFileName))
        referenceVideoSize = os.stat(referenceFileName)[6]

        EDAssert.equal(outputVideoSize, referenceVideoSize,
                       "Identification of the video file by its size")
        ################################################################################
        # Identification of the video by mplayer
        ################################################################################
        outputVideoLog = subprocess.Popen(
            "mplayer  -identify -vo null -ao null -frames 0 2>/dev/null " +
            outputFileName,
            stdout=subprocess.PIPE,
            shell=True).stdout.readlines()
        outputVideoSummary = ""

        for oneLine in outputVideoLog:
            if oneLine.strip() != "":
                if not oneLine.split()[0].split("=")[0] in self.EXCLUDED:
                    outputVideoSummary += oneLine

        referenceVideoLog = subprocess.Popen(
            "mplayer  -identify -vo null -ao null -frames 0 2>/dev/null " +
            referenceFileName,
            stdout=subprocess.PIPE,
            shell=True).stdout.readlines()
        referenceVideoSummary = ""
        for oneLine in referenceVideoLog:
            if oneLine.strip() != "":
                if not oneLine.split()[0].split("=")[0] in self.EXCLUDED:
                    referenceVideoSummary += oneLine

        EDAssert.strAlmostEqual(outputVideoSummary,
                                referenceVideoSummary,
                                "Identification of the video by mplayer",
                                _lstExcluded="edna")
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlRunXdsFastProcv1_0.process")
        # First run is vanilla without any modification
        params = XSDataMinimalXdsIn()
        params.input_file = self.dataInput.input_file
        params.spacegroup = self.dataInput.spacegroup
        params.unit_cell = self.dataInput.unit_cell
        params.start_image = self.dataInput.start_image
        params.end_image = self.dataInput.end_image
        # Fix for 'SPOT_RANGE 0 100' problem
        for srange in self.spot_range:
            if srange[0] > 0:
                xsDataRange = XSDataRange()
                xsDataRange.begin = srange[0]
                xsDataRange.end = srange[1]
                params.addSpot_range(xsDataRange)
        # Gleb on Mon Aug  4 18:54:36 CEST 2014: set jobs parameters in order to prevent
        # params.job = XSDataString('XYCORR INIT COLSPOT IDXREF')
        self.first_run.dataInput = params
        self.first_run.executeSynchronous()
        self.retrieveFailureMessages(self.first_run, "First XDS run")

        EDVerbose.DEBUG('first run completed...')

        if self.first_run.dataOutput is not None and self.first_run.dataOutput.succeeded.value:
            EDVerbose.DEBUG('... and it worked')
            self.successful_run = self.first_run
        else:
            EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            self.second_run = self.loadPlugin(self.controlled_plugin_name)
            self.screen('Retrying with increased SPOT_RANGE')
            self.DEBUG(
                'copying previously generated files to the new plugin dir')
            copy_xds_files(self.first_run.getWorkingDirectory(),
                           self.second_run.getWorkingDirectory())
            params = XSDataMinimalXdsIn()
            params.input_file = self.dataInput.input_file
            # params.job = XSDataString('DEFPIX INTEGRATE CORRECT')
            params.spacegroup = self.dataInput.spacegroup
            params.unit_cell = self.dataInput.unit_cell

            # Extended spot range
            if self.end_image_no - self.start_image_no < 300:
                # All data as spot range
                xsDataRangeLimited = XSDataRange()
                xsDataRangeLimited.begin = self.start_image_no
                xsDataRangeLimited.end = self.end_image_no
                params.addSpot_range(xsDataRangeLimited)
            else:
                # Start spot range
                xsDataRangeLimited = XSDataRange()
                xsDataRangeLimited.begin = self.start_image_no
                xsDataRangeLimited.end = self.start_image_no + 99
                params.addSpot_range(xsDataRangeLimited)
                # Start spot range
                middleImageNumber = self.start_image_no + int(
                    self.end_image_no / 2) - 1
                xsDataRangeLimited = XSDataRange()
                xsDataRangeLimited.begin = middleImageNumber - 49
                xsDataRangeLimited.end = middleImageNumber + 50
                params.addSpot_range(xsDataRangeLimited)
                # End spot range
                xsDataRangeLimited = XSDataRange()
                xsDataRangeLimited.begin = self.end_image_no - 99
                xsDataRangeLimited.end = self.end_image_no
                params.addSpot_range(xsDataRangeLimited)

            self.second_run.dataInput = params
            self.second_run.executeSynchronous()
            self.retrieveFailureMessages(self.second_run, "Second XDS run")

            EDVerbose.DEBUG('second run completed')
            if self.second_run.dataOutput is not None and self.second_run.dataOutput.succeeded.value:
                EDVerbose.DEBUG('... and it worked')
                self.successful_run = self.second_run
            else:
                EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            self.third_run = self.loadPlugin(self.controlled_plugin_name)
            self.screen('Retrying with reduced SPOT_RANGE')
            self.DEBUG(
                'copying previously generated files to the new plugin dir')
            copy_xds_files(self.first_run.getWorkingDirectory(),
                           self.third_run.getWorkingDirectory())
            params = XSDataMinimalXdsIn()
            params.input_file = self.dataInput.input_file
            # params.job = XSDataString('DEFPIX INTEGRATE CORRECT')
            params.spacegroup = self.dataInput.spacegroup
            params.unit_cell = self.dataInput.unit_cell

            # Limited spot range: 1 to 20 or max no data points

            xsDataRangeLimited = XSDataRange()
            xsDataRangeLimited.begin = 1
            xsDataRangeLimited.end = 20 if self.end_image_no > 20 else self.end_image_no

            params.addSpot_range(xsDataRangeLimited)

            self.third_run.dataInput = params
            self.third_run.executeSynchronous()
            self.retrieveFailureMessages(self.third_run, "Second XDS run")

            EDVerbose.DEBUG('second run completed')
            if self.third_run.dataOutput is not None and self.third_run.dataOutput.succeeded.value:
                EDVerbose.DEBUG('... and it worked')
                self.successful_run = self.third_run
            else:
                EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            # all runs failed so bail out ...
            strErrorMessage = "All three XDS runs failed"
            self.addErrorMessage(strErrorMessage)
            self.ERROR(strErrorMessage)
            self.setFailure()
        else:
            # use the xds parser plugin to parse the xds output file...
            parser = self.loadPlugin("EDPluginParseXdsOutputv1_0")
            wd = self.successful_run.getWorkingDirectory()
            parser_input = XSDataXdsOutputFile()
            correct_lp_path = XSDataFile()
            correct_lp_path.path = XSDataString(os.path.join(wd, 'CORRECT.LP'))
            parser_input.correct_lp = correct_lp_path
            gxparm_path = os.path.join(wd, 'GXPARM.XDS')
            if os.path.isfile(gxparm_path):
                gxparm = XSDataFile()
                gxparm.path = XSDataString(os.path.join(wd, 'GXPARM.XDS'))
                parser_input.gxparm = gxparm

            parser.dataInput = parser_input
            parser.executeSynchronous()

            if parser.isFailure():
                # that should not happen
                strErrorMessage = "Parser failure in XDS fast proc"
                self.ERROR(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                return
            self.dataOutput = parser.dataOutput
Exemplo n.º 38
0
    def createStructure(cls, filename, h5path, dictAttributes=None):
        """
        Create an empty HDF5 file with a NeXus structure and return the group to work with.
         
        @param filename: path of the file to be created (just the groups, not the dataset) 
        @type filename: string
        @param h5path: path of the internal NeXus structure to be created
        @type  h5path: string
        @param dictAttributes: dictionary containing h5path: attributes, attributes being a dict
        @type dictAttributes: dictionary (string -> dictionary(string:string)) 
        @rtype: h5py group like
        @return: the h5py implementation of the HDF5 group
        """
        EDVerbose.DEBUG(
            "EDPluginHDF5.createStructure:  HDF5 file %s %s with internal structure %s %s"
            % (filename, filename.__class__, h5path, h5path.__class__))
        if dictAttributes is None:
            dictAttributes = {}
        if isinstance(filename, unicode):
            filename = filename.encode(cls.ENCODING)
        if isinstance(h5path, unicode):
            h5path = h5path.encode(cls.ENCODING)
        EDVerbose.DEBUG(
            "Creation of HDF5 file %s %s with internal structure %s %s" %
            (filename, filename.__class__, h5path, h5path.__class__))
        if not os.path.isdir(os.path.dirname(filename)):
            os.makedirs(os.path.dirname(filename))

        with cls.__semCls:
            if not cls.__dictHDF5.has_key(filename):

                if cls.HDF5_Multifiles:
                    try:
                        cls.__dictHDF5[filename] = h5py.File(filename,
                                                             driver="family")
                    except Exception:
                        EDVerbose.ERROR(
                            "Error in EDPluginHDF5.createStructure during opening HDF5 multi-file "
                            + filename)
                        raise
                else:
                    try:
                        cls.__dictHDF5[filename] = h5py.File(filename)
                    except Exception:
                        EDVerbose.ERROR(
                            "Error in EDPluginHDF5.createStructure during opening HDF5 file %s"
                            % filename)
                        EDVerbose.ERROR(
                            "I will now delete this file: %s and re-create it "
                            % filename)
                        try:
                            os.remove(filename)
                        except Exception:
                            EDVerbose.ERROR(
                                "Fatal error !!! no way to recreate this corruped file %s"
                                % filename)
                            raise
                        cls.__dictHDF5[filename] = h5py.File(filename)
            if not filename in cls.__dictLock:
                cls.__dictLock[filename] = Semaphore()
            filelock = cls.__dictLock[filename]
        with filelock:
            hdf5 = cls.__dictHDF5[filename]
            attrs = hdf5.attrs
            if "/" in dictAttributes:
                for key in dictAttributes["/"]:
                    if not key in attrs:
                        attrs.create(key, dictAttributes["/"][key])
            for key in cls.HDF5_ROOT_ATTRIBUTES:
                if not key in attrs.keys():
                    attrs.create(key, cls.HDF5_ROOT_ATTRIBUTES[key])
            if "file_name" not in attrs:
                file_name = os.path.basename(filename)
                if isinstance(file_name, unicode):
                    file_name = file_name.encode(cls.ENCODING)
                attrs.create("file_name", os.path.basename(file_name))
            if not "file_time" in attrs.keys():
                attrs.create("file_time", cls.getIsoTime())
            hdf5group = hdf5
            for subpath in h5path.split("/"):
                if subpath == "":
                    continue
                hdf5group = hdf5group.require_group(subpath)
                if hdf5group.name in dictAttributes:
                    for key in dictAttributes[hdf5group.name]:
                        if not key in hdf5group.attrs:
                            hdf5group.attrs.create(
                                key, dictAttributes[hdf5group.name][key])
                for key in cls.HDF5_GROUP_ATTRIBUTES:
                    if key not in hdf5group.attrs:
                        hdf5group.attrs.create(key,
                                               cls.HDF5_GROUP_ATTRIBUTES[key])
            for key in cls.NX_GROUP_ATTRIBUTES:
                if key not in hdf5group.attrs:
                    hdf5group.attrs.create(key, cls.NX_GROUP_ATTRIBUTES[key])
        return hdf5group
Exemplo n.º 39
0
numpy = EDFactoryPluginStatic.preImport("numpy",
                                        numpyPath,
                                        _strMethodVersion="__version__")
h5py = EDFactoryPluginStatic.preImport("h5py",
                                       h5pyPath,
                                       _strMethodVersion="version.api_version",
                                       _strForceVersion="1.8")
Image = EDFactoryPluginStatic.preImport("Image",
                                        imagingPath,
                                        _strMethodVersion="VERSION")
fabio = EDFactoryPluginStatic.preImport("fabio",
                                        fabioPath,
                                        _strMethodVersion="version")

if h5py is None:
    EDVerbose.error("h5py is None ... please investigate why !!!")
    EDVerbose.writeErrorTrace()
#    raise ImportError("EDPluginHDF5 cannot work without h5py !!!")

if "EDNA_SITE" not in os.environ:
    os.environ["EDNA_SITE"] = "edna-site"


class EDPluginHDF5(EDPlugin):
    """
    This is a common part for all EDNA plugin writing HDF5. most methods are class methods 
    """
    __semCls = Semaphore()
    __dictHDF5 = {}  #key: filename, value: hdf5 h5py objects
    __dictLock = {}  #key: filename, value:semaphores for writing
    __bConfigured = False
Exemplo n.º 40
0
import os, sys
from EDVerbose                           import EDVerbose
from EDTestCase                          import EDTestCase
from EDAssert                            import EDAssert
from EDUtilsArray                        import EDUtilsArray
from XSDataCommon                        import XSDataArray
from EDUtilsLibraryInstaller             import EDUtilsLibraryInstaller
from EDFactoryPluginStatic               import EDFactoryPluginStatic
from EDUtilsPlatform                     import EDUtilsPlatform

#EDVerbose.screen("Check Install Numpy")
EDFactoryPluginStatic.loadModule("EDInstallNumpyv1_3")
numpyPath = os.path.join(os.environ["EDNA_HOME"], "libraries", "20090405-Numpy-1.3", EDUtilsPlatform.architecture)
numpy = EDFactoryPluginStatic.preImport("numpy", numpyPath, _strMethodVersion="__version__")
if numpy is None:
    EDVerbose.WARNING("Numpy is not directly available, I will run all tests without it")

#EDVerbose.screen("Check Install PIL")
EDFactoryPluginStatic.loadModule("EDInstallPILv1_1_7")
#ImagePath = os.path.join(os.environ["EDNA_HOME"], "libraries", "20091115-PIL-1.1.7", EDUtilsPlatform.architecture)
#Image = EDFactoryPluginStatic.preImport("Image", ImagePath, _strMethodVersion="VERSION")
#if Image is None:
#    EDVerbose.WARNING("Image is not directly available, I will run all tests without it")


#EDVerbose.screen("Check Install Fabio")
EDFactoryPluginStatic.loadModule("EDInstallFabio_v0_0_7")
#fabioPath = os.path.join(os.environ["EDNA_HOME"], "libraries", "FabIO-0.0.7", EDUtilsPlatform.architecture)
#fabio = EDFactoryPluginStatic.preImport("fabio", fabioPath, _strMethodVersion="version")
#if fabio is None:
#    EDVerbose.WARNING("FabIO is not directly available, I will run all tests without it")
Exemplo n.º 41
0
 def doSuccessExecMetadata(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlDevelopRawv1_0.doSuccessExecMetadata")
     self.retrieveSuccessMessages(
         _edPlugin, "EDPluginControlDevelopRawv1_0.doSuccessExecMetadata")
     if self.bCompressRaw is True:
         self.compressRaw()
Exemplo n.º 42
0
 def doSuccessExecBzip2(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlDevelopRawv1_0.doSuccessExecBzip2")
     self.retrieveSuccessMessages(
         _edPlugin, "EDPluginControlDevelopRawv1_0.doSuccessExecBzip2")
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        self.DEBUG("EDPluginExecStitchOffsetedImagev1_0.process")

        shiftedImage = []
        distanceSq = lambda t2f: (t2f[0] * t2f[0] + t2f[1] * t2f[1])
        ref = self._lOffsets[0]
        refOffset = distanceSq(ref)
        shape = self._lImages[0].shape
        if self._strMask:
            mask = (1 - fabio.open(self._strMask).data).astype("bool")
        else:
            mask = 0
        for img, offset, dummy in zip(self._lImages, self._lOffsets,
                                      self._lDummies):
            shImg = scipy.ndimage.shift(img, offset, cval=dummy[0], order=0)
            if dummy[1] == 0:
                if self._strMask:
                    shImgMasked = numpy.ma.MaskedArray(
                        shImg, (shImg == dummy[0]) +
                        scipy.ndimage.shift(mask, offset, cval=1, order=0))
                else:
                    shImgMasked = numpy.ma.MaskedArray(shImg,
                                                       (shImg == dummy[0]))
            else:
                if self._strMask:
                    shImgMasked = numpy.ma.MaskedArray(
                        shImg, (abs(shImg - dummy[0]) <= dummy[1]) +
                        scipy.ndimage.shift(mask, offset, cval=1, order=0))
                else:
                    shImgMasked = numpy.ma.MaskedArray(
                        shImg, (abs(shImg - dummy[0]) <= dummy[1]))
            shiftedImage.append(shImgMasked)
            if (offset != ref) and (distanceSq(offset) < refOffset):
                ref = offset
                refOffset = distanceSq(offset)
        refIdx = self._lOffsets.index(ref)

        if EDVerbose.isVerboseDebug():
            e = edfimage(data=shiftedImage[0].filled(self._fDummy),
                         header={
                             "Dummy": str(self._fDummy),
                             "Offset_1": str(self._lOffsets[0][0]),
                             "Offset_2": str(self._lOffsets[0][1])
                         })
            for img, offset in zip(shiftedImage[1:], self._lOffsets[1:]):
                e.appendFrame(data=img.filled(self._fDummy),
                              header={
                                  "Dummy": str(self._fDummy),
                                  "Offset_1": str(offset[0]),
                                  "Offset_2": str(offset[1])
                              })
            e.write("stack.edf")

        ROI = False
        if self.tCenter is None:
            #the default center is the geometry center of the image ...
            self.tCenter = [i // 2 for i in shape]
        if self.tWidth is not None:
            d0min = max(0, self.tCenter[0] - (self.tWidth[0] // 2))
            d0max = min(shape[0], d0min + self.tWidth[0])
            d1min = max(0, self.tCenter[1] - (self.tWidth[1] // 2))
            d1max = min(shape[1], d1min + self.tWidth[1])
            shape = (d0max - d0min, d1max - d1min)
        else:
            d0min = 0
            d0max = shape[0]
            d1min = 0
            d1max = shape[1]
        refImg = shiftedImage[refIdx]
        stackMaskedImg = numpy.ma.zeros(
            (len(self._lOffsets), refImg.shape[0], refImg.shape[1]))
        self.screen(
            "ROI[%s:%s, %s:%s]\t Autoscale: %s\tBlending method: %s" %
            (d0min, d0max, d1min, d1max, self._bAutoscale, self._strBlending))
        if self._bAutoscale:
            for idx, img in enumerate(shiftedImage):
                ratio = (refImg[d0min:d0max, d1min:d1max] /
                         img[d0min:d0max, d1min:d1max])
                stackMaskedImg[idx] = ratio.mean() * img
        else:
            for idx, img in enumerate(shiftedImage):
                stackMaskedImg[idx] = img

        if self._strBlending.lower().startswith("naive"):
            npaTempBool = numpy.cumsum((1 - stackMaskedImg.mask),
                                       axis=0) * (1 - stackMaskedImg.mask) == 1
            result = numpy.ma.MaskedArray(
                (npaTempBool * stackMaskedImg.data).sum(axis=0),
                stackMaskedImg.mask.prod(axis=0))

        elif self._strBlending.lower().startswith("max"):
            result = stackMaskedImg.max(axis=0)
        elif self._strBlending.lower().startswith("min"):
            result = stackMaskedImg.min(axis=0)
        else:  #self._strBlending.lower() == "mean":
            result = stackMaskedImg.mean(axis=0)

        self._ndaResult = result.filled(self._fDummy)
Exemplo n.º 44
0
 def postProcess(self, _edObject=None):
     EDPluginControl.postProcess(self)
     EDVerbose.DEBUG("EDPluginControlDevelopRawv1_0.postProcess")
     # Create some output data
     xsDataResult = XSDataResultDevelopRawv1()
     self.setDataOutput(xsDataResult)
Exemplo n.º 45
0
 def doFailureActionStrategy(self, _edPlugin=None):
     EDVerbose.DEBUG(
         "EDPluginControlCharacterisationv2_0.doFailureActionStrategy")
     self.retrieveFailureMessages(
         _edPlugin,
         "EDPluginControlCharacterisationv2_0.doFailureActionStrategy")
Exemplo n.º 46
0
 def generateExecutiveSummary(self, _edPlugin):
     """
     Generates a summary of the execution of the plugin.
     """
     EDVerbose.DEBUG(
         "EDPluginControlCharacterisationv2_0.generateExecutiveSummary")
     self.addExecutiveSummaryLine("Summary of characterisation:")
     self.addErrorWarningMessagesToExecutiveSummary(
         "Characterisation failure! Error messages: ")
     self.addExecutiveSummarySeparator()
     xsDataInputStrategy = self.getDataInput("mxv1InputCharacterisation")[0]
     xsDataCollection = xsDataInputStrategy.getDataCollection()
     xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
     self.addExecutiveSummaryLine("Diffraction plan:")
     if (xsDataDiffractionPlan.getComplexity() is not None):
         self.addExecutiveSummaryLine(
             "BEST complexity                       : %s" %
             xsDataDiffractionPlan.getComplexity().getValue())
     if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
         self.addExecutiveSummaryLine(
             "Aimed completeness                    : %6.1f [%%]" %
             (100.0 *
              xsDataDiffractionPlan.getAimedCompleteness().getValue()))
     if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
         self.addExecutiveSummaryLine(
             "Required completeness                 : %6.1f [%%]" %
             (100.0 *
              xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
     if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution()
             is not None):
         self.addExecutiveSummaryLine(
             "Aimed I/sigma at highest resolution   : %6.1f" %
             xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution(
             ).getValue())
     if (xsDataDiffractionPlan.getAimedResolution() is not None):
         self.addExecutiveSummaryLine(
             "Aimed resolution                      : %6.1f [A]" %
             xsDataDiffractionPlan.getAimedResolution().getValue())
     if (xsDataDiffractionPlan.getRequiredResolution() is not None):
         self.addExecutiveSummaryLine(
             "Required resolution                   : %6.1f [A]" %
             xsDataDiffractionPlan.getRequiredResolution().getValue())
     if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
         self.addExecutiveSummaryLine(
             "Aimed multiplicity                    : %6.1f" %
             xsDataDiffractionPlan.getAimedMultiplicity().getValue())
     if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
         self.addExecutiveSummaryLine(
             "Required multiplicity                 : %6.1f" %
             xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
     if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
         self.addExecutiveSummaryLine(
             "Forced space group                    : %6s" %
             xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
     if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection()
             is not None):
         self.addExecutiveSummaryLine(
             "Max exposure time per data collection : %6.1f [s]" %
             xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
             ).getValue())
     self.addExecutiveSummarySeparator()
     if (self.edPluginIndexing is not None):
         self.appendExecutiveSummary(self.edPluginIndexing, "Indexing : ")
     if (self.edPluginIntegration is not None):
         self.appendExecutiveSummary(self.edPluginIntegration,
                                     "Integration : ")
     if (self.edPluginStrategy is not None):
         self.appendExecutiveSummary(self.edPluginStrategy, "Strategy : ")
Exemplo n.º 47
0
    def testExecute(self):
        """
        """
        self.run()
        plugin = self.getPlugin()

        ################################################################################
        # Compare XSDataResults
        ################################################################################

        strExpectedOutput = self.readAndParseFile(
            self.getReferenceDataOutputFile())
        EDVerbose.DEBUG("Checking obtained result...")
        xsDataResultReference = XSDataResultBioSaxsProcessOneFilev1_0.parseString(
            strExpectedOutput)
        xsDataResultObtained = plugin.getDataOutput()
        EDAssert.strAlmostEqual(xsDataResultReference.marshal(),
                                xsDataResultObtained.marshal(),
                                "XSDataResult output are the same",
                                _strExcluded="bioSaxs")

        ################################################################################
        # Compare dictionary
        ################################################################################
        obtFile = xsDataResultObtained.integratedImage.path.value
        refFile = os.path.join(self.getTestsDataImagesHome(),
                               "bioSaxsProcessIntegrated.edf")
        EDVerbose.DEBUG("fileRef=%s fileObt=%s" % (refFile, obtFile))
        edfRef = openimage(refFile)
        edfObt = openimage(obtFile)
        headerRef = edfRef.header
        headerObt = edfObt.header

        keysRef = headerRef.keys()
        keysObt = headerObt.keys()
        keysRef.sort()
        keysObt.sort()
        #        EDAssert.equal(keysRef, keysObt, _strComment="Same keys in the header dict")
        for key in keysRef:
            if not (key.startswith("History") or key in [
                    "Compression", "DDummy", "Dummy", "EDF_HeaderSize",
                    "HeaderID", "Image", "filename", "RasterOrientation"
            ]):
                EDAssert.strAlmostEqual(
                    headerRef[key],
                    headerObt[key],
                    _strComment="header value %s are the same" % key,
                    _strExcluded="bioSaxs")


################################################################################
# Compare images
################################################################################

        outputData = edfRef.data
        referenceData = edfObt.data
        EDAssert.arraySimilar(numpy.maximum(outputData, 0),
                              numpy.maximum(referenceData, 0),
                              _fScaledMaxDelta=0.05,
                              _strComment="Images-data are the same")

        outputData = edfRef.next().data
        referenceData = edfObt.next().data
        EDAssert.arraySimilar(numpy.maximum(outputData, 0),
                              numpy.maximum(referenceData, 0),
                              _fScaledMaxDelta=0.05,
                              _strComment="Images-ESD are the same")

        ################################################################################
        # Compare Ascii files
        ################################################################################
        asciiObt = os.linesep.join([
            i.strip()
            for i in open(xsDataResultObtained.integratedCurve.path.value)
            if "RasterOrientation" not in i
        ])
        asciiRef = os.linesep.join([
            i.strip() for i in EDUtilsFile.readFileAndParseVariables(
                os.path.join(self.getTestsDataImagesHome(),
                             "bioSaxsProcessIntegrated.dat"),
                EDUtilsPath.getDictOfPaths()).split(os.linesep)
            if "RasterOrientation" not in i
        ])
        EDAssert.strAlmostEqual(
            asciiRef,
            asciiObt,
            _strComment="3 column ascii files are the same",
            _fRelError=0.1,
            _strExcluded=os.environ["USER"])
Exemplo n.º 48
0
    def doIntegrationToStrategyTransition(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition"
        )

        xsDataIntegrationOutput = self.edPluginIntegration.getDataOutput()
        self.xsDataResultCharacterisation.setIntegrationResult(
            xsDataIntegrationOutput)
        #EDVerbose.DEBUG( self.xsDataExperimentCharacterisation.marshal() )
        from XSDataMXv1 import XSDataInputStrategy
        xsDataInputStrategyOLD = XSDataInputStrategy()

        xsDataSolutionSelected = self.xsDataResultCharacterisation.getIndexingResult(
        ).getSelectedSolution()

        xsDataInputStrategyOLD.setCrystalRefined(
            xsDataSolutionSelected.getCrystal())
        xsDataInputStrategyOLD.setSample(
            self.xsDataResultCharacterisation.getDataCollection().getSample())

        xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult(
        )

        xsDataInputStrategyOLD.setBestFileContentDat(
            xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
        xsDataInputStrategyOLD.setBestFileContentPar(
            xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
        xsDataInputStrategyOLD.setExperimentalCondition(
            xsDataIntegrationSubWedgeResultList[0].
            getExperimentalConditionRefined())

        for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
            xsDataInputStrategyOLD.addBestFileContentHKL(
                xsDataIntegrationSubWedgeResult.getBestfileHKL())

        xsDataInputStrategyOLD.setDiffractionPlan(
            self.xsDataResultCharacterisation.getDataCollection(
            ).getDiffractionPlan())
        xsDataInputStrategyOLD.setXdsBackgroundImage(
            self.xsDataResultCharacterisation.getXdsBackgroundImage())

        #print xsDataInputStrategy.marshal()
        self.edPluginStrategy.setDataInput(xsDataInputStrategyOLD,
                                           "mxv1InputStrategy")
        if self.hasDataInput("mxv2DataCollection"):
            self.edPluginStrategy.setDataInput(
                self.getDataInput("mxv2DataCollection")[0],
                "mxv2DataCollection")
        self.edPluginStrategy.setDataInput(
            self.xsDataResultCharacterisation.getIndexingResult(),
            "mxv1IndexingResult")

        #            xsDataInputStrategy= EDList()
        #            xsDataInputStrategy.add(xsDataInputStrategyOLD)
        #            xsDataInputStrategy.add(self.getDataInput()[1])
        #            xsDataInputStrategy.add(self.xsDataResultCharacterisationv2_0.getIndexingResult())
        #            self.edPluginStrategy.setDataInput( xsDataInputStrategy )
        self.edPluginStrategy.executeSynchronous()
Exemplo n.º 49
0
 def doFailure_MTZDUMP(self, _edPlugin=None):
     """
     Method called after the MTZDUMPUnitCellSpaceGroup execution plugin has failed during it process processed.
     This is the place for doing error handling
     """
     EDVerbose.DEBUG("*** doFailure_MTZDUMP")
Exemplo n.º 50
0
 def doFailure_PDBSET(self, _edPlugin=None):
     """
     Method called after the PDBSETUnitCell execution plugin has failed during it's process.
     This is the place for doing error handling.
     """
     EDVerbose.DEBUG("*** doFailure_PDBSET")
 def usage(self):
     """
     Print usage...
     """
     EDVerbose.screen("")
     EDVerbose.screen("Usage: ")
     EDVerbose.screen("----- ")
     EDVerbose.screen("")
     EDVerbose.screen(" Either use:")
     EDVerbose.screen("")
     EDVerbose.screen(" - the full/advanced XML input:")
     EDVerbose.screen("")
     EDVerbose.screen(
         "   edna-mxv1-characterisation --data path_to_xsDataInputCharacterisation_xml_file"
     )
     EDVerbose.screen("")
     EDVerbose.screen(
         " - or use the --image keyword (note that all these keywords are ignored if the --data option is used):"
     )
     EDVerbose.screen("")
     EDVerbose.screen(
         "   edna-mxv1-characterisation --image image1 [image2 image3 ...]")
     EDVerbose.screen("")
     EDVerbose.screen(
         " In the case of using the --image command line keyword the following arguments are optional:"
     )
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : BEST complexity [none (default), min or full]" %
         (EDApplicationMXv1Characterisation.COMPLEXITY_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen("%35s : Beam flux [photon/s]" %
                      (EDApplicationMXv1Characterisation.FLUX_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Beam size [mm] (beam assumed to be square)" %
         (EDApplicationMXv1Characterisation.BEAM_SIZE_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Beam position X [mm] (MOSFLM ordering)" %
         (EDApplicationMXv1Characterisation.BEAM_POS_X_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Beam position Y [mm] (MOSFLM ordering)" %
         (EDApplicationMXv1Characterisation.BEAM_POS_Y_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Max exposure time per data collection [s]" %
         (EDApplicationMXv1Characterisation.MAX_EXPOSURE_TIME_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Min exposure time per image [s]" %
         (EDApplicationMXv1Characterisation.MIN_EXPOSURE_TIME_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Forced space group for indexing" %
         (EDApplicationMXv1Characterisation.FORCED_SPACE_GROUP_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Anomalous data" %
         (EDApplicationMXv1Characterisation.ANOMALOUS_DATA_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Incoming transmission [%%]" %
         (EDApplicationMXv1Characterisation.TRANSMISSION_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Optional command to BEST, the currently only supported command is: -DamPar"
         % (EDApplicationMXv1Characterisation.STRATEGY_OPTION_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "-----------------------------------------------------------------------------------------------------------"
     )
     EDVerbose.screen("")
     EDVerbose.screen(" Additional options available:")
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Generates an xml template input file for edna" %
         (EDApplicationMXv1Characterisation.TEMPLATE_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Generates an xml file containing the characterisation results"
         % (EDApplicationMXv1Characterisation.RESULTS_FILE_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen("%35s : DEBUG log traces" %
                      (EDApplicationMXv1Characterisation.DEBUG_PARAM_LABEL))
     EDVerbose.screen("")
     EDVerbose.screen(
         "%35s : Executable version info" %
         (EDApplicationMXv1Characterisation.VERSION_PARAM_LABEL))
     EDVerbose.screen("")
Exemplo n.º 52
0
strEdnaHome = dirname(dirname(dirname(os.path.abspath(sys.argv[0]))))

if ("EDNA_HOME" in os.environ):
    if  (os.environ["EDNA_HOME"] != strEdnaHome):
        print("Warning: EDNA_HOME redefined to %s" % strEdnaHome)
        os.environ["EDNA_HOME"] = strEdnaHome
else:
    os.environ["EDNA_HOME"] = strEdnaHome
sys.path.append(os.path.join(os.environ["EDNA_HOME"], "kernel", "src"))
from EDUtilsLibraryInstaller import EDUtilsLibraryInstaller
from EDVerbose import EDVerbose


if __name__ == "__main__":
    installDir = os.path.abspath(sys.argv[0]).split(os.sep)[-2]
    EDVerbose.screen("Building %s" % installDir)
    install = EDUtilsLibraryInstaller(installDir, strArchiveName)
    install.checkPythonVersion()
    install.downloadLibrary()
    install.dependency("numpy", "20090405-Numpy-1.3")
    install.unZipArchive()
    try:
        install.buildSources()
    except Exception:
        EDVerbose.ERROR("Error in the build")
    install.installBuilt()
    if not EDVerbose.isVerboseDebug():
        install.cleanSources()

else:
    EDVerbose.ERROR("This installer program is not made to be imported, please just run it")
Exemplo n.º 53
0
 def doFailureExecTemplate(self, _edPlugin=None):
     EDVerbose.DEBUG(
         "*** EDPluginControlDCTReadHeaderv1_0.doFailureExecTemplate")
     self.retrieveFailureMessages(
         _edPlugin,
         "EDPluginControlDCTReadHeaderv1_0.doFailureExecTemplate")
    def readAndProcessCommandLine(self):
        """
        Reads and processes the command line
        """
        EDVerbose.DEBUG(
            "EDApplicationMXv1Characterisation.readAndProcessCommandLine")
        bCommandLineIsOk = False
        strResultsFilePath = self.getCommandLineArgument(
            EDApplicationMXv1Characterisation.RESULTS_FILE_LABEL)
        if (strResultsFilePath is not None):
            self.__strResultsFilePath = strResultsFilePath
            EDVerbose.screen(
                "Results written to file                      : %s" %
                (self.__strResultsFilePath))
        strShortComments = self.getCommandLineArgument(
            EDApplicationMXv1Characterisation.SHORTCOMMENTS_LABEL)
        if (strShortComments is not None):
            self.__strShortComments = strShortComments
            EDVerbose.screen(
                "Short comments                               : %s" %
                (self.__strShortComments))
        strComments = self.getCommandLineArgument(
            EDApplicationMXv1Characterisation.COMMENTS_LABEL)
        if (strComments is not None):
            self.__strComments = strComments
            EDVerbose.screen(
                "Comments                                     : %s" %
                (self.__strComments))
        # Check if m_strDATASET_PARAM_LABEL is given:
        self.__strDatasetFileName = self.getCommandLineArgument(
            EDApplicationMXv1Characterisation.DATASET_PARAM_LABEL)
        if (self.__strDatasetFileName is not None):
            if (not os.path.isabs(self.__strDatasetFileName)):
                self.__strDatasetFileName = os.path.abspath(
                    os.path.join(self.getCurrentWorkingDirectory(),
                                 self.__strDatasetFileName))
            EDVerbose.screen("Reading input data from : %s" %
                             (self.__strDatasetFileName))
            EDVerbose.screen(
                "(Any other command line arguments are neglected.)")
            bCommandLineIsOk = True
        else:
            # Special processing necessary for image list:
            EDVerbose.DEBUG(
                "EDApplicationMXv1Characterisation.readAndProcessCommandLine: Searching for "
                + EDApplicationMXv1Characterisation.IMAGE_PARAM_LABEL +
                " tag.")
            strCommandLine = self.getCommandLine()
            EDVerbose.DEBUG(
                "EDApplicationMXv1Characterisation.readAndProcessCommandLine: Command line: "
                + strCommandLine)
            listCommandLine = self.getEdCommandLine().getCommandLineArguments()
            # First go through in order to find if there are any images
            bFoundImageToken = False
            for strCommandLineItem in listCommandLine:

                bFoundImageToken = self.processCommandLineItems(
                    strCommandLineItem, bFoundImageToken)

            # Check that we have at least one image...
            if (self.__listImagePaths is not None):
                # Then find any other optional parameters
                strComplexity = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.COMPLEXITY_PARAM_LABEL)
                if (strComplexity is not None):
                    self.__strComplexity = strComplexity
                EDVerbose.screen(
                    "BEST complexity set to                       : %s" %
                    (self.__strComplexity))
                strFlux = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.FLUX_PARAM_LABEL)
                if (strFlux is not None):
                    self.__fFlux = float(strFlux)
                    EDVerbose.screen(
                        "Beamline flux set to                         : %7.1f [photons/s]"
                        % (self.__fFlux))
                strMaxExposureTimePerDataCollection = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.
                    MAX_EXPOSURE_TIME_PARAM_LABEL)
                if (strMaxExposureTimePerDataCollection is not None):
                    self.__fMaxExposureTimePerDataCollection = float(
                        strMaxExposureTimePerDataCollection)
                    EDVerbose.screen(
                        "Max exposure time per data collection set to : %7.1f [s]"
                        % (self.__fMaxExposureTimePerDataCollection))
                else:
                    EDVerbose.screen(
                        "Max exposure time per data collection set to : %7.1f [s] (default value for MXv1)"
                        % (self.__fMaxExposureTimePerDataCollection))
                strMinExposureTimePerImage = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.
                    MIN_EXPOSURE_TIME_PARAM_LABEL)
                if (strMinExposureTimePerImage is not None):
                    self.__fMinExposureTimePerImage = float(
                        strMinExposureTimePerImage)
                    EDVerbose.screen(
                        "Minimum exposure time per image set to       : %7.3f [s]"
                        % (self.__fMinExposureTimePerImage))
                strBeamSize = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.BEAM_SIZE_PARAM_LABEL)
                if (strBeamSize is not None):
                    self.__fBeamSize = float(strBeamSize)
                    EDVerbose.screen(
                        "Beam size (beam assumed to be square)        : %7.3f [mm]"
                        % (self.__fBeamSize))
                strBeamPosX = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.BEAM_POS_X_PARAM_LABEL)
                if (strBeamPosX is not None):
                    self.__fBeamPosX = float(strBeamPosX)
                    EDVerbose.screen(
                        "Beam position X (MOSFLM ordering)            : %7.3f [mm]"
                        % (self.__fBeamPosX))
                strBeamPosY = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.BEAM_POS_Y_PARAM_LABEL)
                if (strBeamPosY is not None):
                    self.__fBeamPosY = float(strBeamPosY)
                    EDVerbose.screen(
                        "Beam position Y (MOSFLM ordering)            : %7.3f [mm]"
                        % (self.__fBeamPosY))
                strForcedSpaceGroup = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.FORCED_SPACE_GROUP_LABEL)
                if (strForcedSpaceGroup is not None):
                    self.__strForcedSpaceGroup = strForcedSpaceGroup
                    EDVerbose.screen(
                        "Forced space group for indexing              : %s" %
                        (self.__strForcedSpaceGroup))
                strStrategyOption = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.STRATEGY_OPTION_LABEL)
                if (strStrategyOption is not None):
                    self.__strStrategyOption = strStrategyOption
                    EDVerbose.screen(
                        "Strategy option                              : %s" %
                        (self.__strStrategyOption))
                strTransmission = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.TRANSMISSION_LABEL)
                if (strTransmission is not None):
                    self.__fTransmission = float(strTransmission)
                    EDVerbose.screen(
                        "Transmission                                 : %.1f [%%]"
                        % (self.__fTransmission))
                strDoseLimit = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.DOSELIMIT)
                if (strDoseLimit is not None):
                    self.__fDoseLimit = 1.e6 * float(strDoseLimit)
                    EDVerbose.screen(
                        "Dose Limit (best -DMAX *1.e-6)               : %7.3f [MGy]"
                        % (self.__fDoseLimit * 1.e-6))
                strAimedResolution = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.AIMED_RESOLUTION)
                if (strAimedResolution is not None):
                    self.__fAimedResolution = float(strAimedResolution)
                    EDVerbose.screen(
                        "Aimed Resolution (BEST -r)                   : %7.3f [A]"
                        % (self.__fAimedResolution))
                strAimedCompleteness = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.AIMED_COMPLETENESS)
                if (strAimedCompleteness is not None):
                    self.__fAimedCompleteness = float(strAimedCompleteness)
                    EDVerbose.screen(
                        "Aimed Resolution (BEST -C) as decimal        : %7.3f []"
                        % (self.__fAimedCompleteness))
                strAimedMultiplicity = self.getCommandLineArgument(
                    EDApplicationMXv1Characterisation.AIMED_MULTIPLICITY)
                if (strAimedMultiplicity is not None):
                    self.__fAimedMultiplicity = float(AimedMultiplicity)
                    EDVerbose.screen(
                        "Aimed Multiplicity (BEST -R)                 : %7.3f []"
                        % (self.__fAimedMultiplicity))
                bCommandLineIsOk = True
            elif (not self.__strGeneratedTemplateFile is None):
                bCommandLineIsOk = True
            else:
                # Check for -v or --v which has already been processed by EDApplciation
                if not ((EDApplication.VERSION_PARAM_LABEL_1 in listCommandLine) or \
                        (EDApplication.VERSION_PARAM_LABEL_2 in listCommandLine) or \
                        (EDApplication.HELP_LABEL_1 in listCommandLine) or \
                        (EDApplication.HELP_LABEL_2 in listCommandLine)):
                    self.usage()
                    bCommandLineIsOk = False
        return bCommandLineIsOk
Exemplo n.º 55
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlRunXds.process")
        # First run is vanilla without any modification
        params = XSDataMinimalXdsIn()
        params.input_file = self.dataInput.input_file
        self.first_run.dataInput = params
        self.first_run.executeSynchronous()

        EDVerbose.DEBUG('first run completed...')

        if self.first_run.dataOutput is not None and self.first_run.dataOutput.succeeded:
            EDVerbose.DEBUG('... and it worked')
            self.successful_run = self.first_run
        else:
            EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            # second run w/ JOB set to DEFPIX INTEGRATE CORRECT
            self.second_run = self.loadPlugin(self.controlled_plugin_name)
            params = XSDataMinimalXdsIn()
            params.input_file = self.dataInput.input_file
            params.jobs = 'DEFPIX INTEGRATE CORRECT'
            self.second_run.dataInput = params
            self.second_run.executeSynchronous()

            EDVerbose.DEBUG('second run completed')
            if self.second_run.dataOutput is not None and self.second_run.dataOutput.succeeded:
                EDVerbose.DEBUG('... and it worked')
                self.successful_run = self.second_run
            else:
                EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            # third run with JOB set to ALL and mxaprocs = 4 and maxjobs = 1
            self.third_run = self.loadPlugin(self.controlled_plugin_name)
            params = XSDataMinimalXdsIn()
            params.input_file = self.dataInput.input_file
            params.jobs = 'ALL'
            params.maxprocs = 4
            params.maxjobs = 1
            self.third_run.dataInput = params
            self.third_run.executeSynchronous()

            EDVerbose.DEBUG('third run completed')
            if self.third_run.dataOutput is not None and self.third_run.dataOutput.succeeded:
                EDVerbose.DEBUG('... and it worked')
                self.successful_run = self.third_run
            else:
                EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            # final run with parallelism like 3 but JOB like 2
            self.final_run = self.loadPlugin(self.controlled_plugin_name)
            params = XSDataMinimalXdsIn()
            params.input_file = self.dataInput.input_file
            params.jobs = 'DEFPIX INTEGRATE CORRECT'
            params.maxprocs = 4
            params.maxjobs = 1
            self.final_run.dataInput = params
            self.final_run.executeSynchronous()

            EDVerbose.DEBUG('final run completed')
            if self.final_run.dataOutput is not None and self.final_run.dataOutput.succeeded:
                EDVerbose.DEBUG('... and it worked')
                self.successful_run = self.final_run
            else:
                EDVerbose.DEBUG('... and it failed')

        if not self.successful_run:
            # all runs failed so bail out ...
            self.setFailure()
        else:
            # use the xds parser plugin to parse the xds output file...
            parser = self.loadPlugin("EDPluginParseXdsOutput")
            wd = self.successful_run.getWorkingDirectory()
            parser_input = XSDataXdsOutputFile()
            correct_lp_path = XSDataFile()
            correct_lp_path.path = XSDataString(os.path.join(wd, 'CORRECT.LP'))
            parser_input.correct_lp = correct_lp_path
            gxparm_path = os.path.join(wd, 'GXPARM.XDS')
            if os.path.isfile(gxparm_path):
                gxparm = XSDataFile()
                gxparm.path = XSDataString(os.path.join(wd, 'GXPARM.XDS'))
                parser_input.gxparm = gxparm

            parser.dataInput = parser_input
            parser.executeSynchronous()

            if parser.isFailure():
                # that should not happen
                self.setFailure()
                return
            self.dataOutput = parser.dataOutput
Exemplo n.º 56
0
 def postProcess(self, _edObject=None):
     EDPluginControl.postProcess(self)
     EDVerbose.DEBUG("*** EDPluginControlDCTReadHeaderv1_0.postProcess")
 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"
     ]:
         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)
Exemplo n.º 58
0
__copyright__ = "2012 European Synchrotron Radiation Facility"

import os
import numpy as np
from EDUtilsArray import EDUtilsArray
from EDUtilsUnit import EDUtilsUnit
from EDPluginExec import EDPluginExec
from EDVerbose import EDVerbose
from EDThreading import Semaphore
from XSDataPyFAIv1_0 import XSDataInputPyFAI, XSDataResultPyFAI, XSDataGeometryFit2D, XSDataGeometryPyFAI
from XSDataCommon import XSDataImageExt, XSDataString

try:
    import pyFAI
except ImportError:
    EDVerbose.ERROR("Failed to import PyFAI: download and install it from \
        https://forge.epn-campus.eu/projects/azimuthal/files")
try:
    import fabio
except ImportError:
    EDVerbose.ERROR(
        "Failed to import Fabio: download and install it from sourceforge")


class EDPluginExecPyFAIv1_0(EDPluginExec):
    """
    This is the basic plugin of PyFAI for azimuthal integration
    """

    _dictGeo = {}  #key:tuple(ai.param), value= ai
    _sem = Semaphore()
Exemplo n.º 59
0
 def unitTestSep(self):
     """
     Test os.sep
     """
     EDVerbose.DEBUG("EDTestCaseEDUtilsPlatform.unitTestSep")
     EDAssert.equal(os.sep, EDUtilsPlatform.sep, "os.sep equivalent")
Exemplo n.º 60
0
if ("EDNA_HOME" in os.environ):
    if (os.environ["EDNA_HOME"] != strEdnaHome):
        print("Warning: EDNA_HOME redefined to %s" % strEdnaHome)
        os.environ["EDNA_HOME"] = strEdnaHome
else:
    os.environ["EDNA_HOME"] = strEdnaHome

sys.path.append(os.path.join(strEdnaHome, "kernel", "src"))
from EDUtilsLibraryInstaller import EDUtilsLibraryInstaller
from EDVerbose import EDVerbose

strLibrary = "SpecClient.tar.bz2"

if __name__ == "__main__":
    installDir = os.path.abspath(sys.argv[0]).split(os.sep)[-2]
    EDVerbose.screen("Building %s" % strLibrary)
    install = EDUtilsLibraryInstaller(installDir, strLibrary)
    install.checkPythonVersion()
    install.getArchitecture()
    install.downloadLibrary()
    install.getArchiveName()
    install.unZipArchive()
    install.buildSources()
    install.installBuilt()
    install.cleanSources()

else:
    print(
        "This installer program is not made to be imported, please just run it"
    )