예제 #1
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.preProcess")
        # Read the parameter file
        if self.getDataInput().getCorrectMask() is not None:
            self.bCorrectMask = bool(
                self.getDataInput().getCorrectMask().getValue())

        strPathToParameterFile = self.getDataInput().getParameterFile(
        ).getPath().getValue()

        if os.path.exists(strPathToParameterFile):
            EDPluginControlID11v1_0.__semaphore.acquire()
            if strPathToParameterFile in EDPluginControlID11v1_0.__dictParamID11XSD:
                self.__dictID11, strInputSPDCake = EDPluginControlID11v1_0.__dictParamID11XSD[
                    strPathToParameterFile]
                self.__xsDataInputSPDCake = XSDataInputSPDCake.parseString(
                    strInputSPDCake)
            else:
                self.parseParameterFiles(strPathToParameterFile)
                self.__xsDataInputSPDCake = self.populateXSDataInputSPDCake()
                EDPluginControlID11v1_0.__dictParamID11XSD[
                    strPathToParameterFile] = (
                        self.__dictID11, self.__xsDataInputSPDCake.marshal())
            EDPluginControlID11v1_0.__semaphore.release()
            # Load the execution plugin
            self.synchronizeOn()
            self.__edPluginWaitMultipleFile = self.loadPlugin(
                self.__strControlledPluginWait)
            self.synchronizeOff()
            #            self.__edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
            # Paths to the data files
            self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
            for xsDataFile in self.getDataInput().getDataFile():
                self.__xsDataInputWaitMultipleFile.addExpectedFile(xsDataFile)
            # we are expecting unsigned int
            self.__xsDataInputWaitMultipleFile.setExpectedSize(
                XSDataInteger(512 + 2 * int(self.__dictID11["DIM1_DATA"]) *
                              int(self.__dictID11["DIM2_DATA"])))
            self.__edPluginWaitMultipleFile.setDataInput(
                self.__xsDataInputWaitMultipleFile)

        else:
            self.ERROR("Path to parameter file does not exist: %s" %
                       strPathToParameterFile)
            self.setFailure()
        xsdOutputDir = self.getDataInput().getOutputdir()
        if xsdOutputDir is not None:
            self.__xsDataInputSPDCake.setOutputDir(xsdOutputDir)
            self.__dictID11["output_dir"] = xsdOutputDir.getPath().getValue()
예제 #2
0
 def __init__(self):
     """
     """
     EDPluginControl.__init__(self)
     self.setXSDataInputClass(XSDataInputID11)
     self.bTimedOut = False
     self.__dictID11 = {}
     self.__strControlledPluginWait = "EDPluginWaitMultiFile"
     self.__edPluginWaitMultipleFile = None
     self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
     self.__listProcessedFiles = []
     self.__strControlledPluginSPD = "EDPluginSPDCakev1_5"
     self.__xsDataInputSPDCake = None
     self.__strControlledPluginEDF = "EDPluginExportAsciiPowderv1_0"
     self.bCorrectMask = True
예제 #3
0
 def testCheckParameters(self):
     xsDataInput = XSDataInputWaitMultiFile()
     xsDataInput.setExpectedFile([XSDataFile(XSDataString("toto"))])
     xsDataInput.setExpectedSize(XSDataInteger(10))
     edPluginWaitMultiFile = self.createPlugin()
     edPluginWaitMultiFile.setDataInput(xsDataInput)
     edPluginWaitMultiFile.checkParameters()
예제 #4
0
 def __init__(self):
     """
     """
     EDPluginControl.__init__(self)
     self.setXSDataInputClass(XSDataInputID11)
     self.bTimedOut = False
     self.__dictID11 = {}
     self.__strControlledPluginWait = "EDPluginWaitMultiFile"
     self.__edPluginWaitMultipleFile = None
     self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
     self.__listProcessedFiles = []
     self.__strControlledPluginSPD = "EDPluginSPDCakev1_5"
     self.__xsDataInputSPDCake = None
     self.__strControlledPluginEDF = "EDPluginExportAsciiPowderv1_0"
     self.bCorrectMask = True
예제 #5
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        EDVerbose.DEBUG("EDPluginBioSaxsAveragev1_0.process")

        xsdiWaitMultiFile = XSDataInputWaitMultiFile(
            expectedFile=[
                XSDataFile(i.path) for i in self.dataInput.integratedImage
            ],
            expectedSize=self.dataInput.integratedImageSize,
            timeOut=XSDataTime(30))
        self.__edPluginWaitMultiFile.setDataInput(xsdiWaitMultiFile)
        self.__edPluginWaitMultiFile.connectSUCCESS(
            self.doSuccessWaitMultiFile)
        self.__edPluginWaitMultiFile.connectFAILURE(
            self.doFailureWaitMultiFile)
        self.__edPluginWaitMultiFile.executeSynchronous()
 def preProcess(self, _edPlugin=None):
     """
     Prepares the execution plugin
     """
     EDPluginControl.preProcess(self, _edPlugin)
     EDVerbose.DEBUG("EDPluginControlImageQualityIndicatorsv1_1.preProcess...")
     # List containing instances of all the exeuction plugins
     self.listPluginExecImageQualityIndicator = []
     # Loop through all the incoming reference images
     self.edPluginWaitMultiFile = self.loadPlugin(self.strPluginExecWaitMultiFileName)
     listXSDataImage = self.getDataInput().getImage()
     xsDataInputWaitMultiFile = XSDataInputWaitMultiFile()
     for xsDataImage in listXSDataImage:
         xsDataInputWaitMultiFile.addExpectedFile(XSDataFile(xsDataImage.getPath()))
     xsDataInputWaitMultiFile.setExpectedSize(XSDataInteger(100000))
     xsDataInputWaitMultiFile.setTimeOut(XSDataTime(self.fWaitFileTimeOut))
     self.DEBUG("Wait file timeOut set to %f" % self.fWaitFileTimeOut)
     self.edPluginWaitMultiFile.setDataInput(xsDataInputWaitMultiFile)
     self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators()
 def preProcess(self, _edPlugin=None):
     """
     Prepares the execution plugin
     """
     EDPluginControl.preProcess(self, _edPlugin)
     EDVerbose.DEBUG("EDPluginControlImageQualityIndicatorsv1_1.preProcess...")
     # List containing instances of all the exeuction plugins
     self.listPluginExecImageQualityIndicator = []
     # Loop through all the incoming reference images
     self.edPluginWaitMultiFile = self.loadPlugin(self.strPluginExecWaitMultiFileName)
     listXSDataImage = self.getDataInput().getImage()
     xsDataInputWaitMultiFile = XSDataInputWaitMultiFile()
     for xsDataImage in listXSDataImage:
         xsDataInputWaitMultiFile.addExpectedFile(XSDataFile(xsDataImage.getPath()))
     xsDataInputWaitMultiFile.setExpectedSize(XSDataInteger(100000))
     xsDataInputWaitMultiFile.setTimeOut(XSDataTime(self.fWaitFileTimeOut))
     self.DEBUG("Wait file timeOut set to %f" % self.fWaitFileTimeOut)
     self.edPluginWaitMultiFile.setDataInput(xsDataInputWaitMultiFile)
     self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators()
예제 #8
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.preProcess")
        # Read the parameter file
        if self.getDataInput().getCorrectMask() is not None:
            self.bCorrectMask = bool(self.getDataInput().getCorrectMask().getValue())

        strPathToParameterFile = self.getDataInput().getParameterFile().getPath().getValue()

        if os.path.exists(strPathToParameterFile):
            EDPluginControlID11v1_0.__semaphore.acquire()
            if strPathToParameterFile in EDPluginControlID11v1_0.__dictParamID11XSD:
                self.__dictID11, strInputSPDCake = EDPluginControlID11v1_0.__dictParamID11XSD[strPathToParameterFile]
                self.__xsDataInputSPDCake = XSDataInputSPDCake.parseString(strInputSPDCake)
            else:
                self.parseParameterFiles(strPathToParameterFile)
                self.__xsDataInputSPDCake = self.populateXSDataInputSPDCake()
                EDPluginControlID11v1_0.__dictParamID11XSD[strPathToParameterFile] = (self.__dictID11, self.__xsDataInputSPDCake.marshal())
            EDPluginControlID11v1_0.__semaphore.release()
            # Load the execution plugin
            self.synchronizeOn()
            self.__edPluginWaitMultipleFile = self.loadPlugin(self.__strControlledPluginWait)
            self.synchronizeOff()
#            self.__edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
            # Paths to the data files
            self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
            for xsDataFile in self.getDataInput().getDataFile():
                self.__xsDataInputWaitMultipleFile.addExpectedFile(xsDataFile)
            # we are expecting unsigned int 
            self.__xsDataInputWaitMultipleFile.setExpectedSize(XSDataInteger(512 + 2 * int(self.__dictID11["DIM1_DATA"]) * int(self.__dictID11["DIM2_DATA"])))
            self.__edPluginWaitMultipleFile.setDataInput(self.__xsDataInputWaitMultipleFile)

        else:
            self.ERROR("Path to parameter file does not exist: %s" % strPathToParameterFile)
            self.setFailure()
        xsdOutputDir = self.getDataInput().getOutputdir()
        if xsdOutputDir is not None:
            self.__xsDataInputSPDCake.setOutputDir(xsdOutputDir)
            self.__dictID11["output_dir"] = xsdOutputDir.getPath().getValue()
