Example #1
0
 def doFailureIndexingIndicators(self, _edPlugin=None):
     self.DEBUG(
         "EDPluginControlCharacterisationv1_4.doFailureIndexingIndicators")
     # If more than two reference images try to index with MOSFLM:
     if self._edPluginControlIndexingIndicators.hasDataOutput(
             "indicatorsShortSummary"):
         indicatorsShortSummary = self._edPluginControlIndexingIndicators.getDataOutput(
             "indicatorsShortSummary")[0].getValue()
         self._strCharacterisationShortSummary += indicatorsShortSummary
         self.sendMessageToMXCuBE(indicatorsShortSummary)
     if self._iNoImagesWithDozorScore > 0:
         if not self._bDoOnlyMoslmfIndexing:
             strWarningMessage = "Execution of Indexing and Indicators plugin failed - trying to index with MOSFLM."
             self.WARNING(strWarningMessage)
             self.sendMessageToMXCuBE(strWarningMessage, "warning")
             self.addWarningMessage(strWarningMessage)
         xsDataIndexingInput = XSDataIndexingInput()
         xsDataIndexingInput.dataCollection = self._xsDataCollection
         xsDataIndexingInput.experimentalCondition = self._xsDataCollection.subWedge[
             0].experimentalCondition
         xsDataIndexingInput.crystal = self._xsDataCrystal
         self._edPluginControlIndexingMOSFLM.dataInput = xsDataIndexingInput
         self.executePluginSynchronous(self._edPluginControlIndexingMOSFLM)
     else:
         strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
         self.ERROR(strErrorMessage)
         self.sendMessageToMXCuBE(strErrorMessage, "error")
         self.addErrorMessage(strErrorMessage)
         self.generateExecutiveSummary(self)
         if self._xsDataResultCharacterisation is not None:
             self.setDataOutput(self._xsDataResultCharacterisation)
         self.setFailure()
         if self._strStatusMessage != None:
             self.setDataOutput(XSDataString(self._strStatusMessage),
                                "statusMessage")
             self.writeDataOutput()
Example #2
0
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
Example #3
0
 def doFailureExecAutoRg(self, _edPlugin=None):
     self.DEBUG("EDPluginAutoSubv1_1.doFailureExecAutoRg")
     self.retrieveFailureMessages(
         _edPlugin, "EDPluginAutoSubv1_1.doFailureExecAutoRg")
     self.lstProcessLog.append("Failure in AutoRg")
     if len(_edPlugin.dataInput.inputCurve) == 2:
         # we were comparing 2 buffers but were analyzed by AutoRg
         for fn in self.buffers:
             self.dictRg[fn] = (0, numpy.loadtxt(fn, unpack=True)[1].sum())
     elif os.path.exists(self.subtractedCurve):
         #we don't want to fail the subtraction plugin because the result has no Rg - default to 0
         res = XSDataAutoRg()
         res.rg = XSDataLength(0.0)
         res.rgStdev = XSDataLength(0.0)
         res.i0 = XSDataDouble(0.0)
         res.i0Stdev = XSDataDouble(0.0)
         res.firstPointUsed = XSDataInteger(0)
         res.lastPointUsed = XSDataInteger(0)
         res.quality = XSDataDouble(0.0)
         res.isagregated = XSDataDouble(bool(0))
         res.filename = XSDataFile(XSDataString(self.subtractedCurve))
         self.xsDataResult.autoRg = res
     else:
         self.setFailure()
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginBioSaxsProcessOneFilev1_4.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

        q, I, std = self.integrate()
        I = self.normalize(I)
        std = self.normalize(std)
        self.write3ColumnAscii(q, I, std, self.integratedCurve)
        self.xsDataResult.dataQ = EDUtilsArray.arrayToXSData(q)
        self.xsDataResult.dataI = EDUtilsArray.arrayToXSData(I)
        self.xsDataResult.dataStdErr = EDUtilsArray.arrayToXSData(std)
Example #5
0
 def postProcess(self, _edObject=None):
     EDPluginExecProcessScript.postProcess(self)
     self.DEBUG("EDPluginExecDatGnomv1_1.postProcess")
     # Create some output data
     cwd = self.getWorkingDirectory()
     outfile = os.path.join(cwd, os.path.basename(self.outFile))
     if not os.path.isfile(outfile):
         self.error(
             "EDPluginExecDatGnomv1_1 did not produce output file %s as expected !"
             % self.outFile)
         self.setFailure()
         self.dataOutput = XSDataResultDatGnom()
         return
     try:
         os.rename(outfile, self.outFile)
     except OSError:  # may fail if src and dst on different filesystem
         shutil.copy(outfile, self.outFile)
     gnom = XSDataGnom(gnomFile=XSDataFile(XSDataString(self.outFile)))
     logfile = os.path.join(self.getWorkingDirectory(),
                            self.getScriptLogFileName())
     out = open(logfile, "r").read().split()
     for key, val, typ in (("dmax:", "dmax", XSDataLength),
                           ("Guinier:", "rgGuinier", XSDataLength),
                           ("Gnom:", "rgGnom", XSDataLength),
                           ("Total:", "total", XSDataDouble)):
         if key in out:
             idx = out.index(key)
             res = out[idx + 1]
             gnom.__setattr__(val, typ(float(res)))
         else:
             self.error(
                 "EDPluginExecDatGnomv1_1.postProcess No key %s in file %s"
                 % (key, logfile))
             self.setFailure()
     self.dataOutput = XSDataResultDatGnom(gnom=gnom)
     self.dataOutput.status = XSDataStatus(message=self.getXSDataMessage())
    def postProcess(self, _edObject=None):
        EDPluginControl.postProcess(self)
        self.DEBUG("EDPluginControlSaxsAnalysisv1_0.postProcess")
        # Create some output data
        strLog = """Rg   =   %.2f +/- %2f
I(0) =   %.2e +/- %.2e
Points   %i to %i
Quality: %4.2f%%     Aggregated: %s""" % (
            self.autoRg.rg.value, self.autoRg.rgStdev.value,
            self.autoRg.i0.value, self.autoRg.i0Stdev.value,
            self.autoRg.firstPointUsed.value, self.autoRg.lastPointUsed.value,
            self.autoRg.quality.value * 100., self.autoRg.isagregated.value)
        if self.gnom is None:
            strLog += """
datGnom failed"""
        else:
            strLog += """
Dmax    =    %12.2f       Total =   %12.2f
Guinier =    %12.2f       Gnom =    %12.2f""" % (
                self.gnom.dmax.value, self.gnom.total.value,
                self.gnom.rgGuinier.value, self.gnom.rgGnom.value)
        if self.xVolume is None:
            strLog += """
datPorod failed"""
        else:
            strLog += """
Volume  =    %12.2f""" % (self.xVolume.value)

        self.xsDataResult.autoRg = self.autoRg
        self.xsDataResult.gnom = self.gnom
        self.xsDataResult.volume = self.xVolume
        self.xsDataResult.rti = self.rti
        self.xsDataResult.status = XSDataStatus(
            executiveSummary=XSDataString(strLog),
            message=self.getXSDataMessage())
        self.setDataOutput(self.xsDataResult)
