Exemple #1
0
    def strategySummaryItemListToStrategySummary(self,
                                                 _xsStrategySummaryItemList):
        xsDataStrategySummary = XSDataBestStrategySummary()

        xsItemDistance = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "distance")
        fDistance = float(xsItemDistance.getValueOf_())
        xsDataStrategySummary.setDistance(XSDataLength(fDistance))

        strItemTransmission = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "transmission")
        fTransmission = float(strItemTransmission.getValueOf_())
        xsDataStrategySummary.setTransmission(XSDataDouble(fTransmission))

        strItemCompleteness = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "completeness")
        # For homegeneity concerns, EDNA data model should store all the completeness value in fraction
        # ( DNA table xml file stores the summary strategy completeness in percentage whereas
        # the resolution bin completeness are in fraction )
        fCompleteness = float(strItemCompleteness.getValueOf_()) / 100
        xsDataStrategySummary.setCompleteness(XSDataDouble(fCompleteness))

        strItemISigma = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "i_sigma")
        fISigma = float(strItemISigma.getValueOf_())
        xsDataStrategySummary.setISigma(XSDataDouble(fISigma))

        strItemRedundancy = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "redundancy")
        fRedundancy = float(strItemRedundancy.getValueOf_())
        xsDataStrategySummary.setRedundancy(XSDataDouble(fRedundancy))

        strItemResolution = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "resolution")
        fResolution = float(strItemResolution.getValueOf_())
        xsDataStrategySummary.setResolution(XSDataDouble(fResolution))

        strItemResolutionReasoning = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "resolution_reasoning")
        strResolutionReasoning = strItemResolutionReasoning.getValueOf_()
        xsDataStrategySummary.setResolutionReasoning(
            XSDataString(strResolutionReasoning))

        strItemTotalDataCollectionTime = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "total_data_collection_time")
        fTotalDataCollectionTime = float(
            strItemTotalDataCollectionTime.getValueOf_())
        xsDataStrategySummary.setTotalDataCollectionTime(
            XSDataTime(fTotalDataCollectionTime))

        strItemTotalExposureTime = EDUtilsTable.getItemFromList(
            _xsStrategySummaryItemList, "total_exposure_time")
        fTotalExposureTime = float(strItemTotalExposureTime.getValueOf_())
        xsDataStrategySummary.setTotalExposureTime(
            XSDataTime(fTotalExposureTime))

        return xsDataStrategySummary
Exemple #2
0
    def collectionRunItemListToCollectionRun(self, _xsCollectionRunItemList):
        xsDataCollectionRun = XSDataBestCollectionRun()

        xsItemExposureTime = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "exposure_time")
        fExposureTime = float(xsItemExposureTime.getValueOf_())
        xsDataCollectionRun.setExposureTime(XSDataTime(fExposureTime))

        xsItemDistance = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "distance")
        fDistance = float(xsItemDistance.getValueOf_())
        xsDataCollectionRun.setDistance(XSDataLength(fDistance))

        xsItemRotationAxisStart = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "phi_start")
        fRotationAxisStart = float(xsItemRotationAxisStart.getValueOf_())
        xsDataCollectionRun.setPhiStart(XSDataAngle(fRotationAxisStart))

        xsNumberOfImages = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "number_of_images")
        iNumberOfImages = int(xsNumberOfImages.getValueOf_())
        xsDataCollectionRun.setNumberOfImages(XSDataInteger(iNumberOfImages))

        xsItemPhiWidth = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "phi_width")
        fPhiWidth = float(xsItemPhiWidth.getValueOf_())
        xsDataCollectionRun.setPhiWidth(XSDataAngle(fPhiWidth))

        xsItemOverlaps = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "overlaps")
        strOverlaps = xsItemOverlaps.getValueOf_()
        xsDataCollectionRun.setOverlaps(XSDataString(strOverlaps))

        return xsDataCollectionRun
 def process(self, _edObject=None):
     EDPluginControl.process(self)
     self.DEBUG("EDPluginBioSaxsAzimutIntv1_2.process")
     xsdiWaitFile = XSDataInputWaitFile(
         expectedFile=XSDataFile(self.dataInput.normalizedImage.path),
         expectedSize=self.dataInput.normalizedImageSize,
         timeOut=XSDataTime(30))
     self.__edPluginWaitFile.setDataInput(xsdiWaitFile)
     self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile)
     self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile)
     self.__edPluginWaitFile.executeSynchronous()
     if not self.isFailure():
         self.__edPluginSaxsGetMetadata.connectSUCCESS(
             self.doSuccessGetMetadata)
         self.__edPluginSaxsGetMetadata.connectFAILURE(
             self.doFailureGetMetadata)
         self.__edPluginSaxsGetMetadata.executeSynchronous()
     if not self.isFailure():
         self.__edPluginSaxsAngle.connectSUCCESS(self.doSuccessSaxsAngle)
         self.__edPluginSaxsAngle.connectFAILURE(self.doFailureSaxsAngle)
         self.__edPluginSaxsAngle.executeSynchronous()
     if not self.isFailure():
         self.write3ColumnAscii(self.integratedImage, self.integratedCurve)
         self.lstProcessLog.append(
             "Conversion to ascii: '%s' --> '%s'" %
             (self.integratedImage, self.integratedCurve))
         self.xsdResult.setIntegratedCurve(self.dataInput.integratedCurve)
Exemple #4
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsNormalizev1_1.process")
        xsdiWaitFile = XSDataInputWaitFile(expectedFile=XSDataFile(self.xsdInput.rawImage.path),
                                           expectedSize=self.xsdInput.rawImageSize,
                                           timeOut=XSDataTime(value=30))
        self.__edPluginExecWaitFile.setDataInput(xsdiWaitFile)
        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWaitFile)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWaitFile)
        self.__edPluginExecWaitFile.executeSynchronous()
        if self.isFailure():
            return