예제 #9
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsSmartMergev1_3.process")

        xsdwf = XSDataInputWaitMultiFile(timeOut=XSDataTime(30),
                                        expectedSize=XSDataInteger(10000),
                                        expectedFile=[XSDataFile(i.path) for i in self.lstInput])
        self.__edPluginExecWaitFile.setDataInput(xsdwf)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWait)
        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWait)
        self.__edPluginExecWaitFile.executeSynchronous()
        if self.isFailure():
            return
        if len(self.lstInput) == 1:
            inp = self.lstInput[0].path.value
            dst = self.dataInput.mergedCurve.path.value
            if not os.path.isdir(os.path.dirname(dst)):
                 self.error("Output directory for %s does not exist"%dst)
                 os.makedirs(os.path.dirname(dst))
            if not os.path.exists(inp):
                 self.warning("Input %s does not (yet?) exist"%inp)
                 time.sleep(1.0)
            shutil.copyfile(inp, dst)
        else:
            self.lstMerged = []
            if (self.absoluteFidelity is not None) or (self.relativeFidelity is not None):
                if self.absoluteFidelity is not None :
                    for idx, oneFile in enumerate(self.lstInput[1:]):
                        self.DEBUG("Calculating similarity of 0 and %s" % idx)
                        edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], oneFile])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                if (self.relativeFidelity is not None):
                    if (self.absoluteFidelity is  None):
                        self.DEBUG("Calculating similarity of 0 and 1")
                        edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], self.lstInput[1] ])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                    if (len(self.lstInput) > 2):
                        for idx, oneFile in enumerate(self.lstInput[2:]):
                            self.DEBUG("Calculating similarity of %s and %s" % (idx, idx + 1))
                            edPluginExecRelativeFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
                            xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[idx + 1], oneFile])
                            edPluginExecRelativeFidelity.setDataInput(xsd)
                            edPluginExecRelativeFidelity.connectFAILURE(self.doFailureExecDatcmp)
                            edPluginExecRelativeFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
                            edPluginExecRelativeFidelity.execute()
            self.synchronizePlugins()

            for idx, oneFile in enumerate(self.lstInput):
                if idx == 0:
                    self.lstMerged.append(oneFile)
                elif (self.absoluteFidelity is not None) and (self.relativeFidelity is not None):
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))
                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))

                    if (self.dictSimilarities[(0, idx)] >= self.absoluteFidelity) and (self.dictSimilarities[(idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.absoluteFidelity is not None) :
                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))

                    if (self.dictSimilarities[(0, idx)] >= self.absoluteFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.relativeFidelity is not None) :
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))

                    if (self.dictSimilarities[(idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                else:
                    self.lstMerged.append(oneFile)
            self.lstMerged.sort(cmp)
            if len(self.lstMerged) != len(self.lstInput):
                self.strRadiationDamage = "Radiation damage detected, merged %i curves" % len(self.lstMerged)
                self.WARNING(self.strRadiationDamage)
                self.lstSummary.append("WARNING: " + self.strRadiationDamage)
            self.lstSummary.append("Merging files: " + " ".join([os.path.basename(i.path.value) for i in self.lstMerged]))
            if len(self.lstMerged) == 1:
                self.rewriteHeader(self.lstMerged[0].path.value, self.strMergedFile)
            else:
                self.__edPluginExecDataver = self.loadPlugin(self.__strControlledPluginDataver)
                xsd = XSDataInputDataver(inputCurve=self.lstMerged)
                #outputCurve=self.dataInput.mergedCurve,
                self.__edPluginExecDataver.setDataInput(xsd)
                self.__edPluginExecDataver.connectSUCCESS(self.doSuccessExecDataver)
                self.__edPluginExecDataver.connectFAILURE(self.doFailureExecDataver)
                self.__edPluginExecDataver.executeSynchronous()

            if (self.fConcentration == 0) and (self.strSubFile is not None):
                if (self.__class__.lastBuffer is not None) and (self.__class__.lastSample is not None):
                    self.__edPluginExecAutoSub = self.loadPlugin(self.__strControlledPluginAutoSub)
                    base = "_".join(os.path.basename(self.__class__.lastSample.path.value).split("_")[:-1])
                    suff = os.path.basename(self.strSubFile).split("_")[-1]
                    sub = os.path.join(os.path.dirname(self.strSubFile), base + "_" + suff)
                    xsd = XSDataInputAutoSub(sampleCurve=self.__class__.lastSample,
                                             buffers=[self.__class__.lastBuffer, self.dataInput.mergedCurve],
                                             subtractedCurve=XSDataFile(XSDataString(sub))
                                             )
                    self.__edPluginExecAutoSub.setDataInput(xsd)
                    self.__edPluginExecAutoSub.connectSUCCESS(self.doSuccessExecAutoSub)
                    self.__edPluginExecAutoSub.connectFAILURE(self.doFailureExecAutoSub)
                    self.__edPluginExecAutoSub.executeSynchronous()
                self.__class__.lastBuffer = self.dataInput.mergedCurve
                self.__class__.lastSample = None
            else:
                self.__class__.lastSample = self.dataInput.mergedCurve
예제 #10
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsSmartMergev1_1.process")

        xsdwf = XSDataInputWaitMultiFile(timeOut=XSDataTime(30),
                                        expectedSize=XSDataInteger(10000),
                                        expectedFile=[XSDataFile(i.path) for i in self.lstInput])
        self.__edPluginExecWaitFile.setDataInput(xsdwf)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWait)
        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWait)
        self.__edPluginExecWaitFile.executeSynchronous()
        if self.isFailure():
            return
        if len(self.lstInput) == 1:
            shutil.copyfile(self.lstInput[0].path.value, self.dataInput.mergedCurve.path.value)
        else:
            self.lstMerged = []
            if (self.absoluteFidelity is not None) or (self.relativeFidelity is not None):
                if self.absoluteFidelity is not None :
                    for idx, oneFile in enumerate(self.lstInput[1:]):
                        self.DEBUG("Calculating similarity of 0 and %s" % idx)
                        edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], oneFile])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                if (self.relativeFidelity is not None):
                    if (self.absoluteFidelity is  None):
                        self.DEBUG("Calculating similarity of 0 and 1")
                        edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], self.lstInput[1] ])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                    if (len(self.lstInput) > 2):
                        for idx, oneFile in enumerate(self.lstInput[2:]):
                            self.DEBUG("Calculating similarity of %s and %s" % (idx, idx + 1))
                            edPluginExecRelativeFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
                            xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[idx + 1], oneFile])
                            edPluginExecRelativeFidelity.setDataInput(xsd)
                            edPluginExecRelativeFidelity.connectFAILURE(self.doFailureExecDatcmp)
                            edPluginExecRelativeFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
                            edPluginExecRelativeFidelity.execute()
            self.synchronizePlugins()

            for idx, oneFile in enumerate(self.lstInput):
                if idx == 0:
                    self.lstMerged.append(oneFile)
                elif (self.absoluteFidelity is not None) and (self.relativeFidelity is not None):
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))
                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))

                    if (self.dictSimilarities[(0, idx)] >= self.absoluteFidelity) and (self.dictSimilarities[(idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.absoluteFidelity is not None) :
                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))

                    if (self.dictSimilarities[(0, idx)] >= self.absoluteFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.relativeFidelity is not None) :
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities]))

                    if (self.dictSimilarities[(idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                else:
                    self.lstMerged.append(oneFile)
            self.lstMerged.sort(cmp)
            if len(self.lstMerged) != len(self.lstInput):
                self.strRadiationDamage = "Radiation damage detected, merged %i curves" % len(self.lstMerged)
                self.WARNING(self.strRadiationDamage)
                self.lstSummary.append("WARNING: " + self.strRadiationDamage)
            self.lstSummary.append("Merging files: " + " ".join([os.path.basename(i.path.value) for i in self.lstMerged]))
            if len(self.lstMerged) == 1:
                shutil.copyfile(self.lstMerged[0].path.value, self.dataInput.mergedCurve.path.value)
            else:
                self.__edPluginExecDataver = self.loadPlugin(self.__strControlledPluginDataver)
                xsd = XSDataInputDataver(inputCurve=self.lstMerged)
                #outputCurve=self.dataInput.mergedCurve,
                self.__edPluginExecDataver.setDataInput(xsd)
                self.__edPluginExecDataver.connectSUCCESS(self.doSuccessExecDataver)
                self.__edPluginExecDataver.connectFAILURE(self.doFailureExecDataver)
                self.__edPluginExecDataver.executeSynchronous()

            if self.isFailure():
                return
            self.__edPluginExecAutoRg = self.loadPlugin(self.__strControlledPluginAutoRG)
            xsd = XSDataInputAutoRg(inputCurve=[self.dataInput.mergedCurve])
            self.__edPluginExecAutoRg.setDataInput(xsd)
            self.__edPluginExecAutoRg.connectSUCCESS(self.doSuccessExecAutoRg)
            self.__edPluginExecAutoRg.connectFAILURE(self.doFailureExecAutoRg)
            self.__edPluginExecAutoRg.executeSynchronous()
예제 #11
0
class EDPluginControlID11v1_0(EDPluginControl):
    """
    Plugin specific to ID11
    """
    __semaphore = threading.Semaphore()
    __dictParamID11XSD = {} #key=filename, value=(dictID11,strXSD


    def __init__(self):
        """
        """
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputID11)
        self.bTimedOut = False
        self.__dictID11 = {}
        self.__strControlledPluginWait = "EDPluginWaitMultiFile"
        self.__edPluginWaitMultipleFile = None
        self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
        self.__listProcessedFiles = []
        self.__strControlledPluginSPD = "EDPluginSPDCakev1_5"
        self.__xsDataInputSPDCake = None
        self.__strControlledPluginEDF = "EDPluginExportAsciiPowderv1_0"
        self.bCorrectMask = True


    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlID11v1_0.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getParameterFile(), "No parameter file!")


    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.preProcess")
        # Read the parameter file
        if self.getDataInput().getCorrectMask() is not None:
            self.bCorrectMask = bool(self.getDataInput().getCorrectMask().getValue())

        strPathToParameterFile = self.getDataInput().getParameterFile().getPath().getValue()

        if os.path.exists(strPathToParameterFile):
            EDPluginControlID11v1_0.__semaphore.acquire()
            if strPathToParameterFile in EDPluginControlID11v1_0.__dictParamID11XSD:
                self.__dictID11, strInputSPDCake = EDPluginControlID11v1_0.__dictParamID11XSD[strPathToParameterFile]
                self.__xsDataInputSPDCake = XSDataInputSPDCake.parseString(strInputSPDCake)
            else:
                self.parseParameterFiles(strPathToParameterFile)
                self.__xsDataInputSPDCake = self.populateXSDataInputSPDCake()
                EDPluginControlID11v1_0.__dictParamID11XSD[strPathToParameterFile] = (self.__dictID11, self.__xsDataInputSPDCake.marshal())
            EDPluginControlID11v1_0.__semaphore.release()
            # Load the execution plugin
            self.synchronizeOn()
            self.__edPluginWaitMultipleFile = self.loadPlugin(self.__strControlledPluginWait)
            self.synchronizeOff()
#            self.__edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
            # Paths to the data files
            self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
            for xsDataFile in self.getDataInput().getDataFile():
                self.__xsDataInputWaitMultipleFile.addExpectedFile(xsDataFile)
            # we are expecting unsigned int 
            self.__xsDataInputWaitMultipleFile.setExpectedSize(XSDataInteger(512 + 2 * int(self.__dictID11["DIM1_DATA"]) * int(self.__dictID11["DIM2_DATA"])))
            self.__edPluginWaitMultipleFile.setDataInput(self.__xsDataInputWaitMultipleFile)

        else:
            self.ERROR("Path to parameter file does not exist: %s" % strPathToParameterFile)
            self.setFailure()
        xsdOutputDir = self.getDataInput().getOutputdir()
        if xsdOutputDir is not None:
            self.__xsDataInputSPDCake.setOutputDir(xsdOutputDir)
            self.__dictID11["output_dir"] = xsdOutputDir.getPath().getValue()


    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlID11v1_0.process")
        self.__edPluginWaitMultipleFile.connectSUCCESS(self.doSuccessExecWaitMultipleFile)
        self.__edPluginWaitMultipleFile.connectFAILURE(self.doFailureExecWaitMultipleFile)
        self.__edPluginWaitMultipleFile.executeSynchronous()

        # SPD launch
        if self.bTimedOut:
            self.ERROR("EDPluginControlID11v1_0.process: Wait Multi File ended in Timeout")
            self.setFailure()
            return

        for onefile in self.getDataInput().getDataFile():
            self.synchronizeOn()
            edPluginSPD = self.loadPlugin(self.__strControlledPluginSPD)
            self.__xsDataInputSPDCake.setInputFile(onefile)
            edPluginSPD.setDataInput(self.__xsDataInputSPDCake)
            edPluginSPD.connectSUCCESS(self.doSuccessExecSPDCake)
            edPluginSPD.connectFAILURE(self.doFailureExecSPDCake)
            edPluginSPD.execute()
            self.synchronizeOff()



    def postProcess(self, _edObject=None):
        EDPluginControl.postProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.postProcess")
        #Wait for all plugins to finish
        self.synchronizePlugins()
        # Create some output data
        xsDataResult = XSDataResultID11()
        xsDataResult.setOutputFile(self.__listProcessedFiles)
        self.setDataOutput(xsDataResult)


    def populateXSDataInputSPDCake(self, _inputDict=None):
        self.DEBUG("EDPluginControlID11v1_0.populateXSDataInputSPDCake")
        xsDataInputSPDCake = XSDataInputSPDCake()
        if isinstance(_inputDict, dict):
            self.__dictID11 = _inputDict

    # Angle of tilt
        if "ANGLE OF TILT" in self.__dictID11:
            xsDataTilt = XSDataAngle()
            xsDataTilt.setValue(float(self.__dictID11["ANGLE OF TILT"]))
            xsDataTilt.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setAngleOfTilt(xsDataTilt)

        if "TILT ROTATION" in self.__dictID11:
            xsDataTiltRot = XSDataAngle()
            xsDataTiltRot.setValue(float(self.__dictID11["TILT ROTATION"]))
            xsDataTiltRot.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setTiltRotation(xsDataTiltRot)

        if "X-PIXEL SIZE" in self.__dictID11:
            xsDataXPixel = XSDataLength()
            xsDataXPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"]))
            xsDataXPixel.setUnit(XSDataString("micron"))
            xsDataInputSPDCake.setPixelSizeX(xsDataXPixel)

        if "Y-PIXEL SIZE" in self.__dictID11:
            xsDataYPixel = XSDataLength()
            xsDataYPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"]))
            xsDataYPixel.setUnit(XSDataString("micron"))
            xsDataInputSPDCake.setPixelSizeY(xsDataYPixel)

        if "DISTANCE" in self.__dictID11:
            xsDataDistance = XSDataLength()
            xsDataDistance.setValue(float(self.__dictID11["DISTANCE"]))
            xsDataDistance.setUnit(XSDataString("mm"))
            xsDataInputSPDCake.setSampleToDetectorDistance(xsDataDistance)

        if "WAVELENGTH" in self.__dictID11:
            xsDataWaweLength = XSDataWavelength()
            xsDataWaweLength.setValue(float(self.__dictID11["WAVELENGTH"]))
            xsDataWaweLength.setUnit(XSDataString("A"))
            xsDataInputSPDCake.setWavelength(xsDataWaweLength)

        if "DIM1_DATA" in self.__dictID11:
            xsDataBufferSizeX = XSDataInteger(int(self.__dictID11["DIM1_DATA"]))
            xsDataInputSPDCake.setBufferSizeX(xsDataBufferSizeX)

        if "DIM2_DATA" in self.__dictID11:
            xsDataBufferSizeY = XSDataInteger(int(self.__dictID11["DIM2_DATA"]))
            xsDataInputSPDCake.setBufferSizeY(xsDataBufferSizeY)

    # Dark current
        if ("DARK CURRENT" in self.__dictID11) and (self.__dictID11["DARK CURRENT"] == "YES") :
            if  ("DC FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["DC FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["DC FILE"]))
                xsDataInputSPDCake.setDarkCurrentImageFile(xsDataFile)
            else:
                self.warning("Asked for DC Current correction but no DC current file")

        if ("FLAT-FIELD" in self.__dictID11) and (self.__dictID11["FLAT-FIELD"] == "YES"):
            if  ("FF FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["FF FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["FF FILE"]))
                xsDataInputSPDCake.setFlatFieldImageFile(xsDataFile)
            else:
                self.warning("Asked for FLAT-FIELD correction but no FLAT-FIELD file")

        if ("MASK FILE" in self.__dictID11) and (self.__dictID11["USE MASK"] == "YES") :
            if  ("MASK FILE" in self.__dictID11) and os.path.isfile(self.__dictID11["MASK FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["MASK FILE"]))
                xsDataInputSPDCake.setMaskFile(xsDataFile)
            else:
                self.warning("Asked for DC Current correction but no DC current file")


        if ("FF SCALE" in self.__dictID11) and (self.__dictID11["FF SCALE"] == "YES"):
            if ("FF MULTIPLIER" in self.__dictID11):
                try:
                    value = float(self.__dictID11["FF MULTIPLIER"])
                except Exception:
                    self.warning("Asked for FF SCALE correction but FF MULTIPLIER provided (%s) in not float !" % (self.__dictID11["FF MULTIPLIER"]))
                else:
                     xsDataInputSPDCake.setIntensityScaleFactor(XSDataDouble(1 / value))
            else:
                self.warning("Asked for FF SCALE correction but no FF MULTIPLIER provided")


        if ("SPATIAL DIS." in self.__dictID11) and (self.__dictID11["SPATIAL DIS."] == "YES"):
            if  ("SD FILE" in self.__dictID11) and  os.path.isfile(self.__dictID11["SD FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["SD FILE"]))
                xsDataInputSPDCake.setSpatialDistortionFile(xsDataFile)
            else :
                self.warning("Asked for SPATIAL DISTORSION correction but no SPATIAL DISTORSION file")

        if "START AZIMUTH" in self.__dictID11:
            xsDataAzimuthStart = XSDataAngle()
            xsDataAzimuthStart.setValue(float(self.__dictID11["START AZIMUTH"]))
            xsDataAzimuthStart.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStartAzimuth(xsDataAzimuthStart)

        if "END AZIMUTH" in self.__dictID11:
            xsDataAzimuthStop = XSDataAngle()
            xsDataAzimuthStop.setValue(float(self.__dictID11["END AZIMUTH"]))
            xsDataAzimuthStop.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStopAzimuth(xsDataAzimuthStop)

        if "AZIMUTH BINS" in self.__dictID11:
            xsDataAzimuthStep = XSDataAngle()
            xsDataAzimuthStep.setValue((float(self.__dictID11["END AZIMUTH"]) - float(self.__dictID11["START AZIMUTH"])) /
                                       float(self.__dictID11["AZIMUTH BINS"]))
            xsDataAzimuthStep.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStepAzimuth(xsDataAzimuthStep)

        if "INNER RADIUS" in self.__dictID11:
            xsDataInnerRadius = XSDataDouble()
            xsDataInnerRadius.setValue(float(self.__dictID11["INNER RADIUS"]))
            xsDataInputSPDCake.setInnerRadius(xsDataInnerRadius)

        if "OUTER RADIUS" in self.__dictID11:
            xsDataOuterRadius = XSDataDouble()
            xsDataOuterRadius.setValue(float(self.__dictID11["OUTER RADIUS"]))
            xsDataInputSPDCake.setOuterRadius(xsDataOuterRadius)

        if "X-BEAM CENTRE" in self.__dictID11:
            xsDataXBeamCentre = XSDataDouble()
            xsDataXBeamCentre.setValue(float(self.__dictID11["X-BEAM CENTRE"]))
            xsDataInputSPDCake.setBeamCentreInPixelsX(xsDataXBeamCentre)

        if "Y-BEAM CENTRE" in self.__dictID11:
            xsDataYBeamCentre = XSDataDouble()
            xsDataYBeamCentre.setValue(float(self.__dictID11["Y-BEAM CENTRE"]))
            xsDataInputSPDCake.setBeamCentreInPixelsY(xsDataYBeamCentre)

#        if "saving_format" in self.__dictID11:
#            xsSaveFormat = XSDataString()
#            if self.__dictID11["saving_format"] == "SPREAD SHEET":
#                xsSaveFormat.setValue("spr")
#            elif self.__dictID11["saving_format"] == "CIF":
#                xsSaveFormat.setValue("cif")
#            elif self.__dictID11["saving_format"] == "CHIPLOT":
#                xsSaveFormat.setValue("chi")
#            else:
#                xsSaveFormat.setValue("edf")
#            xsDataInputSPDCake.setOutputFileType(xsSaveFormat)

        if "output_dir" in self.__dictID11:
            xsOutputDir = XSDataFile()
            xsOutputDir.setPath(XSDataString(self.__dictID11["output_dir"]))
            xsDataInputSPDCake.setOutputDir(xsOutputDir)

        #Default options to SPD
        xsDataInputSPDCake.setOutputFileType(XSDataString("azim"))
        xsDataInputSPDCake.setDeleteCorImg(XSDataBoolean(not self.isVerboseDebug()))
        xsDataInputSPDCake.setCorrectTiltMask(XSDataBoolean(self.bCorrectMask))
        return xsDataInputSPDCake


    def parseParameterFiles(self, _strPath):
        """
        parses Configuration file
        """
        self.DEBUG("EDPluginControlID11v1_0.parseParameterFiles")
        self.__dictID11 = {}
        dictSub = {"${TEST_DATA_IMAGES_HOME}": EDUtilsTest.getTestsDataImagesHome()}
        for linefile in EDUtilsFile.readFileAndParseVariables(_strPath, dictSub).split("\n"):
            strLineData = linefile.strip()
            #discard comment lines 
            if not strLineData.startswith('#') :
                #  discard end line carriage return
                splited = strLineData.split("=", 1)
                if len(splited) == 2:
                    self.__dictID11[splited[0].strip()] = splited[1].strip()
        return self.__dictID11


    def doSuccessExecWaitMultipleFile(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doSuccessExecWaitMultipleFile")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlID11v1_0.doSuccessExecWaitMultipleFile")
        xsDataResult = self.__edPluginWaitMultipleFile.getDataOutput()
        self.bTimedOut = xsDataResult.getTimedOut().getValue()
#        self.screen("got TimeOut=%s Type is %s" % (self.bTimedOut, type(self.bTimedOut)))


    def doFailureExecWaitMultipleFile(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doFailureExecWaitMultipleFile")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlID11v1_0.doFailureExecWaitMultipleFile")
        self.setFailure()


    def doSuccessExecSPDCake(self, _edPlugin=None):
        self.synchronizeOn()
        self.DEBUG("EDPluginControlID11v1_0.doSuccessExecSPDCake")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlID11v1_0.doSuccessExecSPDCake")

        xsdOut = _edPlugin.getDataOutput()

        xsdAzimFile = xsdOut.getCakedFile()
        xsdIn = XSDataInput1DPowderEDF()
        xsdIn.setEdfFile(xsdAzimFile)

        strInputFile = os.path.basename(_edPlugin.getDataInput().getInputFile().getPath().getValue())
        xsdFile = XSDataFile()
        xsdFile.setPath(XSDataString(
               os.path.join(self.__dictID11["output_dir"], os.path.splitext(strInputFile)[0] + "." + self.__dictID11["output_extn"])
                                     ))
        xsdIn.setOutputFile(xsdFile)

        xsdIn.setEdfFile(xsdOut.getCakedFile())

        xsdIn.setOutputFormat(XSDataString(self.__dictID11["output_extn"]))
        xsdIn.setNumberOfBins(XSDataInteger(int(self.__dictID11["RADIAL BINS"])))

        # EDF Launch
        edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
        edPluginEDF.setDataInput(xsdIn)
        edPluginEDF.connectSUCCESS(self.doSuccessExec1DPowderEDF)
        edPluginEDF.connectFAILURE(self.doFailureExec1DPowderEDF)
        edPluginEDF.execute()
        self.synchronizeOff()


    def doFailureExecSPDCake(self, _edPlugin=None):
        self.synchronizeOn()
        self.DEBUG("EDPluginControlID11v1_0.doFailureExecSPDCake")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlID11v1_0.doFailureExecSPDCake")
        xsd = _edPlugin.getDataInput()
        if xsd is not None:
            filename = xsd.getInputFile().getPath().getValue()
            self.ERROR("SPD ended in error with file %s" % filename)
        else:
            self.ERROR("SPD ended in error with no input data (!!!!)")
        self.setFailure()
        self.synchronizeOff()


    def doSuccessExec1DPowderEDF(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doSuccessExec1DPowderEDF")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlID11v1_0.doSuccessExec1DPowderEDF")
        self.synchronizeOn()
        self.__listProcessedFiles.append(_edPlugin.getDataOutput().getOutputFile())
        self.synchronizeOff()


    def doFailureExec1DPowderEDF(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doFailureExec1DPowderEDF")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlID11v1_0.doFailureExec1DPowderEDF")
        self.setFailure()
예제 #12
0
class EDPluginControlID11v1_0(EDPluginControl):
    """
    Plugin specific to ID11
    """
    __semaphore = threading.Semaphore()
    __dictParamID11XSD = {}  #key=filename, value=(dictID11,strXSD

    def __init__(self):
        """
        """
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputID11)
        self.bTimedOut = False
        self.__dictID11 = {}
        self.__strControlledPluginWait = "EDPluginWaitMultiFile"
        self.__edPluginWaitMultipleFile = None
        self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
        self.__listProcessedFiles = []
        self.__strControlledPluginSPD = "EDPluginSPDCakev1_5"
        self.__xsDataInputSPDCake = None
        self.__strControlledPluginEDF = "EDPluginExportAsciiPowderv1_0"
        self.bCorrectMask = True

    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlID11v1_0.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(),
                                      "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getParameterFile(),
                                      "No parameter file!")

    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.preProcess")
        # Read the parameter file
        if self.getDataInput().getCorrectMask() is not None:
            self.bCorrectMask = bool(
                self.getDataInput().getCorrectMask().getValue())

        strPathToParameterFile = self.getDataInput().getParameterFile(
        ).getPath().getValue()

        if os.path.exists(strPathToParameterFile):
            EDPluginControlID11v1_0.__semaphore.acquire()
            if strPathToParameterFile in EDPluginControlID11v1_0.__dictParamID11XSD:
                self.__dictID11, strInputSPDCake = EDPluginControlID11v1_0.__dictParamID11XSD[
                    strPathToParameterFile]
                self.__xsDataInputSPDCake = XSDataInputSPDCake.parseString(
                    strInputSPDCake)
            else:
                self.parseParameterFiles(strPathToParameterFile)
                self.__xsDataInputSPDCake = self.populateXSDataInputSPDCake()
                EDPluginControlID11v1_0.__dictParamID11XSD[
                    strPathToParameterFile] = (
                        self.__dictID11, self.__xsDataInputSPDCake.marshal())
            EDPluginControlID11v1_0.__semaphore.release()
            # Load the execution plugin
            self.synchronizeOn()
            self.__edPluginWaitMultipleFile = self.loadPlugin(
                self.__strControlledPluginWait)
            self.synchronizeOff()
            #            self.__edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
            # Paths to the data files
            self.__xsDataInputWaitMultipleFile = XSDataInputWaitMultiFile()
            for xsDataFile in self.getDataInput().getDataFile():
                self.__xsDataInputWaitMultipleFile.addExpectedFile(xsDataFile)
            # we are expecting unsigned int
            self.__xsDataInputWaitMultipleFile.setExpectedSize(
                XSDataInteger(512 + 2 * int(self.__dictID11["DIM1_DATA"]) *
                              int(self.__dictID11["DIM2_DATA"])))
            self.__edPluginWaitMultipleFile.setDataInput(
                self.__xsDataInputWaitMultipleFile)

        else:
            self.ERROR("Path to parameter file does not exist: %s" %
                       strPathToParameterFile)
            self.setFailure()
        xsdOutputDir = self.getDataInput().getOutputdir()
        if xsdOutputDir is not None:
            self.__xsDataInputSPDCake.setOutputDir(xsdOutputDir)
            self.__dictID11["output_dir"] = xsdOutputDir.getPath().getValue()

    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlID11v1_0.process")
        self.__edPluginWaitMultipleFile.connectSUCCESS(
            self.doSuccessExecWaitMultipleFile)
        self.__edPluginWaitMultipleFile.connectFAILURE(
            self.doFailureExecWaitMultipleFile)
        self.__edPluginWaitMultipleFile.executeSynchronous()

        # SPD launch
        if self.bTimedOut:
            self.ERROR(
                "EDPluginControlID11v1_0.process: Wait Multi File ended in Timeout"
            )
            self.setFailure()
            return

        for onefile in self.getDataInput().getDataFile():
            self.synchronizeOn()
            edPluginSPD = self.loadPlugin(self.__strControlledPluginSPD)
            self.__xsDataInputSPDCake.setInputFile(onefile)
            edPluginSPD.setDataInput(self.__xsDataInputSPDCake)
            edPluginSPD.connectSUCCESS(self.doSuccessExecSPDCake)
            edPluginSPD.connectFAILURE(self.doFailureExecSPDCake)
            edPluginSPD.execute()
            self.synchronizeOff()

    def postProcess(self, _edObject=None):
        EDPluginControl.postProcess(self)
        self.DEBUG("EDPluginControlID11v1_0.postProcess")
        #Wait for all plugins to finish
        self.synchronizePlugins()
        # Create some output data
        xsDataResult = XSDataResultID11()
        xsDataResult.setOutputFile(self.__listProcessedFiles)
        self.setDataOutput(xsDataResult)

    def populateXSDataInputSPDCake(self, _inputDict=None):
        self.DEBUG("EDPluginControlID11v1_0.populateXSDataInputSPDCake")
        xsDataInputSPDCake = XSDataInputSPDCake()
        if isinstance(_inputDict, dict):
            self.__dictID11 = _inputDict

    # Angle of tilt
        if "ANGLE OF TILT" in self.__dictID11:
            xsDataTilt = XSDataAngle()
            xsDataTilt.setValue(float(self.__dictID11["ANGLE OF TILT"]))
            xsDataTilt.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setAngleOfTilt(xsDataTilt)

        if "TILT ROTATION" in self.__dictID11:
            xsDataTiltRot = XSDataAngle()
            xsDataTiltRot.setValue(float(self.__dictID11["TILT ROTATION"]))
            xsDataTiltRot.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setTiltRotation(xsDataTiltRot)

        if "X-PIXEL SIZE" in self.__dictID11:
            xsDataXPixel = XSDataLength()
            xsDataXPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"]))
            xsDataXPixel.setUnit(XSDataString("micron"))
            xsDataInputSPDCake.setPixelSizeX(xsDataXPixel)

        if "Y-PIXEL SIZE" in self.__dictID11:
            xsDataYPixel = XSDataLength()
            xsDataYPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"]))
            xsDataYPixel.setUnit(XSDataString("micron"))
            xsDataInputSPDCake.setPixelSizeY(xsDataYPixel)

        if "DISTANCE" in self.__dictID11:
            xsDataDistance = XSDataLength()
            xsDataDistance.setValue(float(self.__dictID11["DISTANCE"]))
            xsDataDistance.setUnit(XSDataString("mm"))
            xsDataInputSPDCake.setSampleToDetectorDistance(xsDataDistance)

        if "WAVELENGTH" in self.__dictID11:
            xsDataWaweLength = XSDataWavelength()
            xsDataWaweLength.setValue(float(self.__dictID11["WAVELENGTH"]))
            xsDataWaweLength.setUnit(XSDataString("A"))
            xsDataInputSPDCake.setWavelength(xsDataWaweLength)

        if "DIM1_DATA" in self.__dictID11:
            xsDataBufferSizeX = XSDataInteger(int(
                self.__dictID11["DIM1_DATA"]))
            xsDataInputSPDCake.setBufferSizeX(xsDataBufferSizeX)

        if "DIM2_DATA" in self.__dictID11:
            xsDataBufferSizeY = XSDataInteger(int(
                self.__dictID11["DIM2_DATA"]))
            xsDataInputSPDCake.setBufferSizeY(xsDataBufferSizeY)

    # Dark current
        if ("DARK CURRENT"
                in self.__dictID11) and (self.__dictID11["DARK CURRENT"]
                                         == "YES"):
            if ("DC FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["DC FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["DC FILE"]))
                xsDataInputSPDCake.setDarkCurrentImageFile(xsDataFile)
            else:
                self.warning(
                    "Asked for DC Current correction but no DC current file")

        if ("FLAT-FIELD" in self.__dictID11) and (self.__dictID11["FLAT-FIELD"]
                                                  == "YES"):
            if ("FF FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["FF FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["FF FILE"]))
                xsDataInputSPDCake.setFlatFieldImageFile(xsDataFile)
            else:
                self.warning(
                    "Asked for FLAT-FIELD correction but no FLAT-FIELD file")

        if ("MASK FILE" in self.__dictID11) and (self.__dictID11["USE MASK"]
                                                 == "YES"):
            if ("MASK FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["MASK FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["MASK FILE"]))
                xsDataInputSPDCake.setMaskFile(xsDataFile)
            else:
                self.warning(
                    "Asked for DC Current correction but no DC current file")

        if ("FF SCALE" in self.__dictID11) and (self.__dictID11["FF SCALE"]
                                                == "YES"):
            if ("FF MULTIPLIER" in self.__dictID11):
                try:
                    value = float(self.__dictID11["FF MULTIPLIER"])
                except Exception:
                    self.warning(
                        "Asked for FF SCALE correction but FF MULTIPLIER provided (%s) in not float !"
                        % (self.__dictID11["FF MULTIPLIER"]))
                else:
                    xsDataInputSPDCake.setIntensityScaleFactor(
                        XSDataDouble(1 / value))
            else:
                self.warning(
                    "Asked for FF SCALE correction but no FF MULTIPLIER provided"
                )

        if ("SPATIAL DIS."
                in self.__dictID11) and (self.__dictID11["SPATIAL DIS."]
                                         == "YES"):
            if ("SD FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["SD FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["SD FILE"]))
                xsDataInputSPDCake.setSpatialDistortionFile(xsDataFile)
            else:
                self.warning(
                    "Asked for SPATIAL DISTORSION correction but no SPATIAL DISTORSION file"
                )

        if "START AZIMUTH" in self.__dictID11:
            xsDataAzimuthStart = XSDataAngle()
            xsDataAzimuthStart.setValue(float(
                self.__dictID11["START AZIMUTH"]))
            xsDataAzimuthStart.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStartAzimuth(xsDataAzimuthStart)

        if "END AZIMUTH" in self.__dictID11:
            xsDataAzimuthStop = XSDataAngle()
            xsDataAzimuthStop.setValue(float(self.__dictID11["END AZIMUTH"]))
            xsDataAzimuthStop.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStopAzimuth(xsDataAzimuthStop)

        if "AZIMUTH BINS" in self.__dictID11:
            xsDataAzimuthStep = XSDataAngle()
            xsDataAzimuthStep.setValue(
                (float(self.__dictID11["END AZIMUTH"]) -
                 float(self.__dictID11["START AZIMUTH"])) /
                float(self.__dictID11["AZIMUTH BINS"]))
            xsDataAzimuthStep.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStepAzimuth(xsDataAzimuthStep)

        if "INNER RADIUS" in self.__dictID11:
            xsDataInnerRadius = XSDataDouble()
            xsDataInnerRadius.setValue(float(self.__dictID11["INNER RADIUS"]))
            xsDataInputSPDCake.setInnerRadius(xsDataInnerRadius)

        if "OUTER RADIUS" in self.__dictID11:
            xsDataOuterRadius = XSDataDouble()
            xsDataOuterRadius.setValue(float(self.__dictID11["OUTER RADIUS"]))
            xsDataInputSPDCake.setOuterRadius(xsDataOuterRadius)

        if "X-BEAM CENTRE" in self.__dictID11:
            xsDataXBeamCentre = XSDataDouble()
            xsDataXBeamCentre.setValue(float(self.__dictID11["X-BEAM CENTRE"]))
            xsDataInputSPDCake.setBeamCentreInPixelsX(xsDataXBeamCentre)

        if "Y-BEAM CENTRE" in self.__dictID11:
            xsDataYBeamCentre = XSDataDouble()
            xsDataYBeamCentre.setValue(float(self.__dictID11["Y-BEAM CENTRE"]))
            xsDataInputSPDCake.setBeamCentreInPixelsY(xsDataYBeamCentre)