Example #7
0
    def getXSDataInputFIT2DCake(self, _xsDataInputPowderIntegration):
        """
        """

        xsDataInputFIT2DCake = XSDataInputFIT2DCake()

        imageFile = _xsDataInputPowderIntegration.getImageFile()
        instrumentParameters = _xsDataInputPowderIntegration.getInstrumentParameters()
        imageParameters = _xsDataInputPowderIntegration.getImageParameters()

        xsDataInputFIT2DCake.setInputFile(imageFile)

        xsDataInputFIT2DCake.setWavelength(instrumentParameters.get_diffrn_radiation_wavelength())
        xsDataInputFIT2DCake.setSampleToDetectorDistance(instrumentParameters.get_pd_instr_dist_spec_detc())

        xsDataInputFIT2DCake.setAngleOfTilt(imageParameters.get_pd_instr_special_details_tilt_angle())
        xsDataInputFIT2DCake.setTiltRotation(imageParameters.get_pd_instr_special_details_tilt_rotation())

        xsDataInputFIT2DCake.setDarkCurrentImageFile(imageParameters.get_file_correction_image_dark_current())
        xsDataInputFIT2DCake.setFlatFieldImageFile(imageParameters.get_file_correction_image_flat_field())
        xsDataInputFIT2DCake.setSpatialDistortionFile(imageParameters.get_file_correction_spline_spatial_distortion())

        fBeamCentreInMillimetersX = imageParameters.get_diffrn_detector_element_center_1().getValue()
        fBeamCentreInMillimetersY = imageParameters.get_diffrn_detector_element_center_2().getValue()
        fPixelSizeInMetersX = imageParameters.get_array_element_size_1().getValue()
        fPixelSizeInMetersY = imageParameters.get_array_element_size_2().getValue()
        xsDataInputFIT2DCake.setBeamCentreInPixelsX(XSDataLength(fBeamCentreInMillimetersX / fPixelSizeInMetersX / 1000))
        xsDataInputFIT2DCake.setBeamCentreInPixelsY(XSDataLength(fBeamCentreInMillimetersY / fPixelSizeInMetersX / 1000))
        xsDataInputFIT2DCake.setPixelSizeX(XSDataLength(fPixelSizeInMetersX * 1000))
        xsDataInputFIT2DCake.setPixelSizeY(XSDataLength(fPixelSizeInMetersY * 1000))

        xsDataInputFIT2DCake.setBufferSizeX(XSDataInteger(2048))
        xsDataInputFIT2DCake.setBufferSizeY(XSDataInteger(2048))
        xsDataInputFIT2DCake.setOutputFileType(XSDataString("CHIPLOT"))

        return xsDataInputFIT2DCake
Example #8
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 getXSDataMOSFLMDetector(_xsDataDetector):
     """
     Translates an XSDataDetector object to XSDataMOSFLMv10.
     """
     EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
     from XSDataMOSFLMv10 import XSDataMOSFLMDetector
     xsDataMOSFLMDetector = XSDataMOSFLMDetector()
     strDetectorType = _xsDataDetector.getType().getValue()
     if (strDetectorType == "q4") or \
          (strDetectorType == "q4-2x") or \
          (strDetectorType == "q210") or \
          (strDetectorType == "q210-2x") or \
          (strDetectorType == "q315") or \
          (strDetectorType == "q315-2x"):
         xsDataMOSFLMDetector.setType(XSDataString("ADSC"))
     elif (strDetectorType == "mar165") or \
            (strDetectorType == "mar225"):
         xsDataMOSFLMDetector.setType(XSDataString("MARCCD"))
     elif (strDetectorType == "pilatus6m"
           or strDetectorType == "pilatus2m"):
         xsDataMOSFLMDetector.setType(XSDataString("PILATUS"))
     elif strDetectorType.startswith("eiger2"):
         xsDataMOSFLMDetector.setType(XSDataString("EIGER2"))
     elif strDetectorType.startswith("eiger"):
         xsDataMOSFLMDetector.setType(XSDataString("EIGER"))
     elif (strDetectorType == "raxis4"):
         xsDataMOSFLMDetector.setType(XSDataString("RAXISIV"))
     else:
         # This is a temporary solution for the exception problem pointed out in bug #43.
         # Instead of raising an exception with a known type we send the error message as a string.
         strErrorMessage = "EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector: Unknown detector type : " + strDetectorType
         raise BaseException(strErrorMessage)
     if (_xsDataDetector.getNumberPixelX() is not None):
         xsDataMOSFLMDetector.setNumberPixelX(
             _xsDataDetector.getNumberPixelX())
     if (_xsDataDetector.getNumberPixelY() is not None):
         xsDataMOSFLMDetector.setNumberPixelY(
             _xsDataDetector.getNumberPixelY())
     if (_xsDataDetector.getPixelSizeX() is not None):
         xsDataMOSFLMDetector.setPixelSizeX(_xsDataDetector.getPixelSizeX())
     if (_xsDataDetector.getPixelSizeY() is not None):
         xsDataMOSFLMDetector.setPixelSizeY(_xsDataDetector.getPixelSizeY())
     return xsDataMOSFLMDetector