#        Small Numpy processing:
        fabIn = fabio.open(self.strRawImage)
        if "time_of_day" in fabIn.header:
            self.dictOutputHeader["time_of_day"] = fabIn.header["time_of_day"]
        if "Mask" in self.dictOutputHeader:
            mask = self.getMask(self.dictOutputHeader["Mask"])
            npaMaskedData = numpy.ma.masked_array(fabIn.data.astype("float32"),
                                                  ((fabIn.data < 0) + (mask[:fabIn.dim2, :fabIn.dim1 ] < 0)))
        else:
            npaMaskedData = numpy.ma.masked_array(fabIn.data.astype("float32"), (fabIn.data < 0))
        scale = self.dictOutputHeader["Normalization"] / self.dictOutputHeader["DiodeCurr"]
        self.dictOutputHeader["Dummy"] = str(self.dummy)
        self.dictOutputHeader["DDummy"] = "0.1"
        self.dictOutputHeader["EDF_DataBlockID"] = "1.Image.Psd"
        header_keys = self.dictOutputHeader.keys()
        header_keys.sort()
        fabioOut = fabio.edfimage.edfimage(header=self.dictOutputHeader, header_keys=header_keys,
                             data=numpy.ma.filled(npaMaskedData * scale, float(self.dummy)))
        fabioOut.appendFrame(header={"Dummy": str(self.dummy), "DDummy":"0.1", "EDF_DataBlockID":"1.Image.Error"},
                              data=(numpy.ma.filled(npaMaskedData * (scale ** 2), float(self.dummy))))
        fabioOut.write(self.strNormalizedImage)
        self.lstProcessLog.append("Normalized image by factor %.3f " % (scale))
 def process(self, _edObject=None):
     EDPluginControl.process(self)
     EDVerbose.DEBUG("EDPluginBioSaxsAzimutIntv1_1.process")
     xsdiWaitFile = XSDataInputWaitFile(
         expectedFile=XSDataFile(self.dataInput.normalizedImage.path),
         expectedSize=self.dataInput.normalizedImageSize,
         timeOut=XSDataTime(30))
     self.__edPluginWaitFile.setDataInput(xsdiWaitFile)
     self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile)
     self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile)
     self.__edPluginWaitFile.executeSynchronous()
     if not self.isFailure():
         self.__edPluginSaxsGetMetadata.connectSUCCESS(
             self.doSuccessGetMetadata)
         self.__edPluginSaxsGetMetadata.connectFAILURE(
             self.doFailureGetMetadata)
         self.__edPluginSaxsGetMetadata.executeSynchronous()
     if not self.isFailure():
         self.__edPluginSaxsAngle.connectSUCCESS(self.doSuccessSaxsAngle)
         self.__edPluginSaxsAngle.connectFAILURE(self.doFailureSaxsAngle)
         self.__edPluginSaxsAngle.executeSynchronous()
     if not self.isFailure():
         self.__edPluginAsciiExport.connectSUCCESS(
             self.doSuccessAsciiExport)
         self.__edPluginAsciiExport.connectFAILURE(
             self.doFailureAsciiExport)
         self.__edPluginAsciiExport.executeSynchronous()
    def integrate(self):
        img = fabio.open(self.rawImage)
        if "Date" in img.header:
            self.experimentSetup.timeOfFrame = XSDataTime(time.mktime(time.strptime(img.header["Date"], "%a %b %d %H:%M:%S %Y")))
        wavelength = EDUtilsUnit.getSIValue(self.experimentSetup.wavelength)
        current_config = self.integrator.getPyFAI()
        short_config = {}
        for key in self.integrator_config:
            short_config[key] = current_config[key]

        with self.__class__.semaphore:
            if (short_config != self.integrator_config) or \
               (self.integrator.wavelength != wavelength) or\
               (self.maskfile != self.experimentSetup.maskFile.path.value):
                self.screen("Resetting PyFAI integrator")
                self.integrator.setPyFAI(**self.integrator_config)
                self.integrator.wavelength = wavelength
                self.integrator.detector.mask = self.calc_mask()

            q, I, std = self.integrator.integrate1d(img.data, max(img.dim1, img.dim2),
                                       correctSolidAngle=True,
                                       dummy=self.dummy, delta_dummy=self.delta_dummy,
                                       filename=None,
                                       error_model="poisson",
                                       radial_range=None, azimuth_range=None,
                                       polarization_factor=0, dark=None, flat=None,
                                       method=self.METHOD, unit="q_nm^-1", safe=False)
        self.lstExecutiveSummary.append("Azimuthal integration of raw image '%s'-->'%s'." % (self.rawImage, self.integratedCurve))
        return q, I, std