#        if "saving_format" in self.__dictID11:
#            xsSaveFormat = XSDataString()
#            if self.__dictID11["saving_format"] == "SPREAD SHEET":
#                xsSaveFormat.setValue("spr")
#            elif self.__dictID11["saving_format"] == "CIF":
#                xsSaveFormat.setValue("cif")
#            elif self.__dictID11["saving_format"] == "CHIPLOT":
#                xsSaveFormat.setValue("chi")
#            else:
#                xsSaveFormat.setValue("edf")
#            xsDataInputSPDCake.setOutputFileType(xsSaveFormat)

        if "output_dir" in self.__dictID11:
            xsOutputDir = XSDataFile()
            xsOutputDir.setPath(XSDataString(self.__dictID11["output_dir"]))
            xsDataInputSPDCake.setOutputDir(xsOutputDir)

        #Default options to SPD
        xsDataInputSPDCake.setOutputFileType(XSDataString("azim"))
        xsDataInputSPDCake.setDeleteCorImg(
            XSDataBoolean(not self.isVerboseDebug()))
        xsDataInputSPDCake.setCorrectTiltMask(XSDataBoolean(self.bCorrectMask))
        return xsDataInputSPDCake

    def parseParameterFiles(self, _strPath):
        """
        parses Configuration file
        """
        self.DEBUG("EDPluginControlID11v1_0.parseParameterFiles")
        self.__dictID11 = {}
        dictSub = {
            "${TEST_DATA_IMAGES_HOME}": EDUtilsTest.getTestsDataImagesHome()
        }
        for linefile in EDUtilsFile.readFileAndParseVariables(
                _strPath, dictSub).split("\n"):
            strLineData = linefile.strip()
            #discard comment lines
            if not strLineData.startswith('#'):
                #  discard end line carriage return
                splited = strLineData.split("=", 1)
                if len(splited) == 2:
                    self.__dictID11[splited[0].strip()] = splited[1].strip()
        return self.__dictID11

    def doSuccessExecWaitMultipleFile(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doSuccessExecWaitMultipleFile")
        self.retrieveSuccessMessages(
            _edPlugin, "EDPluginControlID11v1_0.doSuccessExecWaitMultipleFile")
        xsDataResult = self.__edPluginWaitMultipleFile.getDataOutput()
        self.bTimedOut = xsDataResult.getTimedOut().getValue()
#        self.screen("got TimeOut=%s Type is %s" % (self.bTimedOut, type(self.bTimedOut)))

    def doFailureExecWaitMultipleFile(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doFailureExecWaitMultipleFile")
        self.retrieveFailureMessages(
            _edPlugin, "EDPluginControlID11v1_0.doFailureExecWaitMultipleFile")
        self.setFailure()

    def doSuccessExecSPDCake(self, _edPlugin=None):
        self.synchronizeOn()
        self.DEBUG("EDPluginControlID11v1_0.doSuccessExecSPDCake")
        self.retrieveSuccessMessages(
            _edPlugin, "EDPluginControlID11v1_0.doSuccessExecSPDCake")

        xsdOut = _edPlugin.getDataOutput()

        xsdAzimFile = xsdOut.getCakedFile()
        xsdIn = XSDataInput1DPowderEDF()
        xsdIn.setEdfFile(xsdAzimFile)

        strInputFile = os.path.basename(
            _edPlugin.getDataInput().getInputFile().getPath().getValue())
        xsdFile = XSDataFile()
        xsdFile.setPath(
            XSDataString(
                os.path.join(
                    self.__dictID11["output_dir"],
                    os.path.splitext(strInputFile)[0] + "." +
                    self.__dictID11["output_extn"])))
        xsdIn.setOutputFile(xsdFile)

        xsdIn.setEdfFile(xsdOut.getCakedFile())

        xsdIn.setOutputFormat(XSDataString(self.__dictID11["output_extn"]))
        xsdIn.setNumberOfBins(
            XSDataInteger(int(self.__dictID11["RADIAL BINS"])))

        # EDF Launch
        edPluginEDF = self.loadPlugin(self.__strControlledPluginEDF)
        edPluginEDF.setDataInput(xsdIn)
        edPluginEDF.connectSUCCESS(self.doSuccessExec1DPowderEDF)
        edPluginEDF.connectFAILURE(self.doFailureExec1DPowderEDF)
        edPluginEDF.execute()
        self.synchronizeOff()

    def doFailureExecSPDCake(self, _edPlugin=None):
        self.synchronizeOn()
        self.DEBUG("EDPluginControlID11v1_0.doFailureExecSPDCake")
        self.retrieveFailureMessages(
            _edPlugin, "EDPluginControlID11v1_0.doFailureExecSPDCake")
        xsd = _edPlugin.getDataInput()
        if xsd is not None:
            filename = xsd.getInputFile().getPath().getValue()
            self.ERROR("SPD ended in error with file %s" % filename)
        else:
            self.ERROR("SPD ended in error with no input data (!!!!)")
        self.setFailure()
        self.synchronizeOff()

    def doSuccessExec1DPowderEDF(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doSuccessExec1DPowderEDF")
        self.retrieveSuccessMessages(
            _edPlugin, "EDPluginControlID11v1_0.doSuccessExec1DPowderEDF")
        self.synchronizeOn()
        self.__listProcessedFiles.append(
            _edPlugin.getDataOutput().getOutputFile())
        self.synchronizeOff()

    def doFailureExec1DPowderEDF(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID11v1_0.doFailureExec1DPowderEDF")
        self.retrieveFailureMessages(
            _edPlugin, "EDPluginControlID11v1_0.doFailureExec1DPowderEDF")
        self.setFailure()
예제 #13
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsSmartMergev1_7.process")

        xsdwf = XSDataInputWaitMultiFile(
            timeOut=XSDataTime(30),
            expectedSize=XSDataInteger(self.minimumCurveFileSize),
            expectedFile=[XSDataFile(i.path) for i in self.lstInput])
        self.__edPluginExecWaitFile.setDataInput(xsdwf)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWait)
        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWait)
        self.__edPluginExecWaitFile.executeSynchronous()
        if self.isFailure():
            return
        if len(self.lstInput) == 1:
            inp = self.lstInput[0].path.value
            dst = self.dataInput.mergedCurve.path.value
            if not os.path.isdir(os.path.dirname(dst)):
                self.error("Output directory for %s does not exist" % dst)
                os.makedirs(os.path.dirname(dst))
            if not os.path.exists(inp):
                self.warning("Input %s does not (yet?) exist" % inp)
                time.sleep(1.0)
            shutil.copyfile(inp, dst)
            self.addExecutiveSummaryLine(
                "Got only one frame ... nothing to merge !!!")
        else:
            self.lstMerged = []

            if (self.absoluteFidelity is not None) or (self.relativeFidelity
                                                       is not None):
                if self.absoluteFidelity is not None:
                    for idx, oneFile in enumerate(self.lstInput[1:]):
                        self.DEBUG("Calculating similarity of 0 and %s" % idx)
                        self.datcmp(self.lstInput[0], oneFile)
#                         edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
#                         xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], oneFile])
#                         edPluginExecAbsoluteFidelity.setDataInput(xsd)
#                         edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp)
#                         edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
#                         edPluginExecAbsoluteFidelity.execute()
                if (self.relativeFidelity is not None):
                    if (self.absoluteFidelity is None):
                        self.DEBUG("Calculating similarity of 0 and 1")
                        self.datcmp(self.lstInput[0], self.lstInput[1])
#                         edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
#                         xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], self.lstInput[1] ])
#                         edPluginExecAbsoluteFidelity.setDataInput(xsd)
#                         edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp)
#                         edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
#                         edPluginExecAbsoluteFidelity.execute()
                    if (len(self.lstInput) > 2):
                        for idx, oneFile in enumerate(self.lstInput[2:]):
                            self.DEBUG("Calculating similarity of %s and %s" %
                                       (idx, idx + 1))
                            self.datcmp(self.lstInput[idx + 1], oneFile)
#                             edPluginExecRelativeFidelity = self.loadPlugin(self.__strControlledPluginDatcmp)
#                             xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[idx + 1], oneFile])
#                             edPluginExecRelativeFidelity.setDataInput(xsd)
#                             edPluginExecRelativeFidelity.connectFAILURE(self.doFailureExecDatcmp)
#                             edPluginExecRelativeFidelity.connectSUCCESS(self.doSuccessExecDatcmp)
#                             edPluginExecRelativeFidelity.execute()
            self.synchronizePlugins()

            for idx, oneFile in enumerate(self.lstInput):
                if idx == 0:
                    self.lstMerged.append(oneFile)
                elif (self.absoluteFidelity
                      is not None) and (self.relativeFidelity is not None):
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (self.dictSimilarities[(0, idx)] >=
                            self.absoluteFidelity) and (self.dictSimilarities[
                                (idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)

                elif (self.absoluteFidelity is not None):
                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (self.dictSimilarities[(0, idx)] >=
                            self.absoluteFidelity):
                        self.lstMerged.append(oneFile)

                elif (self.relativeFidelity is not None):
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (self.dictSimilarities[(idx - 1, idx)] >=
                            self.relativeFidelity):
                        self.lstMerged.append(oneFile)

                else:
                    self.lstMerged.append(oneFile)
            self.lstMerged.sort(cmp)
            if len(self.lstMerged) != len(self.lstInput):
                self.strRadiationDamage = "Radiation damage detected, merged %i curves" % len(
                    self.lstMerged)
                self.WARNING(self.strRadiationDamage)
                self.addExecutiveSummaryLine("WARNING: " +
                                             self.strRadiationDamage)
            self.addExecutiveSummaryLine("Merging files: " + " ".join(
                [os.path.basename(i.path.value) for i in self.lstMerged]))
            if len(self.lstMerged) == 1:
                self.rewriteHeader(self.lstMerged[0].path.value,
                                   self.strMergedFile)
            else:
                self.__edPluginExecDataver = self.loadPlugin(
                    self.__strControlledPluginDataver)
                xsd = XSDataInputDataver(inputCurve=self.lstMerged)
                # outputCurve=self.dataInput.mergedCurve,
                self.__edPluginExecDataver.setDataInput(xsd)
                self.__edPluginExecDataver.connectSUCCESS(
                    self.doSuccessExecDataver)
                self.__edPluginExecDataver.connectFAILURE(
                    self.doFailureExecDataver)
                self.__edPluginExecDataver.executeSynchronous()

        if (self.fConcentration == 0) and (self.strSubFile is not None):
            if (self.__class__.lastBuffer
                    is not None) and (self.__class__.lastSample is not None):
                self.__edPluginExecAutoSub = self.loadPlugin(
                    self.__strControlledPluginAutoSub)
                base = "_".join(
                    os.path.basename(
                        self.__class__.lastSample.path.value).split("_")[:-1])
                suff = os.path.basename(self.strSubFile).split("_")[-1]
                sub = os.path.join(os.path.dirname(self.strSubFile),
                                   base + "_" + suff)
                self.xsdSubtractedCurve = XSDataFile(XSDataString(sub))
                #self.curves.append(xsdSubtractedCurve)
                self.__edPluginExecAutoSub.dataInput = XSDataInputAutoSub(
                    sampleCurve=self.__class__.lastSample,
                    buffers=[
                        self.__class__.lastBuffer, self.dataInput.mergedCurve
                    ],
                    subtractedCurve=self.xsdSubtractedCurve)
                self.__edPluginExecAutoSub.connectSUCCESS(
                    self.doSuccessExecAutoSub)
                self.__edPluginExecAutoSub.connectFAILURE(
                    self.doFailureExecAutoSub)
                self.__edPluginExecAutoSub.executeSynchronous()

                if self.isFailure():
                    return

                self.__edPluginSaxsAnalysis = self.loadPlugin(
                    self.__strControlledPluginSaxsAnalysis)
                self.__edPluginSaxsAnalysis.dataInput = XSDataInputSaxsAnalysis(
                    scatterCurve=self.xsdSubtractedCurve,
                    autoRg=self.autoRg,
                    graphFormat=XSDataString("png"))
                self.__edPluginSaxsAnalysis.connectSUCCESS(
                    self.doSuccessSaxsAnalysis)
                self.__edPluginSaxsAnalysis.connectFAILURE(
                    self.doFailureSaxsAnalysis)
                self.__edPluginSaxsAnalysis.executeSynchronous()

            self.__class__.lastBuffer = self.dataInput.mergedCurve
            #self.__class__.lastSample = None #Information neededfor transfer to ISPyB
            self.forgetLastSample = True
        else:
            self.__class__.lastSample = self.dataInput.mergedCurve

        if self.dataInput.sample and self.dataInput.sample.login and self.dataInput.sample.passwd and self.dataInput.sample.measurementID:
            self.addExecutiveSummaryLine("Registering to ISPyB")
            self.lstDiscarded = list(set(self.lstInput) - set(self.lstMerged))
            self.__class__.dictFrames[self.dataInput.mergedCurve] = {
                'averaged': self.lstMerged,
                'discarded': self.lstDiscarded
            }
            self.__edPluginSaxsISPyB = self.loadPlugin(
                self.__strControlledPluginSaxsISPyB)
            if len(self.lstInput) > 1:
                frameAverage = XSDataInteger(len(self.lstInput))
                frameMerged = XSDataInteger(len(self.lstMerged))
            else:
                frameMerged = frameAverage = XSDataInteger(1)
            self.curves = [XSDataFile(i.path) for i in self.lstInput]
            self.discardedCurves = [
                XSDataFile(i.path) for i in self.lstDiscarded
            ]
            self.mergedCurves = [XSDataFile(i.path) for i in self.lstMerged]

            averageFilePath = None
            if self.strMergedFile is not None:
                averageFilePath = XSDataFile(XSDataString(self.strMergedFile))

            self.sampleFrames = self.getAveragedFrameByFilename(
                self.__class__.lastSample)
            lastSample = None
            if self.__class__.lastSample is not None:
                lastSample = self.__class__.lastSample

            subtractedCurve = None
            if self.xsdSubtractedCurve is not None:
                subtractedCurve = self.xsdSubtractedCurve
            else:
                subtractedCurve = None

            xsdin = XSDataInputBioSaxsISPyBv1_0(
                sample=self.dataInput.sample,
                autoRg=self.autoRg,
                gnom=self.gnom,
                volume=self.volume,
                frameAverage=frameAverage,
                frameMerged=frameMerged,
                curves=self.curves,
                discardedFrames=self.discardedCurves,
                averagedFrames=self.mergedCurves,
                averageFilePath=averageFilePath,
                bufferFrames=self.bufferFrames,
                sampleFrames=self.sampleFrames,
                bestBuffer=self.xsBestBuffer,
                averageSample=lastSample,
                scatterPlot=self.xsScatterPlot,
                guinierPlot=self.xsGuinierPlot,
                kratkyPlot=self.xsKratkyPlot,
                densityPlot=self.xsDensityPlot,
                subtractedFilePath=subtractedCurve
                #                                                     destination=self.dataInput.sample.ispybDestination #duplicate, already in sample
            )
            self.__edPluginSaxsISPyB.dataInput = xsdin
            self.__edPluginSaxsISPyB.connectSUCCESS(self.doSuccessISPyB)
            self.__edPluginSaxsISPyB.connectFAILURE(self.doFailureISPyB)
            self.__edPluginSaxsISPyB.execute()

    # transfer analysis data to correct location on nice
        if self.gnom is not None:
            self.outdir = os.path.join(
                os.path.dirname(os.path.dirname(self.lstStrInput[0])),
                "ednaAnalysis")
            basename = os.path.basename(
                os.path.splitext(self.gnom.gnomFile.path.value)[0])
            self.outdir = os.path.join(self.outdir, basename)
            if not os.path.isdir(self.outdir):
                os.makedirs(self.outdir)
            #self.outFile = os.path.join(outdir, "NoResults.html")
            workingdir = os.path.dirname(self.gnom.gnomFile.path.value)

            self.pluginRsync = self.loadPlugin(self.cpRsync)
            self.pluginRsync.dataInput = XSDataInputRsync(
                source=XSDataFile(XSDataString(workingdir)),
                destination=XSDataFile(XSDataString(self.outdir)),
                options=XSDataString("-avx"))

            self.pluginRsync.connectSUCCESS(self.doSuccessExecRsync)
            self.pluginRsync.connectFAILURE(self.doFailureExecRsync)
            self.pluginRsync.executeSynchronous()

        if self.forgetLastSample:
            #Also redefine dictionary to contain the buffer just processed?
            self.__class__.lastSample = None
예제 #14
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsSmartMergev1_0.process")

        xsdwf = XSDataInputWaitMultiFile(
            timeOut=XSDataTime(30),
            expectedSize=XSDataInteger(10000),
            expectedFile=[XSDataFile(i.path) for i in self.lstInput])
        self.__edPluginExecWaitFile.setDataInput(xsdwf)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWait)
        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWait)
        self.__edPluginExecWaitFile.executeSynchronous()
        #        if self.isFailure():
        #            return

        if len(self.lstInput) == 1:
            shutil.copyfile(self.lstInput[0].path.value,
                            self.dataInput.mergedCurve.path.value)
        else:
            self.lstMerged = []
            if (self.absoluteFidelity is not None) or (self.relativeFidelity
                                                       is not None):
                if self.absoluteFidelity is not None:
                    for oneFile in self.lstInput[1:]:
                        edPluginExecAbsoluteFidelity = self.loadPlugin(
                            self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(
                            inputCurve=[self.lstInput[0], oneFile])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(
                            self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(
                            self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                if (self.relativeFidelity
                        is not None) and (len(self.lstInput) > 2):
                    for idx, oneFile in enumerate(self.lstInput[2:]):
                        edPluginExecRelativeFidelity = self.loadPlugin(
                            self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(
                            inputCurve=[self.lstInput[idx + 1], oneFile])
                        edPluginExecRelativeFidelity.setDataInput(xsd)
                        edPluginExecRelativeFidelity.connectFAILURE(
                            self.doFailureExecDatcmp)
                        edPluginExecRelativeFidelity.connectSUCCESS(
                            self.doSuccessExecDatcmp)
                        edPluginExecRelativeFidelity.execute()
            self.synchronizePlugins()

            for idx, oneFile in enumerate(self.lstInput):
                if idx == 0:
                    self.lstMerged.append(oneFile)
                elif (self.absoluteFidelity
                      is not None) and (self.relativeFidelity is not None):
                    if (self.dictSimilarities[(0, idx)] >=
                            self.absoluteFidelity) and (self.dictSimilarities[
                                (idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.absoluteFidelity is not None):
                    if (self.dictSimilarities[(0, idx)] >=
                            self.absoluteFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.relativeFidelity is not None):
                    if (self.dictSimilarities[(idx - 1, idx)] >=
                            self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                else:
                    self.lstMerged.append(oneFile)
            self.lstSummary.append("Merging files: " + " ".join(
                [os.path.basename(i.path.value) for i in self.lstMerged]))
            self.__edPluginExecDataver = self.loadPlugin(
                self.__strControlledPluginDataver)
            xsd = XSDataInputDataver(inputCurve=self.lstMerged)
            self.__edPluginExecDataver.setDataInput(xsd)
            self.__edPluginExecDataver.connectSUCCESS(
                self.doSuccessExecDataver)
            self.__edPluginExecDataver.connectFAILURE(
                self.doFailureExecDataver)
            self.__edPluginExecDataver.executeSynchronous()
예제 #15
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsSmartMergev1_5.process")

        xsdwf = XSDataInputWaitMultiFile(
            timeOut=XSDataTime(30),
            expectedSize=XSDataInteger(10000),
            expectedFile=[XSDataFile(i.path) for i in self.lstInput])
        self.__edPluginExecWaitFile.setDataInput(xsdwf)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWait)
        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWait)
        self.__edPluginExecWaitFile.executeSynchronous()
        if self.isFailure():
            return
        if len(self.lstInput) == 1:
            inp = self.lstInput[0].path.value
            dst = self.dataInput.mergedCurve.path.value
            if not os.path.isdir(os.path.dirname(dst)):
                self.error("Output directory for %s does not exist" % dst)
                os.makedirs(os.path.dirname(dst))
            if not os.path.exists(inp):
                self.warning("Input %s does not (yet?) exist" % inp)
                time.sleep(1.0)
            shutil.copyfile(inp, dst)
            self.addExecutiveSummaryLine(
                "Got only one frame ... nothing to merge !!!")
        else:
            self.lstMerged = []
            if (self.absoluteFidelity is not None) or (self.relativeFidelity
                                                       is not None):
                if self.absoluteFidelity is not None:
                    for idx, oneFile in enumerate(self.lstInput[1:]):
                        self.DEBUG("Calculating similarity of 0 and %s" % idx)
                        edPluginExecAbsoluteFidelity = self.loadPlugin(
                            self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(
                            inputCurve=[self.lstInput[0], oneFile])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(
                            self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(
                            self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                if (self.relativeFidelity is not None):
                    if (self.absoluteFidelity is None):
                        self.DEBUG("Calculating similarity of 0 and 1")
                        edPluginExecAbsoluteFidelity = self.loadPlugin(
                            self.__strControlledPluginDatcmp)
                        xsd = XSDataInputDatcmp(
                            inputCurve=[self.lstInput[0], self.lstInput[1]])
                        edPluginExecAbsoluteFidelity.setDataInput(xsd)
                        edPluginExecAbsoluteFidelity.connectFAILURE(
                            self.doFailureExecDatcmp)
                        edPluginExecAbsoluteFidelity.connectSUCCESS(
                            self.doSuccessExecDatcmp)
                        edPluginExecAbsoluteFidelity.execute()
                    if (len(self.lstInput) > 2):
                        for idx, oneFile in enumerate(self.lstInput[2:]):
                            self.DEBUG("Calculating similarity of %s and %s" %
                                       (idx, idx + 1))
                            edPluginExecRelativeFidelity = self.loadPlugin(
                                self.__strControlledPluginDatcmp)
                            xsd = XSDataInputDatcmp(
                                inputCurve=[self.lstInput[idx + 1], oneFile])
                            edPluginExecRelativeFidelity.setDataInput(xsd)
                            edPluginExecRelativeFidelity.connectFAILURE(
                                self.doFailureExecDatcmp)
                            edPluginExecRelativeFidelity.connectSUCCESS(
                                self.doSuccessExecDatcmp)
                            edPluginExecRelativeFidelity.execute()
            self.synchronizePlugins()

            for idx, oneFile in enumerate(self.lstInput):
                if idx == 0:
                    self.lstMerged.append(oneFile)
                elif (self.absoluteFidelity
                      is not None) and (self.relativeFidelity is not None):
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (self.dictSimilarities[(0, idx)] >=
                            self.absoluteFidelity) and (self.dictSimilarities[
                                (idx - 1, idx)] >= self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.absoluteFidelity is not None):
                    if (0, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (0, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (self.dictSimilarities[(0, idx)] >=
                            self.absoluteFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                elif (self.relativeFidelity is not None):
                    if (idx - 1, idx) not in self.dictSimilarities:
                        self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) +
                                   "\n".join([
                                       "%s: %s" %
                                       (key, self.dictSimilarities[key])
                                       for key in self.dictSimilarities
                                   ]))
                        self.resynchronize()

                    if (self.dictSimilarities[(idx - 1, idx)] >=
                            self.relativeFidelity):
                        self.lstMerged.append(oneFile)
                    else:
                        break
                else:
                    self.lstMerged.append(oneFile)
            self.lstMerged.sort(cmp)
            if len(self.lstMerged) != len(self.lstInput):
                self.strRadiationDamage = "Radiation damage detected, merged %i curves" % len(
                    self.lstMerged)
                self.WARNING(self.strRadiationDamage)
                self.addExecutiveSummaryLine("WARNING: " +
                                             self.strRadiationDamage)
            self.addExecutiveSummaryLine("Merging files: " + " ".join(
                [os.path.basename(i.path.value) for i in self.lstMerged]))
            if len(self.lstMerged) == 1:
                self.rewriteHeader(self.lstMerged[0].path.value,
                                   self.strMergedFile)
            else:
                self.__edPluginExecDataver = self.loadPlugin(
                    self.__strControlledPluginDataver)
                xsd = XSDataInputDataver(inputCurve=self.lstMerged)
                # outputCurve=self.dataInput.mergedCurve,
                self.__edPluginExecDataver.setDataInput(xsd)
                self.__edPluginExecDataver.connectSUCCESS(
                    self.doSuccessExecDataver)
                self.__edPluginExecDataver.connectFAILURE(
                    self.doFailureExecDataver)
                self.__edPluginExecDataver.executeSynchronous()

        if (self.fConcentration == 0) and (self.strSubFile is not None):
            if (self.__class__.lastBuffer
                    is not None) and (self.__class__.lastSample is not None):
                self.__edPluginExecAutoSub = self.loadPlugin(
                    self.__strControlledPluginAutoSub)
                base = "_".join(
                    os.path.basename(
                        self.__class__.lastSample.path.value).split("_")[:-1])
                suff = os.path.basename(self.strSubFile).split("_")[-1]
                sub = os.path.join(os.path.dirname(self.strSubFile),
                                   base + "_" + suff)
                xsdSubtractedCurve = XSDataFile(XSDataString(sub))
                self.curves.append(xsdSubtractedCurve)
                self.__edPluginExecAutoSub.dataInput = XSDataInputAutoSub(
                    sampleCurve=self.__class__.lastSample,
                    buffers=[
                        self.__class__.lastBuffer, self.dataInput.mergedCurve
                    ],
                    subtractedCurve=xsdSubtractedCurve)
                self.__edPluginExecAutoSub.connectSUCCESS(
                    self.doSuccessExecAutoSub)
                self.__edPluginExecAutoSub.connectFAILURE(
                    self.doFailureExecAutoSub)
                self.__edPluginExecAutoSub.executeSynchronous()

                if self.isFailure():
                    return

                self.__edPluginSaxsAnalysis = self.loadPlugin(
                    self.__strControlledPluginSaxsAnalysis)
                self.__edPluginSaxsAnalysis.dataInput = XSDataInputSaxsAnalysis(
                    scatterCurve=xsdSubtractedCurve,
                    autoRg=self.autoRg,
                    graphFormat=XSDataString("png"))
                self.__edPluginSaxsAnalysis.connectSUCCESS(
                    self.doSuccessSaxsAnalysis)
                self.__edPluginSaxsAnalysis.connectFAILURE(
                    self.doFailureSaxsAnalysis)
                self.__edPluginSaxsAnalysis.executeSynchronous()

            self.__class__.lastBuffer = self.dataInput.mergedCurve
            self.__class__.lastSample = None
        else:
            self.__class__.lastSample = self.dataInput.mergedCurve

        if self.dataInput.sample and self.dataInput.sample.login and self.dataInput.sample.passwd and self.dataInput.sample.measurementID:
            self.addExecutiveSummaryLine("Registering to ISPyB")
            self.__edPluginSaxsISPyB = self.loadPlugin(
                self.__strControlledPluginSaxsISPyB)
            if len(self.lstInput) > 1:
                frameAverage = XSDataInteger(len(self.lstInput))
                frameMerged = XSDataInteger(len(self.lstMerged))
            else:
                frameMerged = frameAverage = XSDataInteger(1)
            self.curves = [XSDataFile(i.path) for i in self.lstInput]
            if self.strMergedFile is not None:
                self.curves.append(XSDataFile(XSDataString(
                    self.strMergedFile)))
            xsdin = XSDataInputBioSaxsISPyBv1_0(
                sample=self.dataInput.sample,
                autoRg=self.autoRg,
                gnom=self.gnom,
                volume=self.volume,
                frameAverage=frameAverage,
                frameMerged=frameMerged,
                curves=self.curves,
                bestBuffer=self.xsBestBuffer,
                scatterPlot=self.xsScatterPlot,
                guinierPlot=self.xsGuinierPlot,
                kratkyPlot=self.xsKratkyPlot,
                densityPlot=self.xsDensityPlot
                #                                                     destination=self.dataInput.sample.ispybDestination #duplicate, already in sample
            )
            self.__edPluginSaxsISPyB.dataInput = xsdin
            self.__edPluginSaxsISPyB.connectSUCCESS(self.doSuccessISPyB)
            self.__edPluginSaxsISPyB.connectFAILURE(self.doFailureISPyB)
            self.__edPluginSaxsISPyB.execute()