Example #10
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'geomFile':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setGeomFile(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'cellFile':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setCellFile(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'imagesFullPath':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setImagesFullPath(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'pointGroup':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setPointGroup(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'spaceGroup':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setSpaceGroup(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'resCutOff':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setResCutOff(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'baseFileName':
         obj_ = XSDataString()
         obj_.build(child_)
         self.setBaseFileName(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
Example #11
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginAutoSubv1_0.process")

        basename = os.path.splitext(os.path.basename(self.sampleCurve))[0]
        self.bestBuffer = os.path.join(self.outdir,
                                       "%s_bestbuffer.dat" % basename)
        self.averBuffer = os.path.join(self.outdir,
                                       "%s_averbuffer.dat" % basename)
        for idx, name in enumerate(self.buffers):
            copy(name,
                 os.path.join(self.outdir, "%s_buf%i.dat" % (basename, idx)))
        if len(self.buffers) == 1:
            self.actualBestBuffer = self.buffers[0]
        else:
            self.__edPluginDataver.dataInput = XSDataInputDataver(
                inputCurve=self.dataInput.buffers,
                outputCurve=XSDataFile(XSDataString(self.averBuffer)))
            self.__edPluginDataver.connectSUCCESS(self.doSuccessExecDataver)
            self.__edPluginDataver.connectFAILURE(self.doFailureExecDataver)
            self.__edPluginDataver.execute()

            if len(self.buffers) == 2:
                edPluginDatcmp = self.loadPlugin(self.__strPluginDatcmp)
                edPluginDatcmp.dataInput = XSDataInputDatcmp(
                    inputCurve=self.dataInput.buffers)
                edPluginDatcmp.connectSUCCESS(self.doSuccessExecDatcmp)
                edPluginDatcmp.connectFAILURE(self.doFailureExecDatcmp)
                edPluginDatcmp.executeSynchronous()
                if self.isFailure() or (self.fidelity is None):
                    return
                if self.fidelity < self.BUFFER_SIMILARITY:  #buffer are not the same: keeping the one with lowest Rg/I0
                    edpluginRg = self.loadPlugin(self.__strPluginAutoRg)
                    edpluginRg.dataInput = XSDataInputAutoRg(
                        inputCurve=self.dataInput.buffers)
                    edpluginRg.connectSUCCESS(self.doSuccessExecAutoRg)
                    edpluginRg.connectFAILURE(self.doFailureExecAutoRg)
                    edpluginRg.executeSynchronous()
                    self.actualBestBuffer = self.dictRg.keys()[
                        self.dictRg.values().index(min(self.dictRg.values()))]
                else:
                    self.actualBestBuffer = self.averBuffer
            else:
                self.synchronizePlugins()
                strError = "You should specify exactly 2 buffers for guessing best buffer, I got: " + ", ".join(
                    self.buffers)
                self.WARNING(strError)
                self.lstProcessLog.append(strError)
                self.actualBestBuffer = self.averBuffer

        copy(self.actualBestBuffer, self.bestBuffer)
        self.lstProcessLog.append("Best buffer is %s" % self.actualBestBuffer)
        if self.isFailure() or not os.path.exists(
                self.bestBuffer) or not os.path.exists(self.sampleCurve):
            return
        edPluginDatop = self.loadPlugin(self.__strPluginDatop)
        edPluginDatop.dataInput = XSDataInputDatop(
            operation=XSDataString("SUB"),
            outputCurve=XSDataFile(XSDataString(self.subtractedCurve)),
            inputCurve=[
                XSDataFile(XSDataString(self.sampleCurve)),
                XSDataFile(XSDataString(self.bestBuffer))
            ])
        edPluginDatop.connectSUCCESS(self.doSuccessExecDatop)
        edPluginDatop.connectFAILURE(self.doFailureExecDatop)
        edPluginDatop.executeSynchronous()

        if self.isFailure() or not os.path.exists(self.subtractedCurve):
            return
        self.headers = self.parseHeaders(self.sampleCurve)
        edpluginRg = self.loadPlugin(self.__strPluginAutoRg)
        edpluginRg.dataInput = XSDataInputAutoRg(
            inputCurve=[XSDataFile(XSDataString(self.subtractedCurve))])
        edpluginRg.connectSUCCESS(self.doSuccessExecAutoRg)
        edpluginRg.connectFAILURE(self.doFailureExecAutoRg)
        edpluginRg.executeSynchronous()
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        EDVerbose.DEBUG("*** EDPluginExecReadImageHeaderADSCv10.process")
        xsDataInputReadImageHeader = self.getDataInput()
        xsDataFile = xsDataInputReadImageHeader.getImage()
        strPath = xsDataFile.getPath().getValue()
        strAbsolutePath = os.path.abspath(strPath)
        dictHeader = self.readHeaderADSC(strPath)
        if (dictHeader is None):
            strErrorMessage = "EDPluginExecReadImageHeaderADSCv10.process : error when reading header from %s" % strAbsolutePath
            EDVerbose.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
        else:
            xsDataExperimentalCondition = XSDataExperimentalCondition()
            xsDataDetector = XSDataDetector()

            xsDataDetector.setBeamPositionX(XSDataLength(float(dictHeader[ "BEAM_CENTER_X" ])))
            xsDataDetector.setBeamPositionY(XSDataLength(float(dictHeader[ "BEAM_CENTER_Y" ])))
            xsDataDetector.setDistance(XSDataLength(float(dictHeader[ "DISTANCE"   ])))
            fPixelSize = float(dictHeader[ "PIXEL_SIZE"   ])
            xsDataDetector.setPixelSizeX(XSDataLength(fPixelSize))
            xsDataDetector.setPixelSizeY(XSDataLength(fPixelSize))
            if "TWOTHETA" in dictHeader.keys():
                xsDataDetector.setTwoTheta(XSDataAngle(float(dictHeader[ "TWOTHETA"   ])))
            xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictHeader[ "HEADER_BYTES"   ])))
            xsDataDetector.setSerialNumber(XSDataString(dictHeader[ "DETECTOR_SN"   ]))
            xsDataDetector.setNumberPixelX(XSDataInteger(int(dictHeader[ "SIZE1"   ])))
            xsDataDetector.setNumberPixelY(XSDataInteger(int(dictHeader[ "SIZE2"   ])))
            xsDataDetector.setBin(XSDataString(dictHeader[ "BIN" ]))
            xsDataDetector.setDataType(XSDataString(dictHeader[ "TYPE" ]))
            xsDataDetector.setByteOrder(XSDataString(dictHeader[ "BYTE_ORDER" ]))
            if "CCD_IMAGE_SATURATION" in dictHeader.keys():
                xsDataDetector.setImageSaturation(XSDataInteger(int(dictHeader[ "CCD_IMAGE_SATURATION" ])))

            # Determine type of detector...
            iNoPixelsX = xsDataDetector.getNumberPixelX().getValue()
            iNoPixelsY = xsDataDetector.getNumberPixelY().getValue()
            if (iNoPixelsX == 2304 and iNoPixelsY == 2304):
                xsDataDetector.setName(XSDataString("ADSC Q4"))
                xsDataDetector.setType(XSDataString("q4"))
            elif (iNoPixelsX == 1152 and iNoPixelsY == 1152):
                xsDataDetector.setName(XSDataString("ADSC Q4 bin 2x2"))
                xsDataDetector.setType(XSDataString("q4-2x"))
            elif (iNoPixelsX == 4096 and iNoPixelsY == 4096):
                xsDataDetector.setName(XSDataString("ADSC Q210"))
                xsDataDetector.setType(XSDataString("q210"))
            elif (iNoPixelsX == 2048 and iNoPixelsY == 2048):
                xsDataDetector.setName(XSDataString("ADSC Q210 bin 2x2"))
                xsDataDetector.setType(XSDataString("q210-2x"))
            elif (iNoPixelsX == 6144 and iNoPixelsY == 6144):
                xsDataDetector.setName(XSDataString("ADSC Q315"))
                xsDataDetector.setType(XSDataString("q315"))
            elif (iNoPixelsX == 3072 and iNoPixelsY == 3072):
                xsDataDetector.setName(XSDataString("ADSC Q315 bin 2x2"))
                xsDataDetector.setType(XSDataString("q315-2x"))
            else:
                strErrorMessage = EDMessage.ERROR_DATA_HANDLER_02 % ("EDPluginExecReadImageHeaderADSCv10.process", "Unknown detector type")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

            xsDataExperimentalCondition.setDetector(xsDataDetector)

            # Beam object

            xsDataBeam = XSDataBeam()
            xsDataBeam.setWavelength(XSDataWavelength(float(dictHeader[ "WAVELENGTH" ])))
            xsDataBeam.setExposureTime(XSDataTime(float(dictHeader[ "TIME" ])))
            xsDataExperimentalCondition.setBeam(xsDataBeam)

            # Goniostat object
            xsDataGoniostat = XSDataGoniostat()
            fRotationAxisStart = float(dictHeader[ "OSC_START" ])
            fOscillationWidth = float(dictHeader[ "OSC_RANGE" ])
            xsDataGoniostat.setRotationAxisStart(XSDataAngle(fRotationAxisStart))
            xsDataGoniostat.setRotationAxisEnd(XSDataAngle(fRotationAxisStart + fOscillationWidth))
            xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth))
            strRotationAxis = None
            if ("AXIS" in dictHeader.keys()):
                strRotationAxis = dictHeader[ "AXIS" ]
            elif ("OSC_AXIS" in dictHeader.keys()):
                strRotationAxis = dictHeader[ "OSC_AXIS" ]
            else:
                strErrorMessage = "EDPluginExecReadImageHeaderADSCv10.process : Neither AXIS nor OSC_AXIS header item found."
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
            xsDataGoniostat.setRotationAxis(XSDataString(strRotationAxis))
            xsDataExperimentalCondition.setGoniostat(xsDataGoniostat)

            # Create the image object
            xsDataImage = XSDataImage()
            xsDataImage.setPath(XSDataString(strAbsolutePath))
            xsDataImage.setDate(XSDataString(dictHeader[ "DATE" ]))
            strFileName = os.path.basename(strPath)
            iImageNumber = EDUtilsImage.getImageNumber(strFileName)
            xsDataImage.setNumber(XSDataInteger(iImageNumber))

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

            self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader()
            self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)
Example #13
0
    def doSuccessExecMeasureOffset(self, _edPlugin=None):
        with self.semMeasure:
            self.DEBUG(
                "EDPluginControlAlignStackv1_0.doSuccessExecMeasureOffset")
            self.retrieveSuccessMessages(
                _edPlugin,
                "EDPluginControlAlignStackv1_0.doSuccessExecMeasureOffset")
            listIndex = [i.getValue() for i in _edPlugin.dataInput.index]
            listIndex.sort()
            dataOutput = _edPlugin.dataOutput
            if self.bAlwaysMOvsRef:
                if min(listIndex) < EDPluginControlAlignStackv1_0.__iRefFrame:
                    iToShift, iRef = tuple(listIndex)
                    EDPluginControlAlignStackv1_0.__dictAbsShift[
                        iToShift] = tuple(
                            [-i.getValue() for i in dataOutput.getOffset()])
                else:
                    iRef, iToShift = tuple(listIndex)
                    EDPluginControlAlignStackv1_0.__dictAbsShift[
                        iToShift] = tuple(
                            [i.getValue() for i in dataOutput.getOffset()])
                self.screen(
                    "Frame number %i has absolute offset of %.3f,%.3f" %
                    (iToShift,
                     EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift][0],
                     EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift][1])
                )
                edPluginExecShift = self.loadPlugin(
                    self.__strControlledPluginShift)
                xsdata = XSDataInputShiftImage(
                    index=XSDataInteger(iToShift),
                    offset=[
                        XSDataDouble(i) for i in
                        EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift]
                    ],
                    inputImage=self.getFrameRef(iToShift),
                    outputImage=XSDataImageExt(
                        shared=XSDataString("Shifted-%06i" % iToShift)))
                edPluginExecShift.setDataInput(xsdata)
                edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage)
                edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage)
                self.queue.put(edPluginExecShift)
            else:
                if min(listIndex) < EDPluginControlAlignStackv1_0.__iRefFrame:

                    iToShift, iRef = tuple(listIndex)
                    EDPluginControlAlignStackv1_0.__dictRelShift[
                        iToShift] = tuple(
                            [-i.value for i in dataOutput.offset])
                else:
                    iRef, iToShift = tuple(listIndex)
                    EDPluginControlAlignStackv1_0.__dictRelShift[
                        iToShift] = tuple([i.value for i in dataOutput.offset])
                self.screen(
                    "Frame number %i has relative offset of %.3f,%.3f" %
                    (iToShift,
                     EDPluginControlAlignStackv1_0.__dictRelShift[iToShift][0],
                     EDPluginControlAlignStackv1_0.__dictRelShift[iToShift][1])
                )

                xsdata = XSDataInputAccumulator(
                    item=[XSDataString("shift %04i" % iToShift)])
                edPluginExecAccumulator = self.loadPlugin(
                    self.__strControlledPluginAccumulator)
                edPluginExecAccumulator.setDataInput(xsdata)
                edPluginExecAccumulator.connectSUCCESS(
                    self.doSuccessExecAccumultor)
                edPluginExecAccumulator.connectFAILURE(
                    self.doFailureExecAccumulator)
                self.queue.put(edPluginExecAccumulator)