Exemple #7
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsNormalizev1_0.process")
        xsdiWaitFile = XSDataInputWaitFile(
            expectedFile=XSDataFile(self.xsdInput.rawImage.path),
            expectedSize=self.xsdInput.rawImageSize,
            timeOut=XSDataTime(30))
        self.__edPluginExecWaitFile.setDataInput(xsdiWaitFile)

        self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWaitFile)
        self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWaitFile)
        self.__edPluginExecWaitFile.executeSynchronous()

        if self.isFailure():
            return
        self.__edPluginExecSaxsMac.connectSUCCESS(self.doSuccessExecSaxsMac)
        self.__edPluginExecSaxsMac.connectFAILURE(self.doFailureExecSaxsMac)
        self.__edPluginExecSaxsMac.executeSynchronous()

        if self.isFailure():
            return

        self.__edPluginExecMetadata.connectSUCCESS(self.doSuccessExecMetadata)
        self.__edPluginExecMetadata.connectFAILURE(self.doFailureExecMetadata)
        self.__edPluginExecMetadata.executeSynchronous()
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
Exemple #9
0
    def collectionRunItemListToCollectionRun(self, _xsCollectionRunItemList,
                                             _iCollectionRunNumber):
        xsDataCollectionRun = XSDataBestCollectionRun()

        xsItemWedge = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                   "Wedge")
        if xsItemWedge is not None:
            iWedge = int(xsItemWedge.getValueOf_())
        else:
            iWedge = _iCollectionRunNumber
        xsDataCollectionRun.setCollectionRunNumber(XSDataInteger(iWedge))

        xsItemCrystal = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                     "Crystal")
        if xsItemCrystal is not None:
            iCrystal = int(xsItemCrystal.getValueOf_())
            xsDataCollectionRun.setCrystalPosition(XSDataInteger(iCrystal))

        xsItemExposureTime = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "exposure_time")
        fExposureTime = float(xsItemExposureTime.getValueOf_())
        xsDataCollectionRun.setExposureTime(XSDataTime(fExposureTime))

        xsItemAction = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                    "action")
        if (xsItemAction is not None):
            strAction = xsItemAction.getValueOf_()
            xsDataCollectionRun.setAction(XSDataString(strAction))

        xsItemRotationAxisStart = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "phi_start")
        fRotationAxisStart = float(xsItemRotationAxisStart.getValueOf_())
        xsDataCollectionRun.setPhiStart(XSDataAngle(fRotationAxisStart))

        xsNumberOfImages = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "number_of_images")
        iNumberOfImages = int(xsNumberOfImages.getValueOf_())
        xsDataCollectionRun.setNumberOfImages(XSDataInteger(iNumberOfImages))

        xsItemPhiWidth = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "phi_width")
        fPhiWidth = float(xsItemPhiWidth.getValueOf_())
        xsDataCollectionRun.setPhiWidth(XSDataAngle(fPhiWidth))

        xsItemOverlaps = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "overlaps")
        if (xsItemOverlaps is not None):
            strOverlaps = xsItemOverlaps.getValueOf_()
            xsDataCollectionRun.setOverlaps(XSDataString(strOverlaps))

        xsItemTransmission = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "transmission")
        if (xsItemTransmission is not None):
            fTransmission = float(xsItemTransmission.getValueOf_())
            xsDataCollectionRun.setTransmission(XSDataDouble(fTransmission))

        return xsDataCollectionRun
Exemple #10
0
    def getXsdDark(self):
        """
        return XSDataDark object
        """

        if self._xsDataDark is None:
            self._xsDataDark = [XSDataImageExt(path=XSDataString(i["path"]),
                               exposureTime=XSDataTime(i["exposureTime"]))
                              for i in self.darks]
        return self._xsDataDark
Exemple #11
0
    def doSuccessProcessOneFile(self, _edPlugin=None):
        self.DEBUG("EDPluginBioSaxsHPLCv1_5.doSuccessProcessOneFile")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginBioSaxsHPLCv1_5.doSuccessProcessOneFile")
        if _edPlugin and _edPlugin.dataOutput and _edPlugin.dataOutput.status and _edPlugin.dataOutput.status.executiveSummary:
            self.lstExecutiveSummary.append(_edPlugin.dataOutput.status.executiveSummary.value)
        output = _edPlugin.dataOutput
        if not output.integratedCurve:
            strErr = "Edna plugin ProcessOneFile did not produce integrated curve"
            self.ERROR(strErr)
            self.lstExecutiveSummary.append(strErr)
            self.setFailure()
            return
        self.curve = output.integratedCurve.path.value
        if not os.path.exists(self.curve):
            strErr = "Edna plugin ProcessOneFile: integrated curve not on disk !!"
            self.ERROR(strErr)
            self.lstExecutiveSummary.append(strErr)
            self.setFailure()
            return
        self.xsDataResult.integratedCurve = output.integratedCurve
        self.xsDataResult.normalizedImage = output.normalizedImage
        self.xsDataResult.dataI = output.dataI
        self.xsDataResult.dataQ = output.dataQ
        self.xsDataResult.dataStdErr = output.dataStdErr
        self.intensity = EDUtilsArray.xsDataToArray(output.dataI)
        self.stdError = EDUtilsArray.xsDataToArray(output.dataStdErr)
        if output.experimentSetup and output.experimentSetup.timeOfFrame:
            startTime = output.experimentSetup.timeOfFrame.value
        else:
            try:
                startTime = float(fabio.openheader(self.dataInput.rawImage.path.value).header["time_of_day"])
            except Exception:
                self.ERROR("Unable to read time_of_day in header of %s" % self.dataInput.rawImage.path.value)
                startTime = 0

        if not self.hplc_run.first_curve:
            with self._sem:
                if True: #not self.hplc_run.first_curve:
                    # Populate the buffer with the first curve if needed
                    self.hplc_run.first_curve = self.curve
                    self.hplc_run.start_time = startTime
                    self.hplc_run.q = EDUtilsArray.xsDataToArray(output.dataQ)
                    self.hplc_run.size = self.hplc_run.q.size
                    self.hplc_run.buffer_I = self.intensity
                    self.hplc_run.buffer_Stdev = self.stdError
                    self.hplc_run.firstCurveIntensity = self.intensity
                    self.hplc_run.for_buffer_sum_I = self.intensity
                    self.hplc_run.for_buffer_sum_sigma2 = self.stdError ** 2
                    self.hplc_run.for_buffer.append(self.frameId)
        self.frame.curve = self.curve
        self.frame.time = startTime
        self.xsDataResult.timeStamp = XSDataTime(value=(startTime - self.hplc_run.start_time))