Example #14
0
    def create_autoproc_input(self, event, params):
        """Creates processing input xml

        :param event: processing type (after, before, image)
        :type event: str
        :param params: collection parameters
        :type params: dict
        """
        xds_input_file_wait_timeout = 20
        xds_input_file_wait_resolution = 1

        file_name_timestamp = time.strftime("%Y%m%d_%H%M%S")

        autoproc_path = params.get("xds_dir")
        autoproc_xds_filename = os.path.join(autoproc_path, "XDS.INP")
        autoproc_input_filename = os.path.join(\
            autoproc_path,
            "edna-autoproc-input-%s.xml" % \
            file_name_timestamp)
        autoproc_output_file_name = os.path.join(\
            autoproc_path,
            "edna-autoproc-results-%s.xml" % \
            file_name_timestamp)

        autoproc_input = XSDataAutoprocInput()
        autoproc_xds_file = XSDataFile()
        autoproc_xds_file.setPath(XSDataString(autoproc_xds_filename))
        autoproc_input.setInput_file(autoproc_xds_file)

        autoproc_output_file = XSDataFile()
        autoproc_output_file.setPath(XSDataString(autoproc_output_file_name))
        autoproc_input.setOutput_file(autoproc_output_file)

        autoproc_input.setData_collection_id(\
            XSDataInteger(params.get("collection_id")))
        residues_num = float(params.get("residues", 0))
        if residues_num != 0:
            autoproc_input.setNres(XSDataDouble(residues_num))
        space_group = params.get("sample_reference").get("spacegroup", "")
        if len(space_group) > 0:
            autoproc_input.setSpacegroup(XSDataString(space_group))
        unit_cell = params.get("sample_reference").get("cell", "")
        if len(unit_cell) > 0:
            autoproc_input.setUnit_cell(XSDataString(unit_cell))

        autoproc_input.setCc_half_cutoff(XSDataDouble(18.0))

        #Maybe we have to check if directory is there.
        #Maybe create dir with mxcube
        xds_appeared = False
        wait_xds_start = time.time()
        logging.debug("EMBLAutoprocessing: Waiting for XDS.INP " +\
                      "file: %s" % autoproc_xds_filename)
        while not xds_appeared and time.time(
        ) - wait_xds_start < xds_input_file_wait_timeout:
            if os.path.exists(autoproc_xds_filename) and \
               os.stat(autoproc_xds_filename).st_size > 0:
                xds_appeared = True
                logging.debug('EMBLAutoprocessing: XDS.INP file is there, size={0}'.\
                        format(os.stat(autoproc_xds_filename).st_size))
            else:
                os.system("ls %s> /dev/null" %
                          (os.path.dirname(autoproc_path)))
                gevent.sleep(xds_input_file_wait_resolution)
        if not xds_appeared:
            logging.error("EMBLAutoprocessing: XDS.INP file ({0}) failed " +\
                          "to appear after {1} seconds".\
                    format(autoproc_xds_filename, xds_input_file_wait_timeout))
            return None, False

        autoproc_input.exportToFile(autoproc_input_filename)

        return autoproc_input_filename, True
Example #15
0
            yappi = None
        else:
            yappi.start()
    else:
        yappi = None
    if options.verbose:
        reprocess.setVerboseDebugOn()

    keys = [ os.path.abspath(onefile) for onefile in args if os.path.exists(onefile)]
    keys.sort()
    working_dir = "analyse-modeling-%s" % time.strftime("%Y%m%d-%H%M%S")
    base_dir = os.getcwd()
    os.makedirs(working_dir)
    os.chdir(working_dir)
    for run in keys:
        xsd = XSDataInputSaxsAnalysisModeling(scatterCurve=XSDataFile(XSDataString(run)), graphFormat=XSDataString("png"))
        reprocess.startJob(xsd)

    print("All %i jobs queued after %.3fs" % (len(args), time.time() - reprocess.startTime))
    reprocess.join()
    if yappi: yappi.stop()
    print("All %i jobs processed after %.3fs" % (len(args), time.time() - reprocess.startTime))
    print reprocess.statistics()
    if yappi:
        stat = yappi.get_stats(sort_type=yappi.SORTTYPE_TTOT)
        res = {}
        for i in stat.func_stats:
            if i[0] in res:
                res[i[0]][0] += i[1]
                res[i[0]][1] += i[2]
            else:
Example #16
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
Example #17
0
 def process(self, _edObject=None):
     EDPluginControl.process(self)
     self.DEBUG("EDPluginBioSaxsFlushHPLCv1_1.process")
     if self.runId in EDPluginBioSaxsHPLCv1_1.dictHPLC:
         self.processRun(EDPluginBioSaxsHPLCv1_1.dictHPLC[self.runId])
         edpluginIsPyB = self.loadPlugin(self.strControlledPluginISPyB)
         edpluginIsPyB.dataInput=XSDataInputBioSaxsISPyB_HPLCv1_0(sample=self.dataInput.sample,
                                                                  hdf5File=self.xsDataResult.hplcFile,
                                                                  jsonFile=XSDataFile(XSDataString(self.json)),
                                                                  hplcPlot=self.xsDataResult.hplcImage)
         edpluginIsPyB.executeSynchronous()
    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)
Example #19
0
 def finallyProcess(self, _edObject=None):
     EDPluginControl.finallyProcess(self)
     executiveSummary = os.linesep.join(self.lstExecutiveSummary)
     self.xsDataResult.status = XSDataStatus(executiveSummary=XSDataString(executiveSummary))
     self.dataOutput = self.xsDataResult
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess")
     # Check that the input image exists and is of the expected type
     strPathToDiffractionImage = self.dataInput.diffractionImage.path.value
     strImageFileNameExtension = os.path.splitext(
         strPathToDiffractionImage)[1]
     if not strImageFileNameExtension in [
             ".img", ".marccd", ".mccd", ".cbf", ".h5"
     ]:
         self.error(
             "Unknown image file name extension for pyarch thumbnail generator: %s"
             % strPathToDiffractionImage)
         self.setFailure()
     else:
         # Load the MXWaitFile plugin
         xsDataInputMXWaitFile = XSDataInputMXWaitFile()
         pathToImageFile = strPathToDiffractionImage
         # Quite ugly hack to avoid lag problems at the ESRF:
         if EDUtilsPath.isESRF() or EDUtilsPath.isALBA():
             if any(beamline in strPathToDiffractionImage
                    for beamline in ["id23eh1", "id29", "id30b"]):
                 # Pilatus 6M
                 self.minImageSize = 6000000
             elif any(beamline in strPathToDiffractionImage
                      for beamline in ["id23eh2", "id30a1"]):
                 # Pilatus3 2M
                 self.minImageSize = 2000000
             elif strImageFileNameExtension == ".h5":
                 self.h5MasterFilePath, self.h5DataFilePath, self.h5FileNumber = self.getH5FilePath(
                     pathToImageFile)
                 pathToImageFile = self.h5DataFilePath
                 self.isH5 = True
         elif EDUtilsPath.isEMBL():
             self.minImageSize = 10000
         xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
         xsDataInputMXWaitFile.setFile(
             XSDataFile(XSDataString(pathToImageFile)))
         if self.getDataInput().getWaitForFileTimeOut():
             xsDataInputMXWaitFile.setTimeOut(
                 self.getDataInput().getWaitForFileTimeOut())
         self.edPluginMXWaitFile = self.loadPlugin(
             self.strMXWaitFilePluginName)
         self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
         # Load the execution plugin
         self.edPluginExecThumbnail = self.loadPlugin(
             self.strExecThumbnailPluginName)
         xsDataInputMXThumbnail = XSDataInputMXThumbnail()
         xsDataInputMXThumbnail.image = self.getDataInput(
         ).getDiffractionImage()
         xsDataInputMXThumbnail.height = XSDataInteger(1024)
         xsDataInputMXThumbnail.width = XSDataInteger(1024)
         xsDataInputMXThumbnail.format = self.dataInput.format
         # Output path
         strImageNameWithoutExt = os.path.basename(
             os.path.splitext(strPathToDiffractionImage)[0])
         strImageDirname = os.path.dirname(strPathToDiffractionImage)
         if self.getDataInput().getForcedOutputDirectory():
             strForcedOutputDirectory = self.getDataInput(
             ).getForcedOutputDirectory().getPath().getValue()
             if not os.access(strForcedOutputDirectory, os.W_OK):
                 self.error("Cannot write to forced output directory : %s" %
                            strForcedOutputDirectory)
                 self.setFailure()
             else:
                 self.strOutputPathWithoutExtension = os.path.join(
                     strForcedOutputDirectory, strImageNameWithoutExt)
         else:
             # Try to store in the ESRF pyarch directory
             strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath(
                 strImageDirname)
             # Check that output pyarch path exists and is writeable:
             bIsOk = False
             if strOutputDirname:
                 if not os.path.exists(strOutputDirname):
                     # Try to create the directory
                     try:
                         os.makedirs(strOutputDirname)
                         bIsOk = True
                     except Exception as e:
                         self.WARNING("Couldn't create the directory %s" %
                                      strOutputDirname)
                 elif os.access(strOutputDirname, os.W_OK):
                     bIsOk = True
             if not bIsOk:
                 self.warning("Cannot write to pyarch directory: %s" %
                              strOutputDirname)
                 strTmpUser = os.path.join("/tmp", os.environ["USER"])
                 if not os.path.exists(strTmpUser):
                     os.mkdir(strTmpUser, 0o755)
                 strOutputDirname = tempfile.mkdtemp(
                     prefix="EDPluginPyarchThumbnailv10_", dir=strTmpUser)
                 os.chmod(strOutputDirname, 0o755)
                 self.warning("Writing thumbnail images to: %s" %
                              strOutputDirname)
             self.strOutputPathWithoutExtension = os.path.join(
                 strOutputDirname, strImageNameWithoutExt)
         if self.dataInput.format is not None:
             self.strSuffix = self.dataInput.format.value.lower()
             self.strImageFormat = self.dataInput.format.value.upper()
         self.strOutputPath = os.path.join(
             self.strOutputPathWithoutExtension + "." + self.strSuffix)
         xsDataInputMXThumbnail.setOutputPath(
             XSDataFile(XSDataString(self.strOutputPath)))
         self.edPluginExecThumbnail.setDataInput(xsDataInputMXThumbnail)
Example #21
0
    def postProcess(self, _edObject=None):
        """
        postProcess of the plugin EDPluginSPDCakev1_5.py:
        - convert to HDF if needed (to be implemented)
        - convert to chiplot or xye or cif if needed
        - move images (if needed) or delete .cor image 
        - set result XML   
        """
        EDPluginSPDCorrectv10.postProcess(self)
        self.DEBUG("EDPluginSPDCakev1_5.postProcess")

        if not os.path.isdir(self.dictGeometry["OutputDirCake"]):
            os.makedirs(self.dictGeometry["OutputDirCake"])

        strInputImagePathNoSfx = os.path.splitext(
            os.path.basename(self.pathToInputFile))[0]
        strSpdoutCake = strInputImagePathNoSfx + self.dictGeometry[
            "OutputFileType"]

        strOutputCakeFilePath = os.path.join(
            self.dictGeometry["OutputDirCake"], strSpdoutCake)
        xsDataResultSPD = XSDataResultSPDCake()

        if not self.getFireAndForget():
            strTempFilePath = None
            if "corrected" in self.dictRes:
                strSpdoutCor = self.dictRes["corrected"]
            if "regrouped" in self.dictRes:
                strTempFilePath = self.dictRes["regrouped"]

            if self.dictGeometry["OutputFileType"].lower() in [
                    ".hdf5", ".nexus", ".h5", ".nx"
            ]:
                self.WARNING(
                    "HDF5/Nexus output is not yet implemented in the SPD plugin."
                )

            if strTempFilePath is None:
                self.WARNING(
                    "Cannot copy output to %s as there is not input: %s " %
                    (strOutputCakeFilePath, self.dictRes))
            elif os.path.exists(strOutputCakeFilePath):
                self.WARNING(
                    "Destination file exists, I will leave result file in %s."
                    % strTempFilePath)
                strOutputCakeFilePath = strTempFilePath
            else:
                shutil.move(strTempFilePath, strOutputCakeFilePath)

            strOutputCorFilePath = os.path.join(self.dictGeometry["OutputDir"],
                                                os.path.split(strSpdoutCor)[1])
            if self.bDeleteCorImg:
                if os.path.isfile(strSpdoutCor):
                    os.remove(strSpdoutCor)
                else:
                    self.WARNING("Corrected file vanished before removal %s" %
                                 strSpdoutCor)
            else:
                strTempFilePathCor = os.path.join(self.getWorkingDirectory(),
                                                  strSpdoutCor)
                if self.dictGeometry["OutputFileType"].lower() in [
                        ".hdf5", ".nexus", ".h5", ".nx"
                ]:
                    self.WARNING(
                        "HDF5/Nexus output is not yet implemented in the SPD plugin."
                    )
                elif self.dictGeometry["OutputFileType"].lower() not in [
                        ".edf", ".azim", ".cor"
                ]:
                    self.WARNING(
                        "Output file format %s is not yet implemented in the SPD plugin."
                        % self.dictGeometry["OutputFileType"])

                if os.path.exists(strOutputCorFilePath):
                    self.WARNING(
                        "Destination file exists, I will leave result file in %s."
                        % strTempFilePathCor)
                    strOutputCorFilePath = os.path.abspath(strTempFilePathCor)
                else:

                    shutil.move(strTempFilePath, strOutputCorFilePath)
                xsDataFileCorr = XSDataFile()
                xsDataFileCorr.setPath(XSDataString(strOutputCorFilePath))
                xsDataResultSPD.setcorrectedFile(xsDataFileCorr)
#        # Create the output data
        xsDataFileCake = XSDataFile()
        xsDataFileCake.setPath(XSDataString(strOutputCakeFilePath))
        xsDataResultSPD.setCakedFile(xsDataFileCake)

        self.setDataOutput(xsDataResultSPD)
Example #22
0
 def createInputCharacterisationFromSubWedges(self):
     self.DEBUG(
         "EDPluginControlInterfacev1_3.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.fApertureSize is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setApertureSize(XSDataLength(self.fApertureSize))
             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)