#         self.calcIntensity()
        self.frame.sum_I = float(self.intensity.sum())
        self.xsDataResult.summedIntensity = XSDataDouble(value=self.frame.sum_I)
 def createInputCharacterisationFromSubWedges(self):
     EDVerbose.DEBUG(
         "EDPluginControlInterfacev2_0.createInputCharacterisationFromSubWedges"
     )
     xsDataResultSubWedgeAssemble = self.edPluginControlSubWedgeAssemble.getDataOutput(
     )
     self.xsDataInputCharacterisation = XSDataInputCharacterisation()
     xsDataCollection = XSDataCollection()
     # Default exposure time (for the moment, this value should be
     # possible to read from the command line)
     xsDataDiffractionPlan = XSDataDiffractionPlan()
     if (not xsDataResultSubWedgeAssemble is None):
         pyListSubWedge = xsDataResultSubWedgeAssemble.getSubWedge()
         xsDataCollection.setSubWedge(pyListSubWedge)
         for xsDataSubWedge in pyListSubWedge:
             if (self.strComplexity is not None):
                 xsDataDiffractionPlan.setComplexity(
                     XSDataString(self.strComplexity))
             if (self.fFlux is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setFlux(XSDataFloat(self.fFlux))
             if (self.fBeamSize is not None):
                 xsDataSize = XSDataSize()
                 xsDataSize.setX(XSDataLength(self.fBeamSize))
                 xsDataSize.setY(XSDataLength(self.fBeamSize))
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setSize(xsDataSize)
             if (self.fBeamPosX is not None):
                 xsDataSubWedge.getExperimentalCondition().getDetector(
                 ).setBeamPositionX(XSDataLength(self.fBeamPosX))
             if (self.fBeamPosY is not None):
                 xsDataSubWedge.getExperimentalCondition().getDetector(
                 ).setBeamPositionY(XSDataLength(self.fBeamPosY))
             if (self.fMinExposureTimePerImage is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setMinExposureTimePerImage(
                     XSDataFloat(self.fMinExposureTimePerImage))
             if (self.fTransmission is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setTransmission(XSDataDouble(self.fTransmission))
     if (self.strForcedSpaceGroup is not None):
         xsDataDiffractionPlan.setForcedSpaceGroup(
             XSDataString(self.strForcedSpaceGroup))
     xsDataDiffractionPlan.setAnomalousData(
         XSDataBoolean(self.bAnomalousData))
     xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(
         XSDataTime(self.fMaxExposureTimePerDataCollection))
     if (self.strStrategyOption is not None):
         xsDataDiffractionPlan.setStrategyOption(
             XSDataString(self.strStrategyOption))
     xsDataCollection.setDiffractionPlan(xsDataDiffractionPlan)
     self.xsDataInputCharacterisation.setDataCollection(xsDataCollection)
    def integrate(self):
        #with fabio.fabioutils.File(self.rawImage) as raw:
        img = fabio.open(self.rawImage)
        number_of_bins = self.number_of_bins or max(img.dim1, img.dim2)
        if "Date" in img.header:
            self.experimentSetup.timeOfFrame = XSDataTime(
                time.mktime(
                    time.strptime(img.header["Date"], "%a %b %d %H:%M:%S %Y")))

        new_integrator = pyFAI.AzimuthalIntegrator(detector=self.detector)
        new_integrator.setFit2D(
            self.experimentSetup.detectorDistance.value * 1000,
            self.experimentSetup.beamCenter_1.value,
            self.experimentSetup.beamCenter_2.value)
        new_integrator.wavelength = EDUtilsUnit.getSIValue(
            self.experimentSetup.wavelength)

        with self.__class__.semaphore:
            if (str(new_integrator) != str(self.integrator) or
                    self.maskfile != self.experimentSetup.maskFile.path.value):
                self.screen("Resetting PyFAI integrator")
                new_integrator.detector.mask = self.calc_mask()
                self.__class__.integrator = new_integrator

            res_tuple = self.integrator.integrate1d(
                img.data,
                number_of_bins,
                correctSolidAngle=True,
                dummy=self.dummy,
                delta_dummy=self.delta_dummy,
                filename=None,
                error_model="poisson",
                radial_range=None,
                azimuth_range=None,
                polarization_factor=0.99,
                dark=None,
                flat=None,
                method=self.METHOD,
                unit="q_nm^-1",
                safe=False,
                normalization_factor=self.normalization_factor)
        self.lstExecutiveSummary.append(
            "Azimuthal integration of raw image '%s'-->'%s'." %
            (self.rawImage, self.integratedCurve))
        valid_bins = abs(res_tuple.intensity - self.dummy) > self.delta_dummy
        short_tuple = res_tuple.__class__(res_tuple.radial[valid_bins],
                                          res_tuple.intensity[valid_bins],
                                          res_tuple.sigma[valid_bins])
        return short_tuple
Exemple #14
0
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlReadImageHeaderv10.preProcess")
     # First determine the type of image
     xsDataInputReadImageHeader = self.getDataInput()
     xsDataFileImage = xsDataInputReadImageHeader.getImage()
     self.strFileImagePath = xsDataFileImage.getPath().getValue()
     # Plugin for waiting for files
     self.edPluginExecMXWaitFile = self.loadPlugin(
         self.strPluginExecMXWaitFile)
     xsDataInputMXWaitFile = XSDataInputMXWaitFile()
     xsDataInputMXWaitFile.setFile(
         XSDataFile(XSDataString(self.strFileImagePath)))
     xsDataInputMXWaitFile.setSize(XSDataInteger(100000))
     xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
     self.edPluginExecMXWaitFile.setDataInput(xsDataInputMXWaitFile)
    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()
Exemple #16
0
    def doSuccessProcessOneFile(self, _edPlugin=None):
        self.DEBUG("EDPluginBioSaxsHPLCv1_2.doSuccessProcessOneFile")
        self.retrieveSuccessMessages(
            _edPlugin, "EDPluginBioSaxsHPLCv1_2.doSuccessProcessOneFile")
        if _edPlugin and _edPlugin.dataOutput and _edPlugin.dataOutput.status and _edPlugin.dataOutput.status.executiveSummary:
            self.lstExecutiveSummary.append(
                _edPlugin.dataOutput.status.executiveSummary.value)
        output = _edPlugin.dataOutput
        if not output.integratedCurve:
            strErr = "Edna plugin ProcessOneFile did not produce integrated curve"
            self.ERROR(strErr)
            self.lstExecutiveSummary.append(strErr)
            self.setFailure()
            return
        self.curve = output.integratedCurve.path.value
        if not os.path.exists(self.curve):
            strErr = "Edna plugin ProcessOneFile: integrated curve not on disk !!"
            self.ERROR(strErr)
            self.lstExecutiveSummary.append(strErr)
            self.setFailure()
            return
        self.xsDataResult.integratedCurve = output.integratedCurve
        self.xsDataResult.normalizedImage = output.normalizedImage
        self.xsDataResult.dataI = output.dataI
        self.xsDataResult.dataQ = output.dataQ
        self.xsDataResult.dataStdErr = output.dataStdErr
        if output.experimentSetup and output.experimentSetup.timeOfFrame:
            startTime = output.experimentSetup.timeOfFrame.value
        else:
            try:
                startTime = float(
                    fabio.openheader(self.dataInput.rawImage.path.value).
                    header["time_of_day"])
            except Exception:
                self.ERROR("Unable to read time_of_day in header of %s" %
                           self.dataInput.rawImage.path.value)
                startTime = 0

        with self._sem:
            if not self.hplc_run.first_curve:
                self.hplc_run.first_curve = self.curve
                self.hplc_run.start_time = startTime
        self.frame.curve = self.curve
        self.frame.time = startTime
        self.xsDataResult.timeStamp = XSDataTime(
            value=(startTime - self.hplc_run.start_time))
        self.calcIntensity()
Exemple #17
0
 def createInputCharacterisationFromSubWedges(self):
     self.DEBUG("EDPluginControlInterfacev1_2.createInputCharacterisationFromSubWedges")
     xsDataResultSubWedgeAssemble = self.edPluginControlSubWedgeAssemble.getDataOutput()
     self.xsDataInputCharacterisation = XSDataInputCharacterisation()
     xsDataCollection = XSDataCollection()
     # Default exposure time (for the moment, this value should be
     # possible to read from the command line)
     if self.xsDataDiffractionPlan is None:
         self.xsDataDiffractionPlan = XSDataDiffractionPlan()
     if (not xsDataResultSubWedgeAssemble is None):
         pyListSubWedge = xsDataResultSubWedgeAssemble.getSubWedge()
         xsDataCollection.setSubWedge(pyListSubWedge)
         for xsDataSubWedge in pyListSubWedge:
             if (self.strComplexity is not None):
                 self.xsDataDiffractionPlan.setComplexity(XSDataString(self.strComplexity))
             if (self.fFlux is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam().setFlux(XSDataFlux(self.fFlux))
             if (self.fBeamSizeX is not None) and (self.fBeamSizeY is not None):
                 xsDataSize = XSDataSize()
                 xsDataSize.setX(XSDataLength(self.fBeamSizeX))
                 xsDataSize.setY(XSDataLength(self.fBeamSizeY))
                 xsDataSubWedge.getExperimentalCondition().getBeam().setSize(xsDataSize)
             if (self.fBeamPosX is not None):
                 xsDataSubWedge.getExperimentalCondition().getDetector().setBeamPositionX(XSDataLength(self.fBeamPosX))
             if (self.fBeamPosY is not None):
                 xsDataSubWedge.getExperimentalCondition().getDetector().setBeamPositionY(XSDataLength(self.fBeamPosY))
             if (self.fMinExposureTimePerImage is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam().setMinExposureTimePerImage(XSDataTime(self.fMinExposureTimePerImage))
             if (self.fTransmission is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam().setTransmission(XSDataDouble(self.fTransmission))
             if (self.fWavelength is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam().setWavelength(XSDataWavelength(self.fWavelength))
             if self.fMinOscillationWidth != None:
                 xsDataSubWedge.getExperimentalCondition().getGoniostat().setMinOscillationWidth(XSDataAngle(self.fMinOscillationWidth))
             if self.fMaxOscillationSpeed != None:
                 xsDataSubWedge.getExperimentalCondition().getGoniostat().setMaxOscillationSpeed(XSDataAngularSpeed(self.fMaxOscillationSpeed))
     if (self.strForcedSpaceGroup is not None):
         self.xsDataDiffractionPlan.setForcedSpaceGroup(XSDataString(self.strForcedSpaceGroup))
     self.xsDataDiffractionPlan.setAnomalousData(XSDataBoolean(self.bAnomalousData))
     self.xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(XSDataTime(self.fMaxExposureTimePerDataCollection))
     if (self.strStrategyOption is not None):
         self.xsDataDiffractionPlan.setStrategyOption(XSDataString(self.strStrategyOption))
     xsDataCollection.setDiffractionPlan(self.xsDataDiffractionPlan)
     if self.xsDataSample is not None:
         xsDataCollection.setSample(XSDataSampleCrystalMM.parseString(self.xsDataSample.marshal()))
     self.xsDataInputCharacterisation.setDataCollection(xsDataCollection)
     self.xsDataInputCharacterisation.setToken(self.xsDataToken)
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'diffractionImage':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.diffractionImage.append(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'forcedOutputDirectory':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.setForcedOutputDirectory(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'waitForFileTimeOut':
         obj_ = XSDataTime()
         obj_.build(child_)
         self.setWaitForFileTimeOut(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
Exemple #19
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'expectedFile':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.expectedFile.append(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'expectedSize':
         obj_ = XSDataInteger()
         obj_.build(child_)
         self.setExpectedSize(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'timeOut':
         obj_ = XSDataTime()
         obj_.build(child_)
         self.setTimeOut(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
Exemple #20
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsProcessOneFilev1_3.process")

        xsd = XSDataInputWaitFile(expectedFile=XSDataFile(XSDataString(self.rawImage)),
                                           expectedSize=self.rawImageSize,
                                           timeOut=XSDataTime(30))
        self.__edPluginWaitFile.setDataInput(xsd)
        self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile)
        self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile)
        self.__edPluginWaitFile.executeSynchronous()
        if self.isFailure():
            return

        q, I, std = self.integrate()
        I = self.normalize(I)
        std = self.normalize(std)
        self.write3ColumnAscii(q, I, std, self.integratedCurve)
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlGridScreeningv1_0.preProcess")
     # Load the plugins
     self.edPluginControlReadImageHeader = self.loadPlugin(self.strControlReadImageHeaderPluginName, \
                                                                "ReadImageHeader")
     self.edPluginControlIndicators = self.loadPlugin(self.strControlledIndicatorsPluginName, \
                                                                "ControlIndicators")
     self.edPluginMOSFLMIndexing = self.loadPlugin(self.strIndexingMOSFLMPluginName, \
                                                                "IndexingMOSFLM")
     self.edPluginControlIntegration = self.loadPlugin(self.strPluginControlIntegration, \
                                                         "Integration")
     self.edPluginControlStrategy = self.loadPlugin(self.strPluginControlStrategy, \
                                                      "Strategy")
     self.edPluginExecMtz2Various = self.loadPlugin(self.strPluginExecMtz2Various, \
                                                      "Mtz2Various")
     # Input data
     self.strImageFile = self.getDataInput().getImageFile().getPath(
     ).getValue()
     self.xsDataGridScreeningFileNameParameters = self.getFileNameParameters(
         self.strImageFile)
     self.xsDataDiffractionPlan = self.getDataInput().getDiffractionPlan()
     if self.xsDataDiffractionPlan is None:
         self.xsDataDiffractionPlan = XSDataDiffractionPlan()
     if self.xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
     ) is None:
         # Default max esposure time: 10000s
         self.xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(
             XSDataTime(10000))
     self.xsDataDiffractionPlan.setEstimateRadiationDamage(
         XSDataBoolean(False))
     # Image quality indicators
     if self.getDataInput().getStoreImageQualityIndicatorsInISPyB():
         self.bStoreImageQualityIndicatorsInISPyB = self.getDataInput(
         ).getStoreImageQualityIndicatorsInISPyB().getValue()
     if self.getDataInput().getDoOnlyImageQualityIndicators():
         self.bDoOnlyImageQualityIndicators = self.getDataInput(
         ).getDoOnlyImageQualityIndicators().getValue()
     if self.getDataInput().getDoOnlyIntegrationWithXMLOutput():
         self.bDoOnlyIntegrationWithXMLOutput = self.getDataInput(
         ).getDoOnlyIntegrationWithXMLOutput().getValue()
     if self.bStoreImageQualityIndicatorsInISPyB:
         self.edPluginISPyBStoreImageQualityIndicators = self.loadPlugin(self.strISPyBStoreImageQualityIndicatorsPluginName, \
                                                      "ISPyBStoreImageQualityIndicators")
Exemple #22
0
    def setPluginInput(self, _edPlugin):
        xsDataDiffractionPlan = XSDataDiffractionPlan()
        if (not self.__fMaxExposureTimePerDataCollection is None):
            xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(XSDataTime(self.__fMaxExposureTimePerDataCollection))
        if (not self.__strForcedSpaceGroup is None):
            xsDataDiffractionPlan.setForcedSpaceGroup(XSDataString(self.__strForcedSpaceGroup))
        if (not self.__bAnomalousData is None):
            xsDataDiffractionPlan.setAnomalousData(XSDataBoolean(self.__bAnomalousData))
        if (not self.__strStrategyOption is None):
            xsDataDiffractionPlan.setStrategyOption(XSDataString(self.__strStrategyOption))
        if (not self.__strComplexity is None):
            xsDataDiffractionPlan.setComplexity(XSDataString(self.__strComplexity))
        _edPlugin.setDataInput(xsDataDiffractionPlan, "diffractionPlan")

        if (not self.__listImagePaths is None):
            for strImagePath in self.__listImagePaths:
                _edPlugin.setDataInput(XSDataString(strImagePath), "imagePaths")

        if (not self.__xsDataInputCharacterisation is None):
            _edPlugin.setDataInput(self.__xsDataInputCharacterisation, "inputCharacterisation")
        if (not self.__fFlux is None):
            _edPlugin.setDataInput(XSDataFloat(self.__fFlux), "flux")
        if (not self.__fMinExposureTimePerImage is None):
            _edPlugin.setDataInput(XSDataFloat(self.__fMinExposureTimePerImage), "minExposureTimePerImage")
        if (not self.__fBeamSize is None):
            _edPlugin.setDataInput(XSDataFloat(self.__fBeamSize), "beamSize")
        if (not self.__bTemplateMode is None):
            _edPlugin.setDataInput(XSDataBoolean(self.__bTemplateMode), "templateMode")
        if (not self.__strGeneratedTemplateFile is None):
            _edPlugin.setDataInput(XSDataString(self.__strGeneratedTemplateFile), "generatedTemplateFile")
        if (not self.__strResultsFilePath is None):
            _edPlugin.setDataInput(XSDataString(self.__strResultsFilePath), "resultsFilePath")
        if (not self.__fBeamPosX is None):
            _edPlugin.setDataInput(XSDataFloat(self.__fBeamPosX), "beamPosX")
        if (not self.__fBeamPosY is None):
            _edPlugin.setDataInput(XSDataFloat(self.__fBeamPosY), "beamPosY")
        if (not self.__iDataCollectionId is None):
            _edPlugin.setDataInput(XSDataInteger(self.__iDataCollectionId), "dataCollectionId")
        if (not self.__strShortComments is None):
            _edPlugin.setDataInput(XSDataString(self.__strShortComments), "shortComments")
        if (not self.__strComments is None):
            _edPlugin.setDataInput(XSDataString(self.__strComments), "comments")
        if (not self.__fTransmission is None):
            _edPlugin.setDataInput(XSDataDouble(self.__fTransmission), "transmission")
 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()
Exemple #24
0
	def buildChildren(self, child_, nodeName_):
		if child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'absorbedDose':
			obj_ = XSDataDouble()
			obj_.build(child_)
			self.setAbsorbedDose(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'absorbedDoseRate':
			obj_ = XSDataAbsorbedDoseRate()
			obj_.build(child_)
			self.setAbsorbedDoseRate(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'pathToLogFile':
			obj_ = XSDataFile()
			obj_.build(child_)
			self.setPathToLogFile(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'timeToReachHendersonLimit':
			obj_ = XSDataTime()
			obj_.build(child_)
			self.setTimeToReachHendersonLimit(obj_)
		XSDataResult.buildChildren(self, child_, nodeName_)
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsProcessOneFilev1_6.process")

        xsd = XSDataInputWaitFile(expectedFile=XSDataFile(XSDataString(self.rawImage)),
                                  expectedSize=self.rawImageSize,
                                  timeOut=XSDataTime(30))
        self.__edPluginWaitFile.setDataInput(xsd)
        self.__edPluginWaitFile.connectSUCCESS(self.doSuccessWaitFile)
        self.__edPluginWaitFile.connectFAILURE(self.doFailureWaitFile)
        self.__edPluginWaitFile.executeSynchronous()
        if self.isFailure():
            return

        self.xsDataResult.sample = self.sample
        self.xsDataResult.experimentSetup = self.experimentSetup

        res = self.integrate()
        self.write3ColumnAscii(res, self.integratedCurve)
        self.xsDataResult.dataQ = EDUtilsArray.arrayToXSData(res.radial)
        self.xsDataResult.dataI = EDUtilsArray.arrayToXSData(res.intensity)
        self.xsDataResult.dataStdErr = EDUtilsArray.arrayToXSData(res.sigma)
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")):
        xsDataInputInterface = XSDataInputInterface()
        xsDataDiffractionPlan = XSDataDiffractionPlan()
        xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(XSDataTime(EDParallelExecuteMXv1Characterisation.m_fMaxExposureTime))
        xsDataInputInterface.setDiffractionPlan(xsDataDiffractionPlan)
        xsDataFile = XSDataFile()
        xsDataFile.setPath(XSDataString(_strFilename))
        xsDataInputInterface.addImagePath(xsDataFile)
        strXML = xsDataInputInterface.marshal()
    else:
        EDVerbose.screen("File name not ending with .img or .mccd - ignored : %s" % _strFilename)
    return strXML
    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
Exemple #28
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()
Exemple #29
0
    def from_params(self, data_collection, char_params):
        edna_input = XSDataInputMXCuBE.parseString(self.edna_default_input)

        if data_collection.id:
            edna_input.setDataCollectionId(XSDataInteger(data_collection.id))

        #Beam object
        beam = edna_input.getExperimentalCondition().getBeam()

        try:
            transmission = self.collect_obj.get_transmission()
            beam.setTransmission(XSDataDouble(transmission))
        except AttributeError:
            pass

        try:
            wavelength = self.collect_obj.get_wavelength()
            beam.setWavelength(XSDataWavelength(wavelength))
        except AttributeError:
            pass

        try:
            beam.setFlux(XSDataFlux(self.collect_obj.get_measured_intensity()))
        except AttributeError:
            pass

        try:
            beamsize = self.get_beam_size()
            if not None in beamsize:
                beam.setSize(
                    XSDataSize(x=XSDataLength(float(beamsize[0])),
                               y=XSDataLength(float(beamsize[1]))))
        except AttributeError:
            pass

        #Optimization parameters
        diff_plan = edna_input.getDiffractionPlan()

        aimed_i_sigma = XSDataDouble(char_params.aimed_i_sigma)
        aimed_completness = XSDataDouble(char_params.aimed_completness)
        aimed_multiplicity = XSDataDouble(char_params.aimed_multiplicity)
        aimed_resolution = XSDataDouble(char_params.aimed_resolution)

        complexity = char_params.strategy_complexity
        complexity = XSDataString(qme.STRATEGY_COMPLEXITY[complexity])

        permitted_phi_start = XSDataAngle(char_params.permitted_phi_start)
        _range = char_params.permitted_phi_end - char_params.permitted_phi_start
        rotation_range = XSDataAngle(_range)

        diff_plan.setAimedIOverSigmaAtHighestResolution(aimed_i_sigma)
        diff_plan.setAimedCompleteness(aimed_completness)

        if char_params.use_aimed_multiplicity:
            diff_plan.setAimedMultiplicity(aimed_multiplicity)

        if char_params.use_aimed_resolution:
            diff_plan.setAimedResolution(aimed_resolution)

        diff_plan.setComplexity(complexity)

        if char_params.use_permitted_rotation:
            diff_plan.setUserDefinedRotationStart(permitted_phi_start)
            diff_plan.setUserDefinedRotationRange(rotation_range)

        #Vertical crystal dimension
        sample = edna_input.getSample()
        sample.getSize().setY(XSDataLength(char_params.max_crystal_vdim))
        sample.getSize().setZ(XSDataLength(char_params.min_crystal_vdim))

        #Radiation damage model
        sample.setSusceptibility(XSDataDouble(char_params.rad_suscept))
        sample.setChemicalComposition(None)
        sample.setRadiationDamageModelBeta(XSDataDouble(char_params.beta /
                                                        1e6))
        sample.setRadiationDamageModelGamma(
            XSDataDouble(char_params.gamma / 1e6))

        diff_plan.setForcedSpaceGroup(XSDataString(char_params.space_group))

        # Characterisation type - Routine DC
        if char_params.use_min_dose:
            pass

        if char_params.use_min_time:
            time = XSDataTime(char_params.min_time)
            diff_plan.setMaxExposureTimePerDataCollection(time)

        # Account for radiation damage
        if char_params.induce_burn:
            diff_plan.setStrategyOption(XSDataString("-DamPar"))
        else:
            diff_plan.setStrategyOption(None)

        # Characterisation type - SAD
        if char_params.opt_sad:
            diff_plan.setAnomalousData(XSDataBoolean(True))
        else:
            diff_plan.setAnomalousData(XSDataBoolean(False))

        #Data set
        data_set = XSDataMXCuBEDataSet()
        acquisition_parameters = data_collection.acquisitions[
            0].acquisition_parameters
        path_template = data_collection.acquisitions[0].path_template
        path_str = os.path.join(path_template.directory,
                                path_template.get_image_file_name())

        for img_num in range(int(acquisition_parameters.num_images)):
            image_file = XSDataFile()
            path = XSDataString()
            path.setValue(path_str % (img_num + 1))
            image_file.setPath(path)
            data_set.addImageFile(image_file)

        edna_input.addDataSet(data_set)
        edna_input.process_directory = path_template.process_directory

        return edna_input
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        self.DEBUG("EDPluginExecReadImageHeaderEiger4Mv10.process")
        xsDataInputReadImageHeader = self.getDataInput()
        xsDataFile = xsDataInputReadImageHeader.getImage()
        strPath = xsDataFile.getPath().getValue()
        dictEiger4MHeader = self.readHeaderEiger4M(strPath)
        if (dictEiger4MHeader is None):
            strErrorMessage = "EDPluginExecReadImageHeaderEiger4Mv10.process : Cannot read header : %s" % strPath
            self.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
        else:
            xsDataExperimentalCondition = XSDataExperimentalCondition()
            xsDataDetector = XSDataDetector()

            iNoPixelsX = 2070
            iNoPixelsY = 2167
            xsDataDetector.setNumberPixelX(XSDataInteger(iNoPixelsX))
            xsDataDetector.setNumberPixelY(XSDataInteger(iNoPixelsY))
            # Pixel size
            listPixelSizeXY = dictEiger4MHeader[ "Pixel_size"   ].split(" ")
            fPixelSizeX = float(listPixelSizeXY[0]) * 1000
            xsDataDetector.setPixelSizeX(XSDataLength(fPixelSizeX))
            fPixelSizeY = float(listPixelSizeXY[3]) * 1000
            xsDataDetector.setPixelSizeY(XSDataLength(fPixelSizeY))
            # Beam position
            listBeamPosition = dictEiger4MHeader["Beam_xy"].replace("(", " ").replace(")", " ").replace(",", " ").split()
            fBeamPositionX = float(listBeamPosition[1]) * fPixelSizeX
            fBeamPositionY = float(listBeamPosition[0]) * fPixelSizeY
            xsDataDetector.setBeamPositionX(XSDataLength(fBeamPositionX))
            xsDataDetector.setBeamPositionY(XSDataLength(fBeamPositionY))
            fDistance = float(dictEiger4MHeader[ "Detector_distance" ].split(" ")[0]) * 1000
            xsDataDetector.setDistance(XSDataLength(fDistance))
#            xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictEiger4MHeader[ "header_size"   ])))
            xsDataDetector.setSerialNumber(XSDataString(dictEiger4MHeader[ "Detector:"   ]))
#            #xsDataDetector.setBin(                 XSDataString(   dictEiger4MHeader[ "BIN" ] ) ) )
#            #xsDataDetector.setDataType(            XSDataString(   dictEiger4MHeader[ "TYPE" ] ) ) )
#            #xsDataDetector.setByteOrder(           XSDataString(   dictEiger4MHeader[ "BYTE_ORDER" ] ) ) )
#            xsDataDetector.setImageSaturation(XSDataInteger(int(dictEiger4MHeader[ "saturation_level" ])))
            xsDataDetector.setName(XSDataString("EIGER 4M"))
            xsDataDetector.setType(XSDataString("eiger4m"))
            xsDataExperimentalCondition.setDetector(xsDataDetector)

            # Beam object

            xsDataBeam = XSDataBeam()
            xsDataBeam.setWavelength(XSDataWavelength(float(dictEiger4MHeader[ "Wavelength" ].split(" ")[0])))
            xsDataBeam.setExposureTime(XSDataTime(float(dictEiger4MHeader[ "Exposure_time" ].split(" ")[0])))
            xsDataExperimentalCondition.setBeam(xsDataBeam)

            # Goniostat object
            xsDataGoniostat = XSDataGoniostat()
            fRotationAxisStart = float(dictEiger4MHeader[ "Start_angle" ].split(" ")[0])
            fOscillationWidth = float(dictEiger4MHeader[ "Angle_increment" ].split(" ")[0])
            xsDataGoniostat.setRotationAxisStart(XSDataAngle(fRotationAxisStart))
            xsDataGoniostat.setRotationAxisEnd(XSDataAngle(fRotationAxisStart + fOscillationWidth))
            xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth))
            xsDataExperimentalCondition.setGoniostat(xsDataGoniostat)
#
            # Create the image object
            xsDataImage = XSDataImage()
            xsDataImage.setPath(XSDataString(strPath))
            if "DateTime" in dictEiger4MHeader:
                strTimeStamp = dictEiger4MHeader[ "DateTime" ]
                xsDataImage.setDate(XSDataString(strTimeStamp))
            iImageNumber = EDUtilsImage.getImageNumber(strPath)
            xsDataImage.setNumber(XSDataInteger(iImageNumber))

            xsDataSubWedge = XSDataSubWedge()
            xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
            xsDataSubWedge.addImage(xsDataImage)

            self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader()
            self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)