Example #23
0
    def processMerges(self, run):
        # run analysis of merges

        for merge in run.merge_curves:
            if os.path.exists(merge):
                xsdSubtractedCurve = XSDataFile(XSDataString(merge))
                self.__edPluginSaxsAnalysis = self.loadPlugin(
                    self.__strControlledPluginSaxsAnalysis)

                self.__edPluginSaxsAnalysis.dataInput = XSDataInputSaxsAnalysis(
                    scatterCurve=xsdSubtractedCurve,
                    autoRg=run.merge_Rg[merge],
                    graphFormat=XSDataString("png"))
                self.__edPluginSaxsAnalysis.connectSUCCESS(
                    self.doSuccessSaxsAnalysis)
                self.__edPluginSaxsAnalysis.connectFAILURE(
                    self.doFailureSaxsAnalysis)
                self.__edPluginSaxsAnalysis.executeSynchronous()
                xsdBuffer = XSDataFile(XSDataString(run.buffer))
                xsdStartFrame = XSDataString(run.merge_framesDIC[merge][0])
                xsdEndFrame = XSDataString(run.merge_framesDIC[merge][-1])
                self.__edPluginISPyBAnalysis = self.loadPlugin(
                    self.__strControlledPluginISPyBAnalysis)
                try:
                    inputBioSaxsISPyB = XSDataInputBioSaxsISPyBv1_0(
                        sample=self.dataOutputBioSaxsISPyB_HPLC.getSample(),
                        autoRg=run.merge_analysis[merge].autoRg,
                        gnom=run.merge_analysis[merge].gnom,
                        volume=run.merge_analysis[merge].volume,
                        bestBuffer=xsdBuffer,
                        scatterPlot=run.merge_analysis[merge].scatterPlot,
                        guinierPlot=run.merge_analysis[merge].guinierPlot,
                        kratkyPlot=run.merge_analysis[merge].kratkyPlot,
                        densityPlot=run.merge_analysis[merge].densityPlot)

                    xsdISPyBin = XSDataInputBioSaxsISPyBHPLCv1_0(
                        experimentId=self.dataOutputBioSaxsISPyB_HPLC.
                        getExperimentId(),
                        startFrame=xsdStartFrame,
                        endFrame=xsdEndFrame,
                        dataInputBioSaxs=inputBioSaxsISPyB)
                    self.__edPluginISPyBAnalysis.dataInput = xsdISPyBin
                    self.__edPluginISPyBAnalysis.connectSUCCESS(
                        self.doSuccessISPyBAnalysis)
                    self.__edPluginISPyBAnalysis.connectFAILURE(
                        self.doFailureISPyBAnalysis)
                    self.__edPluginISPyBAnalysis.executeSynchronous()
                except Exception as error:
                    traceback.print_stack()
                    self.ERROR(
                        "EDPluginBioSaxsFlushHPLCv1_3 calling to EDPluginHPLCPrimayDataISPyBv1_0: %s"
                        % error)

                # There were some recurring issues with dammin slowing down slavia, therefore I commented this out for the time being
                # Martha, 11.7.2014

    #            mergeNumber = 1
    #             for merge in run.merge_curves:
    #                 try:
    #                     xsdSubtractedCurve = XSDataFile(XSDataString(merge))
    #                     xsdGnomFile = XSDataFile(XSDataString(run.merge_analysis[merge].gnom.gnomFile.path.value))
    #                     destination = XSDataFile(XSDataString(os.path.join(os.path.dirname(os.path.dirname(merge)), "ednaSAS")))
    #                     self.__edPluginSaxsToSAS = self.loadPlugin(self.__strControlledPluginSaxsModeling)
    #                     print "Changing measurentID by runMerge"
    #                     #In order to keep dammin models in different folder a measurementId should be given
    #                     self.__edPluginISPyBAnalysis.xsDataResult.dataInputBioSaxs.sample.measurementID.value = mergeNumber
    #                     print "------------>  MeasurementId changed " + str(self.__edPluginISPyBAnalysis.xsDataResult.dataInputBioSaxs.sample.measurementID.value)
    #                     self.__edPluginSaxsToSAS.dataInput = XSDataInputBioSaxsToSASv1_0(
    #                                                                                         sample=self.__edPluginISPyBAnalysis.xsDataResult.dataInputBioSaxs.sample,
    #                                                                                         subtractedCurve=xsdSubtractedCurve,
    #                                                                                         gnomFile=xsdGnomFile,
    #                                                                                         destinationDirectory=destination)
    #                     self.__edPluginSaxsToSAS.connectSUCCESS(self.doSuccessSaxsToSAS)
    #                     self.__edPluginSaxsToSAS.connectFAILURE(self.doFailureSaxsToSAS)
    #                     mergeNumber = mergeNumber + 1;
    #                     self.__edPluginSaxsToSAS.executeSynchronous()
    #                 except Exception as error:
    #                     traceback.print_stack()
    #                     self.ERROR("EDPluginBioSaxsFlushHPLCv1_3 calling to EDPluginBioSaxsToSASv1_1: %s" % error)
        self.synchronizePlugins()
Example #24
0
    def setup(self, _listInput=[], _mode="offline"):
        """Configure the various options"""

        bOK = False
        if _listInput == []:
            _listInput = [os.getcwd()]
        while not bOK:
            strtmp = raw_input(
                "What are the input directories (mandatory, space separated) %s: "
                % _listInput).strip()
            if len(strtmp) > 0:
                bAllExists = True
                lstTemp = shlex.split(strtmp)
                for oneDir in shlex.split(strtmp):
                    if not os.path.exists(oneDir):
                        EDVerbose.screen("No such file or directory: %s" %
                                         oneDir)
                        bAllExists = False
                if bAllExists is True:
                    self.listInput = lstTemp
                    bOK = True
            else:
                self.listInput = _listInput
                bOK = True
        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is operation mode [offline|online|all] (mandatory: %s): "
                % _mode).strip().lower()
            if len(strtmp) > 0:
                bOK = True
                if strtmp == "offline":
                    self.bNewerOnly = False
                    self.strMode = "OffLine"
                elif strtmp == "online":
                    self.bNewerOnly = True
                    self.strMode = "dirwatch"
                elif strtmp == "all":
                    self.bNewerOnly = False
                    self.strMode = "dirwatch"
                else:
                    bOK = False

        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is the destination directory (mandatory): ").strip()
            if os.path.isdir(strtmp):
                self.destinationDirectory = XSDataFile()
                self.destinationDirectory.setPath(
                    XSDataString(os.path.abspath(strtmp)))
                bOK = True

        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is the sinogram filename prefix  (mandatory): ").strip()
            if strtmp != "":
                self.sinogramFileNamePrefix = XSDataString(strtmp)
                bOK = True

        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is the powder diffraction subdirectory  (mandatory): "
            ).strip()
            if strtmp != "":
                self.powderDiffractionSubdirectory = XSDataString(strtmp)
                bOK = True

        strtmp = raw_input(
            "What is the powder diffraction output format (CHI or CIF, if any ): "
        ).strip().lower()
        if strtmp.find("cif") >= 0:
            self.powderDiffractionFormat = XSDataString("cif")
        elif strtmp.find("chi") >= 0:
            self.powderDiffractionFormat = XSDataString("chi")

        strtmp = raw_input("Process all files ending with: ").strip()
        if len(strtmp) > 0:
            for oneExt in shlex.split(strtmp):
                self.listExtensions.append(oneExt)

        strtmp = raw_input("Exclude all files starting with: ").strip()
        if len(strtmp) > 0:
            for oneExt in shlex.split(strtmp):
                self.listExcludedPrefix.append(oneExt)

        strtmp = raw_input(
            "Do you want to over-ride metadata from the headers [y|N]: "
        ).strip().lower()
        if len(strtmp) > 0 and strtmp[0] == "y":

            strtmp = raw_input("What is the flat field image: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                flatFieldImage = XSDataFile()
                flatFieldImage.setPath(XSDataString(os.path.abspath(strtmp)))
                self.forceImage.set_file_correction_image_flat_field(
                    flatFieldImage)

            strtmp = raw_input("What is the dark current image: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                darkCurrentImage = XSDataFile()
                darkCurrentImage.setPath(XSDataString(os.path.abspath(strtmp)))
                self.forceImage.set_file_correction_image_dark_current(
                    darkCurrentImage)

            strtmp = raw_input("What is the mask file: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                maskFile = XSDataFile()
                maskFile.setPath(XSDataString(strtmp))
                self.forceImage.set_file_correction_image_mask(maskFile)

            strtmp = raw_input("What is the spline file: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                splineFile = XSDataFile()
                splineFile.setPath(XSDataString(os.path.abspath(strtmp)))
                self.forceImage.set_file_correction_spline_spatial_distortion(
                    splineFile)

            strtmp = raw_input(
                "What is the wavelength (like 0.7 A): ").replace(
                    "(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                try:
                    f = float(w[0])
                except ValueError:
                    print("unable to understand what you said, skipping")
                else:
                    wavelength = XSDataWavelength()
                    wavelength.setValue(f)
                    if len(w) == 2:
                        wavelength.setUnit(XSDataString(w[1]))
                    if self.forceInstrument is None:
                        self.forceInstrument = XSDataDiffractionCTInstrument()
                    self.forceInstrument.set_diffrn_radiation_wavelength(
                        wavelength)

            strtmp = raw_input(
                "What is the distance between the sample and the detector along the beam: "
            ).replace("(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                try:
                    f = float(w[0])
                except ValueError:
                    print("unable to understand what you said, skipping")
                else:
                    distance = XSDataLength()
                    distance.setValue(f)
                    if len(w) == 2:
                        distance.setUnit(XSDataString(w[1]))
                    if self.forceInstrument is None:
                        self.forceInstrument = XSDataDiffractionCTInstrument()
                    self.forceInstrument.set_pd_instr_dist_spec_detc(distance)

            strtmp = raw_input(
                "What is the pixel size (like 52.8 um 53.2 um): ").replace(
                    "(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                xsdata1 = None
                xsdata2 = None
                if len(w) == 4:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[2])
                    except ValueError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata1.setUnit(XSDataString(w[1]))
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                        xsdata2.setUnit(XSDataString(w[3]))
                elif len(w) == 2:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[1])
                    except ValueError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                else:
                    print("unable to understand what you said, skipping")
                if (xsdata1 is not None) and (xsdata2 is not None):
                    if self.forceImage is None:
                        self.forceImage = XSDataDiffractionCTImage()
                    self.forceImage.set_array_element_size_1(xsdata1)
                    self.forceImage.set_array_element_size_2(xsdata2)

            strtmp = raw_input(
                "What is the beam center in distance, not pixels (like 53.5 mm 48.2 mm): "
            ).strip().replace("(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                xsdata1 = None
                xsdata2 = None
                if len(w) == 4:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[2])
                    except ValueError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata1.setUnit(XSDataString(w[1]))
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                        xsdata2.setUnit(XSDataString(w[3]))
                elif len(w) == 2:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[1])
                    except ValueError, IndexError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                else:
                    print("unable to understand what you said, skipping")
                if (xsdata1 is not None) and (xsdata2 is not None):
                    if self.forceImage is None:
                        self.forceImage = XSDataDiffractionCTImage()
                    self.forceImage.set_diffrn_detector_element_center_1(
                        xsdata1)
                    self.forceImage.set_diffrn_detector_element_center_2(
                        xsdata2)

            strtmp = raw_input("What is the detector tilt angle: ").strip()
            tiltAngle = None
            try:
                tiltAngle = XSDataAngle(float(strtmp))
            except ValueError:
                print("unable to understand what you said, skipping")
            else:
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                self.forceImage.set_pd_instr_special_details_tilt_angle(
                    tiltAngle)

            strtmp = raw_input("What is the tilt plan rotation: ").strip()
            tiltRotation = None
            try:
                tiltRotation = XSDataAngle(float(strtmp))
            except ValueError:
                print("unable to understand what you said, skipping")
            else:
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                self.forceImage.set_pd_instr_special_details_tilt_rotation(
                    tiltRotation)

            strtmp = raw_input(
                "What is the number of fast motor steps (you will have n+1 points): "
            ).strip()
            try:
                self.fastMotorSteps = int(strtmp)
            except ValueError:
                fastMotorSteps = None
            else:
                if self.forceInstrument is None:
                    self.forceInstrument = XSDataDiffractionCTInstrument()
                self.forceInstrument.set_tomo_spec_displ_x_max(
                    XSDataLength(self.fastMotorSteps))
                self.forceInstrument.set_tomo_spec_displ_x_min(XSDataLength(0))
                self.forceInstrument.set_tomo_spec_displ_x_inc(XSDataLength(1))
                self.forceInstrument.set_tomo_scan_type(XSDataString("flat"))

            strtmp = raw_input(
                "What is the number of slow motor steps (you will have n+1 points): "
            ).strip()
            try:
                self.slowMotorSteps = int(strtmp)
            except ValueError:
                self.slowMotorSteps = None
            else:
                if self.forceInstrument is None:
                    self.forceInstrument = XSDataDiffractionCTInstrument()
                self.forceInstrument.set_tomo_scan_ampl(
                    XSDataLength(self.slowMotorSteps))
                self.forceInstrument.set_tomo_spec_displ_rotation_inc(
                    XSDataLength(1))
                self.forceInstrument.set_tomo_scan_type(XSDataString("flat"))

            strtmp = raw_input(
                "What is the index offset of your images: ").strip()
            try:
                self.indexOffset = int(strtmp)
            except ValueError:
                print("unable to understand what you said, skipping")
Example #25
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
Example #26
0
 def testExecute(self):
     pyarchPath = tempfile.mkdtemp(
         prefix="EDTestCasePluginControlRunDimplev1_0_")
     xsDataPyarchPath = XSDataFile(XSDataString(pyarchPath))
     self._edPlugin.dataInput.pyarchPath = xsDataPyarchPath
     self.run()
Example #27
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlAlignStackv1_0.process")

        for iFrame in self.iFrames:
            edPluginExecAccumulator = self.loadPlugin(
                self.__strControlledPluginAccumulator)
            queryRaw = XSDataQuery()
            queryShift = XSDataQuery()
            queryRaw.setRemoveItems(XSDataBoolean(False))
            queryShift.setRemoveItems(XSDataBoolean(False))
            xsdataAcc = XSDataInputAccumulator()
            if (EDPluginControlAlignStackv1_0.__iRefFrame
                    == iFrame) or (self.bDoAlign == False):
                EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame] = (0.0,
                                                                        0.0)
                EDPluginControlAlignStackv1_0.__dictRelShift[iFrame] = (0.0,
                                                                        0.0)
                self.hdf5_offset(index=iFrame, offset=[0.0, 0.0])
                edPluginExecShift = self.loadPlugin(
                    self.__strControlledPluginShift)
                xsdata = XSDataInputShiftImage(
                    index=XSDataInteger(iFrame),
                    offset=[
                        XSDataDouble(i) for i in
                        EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame]
                    ],
                    inputImage=self.getFrameRef(iFrame),
                    outputImage=XSDataImageExt(
                        shared=XSDataString("Shifted-%06i" % iFrame)))
                edPluginExecShift.setDataInput(xsdata)
                edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage)
                edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage)
                self.queue.put(edPluginExecShift)
                if (self.bDoAlign == False):
                    self.executeControlledPlugins()
                    return

            elif EDPluginControlAlignStackv1_0.__iRefFrame < iFrame:
                if self.bAlwaysMOvsRef:
                    queryRaw.setItem([
                        XSDataString(
                            "raw %04i" %
                            (EDPluginControlAlignStackv1_0.__iRefFrame)),
                        XSDataString("raw %04i" % iFrame)
                    ])
                    xsdataAcc.setQuery([queryRaw])
                else:
                    queryRaw.setItem([
                        XSDataString("raw %04i" % (iFrame - 1)),
                        XSDataString("raw %04i" % iFrame)
                    ])
                    queryShift.setItem([
                        XSDataString("shift %04i" % i) for i in range(
                            EDPluginControlAlignStackv1_0.__iRefFrame +
                            1, iFrame + 1)
                    ])
                    xsdataAcc.setQuery([queryRaw, queryShift])
            elif EDPluginControlAlignStackv1_0.__iRefFrame > iFrame:
                if self.bAlwaysMOvsRef:
                    queryRaw.setItem([
                        XSDataString("raw %04i" % iFrame),
                        XSDataString(
                            "raw %04i" %
                            (EDPluginControlAlignStackv1_0.__iRefFrame))
                    ])
                    xsdataAcc.setQuery([queryRaw])
                else:
                    queryRaw.setItem([
                        XSDataString("raw %04i" % (iFrame + 1)),
                        XSDataString("raw %04i" % iFrame)
                    ])
                    queryShift.setItem([
                        XSDataString("shift %04i" % i) for i in range(
                            EDPluginControlAlignStackv1_0.__iRefFrame -
                            1, iFrame - 1, -1)
                    ])
                    xsdataAcc.setQuery([queryRaw, queryShift])
            if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame):
                self.saveReferenceFrame(iFrame)

            xsdataAcc.setItem([XSDataString("raw %04i" % iFrame)])
            edPluginExecAccumulator.setDataInput(xsdataAcc)
            edPluginExecAccumulator.connectSUCCESS(
                self.doSuccessExecAccumultor)
            edPluginExecAccumulator.connectFAILURE(
                self.doFailureExecAccumulator)
            self.queue.put(edPluginExecAccumulator)
        self.executeControlledPlugins()
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlRunXdsv1_0.process")
        # First run is vanilla without any modification
        params = XSDataMinimalXdsIn()
        params.input_file = self.dataInput.input_file
        self.first_run.dataInput = params
        self.first_run.executeSynchronous()

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

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

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

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

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

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

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

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

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

            parser.dataInput = parser_input
            parser.executeSynchronous()

            if parser.isFailure():
                # that should not happen
                strErrorMessage = "Parser failure in control run XDS"
                self.ERROR(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                return
            self.dataOutput = parser.dataOutput
Example #29
0
    def doSuccessExecAccumultor(self, _edPlugin=None):
        with self.semAccumulator:
            self.DEBUG("EDPluginControlAlignStackv1_0.doSuccessExecAccumultor")
            self.retrieveSuccessMessages(
                _edPlugin,
                "EDPluginControlAlignStackv1_0.doSuccessExecAccumultor")
            for query in _edPlugin.dataOutput.getQuery():
                self.addExtraTime(60)
                _edPlugin.addExtraTime(60)
                accType = query.getItem()[0].getValue().split()[0]
                listInt = [
                    int(i.getValue().split()[1]) for i in query.getItem()
                ]
                if accType == "raw":
                    listFrame = [self.getFrameRef(i) for i in listInt]

                    xsdata = XSDataInputMeasureOffset(image=listFrame)
                    doSIFT = False
                    if self.xsdMeasureOffset is not None:
                        xsdata.setCropBorders(
                            self.xsdMeasureOffset.getCropBorders())
                        xsdata.setSmoothBorders(
                            self.xsdMeasureOffset.getSmoothBorders())
                        xsdata.setBackgroundSubtraction(
                            self.xsdMeasureOffset.getRemoveBackground())
                        if self.xsdMeasureOffset.useSift is not None:
                            doSIFT = self.xsdMeasureOffset.useSift.value
                    if max(listInt
                           ) > EDPluginControlAlignStackv1_0.__iRefFrame:
                        listInt.sort()
                    else:
                        listInt.sort(reverse=True)
                    xsdata.setIndex([XSDataInteger(i) for i in listInt])
                    if doSIFT:
                        edPluginExecMeasure = self.loadPlugin(
                            self.__strControlledPluginMeasureSIFT)
                    else:
                        edPluginExecMeasure = self.loadPlugin(
                            self.__strControlledPluginMeasureFFT)
                    edPluginExecMeasure.setDataInput(xsdata)
                    edPluginExecMeasure.connectSUCCESS(
                        self.doSuccessExecMeasureOffset)
                    edPluginExecMeasure.connectFAILURE(
                        self.doFailureExecMeasureOffset)
                    self.queue.put(edPluginExecMeasure)

                elif accType == "shift":
                    shift_1 = 0.0
                    shift_2 = 0.0

                    for frame in listInt:
                        shift_1 += EDPluginControlAlignStackv1_0.__dictRelShift[
                            frame][0]
                        shift_2 += EDPluginControlAlignStackv1_0.__dictRelShift[
                            frame][1]
                    if listInt[0] > EDPluginControlAlignStackv1_0.__iRefFrame:
                        iFrameShift = max(listInt)
                    else:
                        iFrameShift = min(listInt)
                    EDPluginControlAlignStackv1_0.__dictAbsShift[
                        iFrameShift] = (shift_1, shift_2)
                    self.screen(
                        "Frame number %i has absolute offset of %.3f,%.3f" %
                        (iFrameShift, shift_1, shift_2))

                    edPluginExecShift = self.loadPlugin(
                        self.__strControlledPluginShift)
                    edPluginExecShift.dataInput = XSDataInputShiftImage(
                        index=XSDataInteger(iFrameShift),
                        offset=[XSDataDouble(shift_1),
                                XSDataDouble(shift_2)],
                        inputImage=self.getFrameRef(iFrameShift),
                        outputImage=XSDataImageExt(
                            shared=XSDataString("Shifted-%06i" % iFrameShift)))

                    edPluginExecShift.connectSUCCESS(
                        self.doSuccessExecShiftImage)
                    edPluginExecShift.connectFAILURE(
                        self.doFailureExecShiftImage)
                    self.queue.put(edPluginExecShift)
            self.DEBUG("Items: %s" % EDPluginAccumulatorv1_0.getItems())
            self.DEBUG("Queries: %s" % EDPluginAccumulatorv1_0.getQueries())
    def create_autoproc_input(self, event, params):
        """
        Descript. :
        """
        WAIT_XDS_TIMEOUT = 20
        WAIT_XDS_RESOLUTION = 1

        file_name_timestamp = time.strftime("%Y%m%d_%H%M%S")

        autoproc_path = params.get("xds_dir")
        autoproc_xds_filename = os.path.join(autoproc_path, "XDS.INP")
        autoproc_input_filename = os.path.join(
            autoproc_path, "edna-autoproc-input-%s" % file_name_timestamp
        )
        autoproc_output_file_name = os.path.join(
            autoproc_path, "edna-autoproc-results-%s" % file_name_timestamp
        )

        autoproc_input = XSDataAutoprocInput()
        autoproc_xds_file = XSDataFile()
        autoproc_xds_file.setPath(XSDataString(autoproc_xds_filename))
        autoproc_input.setInput_file(autoproc_xds_file)

        autoproc_output_file = XSDataFile()
        autoproc_output_file.setPath(XSDataString(autoproc_output_file_name))
        autoproc_input.setOutput_file(autoproc_output_file)

        autoproc_input.setData_collection_id(XSDataInteger(params.get("collection_id")))
        residues_num = float(params.get("residues", 0))
        if residues_num != 0:
            autoproc_input.setNres(XSDataDouble(residues_num))
        space_group = params.get("sample_reference").get("spacegroup", "")
        if not isinstance(space_group, int) and len(space_group) > 0:
            autoproc_input.setSpacegroup(XSDataString(space_group))
        unit_cell = params.get("sample_reference").get("cell", "")
        if len(unit_cell) > 0:
            autoproc_input.setUnit_cell(XSDataString(unit_cell))

        autoproc_input.setCc_half_cutoff(XSDataDouble(18.0))

        # Maybe we have to check if directory is there. Maybe create dir with mxcube
        xds_appeared = False
        wait_xds_start = time.time()
        logging.info(
            "MAXIVAutoprocessing: Waiting for XDS.INP file: %s" % autoproc_xds_filename
        )
        while not xds_appeared and time.time() - wait_xds_start < WAIT_XDS_TIMEOUT:
            if (
                os.path.exists(autoproc_xds_filename)
                and os.stat(autoproc_xds_filename).st_size > 0
            ):
                xds_appeared = True
                logging.debug(
                    "MAXIVAutoprocessing: XDS.INP file is there, size={0}".format(
                        os.stat(autoproc_xds_filename).st_size
                    )
                )
            else:
                os.system("ls %s> /dev/null" % (os.path.dirname(autoproc_path)))
                gevent.sleep(WAIT_XDS_RESOLUTION)
        if not xds_appeared:
            logging.error(
                "MAXIVAutoprocessing: XDS.INP file ({0}) failed to appear after {1} seconds".format(
                    autoproc_xds_filename, WAIT_XDS_TIMEOUT
                )
            )
            return None, False

        autoproc_input.exportToFile(autoproc_input_filename)

        return autoproc_input_filename, True