def getH5FilePath(self, filePath, batchSize=1):
     imageNumber = EDUtilsImage.getImageNumber(filePath)
     prefix = EDUtilsImage.getPrefix(filePath)
     h5FileNumber = int((imageNumber - 1) / batchSize) * batchSize + 1
     h5MasterFileName = "{prefix}_{h5FileNumber}_master.h5".format(prefix=prefix,
                                                                   h5FileNumber=h5FileNumber)
     h5MasterFilePath = os.path.join(os.path.dirname(filePath), h5MasterFileName)
     h5DataFileName = "{prefix}_{h5FileNumber}_data_000001.h5".format(prefix=prefix,
                                                                   h5FileNumber=h5FileNumber)
     h5DataFilePath = os.path.join(os.path.dirname(filePath), h5DataFileName)
     return h5MasterFilePath, h5DataFilePath, h5FileNumber
예제 #2
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlDozorv1_0.process")
        xsDataResultControlDozor = XSDataResultControlDozor()
        for xsDataFile in self.dataInput.image:
            edPluginControlReadImageHeader = self.loadPlugin(self.strEDPluginControlReadImageHeaderName)
            xsDataInputReadImageHeader = XSDataInputReadImageHeader()
            xsDataInputReadImageHeader.image = xsDataFile
            edPluginControlReadImageHeader.dataInput = xsDataInputReadImageHeader
            edPluginControlReadImageHeader.executeSynchronous()
            subWedge = edPluginControlReadImageHeader.dataOutput.subWedge
            xsDataInputDozor = XSDataInputDozor()
            beam = subWedge.experimentalCondition.beam
            detector = subWedge.experimentalCondition.detector
            goniostat = subWedge.experimentalCondition.goniostat
            xsDataInputDozor.detectorType = detector.type
            xsDataInputDozor.exposureTime = XSDataDouble(beam.exposureTime.value)
            xsDataInputDozor.spotSize = XSDataDouble(5.0)
            xsDataInputDozor.detectorDistance = XSDataDouble(detector.distance.value)
            xsDataInputDozor.wavelength = XSDataDouble(beam.wavelength.value)
#            xsDataInputDozor.fractionPolatization : XSDataDouble optional
            orgx = detector.beamPositionY.value / detector.pixelSizeY.value
            orgy = detector.beamPositionX.value / detector.pixelSizeX.value
            xsDataInputDozor.orgx = XSDataDouble(orgx)
            xsDataInputDozor.orgy = XSDataDouble(orgy)
            xsDataInputDozor.oscillationRange = XSDataDouble(goniostat.oscillationWidth.value)
#            xsDataInputDozor.imageStep : XSDataDouble optional
            xsDataInputDozor.startingAngle = XSDataDouble(goniostat.rotationAxisStart.value)
            xsDataInputDozor.firstImageNumber = subWedge.image[0].number
            xsDataInputDozor.numberImages = XSDataInteger(1)
            strFileName = subWedge.image[0].path.value
            strPrefix = EDUtilsImage.getPrefix(strFileName)
            strSuffix = EDUtilsImage.getSuffix(strFileName)
            strXDSTemplate = "%s_????.%s" % (strPrefix, strSuffix)
            xsDataInputDozor.nameTemplateImage = XSDataString(os.path.join(os.path.dirname(strFileName), strXDSTemplate))
            edPluginDozor = self.loadPlugin(self.strEDPluginDozorName, "Dozor")
            edPluginDozor.dataInput = xsDataInputDozor
            edPluginDozor.executeSynchronous()
            if edPluginDozor.dataOutput.imageDozor != []:
                xsDataResultDozor = edPluginDozor.dataOutput.imageDozor[0]
                xsDataControlImageDozor = XSDataControlImageDozor()
                xsDataControlImageDozor.image = xsDataFile
                xsDataControlImageDozor.spots_num_of = xsDataResultDozor.spots_num_of
                xsDataControlImageDozor.spots_int_aver = xsDataResultDozor.spots_int_aver
                xsDataControlImageDozor.spots_resolution = xsDataResultDozor.spots_resolution
                xsDataControlImageDozor.powder_wilson_scale = xsDataResultDozor.powder_wilson_scale
                xsDataControlImageDozor.powder_wilson_bfactor = xsDataResultDozor.powder_wilson_bfactor
                xsDataControlImageDozor.powder_wilson_resolution = xsDataResultDozor.powder_wilson_resolution
                xsDataControlImageDozor.powder_wilson_correlation = xsDataResultDozor.powder_wilson_correlation
                xsDataControlImageDozor.powder_wilson_rfactor = xsDataResultDozor.powder_wilson_rfactor
                xsDataControlImageDozor.score = xsDataResultDozor.score
                xsDataResultControlDozor.addImageDozor(xsDataControlImageDozor)
        self.dataOutput = xsDataResultControlDozor
 def getH5FilePath(self, filePath, batchSize=1):
     imageNumber = EDUtilsImage.getImageNumber(filePath)
     prefix = EDUtilsImage.getPrefix(filePath)
     h5FileNumber = int((imageNumber - 1) / batchSize) * batchSize + 1
     h5MasterFileName = "{prefix}_{h5FileNumber}_master.h5".format(
         prefix=prefix, h5FileNumber=h5FileNumber)
     h5MasterFilePath = os.path.join(os.path.dirname(filePath),
                                     h5MasterFileName)
     h5DataFileName = "{prefix}_{h5FileNumber}_data_000001.h5".format(
         prefix=prefix, h5FileNumber=h5FileNumber)
     h5DataFilePath = os.path.join(os.path.dirname(filePath),
                                   h5DataFileName)
     return h5MasterFilePath, h5DataFilePath, h5FileNumber
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlBackground3Dv1_0.process")
        xsDataResultControlBackground3D = XSDataResultControlBackground3D()
        for xsDataFile in self.dataInput.image:
            edPluginControlReadImageHeader = self.loadPlugin(self.strEDPluginControlReadImageHeaderName)
            xsDataInputReadImageHeader = XSDataInputReadImageHeader()
            xsDataInputReadImageHeader.image = xsDataFile
            edPluginControlReadImageHeader.dataInput = xsDataInputReadImageHeader
            edPluginControlReadImageHeader.executeSynchronous()
            subWedge = edPluginControlReadImageHeader.dataOutput.subWedge
            xsDataInputBackground3D = XSDataInputBackground3D()
            beam = subWedge.experimentalCondition.beam
            detector = subWedge.experimentalCondition.detector
            goniostat = subWedge.experimentalCondition.goniostat
            xsDataInputBackground3D.detectorType = detector.type
            xsDataInputBackground3D.exposureTime = XSDataDouble(beam.exposureTime.value)
            xsDataInputBackground3D.detectorDistance = XSDataDouble(detector.distance.value)
            xsDataInputBackground3D.wavelength = XSDataDouble(beam.wavelength.value)
#            xsDataInputBackground3D.fractionPolatization : XSDataDouble optional
            orgx = detector.beamPositionY.value / detector.pixelSizeY.value
            orgy = detector.beamPositionX.value / detector.pixelSizeX.value
            xsDataInputBackground3D.orgx = XSDataDouble(orgx)
            xsDataInputBackground3D.orgy = XSDataDouble(orgy)
            xsDataInputBackground3D.oscillationRange = XSDataDouble(goniostat.oscillationWidth.value)
#            xsDataInputBackground3D.imageStep : XSDataDouble optional
            xsDataInputBackground3D.startingAngle = XSDataDouble(goniostat.rotationAxisStart.value)
            xsDataInputBackground3D.firstImageNumber = subWedge.image[0].number
            xsDataInputBackground3D.numberImages = XSDataInteger(1)
            strFileName = subWedge.image[0].path.value
            strPrefix = EDUtilsImage.getPrefix(strFileName)
            strSuffix = EDUtilsImage.getSuffix(strFileName)
            strXDSTemplate = "%s_????.%s" % (strPrefix, strSuffix)
            xsDataInputBackground3D.nameTemplateImage = XSDataString(os.path.join(os.path.dirname(strFileName), strXDSTemplate))
            edPluginBackground3D = self.loadPlugin(self.strEDPluginBackground3DName, "Background3D")
            edPluginBackground3D.dataInput = xsDataInputBackground3D
            edPluginBackground3D.executeSynchronous()
            if edPluginBackground3D.dataOutput.imageBackground != []:
                xsDataResultBackground3D = edPluginBackground3D.dataOutput.imageBackground[0]
                xsDataControlImageBackground3D = XSDataControlImageBackground3D()
                xsDataControlImageBackground3D.image = xsDataFile
                xsDataControlImageBackground3D.scale = xsDataResultBackground3D.scale
                xsDataControlImageBackground3D.bfactor = xsDataResultBackground3D.bfactor
                xsDataControlImageBackground3D.resolution = xsDataResultBackground3D.resolution
                xsDataControlImageBackground3D.correlation = xsDataResultBackground3D.correlation
                xsDataControlImageBackground3D.rfactor = xsDataResultBackground3D.rfactor
                xsDataControlImageBackground3D.b_coef = xsDataResultBackground3D.b_coef
                xsDataControlImageBackground3D.b_cryst = xsDataResultBackground3D.b_cryst
                xsDataControlImageBackground3D.estimate = xsDataResultBackground3D.estimate
                xsDataResultControlBackground3D.addImageBackground(xsDataControlImageBackground3D)
        self.dataOutput = xsDataResultControlBackground3D
예제 #5
0
 def testGetImageNumber(self):
     """
     Testing retrieving the image number from a image filename
     """
     iImageNumber = EDUtilsImage.getImageNumber(self.__strFileName)
     iReference = 1
     EDAssert.equal(iReference, iImageNumber)
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection()
     if xsDataCollection is not None:
         firstSubWedge = xsDataCollection.subWedge[0]
         # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
         xsDataBeam = firstSubWedge.getExperimentalCondition().getBeam()
         if xsDataBeam.getTransmission() is not None:
             fTransmission = xsDataBeam.getTransmission().getValue()
             if fTransmission < self.fMinTransmission:
                 strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                 strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %" 
                 self.page.font(_color="red", size="+2")
                 self.page.i()
                 self.page.h2(strWarningMessage1+"<br>"+strWarningMessage2)
                 self.page.i.close()
                 self.page.font.close()
         self.page.h2( "Data collection info" )
         firstImage = firstSubWedge.image[0]
         strDate = firstImage.date.value
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         self.page.table( class_='dataCollectionInfo', border_="1", cellpadding_="0")
         self.page.tr( align_="CENTER")
         self.page.th("Data collection date", bgcolor_=self.strTableColourTitle2)
         self.page.th(strDate, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr( align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Image prefix", bgcolor_=self.strTableColourTitle2)
         self.page.th(strPrefix, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr( align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Directory", bgcolor_=self.strTableColourTitle2)
         self.page.th(strDirName, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.table.close()     
 def createImageDict(self, _xsDataControlDozorInput):
     # Create dictionary of all images with the image number as key
     dictImage = {}
     if len(_xsDataControlDozorInput.image) > 0:
         listImage = _xsDataControlDozorInput.image
         pathToFirstImage = listImage[0].path.value
         self.directory = os.path.dirname(pathToFirstImage)
         self.template = os.path.basename(pathToFirstImage).replace(
             "0001", "####")
     else:
         # Create list of images
         listImage = []
         self.directory = _xsDataControlDozorInput.directory.path.value
         self.template = _xsDataControlDozorInput.template.value
         startNo = _xsDataControlDozorInput.startNo.value
         endNo = _xsDataControlDozorInput.endNo.value
         for imageIndex in range(startNo, endNo + 1):
             imageName = self.template % imageIndex
             imagePath = os.path.join(self.directory, imageName)
             listImage.append(XSDataFile(XSDataString(imagePath)))
     for image in listImage:
         imagePath = image.path.value
         imageNo = EDUtilsImage.getImageNumber(imagePath)
         dictImage[imageNo] = image
     return dictImage
예제 #8
0
 def createPyarchHtmlDirectoryPath(_xsDataCollection):
     """
     This method creates a directory path for pyarch: in the same directory were the 
     images are located a new directory is created with the following convention:
     
       edna_html_prefix_runNumber
     
     """
     # First extract all reference image directory paths and names
     listImageDirectoryPath = []
     listImagePrefix = []
     for xsDataSubWedge in _xsDataCollection.getSubWedge():
         for xsDataImage in xsDataSubWedge.getImage():
             strImagePath = xsDataImage.getPath().getValue()
             listImageDirectoryPath.append(os.path.dirname(strImagePath))
             listImagePrefix.append(EDUtilsImage.getPrefix(strImagePath))
     # TODO: Check that all paths and prefixes are the same
     strImageDirectory = listImageDirectoryPath[0]
     strPrefix = listImagePrefix[0]
     # Remove any "ref-" or "postref-" from the prefix in order to make it fully
     # compatitble with DNA standards:
     if (strPrefix is not None):
         if (strPrefix.startswith("ref-")):
             strPrefix = strPrefix[4:]
         elif (strPrefix.startswith("postref-")):
             strPrefix = strPrefix[8:]
     strHtmlDirectoryPath = os.path.join(strImageDirectory,
                                         "%s_dnafiles" % strPrefix)
     strPyarchHtmlDirectoryPath = EDHandlerESRFPyarchv1_0.createPyarchFilePath(
         strHtmlDirectoryPath)
     return strPyarchHtmlDirectoryPath
 def testGetImageNumber(self):
     """
     Testing retrieving the image number from a image filename
     """
     iImageNumber = EDUtilsImage.getImageNumber(self.__strFileName)
     iReference = 1
     EDAssert.equal(iReference, iImageNumber)
예제 #10
0
 def createDNAFileDirectoryPath(self, _xsDataResultCharacterisation):
     """
     This method creates a "DNA" style directory path, i.e. in the same directory were the 
     images are located a new directory is created with the following convention:
     
       dnafiles_prefix_runNumber
     
     The path to this directory is returned if the directory was successfully created.
     """
     # First extract all reference image directory paths and names
     xsDataCollection = _xsDataResultCharacterisation.getDataCollection()
     listImageDirectoryPath = []
     listImagePrefix = []
     for xsDataSubWedge in xsDataCollection.getSubWedge():
         for xsDataImage in xsDataSubWedge.getImage():
             strImagePath = xsDataImage.getPath().getValue()
             listImageDirectoryPath.append(os.path.dirname(strImagePath))
             listImagePrefix.append(EDUtilsImage.getPrefix(strImagePath))
     # TODO: Check that all paths and prefixes are the same
     strImageDirectory = listImageDirectoryPath[0]
     strPrefix = listImagePrefix[0]
     # Remove any "ref-" or "postref-" from the prefix in order to make it fully
     # compatitble with DNA standards:
     if (strPrefix is not None):
         if (strPrefix.startswith("ref-")):
             strPrefix = strPrefix[4:]
         elif (strPrefix.startswith("postref-")):
             strPrefix = strPrefix[8:]
     strDNAFileDirectoryPath = os.path.join(strImageDirectory,
                                            "%s_dnafiles" % strPrefix)
     return strDNAFileDirectoryPath
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection()
     if xsDataCollection is not None:
         firstSubWedge = xsDataCollection.subWedge[0]
         firstImage = firstSubWedge.image[0]
         if firstImage.date is not None:
             strDate = firstImage.date.value
         else:
             strDate = "-----"
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         dictTable = {"type": "table",
                      "title": "Data collection info",
                      "columns": [],
                      "data": []}
         listRow = []
         dictTable["columns"].append("Data collection date")
         listRow.append(strDate)
         dictTable["columns"].append("Image prefix")
         listRow.append(strPrefix)
         dictTable["columns"].append("Directory")
         listRow.append(strDirName)
         dictTable["data"].append(listRow)
         #
         self.workflowStepReport.addTable("Data collection info",
                                          dictTable["columns"],
                                          dictTable["data"],
                                          orientation="vertical")
예제 #12
0
 def createPyarchHtmlDirectoryPath(_xsDataCollection):
     """
     This method creates a directory path for pyarch: in the same directory were the 
     images are located a new directory is created with the following convention:
     
       edna_html_prefix_runNumber
     
     """
     # First extract all reference image directory paths and names
     listImageDirectoryPath = []
     listImagePrefix = []
     for xsDataSubWedge in _xsDataCollection.getSubWedge():
         for xsDataImage in xsDataSubWedge.getImage():
             strImagePath = xsDataImage.getPath().getValue()
             listImageDirectoryPath.append(os.path.dirname(strImagePath))
             listImagePrefix.append(EDUtilsImage.getPrefix(strImagePath))
     # TODO: Check that all paths and prefixes are the same
     strImageDirectory = listImageDirectoryPath[0]
     strPrefix = listImagePrefix[0]
     # Remove any "ref-" or "postref-" from the prefix in order to make it fully
     # compatitble with DNA standards:
     if (strPrefix is not None):
         if (strPrefix.startswith("ref-")):
             strPrefix = strPrefix[4:]
         elif (strPrefix.startswith("postref-")):
             strPrefix = strPrefix[8:]
     strHtmlDirectoryPath = os.path.join(strImageDirectory, "%s_dnafiles" % strPrefix)
     strPyarchHtmlDirectoryPath = EDHandlerESRFPyarchv1_0.createPyarchFilePath(strHtmlDirectoryPath)
     return strPyarchHtmlDirectoryPath
예제 #13
0
 def postProcess(self, _edObject=None):
     EDPluginExecProcessScript.postProcess(self)
     self.DEBUG("EDPluginExecXDSAPPv1_0.postProcess")
     # Populate the results
     prefixRunNumber = EDUtilsImage.getPrefix(self.dataInput.image.path.value)
     xsDataResultXDSAPP = self.parseOutputDirectory(self.getWorkingDirectory(), prefixRunNumber)
     self.dataOutput = xsDataResultXDSAPP
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection()
     if xsDataCollection is not None:
         self.page.h2( "Data collection info" )
         firstSubWedge = xsDataCollection.subWedge[0]
         firstImage = firstSubWedge.image[0]
         strDate = None
         if not firstImage.date is None:
             strDate = firstImage.date.value
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         self.page.table( class_='dataCollectionInfo', border_="1", cellpadding_="0")
         self.page.tr( align_="CENTER")
         self.page.th("Data collection date", bgcolor_=self.strTableColourTitle2)
         if not strDate is None:
             self.page.th(strDate, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr( align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Image prefix", bgcolor_=self.strTableColourTitle2)
         self.page.th(strPrefix, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr( align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Directory", bgcolor_=self.strTableColourTitle2)
         self.page.th(strDirName, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.table.close()     
 def createDNAFileDirectoryPath(self, _xsDataResultCharacterisation):
     """
     This method creates a "DNA" style directory path, i.e. in the same directory were the 
     images are located a new directory is created with the following convention:
     
       dnafiles_prefix_runNumber
     
     The path to this directory is returned if the directory was successfully created.
     """
     # First extract all reference image directory paths and names
     xsDataCollection = _xsDataResultCharacterisation.getDataCollection()
     listImageDirectoryPath = []
     listImagePrefix = []
     for xsDataSubWedge in xsDataCollection.getSubWedge():
         for xsDataImage in xsDataSubWedge.getImage():
             strImagePath = xsDataImage.getPath().getValue()
             listImageDirectoryPath.append(os.path.dirname(strImagePath))
             listImagePrefix.append(EDUtilsImage.getPrefix(strImagePath))
     # TODO: Check that all paths and prefixes are the same
     strImageDirectory = listImageDirectoryPath[0]
     strPrefix = listImagePrefix[0]
     # Remove any "ref-" or "postref-" from the prefix in order to make it fully
     # compatitble with DNA standards:
     if (strPrefix is not None):
         if (strPrefix.startswith("ref-")):
             strPrefix = strPrefix[4:]
         elif (strPrefix.startswith("postref-")):
             strPrefix = strPrefix[8:]
     strDNAFileDirectoryPath = os.path.join(strImageDirectory, "%s_dnafiles" % strPrefix)
     return strDNAFileDirectoryPath
예제 #16
0
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection(
     )
     if xsDataCollection is not None:
         firstSubWedge = xsDataCollection.subWedge[0]
         firstImage = firstSubWedge.image[0]
         if firstImage.date is not None:
             strDate = firstImage.date.value
         else:
             strDate = "-----"
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         dictTable = {
             "type": "table",
             "title": "Data collection info",
             "columns": [],
             "data": []
         }
         listRow = []
         dictTable["columns"].append("Data collection date")
         listRow.append(strDate)
         dictTable["columns"].append("Image prefix")
         listRow.append(strPrefix)
         dictTable["columns"].append("Directory")
         listRow.append(strDirName)
         dictTable["data"].append(listRow)
         #
         self.workflowStepReport.addTable("Data collection info",
                                          dictTable["columns"],
                                          dictTable["data"],
                                          orientation="vertical")
예제 #17
0
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection(
     )
     if xsDataCollection is not None:
         self.page.h2("Data collection info")
         firstSubWedge = xsDataCollection.subWedge[0]
         firstImage = firstSubWedge.image[0]
         strDate = None
         if not firstImage.date is None:
             strDate = firstImage.date.value
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         self.page.table(class_='dataCollectionInfo',
                         border_="1",
                         cellpadding_="0")
         self.page.tr(align_="CENTER")
         self.page.th("Data collection date",
                      bgcolor_=self.strTableColourTitle2)
         if not strDate is None:
             self.page.th(strDate, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr(align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Image prefix", bgcolor_=self.strTableColourTitle2)
         self.page.th(strPrefix, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr(align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Directory", bgcolor_=self.strTableColourTitle2)
         self.page.th(strDirName, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.table.close()
    def doSuccessMXWaitFile(self, _edPlugin=None):
        self.DEBUG("EDPluginControlID29CreateThumbnailv1_0.doSuccessMXWaitFile")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlID29CreateThumbnailv1_0.doSuccessMXWaitFile")
        # Check that the image is really there
        if not self.edPluginMXWaitFile.dataOutput.timedOut.value:
            # Workaround for ESRF lag problem
            if EDUtilsPath.isESRF():
                time.sleep(2)
                if self.isH5:
                    diffractionImagePath = self.dataInput.diffractionImage.path.value
                    imageNumber = EDUtilsImage.getImageNumber(diffractionImagePath)
                    xsDataInputControlH5ToCBF = XSDataInputControlH5ToCBF()
                    xsDataInputControlH5ToCBF.hdf5File = XSDataFile(XSDataString(diffractionImagePath))
                    xsDataInputControlH5ToCBF.imageNumber = XSDataInteger(imageNumber)
                    xsDataInputControlH5ToCBF.hdf5ImageNumber = XSDataInteger(self.h5FileNumber)
                    xsDataInputControlH5ToCBF.ispybDataCollection = None
                    xsDataInputControlH5ToCBF.forcedOutputDirectory = XSDataFile(XSDataString(self.getWorkingDirectory()))
                    edPluginControlH5ToCBF = self.loadPlugin(self.strPluginControlH5ToCBF, "ControlH5ToCBF_{0:04d}".format(imageNumber))
                    edPluginControlH5ToCBF.dataInput = xsDataInputControlH5ToCBF
                    edPluginControlH5ToCBF.executeSynchronous()
                    cbfFile = edPluginControlH5ToCBF.dataOutput.outputCBFFile
                    self.edPluginExecThumbnail.dataInput.image = cbfFile

            # The image is here - make the first thumbnail
            self.edPluginExecThumbnail.connectSUCCESS(self.doSuccessExecThumbnail)
            self.edPluginExecThumbnail.connectFAILURE(self.doFailureExecThumbnail)
            self.edPluginExecThumbnail.executeSynchronous()
        else:
            self.error("Time-out while waiting for image!")
            self.setFailure()
예제 #19
0
    def doSuccessActionOldSubWedgeAssemble(self, _edPlugin=None):
        """
        - gets the result from the old assembler
        - converts it to DMv2
        - reads DC descriptor file prepared by the BCM
        - merges the info together
        """
        EDVerbose.DEBUG(
            "EDPluginControlSubWedgeAssemblyv2_0.doSuccessActionSubWedgeMerge")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlSubWedgeAssemblyv2_0.doSuccessActionOldSubWedgeAssemble"
        )
        if not _edPlugin.isFailure():
            # getting the result from the old assembler
            self.xsDataResultSubWedgeAssemble = _edPlugin.getDataOutput()

            # converts it to DMv2

            # reads DC descriptor file(s) prepared by the BCM
            swList = self.xsDataResultSubWedgeAssemble.getSubWedge()
            try:
                for sw in swList:
                    # get filename
                    imgFname = sw.getImage()[0].getPath().getValue()
                    strMOSFLMTemplate = os.path.dirname(
                        imgFname) + '/edna_' + EDUtilsImage.getTemplate(
                            imgFname, "#")
                    # print strMOSFLMTemplate

                    # read file in
                    #self.xsDatacollection_v2 = XSDataCollection_v2()
                    self.xsDatacollection_v2 = XSDataMXv2.XSDataCollection.parseFile(
                        strMOSFLMTemplate)
            except IOError:
                # TEMP: generates the file to be read in
                ##PARAMS
                calibDate = '2009-12-10'
                omegaR = (0, 0, 1)
                kappaR = (0, 0.707106781187, 0.707106781187)
                phiR = (0, 0, 1)
                beamD = (1, 0, 0)
                polarisationP = (0, 1, 0)
                exposuretime = 1.0
                imagewidth = 1.0
                numberimages = 1
                wavelength = 1.0
                OmegaV = 0.0
                KappaV = 90.0
                PhiV = 40.0
                imgFnames = []
                imgFnames.append(
                    self.xsDataResultSubWedgeAssemble.getSubWedge()
                    [0].getImage()[0].getPath().getValue())

                self.generateDataCollectionDescriptorForSubWedge(
                    calibDate, omegaR, kappaR, phiR, beamD, polarisationP,
                    exposuretime, imagewidth, numberimages, wavelength, OmegaV,
                    KappaV, PhiV, imgFnames)
예제 #20
0
 def testGetTemplateQuestionMark(self):
     """
     Testing retrieving the image number from a image filename
     """
     strSymbol = "?"
     strTemplate = EDUtilsImage.getTemplate(self.__strFileName, strSymbol)
     strTemplateReference = "ref-testscale_1_???.img"
     EDAssert.equal(strTemplateReference, strTemplate)
예제 #21
0
 def testGetTemplateQuestionMark(self):
     """
     Testing retrieving the image number from a image filename
     """
     strSymbol = "?"
     strTemplate = EDUtilsImage.getTemplate(self.__strFileName, strSymbol)
     strTemplateReference = "ref-testscale_1_???.img"
     EDAssert.equal(strTemplateReference, strTemplate)
 def getH5FilePath(self, filePath, batchSize=1, isFastMesh=False):
     imageNumber = EDUtilsImage.getImageNumber(filePath)
     prefix = EDUtilsImage.getPrefix(filePath)
     if isFastMesh:
         h5ImageNumber = int((imageNumber - 1) / 100) + 1
         h5FileNumber = 1
     else:
         h5ImageNumber = 1
         h5FileNumber = int((imageNumber - 1) / batchSize) * batchSize + 1
     h5MasterFileName = "{prefix}_{h5FileNumber}_master.h5".format(prefix=prefix,
                                                                   h5FileNumber=h5FileNumber)
     h5MasterFilePath = os.path.join(os.path.dirname(filePath), h5MasterFileName)
     h5DataFileName = "{prefix}_{h5FileNumber}_data_{h5ImageNumber:06d}.h5".format(prefix=prefix,
                                                                                   h5FileNumber=h5FileNumber,
                                                                                   h5ImageNumber=h5ImageNumber)
     h5DataFilePath = os.path.join(os.path.dirname(filePath), h5DataFileName)
     return h5MasterFilePath, h5DataFilePath, h5FileNumber
예제 #23
0
 def postProcess(self, _edObject=None):
     EDPluginExecProcessScript.postProcess(self)
     self.DEBUG("EDPluginExecXDSAPPv1_0.postProcess")
     # Populate the results
     prefixRunNumber = EDUtilsImage.getPrefix(
         self.dataInput.image.path.value)
     xsDataResultXDSAPP = self.parseOutputDirectory(
         self.getWorkingDirectory(), prefixRunNumber)
     self.dataOutput = xsDataResultXDSAPP
 def getH5FilePath(self, filePath, batchSize=1, isFastMesh=False):
     imageNumber = EDUtilsImage.getImageNumber(filePath)
     prefix = EDUtilsImage.getPrefix(filePath)
     if isFastMesh:
         h5ImageNumber = int((imageNumber - 1) / 100) + 1
         h5FileNumber = 1
     else:
         h5ImageNumber = 1
         h5FileNumber = int((imageNumber - 1) / batchSize) * batchSize + 1
     h5MasterFileName = "{prefix}_{h5FileNumber}_master.h5".format(
         prefix=prefix, h5FileNumber=h5FileNumber)
     h5MasterFilePath = os.path.join(os.path.dirname(filePath),
                                     h5MasterFileName)
     h5DataFileName = "{prefix}_{h5FileNumber}_data_{h5ImageNumber:06d}.h5".format(
         prefix=prefix,
         h5FileNumber=h5FileNumber,
         h5ImageNumber=h5ImageNumber)
     h5DataFilePath = os.path.join(os.path.dirname(filePath),
                                   h5DataFileName)
     return h5MasterFilePath, h5DataFilePath, h5FileNumber
예제 #25
0
 def getBeamlineProposalFromPath(self, _strPathToImage):
     """ESRF specific code for extracting the beamline name and prefix from the path"""
     listPath = _strPathToImage.split("/")
     strPrefix = EDUtilsImage.getPrefix(_strPathToImage).replace("ref-", "")
     if listPath[2] == "visitor":
         strBeamline = listPath[4]
         strProposal = listPath[3]
     elif listPath[3] == "inhouse":
         strBeamline = listPath[2]
         strProposal = listPath[4]
     else:
         strBeamline = "nobeamline"
         strProposal = "noproposal"
     return (strBeamline, strProposal, strPrefix)
 def getBeamlineProposalFromPath(self, _strPathToImage):
     """ESRF specific code for extracting the beamline name and prefix from the path"""
     listPath = _strPathToImage.split("/")
     strPrefix = EDUtilsImage.getPrefix(_strPathToImage).replace("ref-", "")
     if listPath[2] == "visitor":
         strBeamline = listPath[4]
         strProposal = listPath[3]
     elif listPath[3] == "inhouse":
         strBeamline = listPath[2]
         strProposal = listPath[4]
     else:
         strBeamline = "nobeamline"
         strProposal = "noproposal"
     return (strBeamline, strProposal, strPrefix)
    def doSuccessActionOldSubWedgeAssemble(self, _edPlugin=None):
        """
        - gets the result from the old assembler
        - converts it to DMv2
        - reads DC descriptor file prepared by the BCM
        - merges the info together
        """
        EDVerbose.DEBUG("EDPluginControlSubWedgeAssemblyv2_0.doSuccessActionSubWedgeMerge")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlSubWedgeAssemblyv2_0.doSuccessActionOldSubWedgeAssemble")
        if not _edPlugin.isFailure():
            # getting the result from the old assembler
            self.xsDataResultSubWedgeAssemble = _edPlugin.getDataOutput()

            # converts it to DMv2



            # reads DC descriptor file(s) prepared by the BCM
            swList = self.xsDataResultSubWedgeAssemble.getSubWedge()
            try:
                for sw in swList:
                    # get filename
                    imgFname = sw.getImage()[0].getPath().getValue()
                    strMOSFLMTemplate = os.path.dirname(imgFname) + '/edna_' + EDUtilsImage.getTemplate(imgFname, "#")
                    # print strMOSFLMTemplate

                    # read file in
                    #self.xsDatacollection_v2 = XSDataCollection_v2()
                    self.xsDatacollection_v2 = XSDataMXv2.XSDataCollection.parseFile(strMOSFLMTemplate)
            except IOError:
                # TEMP: generates the file to be read in
                ##PARAMS
                calibDate = '2009-12-10'
                omegaR = (0, 0, 1)
                kappaR = (0, 0.707106781187, 0.707106781187)
                phiR = (0, 0, 1)
                beamD = (1, 0, 0)
                polarisationP = (0, 1, 0)
                exposuretime = 1.0
                imagewidth = 1.0
                numberimages = 1
                wavelength = 1.0
                OmegaV = 0.0
                KappaV = 90.0
                PhiV = 40.0
                imgFnames = []
                imgFnames.append(self.xsDataResultSubWedgeAssemble.getSubWedge()[0].getImage()[0].getPath().getValue())

                self.generateDataCollectionDescriptorForSubWedge(calibDate, omegaR, kappaR, phiR, beamD, polarisationP, exposuretime, imagewidth, numberimages, wavelength, OmegaV, KappaV, PhiV, imgFnames)
예제 #28
0
 def createImageDictFromISPyB(self, _ispybDataCollection):
     # Create dictionary of all images with the image number as key
     dictImage = {}
     # Create list of images
     listImage = []
     self.directory = _ispybDataCollection.imageDirectory
     self.template = _ispybDataCollection.fileTemplate
     startNo = _ispybDataCollection.startImageNumber
     endNo = _ispybDataCollection.startImageNumber + _ispybDataCollection.numberOfImages - 1
     for imageIndex in range(startNo, endNo + 1):
         imageName = self.template % imageIndex
         imagePath = os.path.join(self.directory, imageName)
         listImage.append(XSDataFile(XSDataString(imagePath)))
     for image in listImage:
         imagePath = image.path.value
         imageNo = EDUtilsImage.getImageNumber(imagePath)
         dictImage[imageNo] = image
     return dictImage
    def doSuccessMXWaitFile(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlID29CreateThumbnailv1_0.doSuccessMXWaitFile")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlID29CreateThumbnailv1_0.doSuccessMXWaitFile")
        # Check that the image is really there
        if not self.edPluginMXWaitFile.dataOutput.timedOut.value:
            # Workaround for ESRF lag problem
            if EDUtilsPath.isESRF():
                time.sleep(2)
                if self.isH5:
                    diffractionImagePath = self.dataInput.diffractionImage.path.value
                    imageNumber = EDUtilsImage.getImageNumber(
                        diffractionImagePath)
                    xsDataInputControlH5ToCBF = XSDataInputControlH5ToCBF()
                    xsDataInputControlH5ToCBF.hdf5File = XSDataFile(
                        XSDataString(diffractionImagePath))
                    xsDataInputControlH5ToCBF.imageNumber = XSDataInteger(
                        imageNumber)
                    xsDataInputControlH5ToCBF.hdf5ImageNumber = XSDataInteger(
                        self.h5FileNumber)
                    xsDataInputControlH5ToCBF.ispybDataCollection = None
                    xsDataInputControlH5ToCBF.forcedOutputDirectory = XSDataFile(
                        XSDataString(self.getWorkingDirectory()))
                    edPluginControlH5ToCBF = self.loadPlugin(
                        self.strPluginControlH5ToCBF,
                        "ControlH5ToCBF_{0:04d}".format(imageNumber))
                    edPluginControlH5ToCBF.dataInput = xsDataInputControlH5ToCBF
                    edPluginControlH5ToCBF.executeSynchronous()
                    cbfFile = edPluginControlH5ToCBF.dataOutput.outputCBFFile
                    self.edPluginExecThumbnail.dataInput.image = cbfFile

            # The image is here - make the first thumbnail
            self.edPluginExecThumbnail.connectSUCCESS(
                self.doSuccessExecThumbnail)
            self.edPluginExecThumbnail.connectFAILURE(
                self.doFailureExecThumbnail)
            self.edPluginExecThumbnail.executeSynchronous()
        else:
            self.error("Time-out while waiting for image!")
            self.setFailure()
    def process(self, _edPlugin=None):
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_4.process...")

        xsDataInputMXCuBE = self.getDataInput()
        xsDataInputInterface = XSDataInputInterface()
        self.edPluginControlInterface = self.loadPlugin(self.strPluginControlInterface)
        self.xsDataFirstImage = None
        for xsDataSetMXCuBE in xsDataInputMXCuBE.getDataSet():
            for xsDataFile in xsDataSetMXCuBE.getImageFile():
                if xsDataFile.path.value.endswith(".h5"):
                    self.bIsEigerDetector = True
                    self.xsDataFirstImage = xsDataFile
                    xsDataInputControlH5ToCBF = XSDataInputControlH5ToCBF()
                    xsDataInputControlH5ToCBF.hdf5File = XSDataFile(xsDataFile.path)
                    xsDataInputControlH5ToCBF.imageNumber = XSDataInteger(
                        EDUtilsImage.getImageNumber(xsDataFile.path.value)
                    )
                    edPluginControlH5ToCBF = self.loadPlugin(self.strPluginControlH5ToCBF, "ControlH5ToCBF")
                    edPluginControlH5ToCBF.dataInput = xsDataInputControlH5ToCBF
                    edPluginControlH5ToCBF.executeSynchronous()
                    cbfFile = edPluginControlH5ToCBF.dataOutput.outputCBFFile
                    xsDataInputInterface.addImagePath(cbfFile)
                else:
                    xsDataInputInterface.addImagePath(xsDataFile)
                if self.xsDataFirstImage is None:
                    self.xsDataFirstImage = xsDataFile

        xsDataExperimentalCondition = self.getFluxAndBeamSizeFromISPyB(
            self.xsDataFirstImage, xsDataInputMXCuBE.getExperimentalCondition()
        )

        xsDataInputInterface.setExperimentalCondition(xsDataExperimentalCondition)
        xsDataInputInterface.setDiffractionPlan(xsDataInputMXCuBE.getDiffractionPlan())
        xsDataInputInterface.setSample(xsDataInputMXCuBE.getSample())
        xsDataInputInterface.setDataCollectionId(xsDataInputMXCuBE.getDataCollectionId())
        self.edPluginControlInterface.setDataInput(xsDataInputInterface)

        if self.edPluginControlInterface is not None:
            self.connectProcess(self.edPluginControlInterface.executeSynchronous)
            self.edPluginControlInterface.connectSUCCESS(self.doSuccessActionInterface)
            self.edPluginControlInterface.connectFAILURE(self.doFailureActionInterface)
예제 #31
0
    def generateCommands(self, _xsDataInputH5ToCBF):
        """
        This method creates a list of commands for H5ToXDS
        """
        self.DEBUG("EDPluginH5ToCBFv1_0.generateCommands")

        hdf5File = _xsDataInputH5ToCBF.hdf5File.path.value
        directory = os.path.dirname(hdf5File)
        prefix = EDUtilsImage.getPrefix(hdf5File)

        imageNumber = _xsDataInputH5ToCBF.imageNumber.value

        if _xsDataInputH5ToCBF.hdf5ImageNumber is None:
            hdf5ImageNumber = imageNumber
        else:
            hdf5ImageNumber = _xsDataInputH5ToCBF.hdf5ImageNumber.value

        if "master" in hdf5File:
            masterFile = hdf5File
        else:
            masterFile = os.path.join(
                directory, prefix + "_{0}_master.h5".format(hdf5ImageNumber))

        CBFFileName = prefix + "_%04d" % imageNumber + ".cbf"
        tmpCBFFileName = "tmp_" + CBFFileName

        if self.dataInput.forcedOutputDirectory is None:
            self.CBFFile = os.path.join(directory, CBFFileName)
        else:
            forcedOutputDirectory = self.dataInput.forcedOutputDirectory.path.value
            if not os.path.exists(forcedOutputDirectory):
                os.makedirs(forcedOutputDirectory, 0o755)
            self.CBFFile = os.path.join(forcedOutputDirectory, CBFFileName)

        self.tmpCBFFile = os.path.join(self.getWorkingDirectory(),
                                       tmpCBFFileName)

        scriptCommandLine = "{0} {1} {2}".format(
            masterFile, imageNumber - hdf5ImageNumber + 1, tmpCBFFileName)

        return scriptCommandLine
예제 #32
0
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection(
     )
     if xsDataCollection is not None:
         firstSubWedge = xsDataCollection.subWedge[0]
         # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
         xsDataBeam = firstSubWedge.getExperimentalCondition().getBeam()
         if xsDataBeam.getTransmission() is not None:
             fTransmission = xsDataBeam.getTransmission().getValue()
             if fTransmission < self.fMinTransmission:
                 strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                 strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %"
                 self.page.font(_color="red", size="+2")
                 self.page.i()
                 self.page.h2(strWarningMessage1 + "<br>" +
                              strWarningMessage2)
                 self.page.i.close()
                 self.page.font.close()
         self.page.h2("Data collection info")
         firstImage = firstSubWedge.image[0]
         strDate = firstImage.date.value
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         self.page.table(class_='dataCollectionInfo',
                         border_="1",
                         cellpadding_="0")
         self.page.tr(align_="CENTER")
         self.page.th("Data collection date",
                      bgcolor_=self.strTableColourTitle2)
         self.page.th(strDate, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr(align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Image prefix", bgcolor_=self.strTableColourTitle2)
         self.page.th(strPrefix, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.tr(align_="CENTER", bgcolor_=self.strTableColourTitle2)
         self.page.th("Directory", bgcolor_=self.strTableColourTitle2)
         self.page.th(strDirName, bgcolor_=self.strTableColourRows)
         self.page.tr.close()
         self.page.table.close()
예제 #33
0
    def generateCommands(self, _xsDataInputH5ToCBF):
        """
        This method creates a list of commands for H5ToXDS
        """
        self.DEBUG("EDPluginH5ToCBFv1_0.generateCommands")

        hdf5File = _xsDataInputH5ToCBF.hdf5File.path.value
        directory = os.path.dirname(hdf5File)
        prefix = EDUtilsImage.getPrefix(hdf5File)

        imageNumber = _xsDataInputH5ToCBF.imageNumber.value

        if _xsDataInputH5ToCBF.hdf5ImageNumber is None:
            hdf5ImageNumber = imageNumber
        else:
            hdf5ImageNumber = _xsDataInputH5ToCBF.hdf5ImageNumber.value

        if "master" in hdf5File:
            masterFile = hdf5File
        else:
            masterFile = os.path.join(directory, prefix + "_{0}_master.h5".format(hdf5ImageNumber))

        CBFFileName = prefix + "_%04d" % imageNumber + ".cbf"
        tmpCBFFileName = "tmp_" + CBFFileName

        if self.dataInput.forcedOutputDirectory is None:
            self.CBFFile = os.path.join(directory, CBFFileName)
        else:
            forcedOutputDirectory = self.dataInput.forcedOutputDirectory.path.value
            if not os.path.exists(forcedOutputDirectory):
                os.makedirs(forcedOutputDirectory, 0755)
            self.CBFFile = os.path.join(forcedOutputDirectory, CBFFileName)

        self.tmpCBFFile = os.path.join(self.getWorkingDirectory(), tmpCBFFileName)

        scriptCommandLine = "{0} {1} {2}".format(masterFile, imageNumber - hdf5ImageNumber + 1, tmpCBFFileName)

        return scriptCommandLine
 def dataCollectionInfo(self):
     xsDataCollection = self.xsDataResultCharacterisation.getDataCollection()
     if xsDataCollection is not None:
         firstSubWedge = xsDataCollection.subWedge[0]
         # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
         xsDataBeam = firstSubWedge.getExperimentalCondition().getBeam()
         if xsDataBeam.getTransmission() is not None:
             fTransmission = xsDataBeam.getTransmission().getValue()
             if fTransmission < self.fMinTransmission:
                 strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                 strWarningMessage2 = "If this transmission setting is not intentional, please consider re-characterising with transmission set to 100 %"
                 self.workflowStepReport.addWarning(strWarningMessage1)
                 self.workflowStepReport.addWarning(strWarningMessage2)
         firstImage = firstSubWedge.image[0]
         if firstImage.date is not None:
             strDate = firstImage.date.value
         else:
             strDate = "-----"
         strPrefix = EDUtilsImage.getPrefix(firstImage.path.value)
         strDirName = os.path.dirname(firstImage.path.value)
         dictTable = {"type": "table",
                      "title": "Data collection info",
                      "columns": [],
                      "data": []}
         listRow = []
         dictTable["columns"].append("Data collection date")
         listRow.append(strDate)
         dictTable["columns"].append("Image prefix")
         listRow.append(strPrefix)
         dictTable["columns"].append("Directory")
         listRow.append(strDirName)
         dictTable["data"].append(listRow)
         #
         self.workflowStepReport.addTable("Data collection info",
                                          dictTable["columns"],
                                          dictTable["data"],
                                          orientation="vertical")
 def createImageDict(self, _xsDataControlDozorInput):
     # Create dictionary of all images with the image number as key
     dictImage = {}
     if len(_xsDataControlDozorInput.image) > 0:
         listImage = _xsDataControlDozorInput.image
         pathToFirstImage = listImage[0].path.value
         self.directory = os.path.dirname(pathToFirstImage)
         self.template = os.path.basename(pathToFirstImage).replace("0001", "####")
     else:
         # Create list of images
         listImage = []
         self.directory = _xsDataControlDozorInput.directory.path.value
         self.template = _xsDataControlDozorInput.template.value
         startNo = _xsDataControlDozorInput.startNo.value
         endNo = _xsDataControlDozorInput.endNo.value
         for imageIndex in range(startNo, endNo + 1):
             imageName = self.template % imageIndex
             imagePath = os.path.join(self.directory, imageName)
             listImage.append(XSDataFile(XSDataString(imagePath)))
     for image in listImage:
         imagePath = image.path.value
         imageNo = EDUtilsImage.getImageNumber(imagePath)
         dictImage[imageNo] = image
     return dictImage
 def process(self, _edObject=None):
     EDPluginControl.process(self)
     self.DEBUG("EDPluginControlDozorv1_0.process")
     xsDataResultControlDozor = XSDataResultControlDozor()
     # Check if connection to ISPyB needed
     if self.dataInput.dataCollectionId is not None:
         edPluginRetrieveDataCollection = self.loadPlugin("EDPluginISPyBRetrieveDataCollectionv1_4")
         xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection()
         xsDataInputRetrieveDataCollection.dataCollectionId = self.dataInput.dataCollectionId
         edPluginRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection
         edPluginRetrieveDataCollection.executeSynchronous()
         ispybDataCollection = edPluginRetrieveDataCollection.dataOutput.dataCollection
         batchSize = ispybDataCollection.numberOfImages
         if batchSize > self.maxBatchSize:
             batchSize = self.maxBatchSize
         if abs(ispybDataCollection.overlap) > 1:
             self.hasOverlap = True
             self.overlap = ispybDataCollection.overlap
         dictImage = self.createImageDictFromISPyB(ispybDataCollection)
     else:
         # No connection to ISPyB, take parameters from input
         if self.dataInput.batchSize is None:
             batchSize = 1
         else:
             batchSize = self.dataInput.batchSize.value
         dictImage = self.createImageDict(self.dataInput)
     listAllBatches = self.createListOfBatches(dictImage.keys(), batchSize)
     if dictImage[listAllBatches[0][0]].path.value.endswith("h5"):
         # Convert HDF5 images to CBF
         self.cbfTempDir = tempfile.mkdtemp(prefix="CbfTemp_")
         dictImage, self.hasHdf5Prefix = self.convertToCBF(dictImage)
     for listBatch in listAllBatches:
         # Read the header from the first image in the batch
         xsDataFile = dictImage[listBatch[0]]
         edPluginControlReadImageHeader = self.loadPlugin(self.strEDPluginControlReadImageHeaderName)
         xsDataInputReadImageHeader = XSDataInputReadImageHeader()
         xsDataInputReadImageHeader.image = xsDataFile
         edPluginControlReadImageHeader.dataInput = xsDataInputReadImageHeader
         edPluginControlReadImageHeader.executeSynchronous()
         subWedge = edPluginControlReadImageHeader.dataOutput.subWedge
         xsDataInputDozor = XSDataInputDozor()
         beam = subWedge.experimentalCondition.beam
         detector = subWedge.experimentalCondition.detector
         goniostat = subWedge.experimentalCondition.goniostat
         xsDataInputDozor.detectorType = detector.type
         xsDataInputDozor.exposureTime = XSDataDouble(beam.exposureTime.value)
         xsDataInputDozor.spotSize = XSDataInteger(3)
         xsDataInputDozor.detectorDistance = XSDataDouble(detector.distance.value)
         xsDataInputDozor.wavelength = XSDataDouble(beam.wavelength.value)
         #            xsDataInputDozor.fractionPolatization : XSDataDouble optional
         orgx = detector.beamPositionY.value / detector.pixelSizeY.value
         orgy = detector.beamPositionX.value / detector.pixelSizeX.value
         xsDataInputDozor.orgx = XSDataDouble(orgx)
         xsDataInputDozor.orgy = XSDataDouble(orgy)
         xsDataInputDozor.oscillationRange = XSDataDouble(goniostat.oscillationWidth.value)
         #            xsDataInputDozor.imageStep : XSDataDouble optional
         xsDataInputDozor.startingAngle = XSDataDouble(goniostat.rotationAxisStart.value)
         xsDataInputDozor.firstImageNumber = subWedge.image[0].number
         xsDataInputDozor.numberImages = XSDataInteger(len(listBatch))
         if self.hasOverlap:
             xsDataInputDozor.overlap = XSDataAngle(self.overlap)
         strFileName = subWedge.image[0].path.value
         strPrefix = EDUtilsImage.getPrefix(strFileName)
         strSuffix = EDUtilsImage.getSuffix(strFileName)
         if EDUtilsPath.isEMBL():
             strXDSTemplate = "%s_?????.%s" % (strPrefix, strSuffix)
         elif self.hasHdf5Prefix and not self.hasOverlap:
             strXDSTemplate = "%s_??????.%s" % (strPrefix, strSuffix)
         else:
             strXDSTemplate = "%s_????.%s" % (strPrefix, strSuffix)
         xsDataInputDozor.nameTemplateImage = XSDataString(
             os.path.join(os.path.dirname(strFileName), strXDSTemplate)
         )
         xsDataInputDozor.wedgeNumber = self.dataInput.wedgeNumber
         xsDataInputDozor.radiationDamage = self.dataInput.radiationDamage
         edPluginDozor = self.loadPlugin(self.strEDPluginDozorName, "Dozor_%05d" % subWedge.image[0].number.value)
         edPluginDozor.dataInput = xsDataInputDozor
         edPluginDozor.executeSynchronous()
         indexImage = 0
         for xsDataResultDozor in edPluginDozor.dataOutput.imageDozor:
             xsDataControlImageDozor = XSDataControlImageDozor()
             xsDataControlImageDozor.number = xsDataResultDozor.number
             xsDataControlImageDozor.image = dictImage[listBatch[indexImage]]
             xsDataControlImageDozor.spotsNumOf = xsDataResultDozor.spotsNumOf
             xsDataControlImageDozor.spotsIntAver = xsDataResultDozor.spotsIntAver
             xsDataControlImageDozor.spotsResolution = xsDataResultDozor.spotsResolution
             xsDataControlImageDozor.powderWilsonScale = xsDataResultDozor.powderWilsonScale
             xsDataControlImageDozor.powderWilsonBfactor = xsDataResultDozor.powderWilsonBfactor
             xsDataControlImageDozor.powderWilsonResolution = xsDataResultDozor.powderWilsonResolution
             xsDataControlImageDozor.powderWilsonCorrelation = xsDataResultDozor.powderWilsonCorrelation
             xsDataControlImageDozor.powderWilsonRfactor = xsDataResultDozor.powderWilsonRfactor
             xsDataControlImageDozor.mainScore = xsDataResultDozor.mainScore
             xsDataControlImageDozor.spotScore = xsDataResultDozor.spotScore
             xsDataControlImageDozor.visibleResolution = xsDataResultDozor.visibleResolution
             xsDataControlImageDozor.spotFile = xsDataResultDozor.spotFile
             xsDataControlImageDozor.angle = xsDataResultDozor.angle
             xsDataResultControlDozor.addImageDozor(xsDataControlImageDozor)
             if xsDataResultControlDozor.inputDozor is None:
                 xsDataResultControlDozor.inputDozor = XSDataDozorInput().parseString(xsDataInputDozor.marshal())
             indexImage += 1
         xsDataResultControlDozor.halfDoseTime = edPluginDozor.dataOutput.halfDoseTime
     self.dataOutput = xsDataResultControlDozor
     if self.cbfTempDir is not None:
         shutil.rmtree(self.cbfTempDir)
예제 #37
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlDozorv1_1.process")
        msg = "EDPluginControlDozorXmlRpcv1_0 started..."
        self.sendMessageToMXCuBE("Processing started...", "info")
        xsDataResultControlDozor = XSDataResultControlDozor()

        firstFileName = self.dataInput.template.value % (
            self.dataInput.first_run_number.value,
            self.dataInput.first_image_number.value)

        fWaitFileTimeout = 180  #sec

        self.waitFileFirst = self.loadPlugin("EDPluginMXWaitFilev1_1",
                                             "MXWaitFileFirst")
        xsDataInputMXWaitFileFirst = XSDataInputMXWaitFile()
        xsDataInputMXWaitFileFirst.file = XSDataFile(
            XSDataString(firstFileName))
        xsDataInputMXWaitFileFirst.timeOut = XSDataTime(fWaitFileTimeout)

        self.waitFileFirst.size = XSDataInteger(1000000)
        self.waitFileFirst.dataInput = xsDataInputMXWaitFileFirst
        self.waitFileFirst.executeSynchronous()
        if self.waitFileFirst.dataOutput.timedOut.value:
            strWarningMessage = "Timeout after %d seconds waiting for the first image %s!" % (
                fWaitFileTimeout, firstFileName)
            #self.addWarningMessage(strWarningMessage)
            #self.WARNING(strWarningMessage)
            #self.sendMessageToMXCuBE(strWarningMessage, "error")

        edPluginControlReadImageHeader = self.loadPlugin(
            self.strEDPluginControlReadImageHeaderName)
        xsDataInputReadImageHeader = XSDataInputReadImageHeader()
        xsDataInputReadImageHeader.image = XSDataFile(
            XSDataString(firstFileName))

        edPluginControlReadImageHeader.dataInput = xsDataInputReadImageHeader
        edPluginControlReadImageHeader.executeSynchronous()
        subWedge = edPluginControlReadImageHeader.dataOutput.subWedge

        xsDataInputDozor = XSDataInputDozor()
        beam = subWedge.experimentalCondition.beam
        detector = subWedge.experimentalCondition.detector
        goniostat = subWedge.experimentalCondition.goniostat
        xsDataInputDozor.detectorType = detector.type
        xsDataInputDozor.exposureTime = XSDataDouble(beam.exposureTime.value)
        xsDataInputDozor.spotSize = XSDataDouble(3.0)
        xsDataInputDozor.detectorDistance = XSDataDouble(
            detector.distance.value)
        xsDataInputDozor.wavelength = XSDataDouble(beam.wavelength.value)
        orgx = detector.beamPositionY.value / detector.pixelSizeY.value
        orgy = detector.beamPositionX.value / detector.pixelSizeX.value
        xsDataInputDozor.orgx = XSDataDouble(orgx)
        xsDataInputDozor.orgy = XSDataDouble(orgy)

        # GB: the 50 might need tunig to CPU speed and number of. 2000 is a current limit of Dozor.
        self.maxChunkSize = 4000  #a min (150 * 2527 * 2463 /detector.numberPixelX.value / detector.numberPixelY.value, 2000)

        _beamstop = self.beamstop(detector)
        if _beamstop is not None:
            #self.WARNING("Setting beamstop shadow: %s"%_beamstop)
            xsDataInputDozor.ixMin = XSDataInteger(_beamstop['ix_min'])
            xsDataInputDozor.iyMin = XSDataInteger(_beamstop['iy_min'])
            xsDataInputDozor.ixMax = XSDataInteger(_beamstop['ix_max'])
            xsDataInputDozor.iyMax = XSDataInteger(_beamstop['iy_max'])

        if self.dataInput.pixelMin is not None:
            xsDataInputDozor.pixelMin = self.dataInput.pixelMin

        if self.dataInput.pixelMax is not None:
            xsDataInputDozor.pixelMax = self.dataInput.pixelMax

        _serial = 0
        _startTime = time.time()
        chunk_list = self.schedule(goniostat.rotationAxisStart.value,
                                   goniostat.oscillationWidth.value)

        for chunk in chunk_list:

            if not self.poll_file(
                    self.dataInput.template.value %
                (chunk['run_number'], chunk['first'] + chunk['number_of'] - 1),
                (beam.exposureTime.value + 0.003) * chunk['number_of'] + 30):
                self.sendMessageToMXCuBE("Timeout waiting for frame: %d" %
                                         (chunk['first'] + chunk['number_of']),
                                         level="error")
                return

            xsDataInputDozor.oscillationRange = XSDataDouble(
                chunk['rotation_range'])
            xsDataInputDozor.startingAngle = XSDataDouble(
                chunk['rotation_start'])
            xsDataInputDozor.firstImageNumber = XSDataInteger(chunk['first'])
            xsDataInputDozor.numberImages = XSDataInteger(chunk['number_of'])

            strFileName = self.dataInput.template.value % (chunk['run_number'],
                                                           chunk['first'])
            strXDSTemplate = EDUtilsImage.getTemplate(strFileName, '?')
            xsDataInputDozor.nameTemplateImage = XSDataString(
                os.path.join(os.path.dirname(strFileName), strXDSTemplate))

            edPluginDozor = self.loadPlugin(self.strEDPluginDozorName, "Dozor")
            edPluginDozor.dataInput = xsDataInputDozor

            edPluginDozor.executeSynchronous()

            xsDataChunkResultControlImageDozor = XSDataResultControlDozor()

            dozor_batch_list = []  #[[1,4,3,8,6],
            #[2, 5, 3, 3, 7],[1, 3, 12, 11, 4],[4, 2, 3, 5, 7]]
            #ozor_image_dict = {}
            diff_image_count = 0

            xsDataControlImageDozor = XSDataControlImageDozor()

            for xsDataResultDozor in edPluginDozor.dataOutput.imageDozor:
                xsDataControlImageDozor = XSDataControlImageDozor()

                xsDataControlImageDozor.number = xsDataResultDozor.number
                strFileName = self.dataInput.template.value % (
                    chunk['run_number'], xsDataControlImageDozor.number.value)
                xsDataControlImageDozor.image = XSDataFile(
                    XSDataString(strFileName))

                xsDataControlImageDozor.spots_num_of = xsDataResultDozor.spots_num_of
                xsDataControlImageDozor.spots_int_aver = xsDataResultDozor.spots_int_aver
                xsDataControlImageDozor.spots_resolution = xsDataResultDozor.spots_resolution
                xsDataControlImageDozor.powder_wilson_scale = xsDataResultDozor.powder_wilson_scale
                xsDataControlImageDozor.powder_wilson_bfactor = xsDataResultDozor.powder_wilson_bfactor
                xsDataControlImageDozor.powder_wilson_resolution = xsDataResultDozor.powder_wilson_resolution
                xsDataControlImageDozor.powder_wilson_correlation = xsDataResultDozor.powder_wilson_correlation
                xsDataControlImageDozor.powder_wilson_rfactor = xsDataResultDozor.powder_wilson_rfactor
                xsDataControlImageDozor.score = xsDataResultDozor.score
                xsDataResultControlDozor.addImageDozor(xsDataControlImageDozor)

                dozor_batch_list.append(
                    (xsDataControlImageDozor.number.getValue(),
                     xsDataControlImageDozor.spots_num_of.getValue(),
                     xsDataControlImageDozor.spots_int_aver.getValue(),
                     xsDataControlImageDozor.spots_resolution.getValue(),
                     xsDataControlImageDozor.score.getValue()))
                if xsDataControlImageDozor.spots_num_of.getValue() > 0:
                    diff_image_count += 1
                xsDataChunkResultControlImageDozor.addImageDozor(
                    xsDataControlImageDozor)

            xsDataChunkResultControlImageDozor.exportToFile(
                "ResultControlDozor_Chunk_%06d.xml" % _serial)

            self.sendResultToMXCuBE(dozor_batch_list)

            _serial += 1
            self.screen("Chunk %d/%d done in %.3f seconds" % \
                 (_serial, len(chunk_list), time.time()-_startTime))
            self.sendMessageToMXCuBE("Chunk %d/%d done in %.2f sec., num diffr. frames: %d/%d" % \
                                     (_serial,
                                      len(chunk_list),
                                      time.time() - _startTime,
                                      diff_image_count,
                                      len(dozor_batch_list)
                                     )
                                    )

            _startTime = time.time()
    def process(self, _edPlugin=None):
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlInterfaceToMXCuBEv1_4.process...")

        xsDataInputMXCuBE = self.getDataInput()
        xsDataInputInterface = XSDataInputInterface()
        self.edPluginControlInterface = self.loadPlugin(self.strPluginControlInterface)
        self.xsDataFirstImage = None
        for xsDataSetMXCuBE in xsDataInputMXCuBE.getDataSet():
            for xsDataFile in xsDataSetMXCuBE.getImageFile():
                if xsDataFile.path.value.endswith(".h5"):
                    self.bIsEigerDetector = True
                    self.xsDataFirstImage = xsDataFile
                    xsDataInputControlH5ToCBF = XSDataInputControlH5ToCBF()
                    xsDataInputControlH5ToCBF.hdf5File = XSDataFile(xsDataFile.path)
                    xsDataInputControlH5ToCBF.imageNumber = XSDataInteger(EDUtilsImage.getImageNumber(xsDataFile.path.value))
                    edPluginControlH5ToCBF = self.loadPlugin(self.strPluginControlH5ToCBF, "ControlH5ToCBF")
                    edPluginControlH5ToCBF.dataInput = xsDataInputControlH5ToCBF
                    edPluginControlH5ToCBF.executeSynchronous()
                    cbfFile = edPluginControlH5ToCBF.dataOutput.outputCBFFile
                    xsDataInputInterface.addImagePath(cbfFile)
                else:
                    xsDataInputInterface.addImagePath(xsDataFile)
                if self.xsDataFirstImage is None:
                    self.xsDataFirstImage = xsDataFile

        # Check that images are on disk, otherwise wait
        for xsDataImagePath in xsDataInputInterface.imagePath:
            imagePath = xsDataImagePath.path.value
            if os.path.exists(imagePath):
                message = "Input file ok: {0}".format(imagePath)
                self.screen(message)
                self.sendMessageToMXCuBE(message)
            else:
                self.sendMessageToMXCuBE("Waiting for file: {0}, timeout {1} s".format(imagePath, self.fMXWaitFileTimeOut))
                edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                xsDataInputMXWaitFile = XSDataInputMXWaitFile()
                xsDataInputMXWaitFile.file = XSDataFile(XSDataString(imagePath))
                xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
                edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                edPluginMXWaitFile.executeSynchronous()
                if edPluginMXWaitFile.dataOutput.timedOut.value:
                    errorMessage = "ERROR! File {0} does not exist on disk.".format(imagePath)
                    self.ERROR(errorMessage)
                    self.sendMessageToMXCuBE(errorMessage, "error")
                    self.setFailure()
                    break


        xsDataExperimentalCondition = self.getFluxAndBeamSizeFromISPyB(self.xsDataFirstImage, \
                                                            xsDataInputMXCuBE.getExperimentalCondition())

        xsDataInputInterface.setExperimentalCondition(xsDataExperimentalCondition)
        xsDataInputInterface.setDiffractionPlan(xsDataInputMXCuBE.getDiffractionPlan())
        xsDataInputInterface.setSample(xsDataInputMXCuBE.getSample())
        xsDataInputInterface.setDataCollectionId(xsDataInputMXCuBE.getDataCollectionId())
        self.edPluginControlInterface.setDataInput(xsDataInputInterface)

        if not self.isFailure() and self.edPluginControlInterface is not None:
            self.connectProcess(self.edPluginControlInterface.executeSynchronous)
            self.edPluginControlInterface.connectSUCCESS(self.doSuccessActionInterface)
            self.edPluginControlInterface.connectFAILURE(self.doFailureActionInterface)
    def generateXSDataMOSFLMInputIndexing(_xsDataIndexingInput):
        """
        Translation from XSDataIndexingInput to XSDataMOSFLMInputIndexing.
        """
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMImage

        EDVerbose.DEBUG(
            "EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing")

        xsDataCollection = _xsDataIndexingInput.getDataCollection()
        xsDataExperimentalCondition = _xsDataIndexingInput.getExperimentalCondition(
        )
        xsDataCrystal = _xsDataIndexingInput.getCrystal()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()
        xsDataMOSFLMInputIndexing = XSDataMOSFLMInputIndexing()

        if (xsDataExperimentalCondition is None):
            xsDataExperimentalCondition = xsDataSubWedgeList[
                0].getExperimentalCondition()

        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataGoniostat = xsDataExperimentalCondition.getGoniostat()

        dWavelength = xsDataBeam.getWavelength().getValue()
        dDistance = xsDataDetector.getDistance().getValue()
        dBeamPositionX = xsDataDetector.getBeamPositionX().getValue()
        dBeamPositionY = xsDataDetector.getBeamPositionY().getValue()

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(XSDataLength(dBeamPositionX))
        xsDataMOSFLMBeamPosition.setY(XSDataLength(dBeamPositionY))
        xsDataMOSFLMInputIndexing.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(
            xsDataDetector)
        xsDataMOSFLMInputIndexing.setDetector(xsDataMOSFLMDetector)

        xsDataMOSFLMInputIndexing.setWavelength(XSDataWavelength(dWavelength))
        xsDataMOSFLMInputIndexing.setDistance(XSDataLength(dDistance))

        xsDataSubWedgeFirst = xsDataSubWedgeList[0]
        xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0]
        strPath = xsDataImageFirst.getPath().getValue()
        strFileName = os.path.basename(strPath)
        strDirectory = os.path.dirname(strPath)

        if xsDataDetector.type.value == "eiger2_16m":
            strMOSFLMTemplate = EDUtilsImage.getH5MasterTemplate(
                strFileName, 1)
        else:
            strMOSFLMTemplate = EDUtilsImage.getTemplate(strFileName, "#")
        xsDataMOSFLMInputIndexing.setTemplate(XSDataString(strMOSFLMTemplate))
        xsDataMOSFLMInputIndexing.setDirectory(XSDataString(strDirectory))

        if (xsDataCrystal is not None):
            xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
            if (xsDataSpaceGroup is not None):
                xsDataStringName = xsDataSpaceGroup.getName()
                if (xsDataStringName is not None):
                    xsDataMOSFLMInputIndexing.setSymmetry(
                        XSDataString(xsDataStringName.getValue()))

        # Loop through the list of sub wedges

        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
            ).getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart(
            ).getValue()
            fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth(
            ).getValue()

            # First find the lowest image number
            iLowestImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                if (iLowestImageNumber is None):
                    iLowestImageNumber = iImageNumber
                elif (iImageNumber < iLowestImageNumber):
                    iLowestImageNumber = iImageNumber

            # Loop through the list of images

            for xsDataImage in xsDataImageList:
                # Create the MOSFLM image object

                xsDataMOSFLMImage = XSDataMOSFLMImage()

                iImageNumber = xsDataImage.getNumber().getValue()
                xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber))

                fImageOscillationStart = fGonioStatOscillationStart + (
                    iImageNumber -
                    iLowestImageNumber) * fGonioStatOscillationRange
                xsDataMOSFLMImage.setRotationAxisStart(
                    XSDataAngle(fImageOscillationStart))
                xsDataMOSFLMImage.setRotationAxisEnd(
                    XSDataAngle(fImageOscillationStart +
                                fGonioStatOscillationRange))

                xsDataMOSFLMInputIndexing.addImage(xsDataMOSFLMImage)

        return xsDataMOSFLMInputIndexing
    def generateXSDataMOSFLMInputGeneratePrediction(
            xsDataGeneratePredictionInput):
        """
        Translation from XSDataGeneratePredictionInput to XSDataMOSFLMInputGeneratePrediction.
        """
        EDVerbose.DEBUG(
            "EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputGeneratePrediction"
        )
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMImage
        from XSDataMOSFLMv10 import XSDataMOSFLMNewmat
        from XSDataMOSFLMv10 import XSDataMOSFLMMissettingsAngles
        from XSDataMOSFLMv10 import XSDataMOSFLMInputGeneratePrediction

        xsDataIndexingSolutionSelected = xsDataGeneratePredictionInput.getSelectedIndexingSolution(
        )

        xsDataCollection = xsDataGeneratePredictionInput.getDataCollection()
        xsDataSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataImageList = xsDataSubWedge.getImage()
        xsDataImageFirst = xsDataImageList[0]

        xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
        xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation()
        xsDataExperimentalCondition = xsDataIndexingSolutionSelected.getExperimentalConditionRefined(
        )
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataMatrixA = xsDataOrientation.getMatrixA()
        xsDataMatrixU = xsDataOrientation.getMatrixU()
        xsDataCell = xsDataCrystal.getCell()

        xsDataMOSFLMInputGeneratePrediction = XSDataMOSFLMInputGeneratePrediction(
        )
        xsDataMOSFLMNewmat = XSDataMOSFLMNewmat()
        xsDataMOSFLMNewmat.setRefinedCell(xsDataCell)
        xsDataMOSFLMNewmat.setAMatrix(xsDataMatrixA)
        xsDataMOSFLMNewmat.setUMatrix(xsDataMatrixU)
        xsDataMOSFLMInputGeneratePrediction.setMatrix(xsDataMOSFLMNewmat)

        xsDataMOSFLMMissettingsAngles = XSDataMOSFLMMissettingsAngles()
        xsDataMOSFLMMissettingsAngles.setPhix(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiy(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiz(XSDataAngle(0.0))
        xsDataMOSFLMNewmat.setMissettingAngles(xsDataMOSFLMMissettingsAngles)

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(xsDataDetector.getBeamPositionX())
        xsDataMOSFLMBeamPosition.setY(xsDataDetector.getBeamPositionY())
        xsDataMOSFLMInputGeneratePrediction.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMInputGeneratePrediction.setMosaicity(
            xsDataCrystal.getMosaicity())
        xsDataMOSFLMInputGeneratePrediction.setSymmetry(
            xsDataCrystal.getSpaceGroup().getName())

        strPathFirst = xsDataImageFirst.getPath().getValue()
        strDirectoryFirst = os.path.dirname(strPathFirst)
        strFilenameFirst = os.path.basename(strPathFirst)

        xsDataMOSFLMInputGeneratePrediction.setWavelength(
            xsDataBeam.getWavelength())
        xsDataMOSFLMInputGeneratePrediction.setDistance(
            xsDataDetector.getDistance())
        xsDataMOSFLMInputGeneratePrediction.setDirectory(
            XSDataString(strDirectoryFirst))
        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(
            xsDataDetector)
        xsDataMOSFLMInputGeneratePrediction.setDetector(xsDataMOSFLMDetector)

        # The MOSFLM plugin can only handle one image

        xsDataImage = xsDataSubWedge.getImage()[0]
        xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
        ).getGoniostat()

        iImageNumber = xsDataImage.getNumber().getValue()

        if xsDataDetector.type.value == "eiger2_16m":
            strMOSFLMTemplate = EDUtilsImage.getH5MasterTemplate(
                strFilenameFirst, iImageNumber)
        else:
            strMOSFLMTemplate = EDUtilsImage.getTemplate(strFilenameFirst, "#")
        xsDataMOSFLMInputGeneratePrediction.setTemplate(
            XSDataString(strMOSFLMTemplate))

        xsDataMOSFLMImage = XSDataMOSFLMImage()
        xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber))

        fOscillationStart = xsDataGoniostat.getRotationAxisStart().getValue()
        fOscillationRange = xsDataGoniostat.getOscillationWidth().getValue()
        xsDataMOSFLMImage.setRotationAxisStart(XSDataAngle(fOscillationStart))
        xsDataMOSFLMImage.setRotationAxisEnd(
            XSDataAngle(fOscillationStart + fOscillationRange))

        xsDataMOSFLMInputGeneratePrediction.setImage(xsDataMOSFLMImage)

        return xsDataMOSFLMInputGeneratePrediction
예제 #41
0
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlDozorv1_0.process")
        self.sendMessageToMXCuBE("Processing started...", "info")
        EDUtilsParallel.initializeNbThread()
        xsDataResultControlDozor = XSDataResultControlDozor()
        # Check if connection to ISPyB needed
        if self.dataInput.dataCollectionId is not None:
            edPluginRetrieveDataCollection = self.loadPlugin("EDPluginISPyBRetrieveDataCollectionv1_4")
            xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection()
            xsDataInputRetrieveDataCollection.dataCollectionId = self.dataInput.dataCollectionId
            edPluginRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection
            edPluginRetrieveDataCollection.executeSynchronous()
            ispybDataCollection = edPluginRetrieveDataCollection.dataOutput.dataCollection
            if self.batchSize is None:
                batchSize = ispybDataCollection.numberOfImages
            else:
                batchSize = self.batchSize
            if batchSize > self.maxBatchSize:
                batchSize = self.maxBatchSize
            if abs(ispybDataCollection.overlap) > 1:
                self.hasOverlap = True
                self.overlap = ispybDataCollection.overlap
            dictImage = self.createImageDictFromISPyB(ispybDataCollection)
        else:
            # No connection to ISPyB, take parameters from input
            if self.dataInput.batchSize is None:
                batchSize = self.maxBatchSize
            else:
                batchSize = self.dataInput.batchSize.value
            dictImage = self.createImageDict(self.dataInput)
        self.screen("Dozor batch size: {0}".format(batchSize))
        if self.dataInput.hdf5BatchSize is not None:
            self.hdf5BatchSize = self.dataInput.hdf5BatchSize.value
        listAllBatches = self.createListOfBatches(dictImage.keys(), batchSize)
        if dictImage[listAllBatches[0][0]].path.value.endswith("h5"):
            # Convert HDF5 images to CBF
            self.screen("HDF5 converter batch size: {0}".format(self.batchSize))
            if self.doRadiationDamage:
                self.cbfTempDir = None
            else:
                self.cbfTempDir = tempfile.mkdtemp(prefix="CbfTemp_")
            listHdf5Batches = self.createListOfBatches(dictImage.keys(), self.batchSize)
            dictImage, self.hasHdf5Prefix = self.convertToCBF(dictImage, listHdf5Batches, self.doRadiationDamage)
        for listBatch in listAllBatches:
            # Read the header from the first image in the batch
            xsDataFile = dictImage[listBatch[0]]
            edPluginControlReadImageHeader = self.loadPlugin(self.strEDPluginControlReadImageHeaderName)
            xsDataInputReadImageHeader = XSDataInputReadImageHeader()
            xsDataInputReadImageHeader.image = xsDataFile
            edPluginControlReadImageHeader.dataInput = xsDataInputReadImageHeader
            edPluginControlReadImageHeader.executeSynchronous()
            subWedge = edPluginControlReadImageHeader.dataOutput.subWedge
            xsDataInputDozor = XSDataInputDozor()
            beam = subWedge.experimentalCondition.beam
            detector = subWedge.experimentalCondition.detector
            goniostat = subWedge.experimentalCondition.goniostat
            xsDataInputDozor.detectorType = detector.type
            xsDataInputDozor.exposureTime = XSDataDouble(beam.exposureTime.value)
            xsDataInputDozor.spotSize = XSDataInteger(3)
            xsDataInputDozor.detectorDistance = XSDataDouble(detector.distance.value)
            xsDataInputDozor.wavelength = XSDataDouble(beam.wavelength.value)
#            xsDataInputDozor.fractionPolatization : XSDataDouble optional
            orgx = detector.beamPositionY.value / detector.pixelSizeY.value
            orgy = detector.beamPositionX.value / detector.pixelSizeX.value
            xsDataInputDozor.orgx = XSDataDouble(orgx)
            xsDataInputDozor.orgy = XSDataDouble(orgy)
            xsDataInputDozor.oscillationRange = XSDataDouble(goniostat.oscillationWidth.value)
#            xsDataInputDozor.imageStep : XSDataDouble optional
            xsDataInputDozor.startingAngle = XSDataDouble(goniostat.rotationAxisStart.value)
            xsDataInputDozor.firstImageNumber = subWedge.image[0].number
            xsDataInputDozor.numberImages = XSDataInteger(len(listBatch))
            if self.hasOverlap:
                xsDataInputDozor.overlap = XSDataAngle(self.overlap)
            strFileName = subWedge.image[0].path.value
            strPrefix = EDUtilsImage.getPrefix(strFileName)
            strSuffix = EDUtilsImage.getSuffix(strFileName)
            if EDUtilsPath.isEMBL():
                strXDSTemplate = "%s_?????.%s" % (strPrefix, strSuffix)
            elif self.hasHdf5Prefix and not self.hasOverlap:
                strXDSTemplate = "%s_??????.%s" % (strPrefix, strSuffix)
            else:
                strXDSTemplate = "%s_????.%s" % (strPrefix, strSuffix)
            xsDataInputDozor.nameTemplateImage = XSDataString(os.path.join(os.path.dirname(strFileName), strXDSTemplate))
            xsDataInputDozor.wedgeNumber = self.dataInput.wedgeNumber
            xsDataInputDozor.radiationDamage = self.dataInput.radiationDamage
            edPluginDozor = self.loadPlugin(self.strEDPluginDozorName, "Dozor_%05d" % subWedge.image[0].number.value)
            edPluginDozor.dataInput = xsDataInputDozor
            edPluginDozor.execute()
            edPluginDozor.synchronize()
            indexImage = 0
            imageDozorBatchList = []

            for xsDataResultDozor in edPluginDozor.dataOutput.imageDozor:
                xsDataControlImageDozor = XSDataControlImageDozor()
                xsDataControlImageDozor.number = xsDataResultDozor.number
                xsDataControlImageDozor.image = dictImage[listBatch[indexImage]]
                xsDataControlImageDozor.spotsNumOf = xsDataResultDozor.spotsNumOf
                xsDataControlImageDozor.spotsIntAver = xsDataResultDozor.spotsIntAver
                xsDataControlImageDozor.spotsResolution = xsDataResultDozor.spotsResolution
                xsDataControlImageDozor.powderWilsonScale = xsDataResultDozor.powderWilsonScale
                xsDataControlImageDozor.powderWilsonBfactor = xsDataResultDozor.powderWilsonBfactor
                xsDataControlImageDozor.powderWilsonResolution = xsDataResultDozor.powderWilsonResolution
                xsDataControlImageDozor.powderWilsonCorrelation = xsDataResultDozor.powderWilsonCorrelation
                xsDataControlImageDozor.powderWilsonRfactor = xsDataResultDozor.powderWilsonRfactor
                xsDataControlImageDozor.mainScore = xsDataResultDozor.mainScore
                xsDataControlImageDozor.spotScore = xsDataResultDozor.spotScore
                xsDataControlImageDozor.visibleResolution = xsDataResultDozor.visibleResolution
                xsDataControlImageDozor.spotFile = xsDataResultDozor.spotFile
                xsDataControlImageDozor.angle = xsDataResultDozor.angle
                xsDataResultControlDozor.addImageDozor(xsDataControlImageDozor)
                if xsDataResultControlDozor.inputDozor is None:
                    xsDataResultControlDozor.inputDozor = XSDataDozorInput().parseString(xsDataInputDozor.marshal())
                indexImage += 1

                dozorSpotListShape = []
                dozorSpotList = []
                spotFile = None
                if xsDataControlImageDozor.spotFile is not None:
                    spotFile = xsDataControlImageDozor.spotFile.path.value
                    if os.path.exists(spotFile):
                        numpyArray = numpy.loadtxt(spotFile, skiprows=3)
                        dozorSpotList = base64.b64encode(numpyArray.tostring())
                        dozorSpotListShape.append(numpyArray.shape[0])
                        if len(numpyArray.shape) > 1:
                            dozorSpotListShape.append(numpyArray.shape[1])

                imageDozorDict = {"index": xsDataControlImageDozor.number.value,
                                  "imageName": xsDataControlImageDozor.image.path.value,
                                  "dozor_score": xsDataControlImageDozor.mainScore.value,
                                  "dozorSpotsNumOf" : xsDataControlImageDozor.spotsNumOf.value,
                                  "dozorSpotFile": spotFile,
                                  "dozorSpotList" : dozorSpotList,
                                  "dozorSpotListShape": dozorSpotListShape,
                                  "dozorSpotsIntAver": xsDataControlImageDozor.spotsIntAver.value,
                                  "dozorSpotsResolution": xsDataControlImageDozor.spotsResolution.value
                                  }
                imageDozorBatchList.append(imageDozorDict)

            xsDataResultControlDozor.halfDoseTime = edPluginDozor.dataOutput.halfDoseTime
            xsDataResultControlDozor.pngPlots = edPluginDozor.dataOutput.pngPlots

            self.sendResultToMXCuBE(imageDozorBatchList)
            self.sendMessageToMXCuBE("Batch processed")
        self.dataOutput = xsDataResultControlDozor
        if self.cbfTempDir is not None:
            if self.dataInput.keepCbfTmpDirectory is not None and self.dataInput.keepCbfTmpDirectory.value:
                self.dataOutput.pathToCbfDirectory = XSDataFile(XSDataString(self.cbfTempDir))
            else:
                shutil.rmtree(self.cbfTempDir)
    def generateDataCollectionDescriptorForSubWedge(self, calibDate, omegaR, kappaR, phiR, beamD, polarisationP, exposuretime, imagewidth, numberimages, wavelength, OmegaV, KappaV, PhiV, imgFnames):
        ##CONTAINER
        self.xsDC_v2 = XSDataCollection_v2()

        ##GonioCalib
        calib = XSDataMXv2.XSCalibration()
        cdate = XSDataMXv2.XSDataDate()
        cdate.setValue(XSDataMXv2.XSDataString(calibDate))
        calib.setDate(cdate)
        #OmegaCalib
        omegacal = XSDataMXv2.XSCalibratedDisplacementAxis()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(omegaR[0])
        zdir.setV2(omegaR[1])
        zdir.setV3(omegaR[2])
        omegacal.setZerodirection(zdir)
        omegacal.setXSCalibration(calib)
        #KappaCalib
        kappacal = XSDataMXv2.XSCalibratedDisplacementAxis()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(kappaR[0])
        zdir.setV2(kappaR[1])
        zdir.setV3(kappaR[2])
        kappacal.setZerodirection(zdir)
        kappacal.setXSCalibration(calib)
        #PhiCalib
        phical = XSDataMXv2.XSCalibratedDisplacementAxis()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(phiR[0])
        zdir.setV2(phiR[1])
        zdir.setV3(phiR[2])
        phical.setZerodirection(zdir)
        phical.setXSCalibration(calib)

        ##goni
        actgonio = XSDataMXv2.XSRotationalGoniostat()
        #omega
        omega = XSDataMXv2.XSGoniostatBaseAxis()
        omega.setName(XSDataMXv2.XSDataString('Omega'))
        omega.setIsscannable(XSDataMXv2.XSDataBoolean(1))
        omega.addXSCalibratedDisplacementAxis(omegacal)
        actgonio.setXSGoniostatBaseAxis(omega)
        #kappa
        kappa = XSDataMXv2.XSGoniostatRotatableAxis()
        kappa.setName(XSDataMXv2.XSDataString('Kappa'))
        kappa.setIsscannable(XSDataMXv2.XSDataBoolean(0))
        kappa.addXSCalibratedDisplacementAxis(kappacal)
        actgonio.addXSGoniostatRotatableAxis(kappa)
        #phi
        phi = XSDataMXv2.XSGoniostatRotatableAxis()
        phi.setName(XSDataMXv2.XSDataString('Phi'))
        phi.setIsscannable(XSDataMXv2.XSDataBoolean(0))
        phi.addXSCalibratedDisplacementAxis(phical)
        actgonio.addXSGoniostatRotatableAxis(phi)

        ##beam
        beam = XSDataMXv2.XSBeam()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(polarisationP[0])
        zdir.setV2(polarisationP[1])
        zdir.setV3(polarisationP[2])
        beam.setPolarisatation(zdir)
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(beamD[0])
        zdir.setV2(beamD[1])
        zdir.setV3(beamD[2])
        beam.setDirection(zdir)

        ##detector
        detector = XSDataMXv2.XSDetector()
        detector.setName(XSDataMXv2.XSDataString('detector'))
        ###detector.set

        ##SUBWEDGE
        sw = XSSubWedge_v2()
        # template
        sw.setImagefilenametemplate(XSDataMXv2.XSDataString(EDUtilsImage.getTemplate(imgFnames[0], "#")))
        # images
        for imgFname in imgFnames:
            img = XSDiffractionImages_v2()
            img.setFilename(XSDataMXv2.XSDataString(imgFname))
            sw.addXSDiffractionImages(img)
        #RotationExposure
        rotexp = XSRotationExposure_v2()
        rotexp.setExposuretime(XSDataMXv2.XSDataTime(exposuretime))
        rotexp.setImagewidth(XSDataMXv2.XSDataAngle(imagewidth))
        rotexp.setNumberimages(XSDataMXv2.XSDataInteger(numberimages))
        rotexp.setXSGoniostatAxis(omega)
        sw.setXSRotationExposure(rotexp)
        #Beamsetting
        beams = XSBeamSetting_v2()
        w = XSDataMXv2.XSDataWavelength()
        w.setValue(wavelength)
        beams.setWavelength(w)
        beams.setXSBeam(beam)
        sw.setXSBeamSetting(beams)
        #RotationalGonioSetting
        rotgset = XSDataMXv2.XSRotationalGoniostatSetting()
        rotgset.setXSRotationalGoniostat(actgonio)
        oang = XSDataMXv2.XSDataAngle()
        oang.setValue(OmegaV)
        rotgset.setBaseaxissetting(oang)
        kang = XSDataMXv2.XSDataAngle()
        kang.setValue(KappaV)
        rotgset.addAxissetting(kang)
        pang = XSDataMXv2.XSDataAngle()
        pang.setValue(PhiV)
        rotgset.addAxissetting(pang)
        sw.setXSRotationalGoniostatSetting(rotgset)
        #DetectorSetting TODOTODO
        detset = XSDataMXv2.XSDetectorSetting()
        #axissetting=(XSDataMXv2.XSDataAngle().setValue(KappaV),XSDataMXv2.XSDataAngle().setValue(PhiV))
        #detset.setAxissetting(axissetting)



        self.xsDC_v2.addXSSubWedge(sw)



        imgFname = self.xsDataResultSubWedgeAssemble.getSubWedge()[0].getImage()[0].getPath().getValue()
        self.xsDC_v2.outputFile(os.path.dirname(imgFname) + '/edna_' + EDUtilsImage.getTemplate(imgFname, "#") + '_auto')
예제 #43
0
    def generateXSDataInputXDS(_xsDataCollection):

        xsDataCollection = _xsDataCollection
        xsDataExperimentalCondition = _xsDataCollection.getSubWedge()[0].getExperimentalCondition()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()

        xsDataInputXDS = XSDataInputXDSGenerateBackgroundImage()

        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataGoniostat = xsDataExperimentalCondition.getGoniostat()

        dWavelength = xsDataBeam.getWavelength().getValue()
        dDistance = xsDataDetector.getDistance().getValue()
        dBeamPositionX = xsDataDetector.getBeamPositionX().getValue()
        dBeamPositionY = xsDataDetector.getBeamPositionY().getValue()

        # Start with the detector

        xsDataXDSDetector = EDHandlerXSDataXDSv1_0.getXSDataXDSDetector(xsDataDetector)
        xsDataInputXDS.setDetector(xsDataXDSDetector)

        # Then the beam

        xsDataXDSBeam = XSDataXDSBeam()

        xsDataVectorDoubleIncidentBeam = XSDataVectorDouble()
        xsDataVectorDoubleIncidentBeam.setV1(0.0)
        xsDataVectorDoubleIncidentBeam.setV2(0.0)
        xsDataVectorDoubleIncidentBeam.setV3(1.0)
        xsDataXDSBeam.setIncident_beam_direction(xsDataVectorDoubleIncidentBeam)

        xsDataVectorDoublePolarizationPlaneNormal = XSDataVectorDouble()
        xsDataVectorDoublePolarizationPlaneNormal.setV1(0.0)
        xsDataVectorDoublePolarizationPlaneNormal.setV2(1.0)
        xsDataVectorDoublePolarizationPlaneNormal.setV3(0.0)
        xsDataXDSBeam.setPolarization_plane_normal(xsDataVectorDoublePolarizationPlaneNormal)

        xsDataXDSBeam.setX_ray_wavelength(XSDataWavelength(dWavelength))

        xsDataInputXDS.setBeam(xsDataXDSBeam)

        # Then the goniostat

        xsDataXDSGoniostat = XSDataXDSGoniostat()

        xsDataVectorDoubleRotationAxis = XSDataVectorDouble()
        xsDataVectorDoubleRotationAxis.setV1(1.0)
        xsDataVectorDoubleRotationAxis.setV2(0.0)
        xsDataVectorDoubleRotationAxis.setV3(0.0)
        xsDataXDSGoniostat.setRotation_axis(xsDataVectorDoubleRotationAxis)

        xsDataXDSGoniostat.setOscillation_range(xsDataGoniostat.getOscillationWidth())

        xsDataXDSGoniostat.setStarting_angle(xsDataGoniostat.getRotationAxisStart())

        xsDataInputXDS.setGoniostat(xsDataXDSGoniostat)

#        # Then the Crystal
#
#        xsDataXDSCrystal = XSDataXDSCrystal()
#
#        xsDataXDSCrystal.setFriedels_law(XSDataString("FALSE"))
#
# #        if ( xsDataCrystal is not None ):
# #            xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
# #            if ( xsDataSpaceGroup is not None ):
# #                xsDataStringName = xsDataSpaceGroup.getName()
# #                if ( xsDataStringName is not None ):
# #                    xsDataInputXDS.setSymmetry( XSDataString( xsDataStringName.getValue() ) )
#        xsDataXDSCrystal.setSpace_group_number(XSDataInteger(0))
#
#        xsDataXDSCrystal.setStrong_pixel(XSDataInteger(8))
#
#        xsDataCell = XSDataCell()
#        xsDataCell.setLength_a(XSDataLength(0.0))
#        xsDataCell.setLength_b(XSDataLength(0.0))
#        xsDataCell.setLength_c(XSDataLength(0.0))
#        xsDataCell.setAngle_alpha(XSDataAngle(0.0))
#        xsDataCell.setAngle_beta(XSDataAngle(0.0))
#        xsDataCell.setAngle_gamma(XSDataAngle(0.0))
#        xsDataXDSCrystal.setUnit_cell_constants(xsDataCell)
#
#        xsDataInputXDS.setCrystal(xsDataXDSCrystal)

        # Finaly the images

        xsDataXDSImage = XSDataXDSImage()

        xsDataSubWedgeFirst = xsDataSubWedgeList[0]
        xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0]
        pyStrPath = xsDataImageFirst.getPath().getValue()
        pyStrFileName = EDUtilsFile.getBaseName(pyStrPath)
        pyStrDirectory = EDUtilsPath.getFolderName(pyStrPath)

        pyStrPrefix = EDUtilsImage.getPrefix(pyStrFileName)
        pyStrSuffix = EDUtilsImage.getSuffix(pyStrFileName)
        pyStrXDSTemplate = "%s_xdslink_?????.%s" % (pyStrPrefix, pyStrSuffix)

        xsDataXDSImage.setName_template_of_data_frames(XSDataString(pyStrXDSTemplate))

        iXDSLowestImageNumberGlobal = 1
        xsDataXDSImage.setStarting_frame(XSDataInteger(iXDSLowestImageNumberGlobal))

        # First we have to find the smallest goniostat rotation axis start:
        fGonioStatOscillationStartMin = None
        for xsDataSubWedge in xsDataSubWedgeList:
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition().getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart().getValue()
            if (fGonioStatOscillationStartMin is None):
                fGonioStatOscillationStartMin = fGonioStatOscillationStart
            elif (fGonioStatOscillationStartMin > fGonioStatOscillationStart):
                fGonioStatOscillationStartMin = fGonioStatOscillationStart

        # Loop through the list of sub wedges

        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition().getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart().getValue()
            fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth().getValue()

            # First find the lowest and highest image numbers
            iLowestImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                if (iLowestImageNumber is None):
                    iLowestImageNumber = iImageNumber
                elif (iImageNumber < iLowestImageNumber):
                    iLowestImageNumber = iImageNumber

            # Loop through the list of images
            iLowestXDSImageNumber = None
            iHighestXDSImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                fImageOscillationStart = fGonioStatOscillationStart + (iImageNumber - iLowestImageNumber) * fGonioStatOscillationRange
                iXDSImageNumber = iXDSLowestImageNumberGlobal + int((fImageOscillationStart - fGonioStatOscillationStartMin) / fGonioStatOscillationRange)
                # print iXDSImageNumber, fImageOscillationStart, fGonioStatOscillationStartMin, fGonioStatOscillationRange
                pyStrSourcePath = xsDataImage.getPath()
                pyStrTarget = "%s_xdslink_%05d.%s" % (pyStrPrefix, iXDSImageNumber, pyStrSuffix)
                xsDataXDSImageLink = XSDataXDSImageLink()
                xsDataFileSource = XSDataFile()
                xsDataFileSource.setPath(pyStrSourcePath)
                xsDataXDSImageLink.setSource(xsDataFileSource)
                xsDataXDSImageLink.setTarget(XSDataString(pyStrTarget))
                xsDataInputXDS.addImage_link(xsDataXDSImageLink)
                if (iLowestXDSImageNumber is None):
                    iLowestXDSImageNumber = iXDSImageNumber
                elif (iLowestXDSImageNumber > iXDSImageNumber):
                    iLowestXDSImageNumber = iXDSImageNumber
                if (iHighestXDSImageNumber is None):
                    iHighestXDSImageNumber = iXDSImageNumber
                elif (iHighestXDSImageNumber < iXDSImageNumber):
                    iHighestXDSImageNumber = iXDSImageNumber
            xsDataXDSIntegerRange = XSDataXDSIntegerRange()
            xsDataXDSIntegerRange.setLower(XSDataInteger(iLowestXDSImageNumber))
            xsDataXDSIntegerRange.setUpper(XSDataInteger(iHighestXDSImageNumber))

            xsDataXDSImage.addBackground_range(xsDataXDSIntegerRange)
            xsDataXDSImage.addData_range(xsDataXDSIntegerRange)
            xsDataXDSImage.addSpot_range(xsDataXDSIntegerRange)

        xsDataInputXDS.setImage(xsDataXDSImage)

        return xsDataInputXDS
예제 #44
0
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        EDVerbose.DEBUG("EDPluginExecReadImageHeaderMARCCDv10.process")
        xsDataInputReadImageHeader = self.getDataInput()
        xsDataFile = xsDataInputReadImageHeader.getImage()
        strPath = xsDataFile.getPath().getValue()
        dictMARCCDHeader = self.readHeaderMarccd(strPath)
        if (dictMARCCDHeader is None):
            strErrorMessage = "EDPluginExecReadImageHeaderMARCCDv10.process : Cannot read header : %s" % strPath
            EDVerbose.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
        else:
            xsDataExperimentalCondition = XSDataExperimentalCondition()
            xsDataDetector = XSDataDetector()

            iNoPixelsX = int(dictMARCCDHeader["nslow"])
            iNoPixelsY = int(dictMARCCDHeader["nfast"])
            xsDataDetector.setNumberPixelX(XSDataInteger(iNoPixelsX))
            xsDataDetector.setNumberPixelY(XSDataInteger(iNoPixelsY))
            fPixelSizeX = float(dictMARCCDHeader["pixelsize_x"]) / 1000.0
            xsDataDetector.setPixelSizeX(XSDataLength(fPixelSizeX))
            fPixelSizeY = float(dictMARCCDHeader["pixelsize_y"]) / 1000.0
            xsDataDetector.setPixelSizeY(XSDataLength(fPixelSizeY))
            fBeamPositionX = float(dictMARCCDHeader["beam_x"]) / 1000.0
            fBeamPositionY = float(dictMARCCDHeader["beam_y"]) / 1000.0
            # Fix for bug 397 - check if the beam position is close to the centre of the image
            fTwoTheta = float(dictMARCCDHeader["end_twotheta"]) / 1000.0
            xsDataDetector.setTwoTheta(XSDataAngle(fTwoTheta))
            if (abs(fTwoTheta) < 0.1):
                if (abs(fBeamPositionX /
                        (fPixelSizeX / 1000.0) - iNoPixelsX / 2.0) >
                    (2 * iNoPixelsX)):
                    fBeamPositionX = fBeamPositionX * fPixelSizeX / 1000.0
                    fBeamPositionY = fBeamPositionY * fPixelSizeY / 1000.0
            xsDataDetector.setBeamPositionX(XSDataLength(fBeamPositionX))
            xsDataDetector.setBeamPositionY(XSDataLength(fBeamPositionY))
            fDistance = float(dictMARCCDHeader["xtal_to_detector"]) / 1000.0
            if (abs(fDistance) < 0.1):
                fDistanceStart = float(
                    dictMARCCDHeader["start_xtal_to_detector"]) / 1000.0
                fDistanceEnd = float(
                    dictMARCCDHeader["end_xtal_to_detector"]) / 1000.0
                if (abs(fDistanceStart - fDistanceEnd) < 0.1):
                    fDistance = fDistanceStart
                else:
                    # Somethings very wrong with the distances...
                    strErrorMessage = "EDPluginExecReadImageHeaderMARCCDv10.process : Inconsistency in MAR CCD image header: start_xtal_to_detector = %d, end_xtal_to_detector = %d" % \
                                                                           (fDistanceStart, fDistanceEnd)
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    self.setFailure()
            xsDataDetector.setDistance(XSDataLength(fDistance))
            xsDataDetector.setNumberBytesInHeader(
                XSDataInteger(float(dictMARCCDHeader["header_size"])))
            #xsDataDetector.setSerialNumber(        XSDataInteger(  dictMARCCDHeader[ "DETECTOR_SN"   ] ) ) )
            #xsDataDetector.setBin(                 XSDataString(   dictMARCCDHeader[ "BIN" ] ) ) )
            #xsDataDetector.setDataType(            XSDataString(   dictMARCCDHeader[ "TYPE" ] ) ) )
            #xsDataDetector.setByteOrder(           XSDataString(   dictMARCCDHeader[ "BYTE_ORDER" ] ) ) )
            xsDataDetector.setImageSaturation(
                XSDataInteger(int(dictMARCCDHeader["saturation_level"])))
            # Determine type of detector...
            if (iNoPixelsX == 2048 and iNoPixelsY == 2048):
                xsDataDetector.setName(XSDataString("MAR CCD 165"))
                xsDataDetector.setType(XSDataString("mar165"))
            elif (iNoPixelsX == 3072 and iNoPixelsY == 3072):
                xsDataDetector.setName(XSDataString("MAR CCD 225"))
                xsDataDetector.setType(XSDataString("mar225"))
            elif (iNoPixelsX == 4096 and iNoPixelsY == 4096):
                xsDataDetector.setName(XSDataString("MAR CCD 325"))
                xsDataDetector.setType(XSDataString("mar325"))
            else:
                strErrorMessage = EDMessage.ERROR_DATA_HANDLER_02 % (
                    "EDPluginExecReadImageHeaderMARCCDv10.process",
                    "Unknown detector type")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

            xsDataExperimentalCondition.setDetector(xsDataDetector)

            # Beam object

            xsDataBeam = XSDataBeam()
            xsDataBeam.setWavelength(
                XSDataWavelength(
                    float(dictMARCCDHeader["source_wavelength"]) / 100000.0))
            xsDataBeam.setExposureTime(
                XSDataTime(float(dictMARCCDHeader["exposure_time"]) / 1000.0))
            xsDataExperimentalCondition.setBeam(xsDataBeam)

            # Goniostat object
            xsDataGoniostat = XSDataGoniostat()
            fRotationAxisStart = float(dictMARCCDHeader["start_phi"]) / 1000.0
            fOscillationWidth = float(
                dictMARCCDHeader["rotation_range"]) / 1000.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))
            strTimeStamp = dictMARCCDHeader["acquire_timestamp"]
            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)
    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)
    def generateXSDataMOSFLMInputGeneratePrediction(xsDataGeneratePredictionInput):
        """
        Translation from XSDataGeneratePredictionInput to XSDataMOSFLMInputGeneratePrediction.
        """
        EDVerbose.DEBUG("EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputGeneratePrediction")
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMImage
        from XSDataMOSFLMv10 import XSDataMOSFLMNewmat
        from XSDataMOSFLMv10 import XSDataMOSFLMMissettingsAngles
        from XSDataMOSFLMv10 import XSDataMOSFLMInputGeneratePrediction

        xsDataIndexingSolutionSelected = xsDataGeneratePredictionInput.getSelectedIndexingSolution()

        xsDataCollection = xsDataGeneratePredictionInput.getDataCollection()
        xsDataSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataImageList = xsDataSubWedge.getImage()
        xsDataImageFirst = xsDataImageList[0]

        xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
        xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation()
        xsDataExperimentalCondition = xsDataIndexingSolutionSelected.getExperimentalConditionRefined()
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataMatrixA = xsDataOrientation.getMatrixA()
        xsDataMatrixU = xsDataOrientation.getMatrixU()
        xsDataCell = xsDataCrystal.getCell()

        xsDataMOSFLMInputGeneratePrediction = XSDataMOSFLMInputGeneratePrediction()
        xsDataMOSFLMNewmat = XSDataMOSFLMNewmat()
        xsDataMOSFLMNewmat.setRefinedCell(xsDataCell)
        xsDataMOSFLMNewmat.setAMatrix(xsDataMatrixA)
        xsDataMOSFLMNewmat.setUMatrix(xsDataMatrixU)
        xsDataMOSFLMInputGeneratePrediction.setMatrix(xsDataMOSFLMNewmat)

        xsDataMOSFLMMissettingsAngles = XSDataMOSFLMMissettingsAngles()
        xsDataMOSFLMMissettingsAngles.setPhix(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiy(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiz(XSDataAngle(0.0))
        xsDataMOSFLMNewmat.setMissettingAngles(xsDataMOSFLMMissettingsAngles)

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(xsDataDetector.getBeamPositionX())
        xsDataMOSFLMBeamPosition.setY(xsDataDetector.getBeamPositionY())
        xsDataMOSFLMInputGeneratePrediction.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMInputGeneratePrediction.setMosaicity(xsDataCrystal.getMosaicity())
        xsDataMOSFLMInputGeneratePrediction.setSymmetry(xsDataCrystal.getSpaceGroup().getName())

        strPathFirst = xsDataImageFirst.getPath().getValue()
        strDirectoryFirst = os.path.dirname(strPathFirst)
        strFilenameFirst = os.path.basename(strPathFirst)

        xsDataMOSFLMInputGeneratePrediction.setWavelength(xsDataBeam.getWavelength())
        xsDataMOSFLMInputGeneratePrediction.setDistance(xsDataDetector.getDistance())
        xsDataMOSFLMInputGeneratePrediction.setDirectory(XSDataString(strDirectoryFirst))
        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(xsDataDetector)
        xsDataMOSFLMInputGeneratePrediction.setDetector(xsDataMOSFLMDetector)

        strMOSFLMTemplate = EDUtilsImage.getTemplate(strFilenameFirst, "#")
        xsDataMOSFLMInputGeneratePrediction.setTemplate(XSDataString(strMOSFLMTemplate))

        # The MOSFLM plugin can only handle one image 

        xsDataImage = xsDataSubWedge.getImage()[0]
        xsDataGoniostat = xsDataSubWedge.getExperimentalCondition().getGoniostat()

        xsDataMOSFLMImage = XSDataMOSFLMImage()

        iImageNumber = xsDataImage.getNumber().getValue()
        xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber))

        fOscillationStart = xsDataGoniostat.getRotationAxisStart().getValue()
        fOscillationRange = xsDataGoniostat.getOscillationWidth().getValue()
        xsDataMOSFLMImage.setRotationAxisStart(XSDataAngle(fOscillationStart))
        xsDataMOSFLMImage.setRotationAxisEnd(XSDataAngle(fOscillationStart + fOscillationRange))

        xsDataMOSFLMInputGeneratePrediction.setImage(xsDataMOSFLMImage)

        return xsDataMOSFLMInputGeneratePrediction
    def generateXSDataMOSFLMInputIndexing(_xsDataIndexingInput):
        """
        Translation from XSDataIndexingInput to XSDataMOSFLMInputIndexing.
        """
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMImage

        EDVerbose.DEBUG("EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing")

        xsDataCollection = _xsDataIndexingInput.getDataCollection()
        xsDataExperimentalCondition = _xsDataIndexingInput.getExperimentalCondition()
        xsDataCrystal = _xsDataIndexingInput.getCrystal()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()
        xsDataMOSFLMInputIndexing = XSDataMOSFLMInputIndexing()

        if (xsDataExperimentalCondition is None):
            xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()

        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataGoniostat = xsDataExperimentalCondition.getGoniostat()

        dWavelength = xsDataBeam.getWavelength().getValue()
        dDistance = xsDataDetector.getDistance().getValue()
        dBeamPositionX = xsDataDetector.getBeamPositionX().getValue()
        dBeamPositionY = xsDataDetector.getBeamPositionY().getValue()

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(XSDataLength(dBeamPositionX))
        xsDataMOSFLMBeamPosition.setY(XSDataLength(dBeamPositionY))
        xsDataMOSFLMInputIndexing.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(xsDataDetector)
        xsDataMOSFLMInputIndexing.setDetector(xsDataMOSFLMDetector)

        xsDataMOSFLMInputIndexing.setWavelength(XSDataWavelength(dWavelength))
        xsDataMOSFLMInputIndexing.setDistance(XSDataLength(dDistance))

        xsDataSubWedgeFirst = xsDataSubWedgeList[0]
        xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0]
        strPath = xsDataImageFirst.getPath().getValue()
        strFileName = os.path.basename(strPath)
        strDirectory = os.path.dirname(strPath)

        strMOSFLMTemplate = EDUtilsImage.getTemplate(strFileName, "#")
        xsDataMOSFLMInputIndexing.setTemplate(XSDataString(strMOSFLMTemplate))
        xsDataMOSFLMInputIndexing.setDirectory(XSDataString(strDirectory))

        if (xsDataCrystal is not None):
            xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
            if (xsDataSpaceGroup is not None):
                xsDataStringName = xsDataSpaceGroup.getName()
                if (xsDataStringName is not None):
                    xsDataMOSFLMInputIndexing.setSymmetry(XSDataString(xsDataStringName.getValue()))

        # Loop through the list of sub wedges 

        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition().getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart().getValue()
            fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth().getValue()

            # First find the lowest image number
            iLowestImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                if (iLowestImageNumber is None):
                    iLowestImageNumber = iImageNumber
                elif (iImageNumber < iLowestImageNumber):
                    iLowestImageNumber = iImageNumber

            # Loop through the list of images

            for xsDataImage in xsDataImageList:
                # Create the MOSFLM image object

                xsDataMOSFLMImage = XSDataMOSFLMImage()

                iImageNumber = xsDataImage.getNumber().getValue()
                xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber))

                fImageOscillationStart = fGonioStatOscillationStart + (iImageNumber - iLowestImageNumber) * fGonioStatOscillationRange
                xsDataMOSFLMImage.setRotationAxisStart(XSDataAngle(fImageOscillationStart))
                xsDataMOSFLMImage.setRotationAxisEnd(XSDataAngle(fImageOscillationStart + fGonioStatOscillationRange))

                xsDataMOSFLMInputIndexing.addImage(xsDataMOSFLMImage)

        return xsDataMOSFLMInputIndexing
    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)
예제 #49
0
    def generateXSDataInputXDS(_xsDataCollection):

        xsDataCollection = _xsDataCollection
        xsDataExperimentalCondition = _xsDataCollection.getSubWedge(
        )[0].getExperimentalCondition()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()

        xsDataInputXDS = XSDataInputXDSGenerateBackgroundImage()

        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataGoniostat = xsDataExperimentalCondition.getGoniostat()

        dWavelength = xsDataBeam.getWavelength().getValue()
        dDistance = xsDataDetector.getDistance().getValue()
        dBeamPositionX = xsDataDetector.getBeamPositionX().getValue()
        dBeamPositionY = xsDataDetector.getBeamPositionY().getValue()

        # Start with the detector

        xsDataXDSDetector = EDHandlerXSDataXDSv1_0.getXSDataXDSDetector(
            xsDataDetector)
        xsDataInputXDS.setDetector(xsDataXDSDetector)

        # Then the beam

        xsDataXDSBeam = XSDataXDSBeam()

        xsDataVectorDoubleIncidentBeam = XSDataVectorDouble()
        xsDataVectorDoubleIncidentBeam.setV1(0.0)
        xsDataVectorDoubleIncidentBeam.setV2(0.0)
        xsDataVectorDoubleIncidentBeam.setV3(1.0)
        xsDataXDSBeam.setIncident_beam_direction(
            xsDataVectorDoubleIncidentBeam)

        xsDataVectorDoublePolarizationPlaneNormal = XSDataVectorDouble()
        xsDataVectorDoublePolarizationPlaneNormal.setV1(0.0)
        xsDataVectorDoublePolarizationPlaneNormal.setV2(1.0)
        xsDataVectorDoublePolarizationPlaneNormal.setV3(0.0)
        xsDataXDSBeam.setPolarization_plane_normal(
            xsDataVectorDoublePolarizationPlaneNormal)

        xsDataXDSBeam.setX_ray_wavelength(XSDataWavelength(dWavelength))

        xsDataInputXDS.setBeam(xsDataXDSBeam)

        # Then the goniostat

        xsDataXDSGoniostat = XSDataXDSGoniostat()

        xsDataVectorDoubleRotationAxis = XSDataVectorDouble()
        xsDataVectorDoubleRotationAxis.setV1(1.0)
        xsDataVectorDoubleRotationAxis.setV2(0.0)
        xsDataVectorDoubleRotationAxis.setV3(0.0)
        xsDataXDSGoniostat.setRotation_axis(xsDataVectorDoubleRotationAxis)

        xsDataXDSGoniostat.setOscillation_range(
            xsDataGoniostat.getOscillationWidth())

        xsDataXDSGoniostat.setStarting_angle(
            xsDataGoniostat.getRotationAxisStart())

        xsDataInputXDS.setGoniostat(xsDataXDSGoniostat)

        #        # Then the Crystal
        #
        #        xsDataXDSCrystal = XSDataXDSCrystal()
        #
        #        xsDataXDSCrystal.setFriedels_law(XSDataString("FALSE"))
        #
        ##        if ( xsDataCrystal is not None ):
        ##            xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
        ##            if ( xsDataSpaceGroup is not None ):
        ##                xsDataStringName = xsDataSpaceGroup.getName()
        ##                if ( xsDataStringName is not None ):
        ##                    xsDataInputXDS.setSymmetry( XSDataString( xsDataStringName.getValue() ) )
        #        xsDataXDSCrystal.setSpace_group_number(XSDataInteger(0))
        #
        #        xsDataXDSCrystal.setStrong_pixel(XSDataInteger(8))
        #
        #        xsDataCell = XSDataCell()
        #        xsDataCell.setLength_a(XSDataLength(0.0))
        #        xsDataCell.setLength_b(XSDataLength(0.0))
        #        xsDataCell.setLength_c(XSDataLength(0.0))
        #        xsDataCell.setAngle_alpha(XSDataAngle(0.0))
        #        xsDataCell.setAngle_beta(XSDataAngle(0.0))
        #        xsDataCell.setAngle_gamma(XSDataAngle(0.0))
        #        xsDataXDSCrystal.setUnit_cell_constants(xsDataCell)
        #
        #        xsDataInputXDS.setCrystal(xsDataXDSCrystal)

        # Finaly the images

        xsDataXDSImage = XSDataXDSImage()

        xsDataSubWedgeFirst = xsDataSubWedgeList[0]
        xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0]
        pyStrPath = xsDataImageFirst.getPath().getValue()
        pyStrFileName = EDUtilsFile.getBaseName(pyStrPath)
        pyStrDirectory = EDUtilsPath.getFolderName(pyStrPath)

        pyStrPrefix = EDUtilsImage.getPrefix(pyStrFileName)
        pyStrSuffix = EDUtilsImage.getSuffix(pyStrFileName)
        pyStrXDSTemplate = "%s_xdslink_?????.%s" % (pyStrPrefix, pyStrSuffix)

        xsDataXDSImage.setName_template_of_data_frames(
            XSDataString(pyStrXDSTemplate))

        iXDSLowestImageNumberGlobal = 1
        xsDataXDSImage.setStarting_frame(
            XSDataInteger(iXDSLowestImageNumberGlobal))

        # First we have to find the smallest goniostat rotation axis start:
        fGonioStatOscillationStartMin = None
        for xsDataSubWedge in xsDataSubWedgeList:
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
            ).getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart(
            ).getValue()
            if (fGonioStatOscillationStartMin is None):
                fGonioStatOscillationStartMin = fGonioStatOscillationStart
            elif (fGonioStatOscillationStartMin > fGonioStatOscillationStart):
                fGonioStatOscillationStartMin = fGonioStatOscillationStart

        # Loop through the list of sub wedges

        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
            ).getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart(
            ).getValue()
            fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth(
            ).getValue()

            # First find the lowest and highest image numbers
            iLowestImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                if (iLowestImageNumber is None):
                    iLowestImageNumber = iImageNumber
                elif (iImageNumber < iLowestImageNumber):
                    iLowestImageNumber = iImageNumber

            # Loop through the list of images
            iLowestXDSImageNumber = None
            iHighestXDSImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                fImageOscillationStart = fGonioStatOscillationStart + (
                    iImageNumber -
                    iLowestImageNumber) * fGonioStatOscillationRange
                iXDSImageNumber = iXDSLowestImageNumberGlobal + int(
                    (fImageOscillationStart - fGonioStatOscillationStartMin) /
                    fGonioStatOscillationRange)
                #print iXDSImageNumber, fImageOscillationStart, fGonioStatOscillationStartMin, fGonioStatOscillationRange
                pyStrSourcePath = xsDataImage.getPath()
                pyStrTarget = "%s_xdslink_%05d.%s" % (
                    pyStrPrefix, iXDSImageNumber, pyStrSuffix)
                xsDataXDSImageLink = XSDataXDSImageLink()
                xsDataFileSource = XSDataFile()
                xsDataFileSource.setPath(pyStrSourcePath)
                xsDataXDSImageLink.setSource(xsDataFileSource)
                xsDataXDSImageLink.setTarget(XSDataString(pyStrTarget))
                xsDataInputXDS.addImage_link(xsDataXDSImageLink)
                if (iLowestXDSImageNumber is None):
                    iLowestXDSImageNumber = iXDSImageNumber
                elif (iLowestXDSImageNumber > iXDSImageNumber):
                    iLowestXDSImageNumber = iXDSImageNumber
                if (iHighestXDSImageNumber is None):
                    iHighestXDSImageNumber = iXDSImageNumber
                elif (iHighestXDSImageNumber < iXDSImageNumber):
                    iHighestXDSImageNumber = iXDSImageNumber
            xsDataXDSIntegerRange = XSDataXDSIntegerRange()
            xsDataXDSIntegerRange.setLower(
                XSDataInteger(iLowestXDSImageNumber))
            xsDataXDSIntegerRange.setUpper(
                XSDataInteger(iHighestXDSImageNumber))

            xsDataXDSImage.addBackground_range(xsDataXDSIntegerRange)
            xsDataXDSImage.addData_range(xsDataXDSIntegerRange)
            xsDataXDSImage.addSpot_range(xsDataXDSIntegerRange)

        xsDataInputXDS.setImage(xsDataXDSImage)

        return xsDataInputXDS
예제 #50
0
    def generateXSDataMOSFLMInputIntegration(_xsDataIntegrationInput):
        """
        Translation from XSDataIntegrationInput to XSDataMOSFLMInputIntegration.
        """
        EDVerbose.DEBUG(
            "EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIntegration")
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMInputIntegration
        from XSDataMOSFLMv10 import XSDataMOSFLMNewmat
        from XSDataMOSFLMv10 import XSDataMOSFLMMissettingsAngles
        xsDataCrystalRefined = _xsDataIntegrationInput.getCrystalRefined()
        xsDataIndexingSolutionSelected = _xsDataIntegrationInput.getSelectedIndexingSolution(
        )

        if (xsDataCrystalRefined is None):
            xsDataCrystalRefined = xsDataIndexingSolutionSelected.getCrystal()

        xsDataCollection = _xsDataIntegrationInput.getDataCollection()
        xsDataSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataImageList = xsDataSubWedge.getImage()
        xsDataImageFirst = xsDataImageList[0]
        xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
        ).getGoniostat()

        xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
        xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation()
        xsDataExperimentalCondition = xsDataIndexingSolutionSelected.getExperimentalConditionRefined(
        )
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataMatrixA = xsDataOrientation.getMatrixA()
        xsDataMatrixU = xsDataOrientation.getMatrixU()
        xsDataCell = xsDataCrystal.getCell()

        xsDataMOSFLMInputIntegration = XSDataMOSFLMInputIntegration()
        xsDataMOSFLMNewmat = XSDataMOSFLMNewmat()
        xsDataMOSFLMNewmat.setRefinedCell(xsDataCell)
        xsDataMOSFLMNewmat.setAMatrix(xsDataMatrixA)
        xsDataMOSFLMNewmat.setUMatrix(xsDataMatrixU)
        xsDataMOSFLMInputIntegration.setMatrix(xsDataMOSFLMNewmat)

        xsDataMOSFLMMissettingsAngles = XSDataMOSFLMMissettingsAngles()
        xsDataMOSFLMMissettingsAngles.setPhix(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiy(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiz(XSDataAngle(0.0))
        xsDataMOSFLMNewmat.setMissettingAngles(xsDataMOSFLMMissettingsAngles)

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(xsDataDetector.getBeamPositionX())
        xsDataMOSFLMBeamPosition.setY(xsDataDetector.getBeamPositionY())
        xsDataMOSFLMInputIntegration.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMInputIntegration.setMosaicity(xsDataCrystal.getMosaicity())
        xsDataMOSFLMInputIntegration.setSymmetry(
            xsDataCrystal.getSpaceGroup().getName())

        strPathFirst = xsDataImageFirst.getPath().getValue()
        strDirectoryFirst = os.path.dirname(strPathFirst)
        strFilenameFirst = os.path.basename(strPathFirst)
        fOscillationRange = xsDataGoniostat.getOscillationWidth().getValue()

        xsDataMOSFLMInputIntegration.setWavelength(xsDataBeam.getWavelength())
        xsDataMOSFLMInputIntegration.setDistance(xsDataDetector.getDistance())
        xsDataMOSFLMInputIntegration.setDirectory(
            XSDataString(strDirectoryFirst))
        xsDataMOSFLMInputIntegration.setOscillationWidth(
            XSDataAngle(fOscillationRange))
        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(
            xsDataDetector)
        xsDataMOSFLMInputIntegration.setDetector(xsDataMOSFLMDetector)

        strMOSFLMTemplate = EDUtilsImage.getTemplate(strFilenameFirst, "#")
        xsDataMOSFLMInputIntegration.setTemplate(
            XSDataString(strMOSFLMTemplate))

        iImageStart = None
        iImageEnd = None
        for xsDataImage in xsDataImageList:
            iImageNumber = xsDataImage.getNumber().getValue()
            if (iImageStart is None):
                iImageStart = iImageNumber
            elif (iImageStart > iImageNumber):
                iImageStart = iImageNumber
            if (iImageEnd is None):
                iImageEnd = iImageNumber
            elif (iImageEnd < iImageNumber):
                iImageEnd = iImageNumber

        xsDataMOSFLMInputIntegration.setImageStart(XSDataInteger(iImageStart))
        xsDataMOSFLMInputIntegration.setImageEnd(XSDataInteger(iImageEnd))
        xsDataMOSFLMInputIntegration.setRotationAxisStart(
            xsDataGoniostat.getRotationAxisStart())

        # print xsDataMOSFLMInputIntegration.marshal()

        return xsDataMOSFLMInputIntegration
예제 #51
0
    def generateDataCollectionDescriptorForSubWedge(self, calibDate, omegaR, kappaR, phiR, beamD, polarisationP, exposuretime, imagewidth, numberimages, wavelength, OmegaV, KappaV, PhiV, imgFnames):
        ##CONTAINER
        self.xsDC_v2 = XSDataCollection_v2()

        ##GonioCalib
        calib = XSDataMXv2.XSCalibration()
        cdate = XSDataMXv2.XSDataDate()
        cdate.setValue(XSDataMXv2.XSDataString(calibDate))
        calib.setDate(cdate)
        #OmegaCalib
        omegacal = XSDataMXv2.XSCalibratedDisplacementAxis()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(omegaR[0])
        zdir.setV2(omegaR[1])
        zdir.setV3(omegaR[2])
        omegacal.setZerodirection(zdir)
        omegacal.setXSCalibration(calib)
        #KappaCalib
        kappacal = XSDataMXv2.XSCalibratedDisplacementAxis()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(kappaR[0])
        zdir.setV2(kappaR[1])
        zdir.setV3(kappaR[2])
        kappacal.setZerodirection(zdir)
        kappacal.setXSCalibration(calib)
        #PhiCalib
        phical = XSDataMXv2.XSCalibratedDisplacementAxis()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(phiR[0])
        zdir.setV2(phiR[1])
        zdir.setV3(phiR[2])
        phical.setZerodirection(zdir)
        phical.setXSCalibration(calib)

        ##goni
        actgonio = XSDataMXv2.XSRotationalGoniostat()
        #omega
        omega = XSDataMXv2.XSGoniostatBaseAxis()
        omega.setName(XSDataMXv2.XSDataString('Omega'))
        omega.setIsscannable(XSDataMXv2.XSDataBoolean(1))
        omega.addXSCalibratedDisplacementAxis(omegacal)
        actgonio.setXSGoniostatBaseAxis(omega)
        #kappa
        kappa = XSDataMXv2.XSGoniostatRotatableAxis()
        kappa.setName(XSDataMXv2.XSDataString('Kappa'))
        kappa.setIsscannable(XSDataMXv2.XSDataBoolean(0))
        kappa.addXSCalibratedDisplacementAxis(kappacal)
        actgonio.addXSGoniostatRotatableAxis(kappa)
        #phi
        phi = XSDataMXv2.XSGoniostatRotatableAxis()
        phi.setName(XSDataMXv2.XSDataString('Phi'))
        phi.setIsscannable(XSDataMXv2.XSDataBoolean(0))
        phi.addXSCalibratedDisplacementAxis(phical)
        actgonio.addXSGoniostatRotatableAxis(phi)

        ##beam
        beam = XSDataMXv2.XSBeam()
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(polarisationP[0])
        zdir.setV2(polarisationP[1])
        zdir.setV3(polarisationP[2])
        beam.setPolarisatation(zdir)
        zdir = XSDataMXv2.XSDataUnitVector()
        zdir.setV1(beamD[0])
        zdir.setV2(beamD[1])
        zdir.setV3(beamD[2])
        beam.setDirection(zdir)

        ##detector
        detector = XSDataMXv2.XSDetector()
        detector.setName(XSDataMXv2.XSDataString('detector'))
        ###detector.set

        ##SUBWEDGE
        sw = XSSubWedge_v2()
        # template
        sw.setImagefilenametemplate(XSDataMXv2.XSDataString(EDUtilsImage.getTemplate(imgFnames[0], "#")))
        # images
        for imgFname in imgFnames:
            img = XSDiffractionImages_v2()
            img.setFilename(XSDataMXv2.XSDataString(imgFname))
            sw.addXSDiffractionImages(img)
        #RotationExposure
        rotexp = XSRotationExposure_v2()
        rotexp.setExposuretime(XSDataMXv2.XSDataTime(exposuretime))
        rotexp.setImagewidth(XSDataMXv2.XSDataAngle(imagewidth))
        rotexp.setNumberimages(XSDataMXv2.XSDataInteger(numberimages))
        rotexp.setXSGoniostatAxis(omega)
        sw.setXSRotationExposure(rotexp)
        #Beamsetting
        beams = XSBeamSetting_v2()
        w = XSDataMXv2.XSDataWavelength()
        w.setValue(wavelength)
        beams.setWavelength(w)
        beams.setXSBeam(beam)
        sw.setXSBeamSetting(beams)
        #RotationalGonioSetting
        rotgset = XSDataMXv2.XSRotationalGoniostatSetting()
        rotgset.setXSRotationalGoniostat(actgonio)
        oang = XSDataMXv2.XSDataAngle()
        oang.setValue(OmegaV)
        rotgset.setBaseaxissetting(oang)
        kang = XSDataMXv2.XSDataAngle()
        kang.setValue(KappaV)
        rotgset.addAxissetting(kang)
        pang = XSDataMXv2.XSDataAngle()
        pang.setValue(PhiV)
        rotgset.addAxissetting(pang)
        sw.setXSRotationalGoniostatSetting(rotgset)
        #DetectorSetting TODOTODO
        detset = XSDataMXv2.XSDetectorSetting()
        #axissetting=(XSDataMXv2.XSDataAngle().setValue(KappaV),XSDataMXv2.XSDataAngle().setValue(PhiV))
        #detset.setAxissetting(axissetting)



        self.xsDC_v2.addXSSubWedge(sw)



        imgFname = self.xsDataResultSubWedgeAssemble.getSubWedge()[0].getImage()[0].getPath().getValue()
        self.xsDC_v2.outputFile(os.path.dirname(imgFname) + '/edna_' + EDUtilsImage.getTemplate(imgFname, "#") + '_auto')
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        EDVerbose.DEBUG("EDPluginExecReadImageHeaderPilatus2Mv10.process")
        xsDataInputReadImageHeader = self.getDataInput()
        xsDataFile = xsDataInputReadImageHeader.getImage()
        strPath = xsDataFile.getPath().getValue()
        dictPilatus2MHeader = self.readHeaderPilatus2M(strPath)
        if (dictPilatus2MHeader is None):
            strErrorMessage = "EDPluginExecReadImageHeaderPilatus2Mv10.process : Cannot read header : %s" % strPath
            EDVerbose.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
        else:
            xsDataExperimentalCondition = XSDataExperimentalCondition()
            xsDataDetector = XSDataDetector()

            iNoPixelsX = 1475
            iNoPixelsY = 1679
            xsDataDetector.setNumberPixelX(XSDataInteger(iNoPixelsX))
            xsDataDetector.setNumberPixelY(XSDataInteger(iNoPixelsY))
            # Pixel size
            listPixelSizeXY = dictPilatus2MHeader[ "Pixel_size"   ].split(" ")
            fPixelSizeX = float(listPixelSizeXY[0]) * 1000
            xsDataDetector.setPixelSizeX(XSDataLength(fPixelSizeX))
            fPixelSizeY = float(listPixelSizeXY[3]) * 1000
            xsDataDetector.setPixelSizeY(XSDataLength(fPixelSizeY))
            # Beam position
            listBeamPosition = dictPilatus2MHeader["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(dictPilatus2MHeader[ "Detector_distance" ].split(" ")[0]) * 1000
            xsDataDetector.setDistance(XSDataLength(fDistance))
#            xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictPilatus2MHeader[ "header_size"   ])))
            xsDataDetector.setSerialNumber(XSDataString(dictPilatus2MHeader[ "Detector:"   ]))
#            #xsDataDetector.setBin(                 XSDataString(   dictPilatus2MHeader[ "BIN" ] ) ) )
#            #xsDataDetector.setDataType(            XSDataString(   dictPilatus2MHeader[ "TYPE" ] ) ) )
#            #xsDataDetector.setByteOrder(           XSDataString(   dictPilatus2MHeader[ "BYTE_ORDER" ] ) ) )
#            xsDataDetector.setImageSaturation(XSDataInteger(int(dictPilatus2MHeader[ "saturation_level" ])))
            xsDataDetector.setName(XSDataString("PILATUS2 3M"))
            xsDataDetector.setType(XSDataString("pilatus2m"))
            xsDataExperimentalCondition.setDetector(xsDataDetector)

            # Beam object

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

            # Goniostat object
            xsDataGoniostat = XSDataGoniostat()
            fRotationAxisStart = float(dictPilatus2MHeader[ "Start_angle" ].split(" ")[0])
            fOscillationWidth = float(dictPilatus2MHeader[ "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 dictPilatus2MHeader:
                strTimeStamp = dictPilatus2MHeader[ "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)
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_5.process")
        EDUtilsParallel.initializeNbThread()
        # Check batch size
        if self.dataInput.batchSize is None:
            batchSize = 1
        else:
            batchSize = self.dataInput.batchSize.value
        self.screen(
            "Image quality indicators batch size: {0}".format(batchSize))
        # Check if we should do distlSignalStrength:
        bDoDistlSignalStrength = True
        if self.dataInput.doDistlSignalStrength is not None:
            if not self.dataInput.doDistlSignalStrength.value:
                bDoDistlSignalStrength = False
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                bDoIndexing = True
        # Check if fast mesh (for HDF5)
        isFastMesh = False
        if self.dataInput.fastMesh:
            isFastMesh = self.dataInput.fastMesh.value
        # Loop through all the incoming reference images
        if len(self.dataInput.image) == 0:
            directory = self.dataInput.directory.path.value
            template = self.dataInput.template.value
            startNo = self.dataInput.startNo.value
            endNo = self.dataInput.endNo.value
            listXSDataImage = []
            for index in range(startNo, endNo + 1):
                imageName = template.replace("####", "{0:04d}".format(index))
                imagePath = os.path.join(directory, imageName)
                xsDataImage = XSDataImage(path=XSDataString(imagePath),
                                          number=XSDataInteger(index))
                listXSDataImage.append(xsDataImage)
        else:
            listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators(
        )
        listPluginDistl = []
        listPluginDozor = []
        listOfImagesInBatch = []
        listOfAllBatches = []
        indexBatch = 0
        listH5FilePath = []
        # Process data in batches
        for xsDataImage in listXSDataImage:
            listOfImagesInBatch.append(xsDataImage.copy())
            if len(listOfImagesInBatch) == batchSize:
                listOfAllBatches.append(listOfImagesInBatch)
                listOfImagesInBatch = []
        if len(listOfImagesInBatch) > 0:
            listOfAllBatches.append(listOfImagesInBatch)
            listOfImagesInBatch = []
        # Loop over batches
        for listOfImagesInBatch in listOfAllBatches:
            # First wait for images
            for image in listOfImagesInBatch:
                strPathToImage = image.path.value
                # If Eiger, just wait for the h5 file
                if strPathToImage.endswith(".h5"):
                    h5MasterFilePath, h5DataFilePath, hdf5ImageNumber = self.getH5FilePath(
                        strPathToImage,
                        batchSize=batchSize,
                        isFastMesh=isFastMesh)
                    #                print(h5FilePath)
                    #                print(hdf5ImageNumber)
                    if not h5DataFilePath in listH5FilePath:
                        self.screen(
                            "ID30a3 Eiger data, waiting for master and data files..."
                        )
                        listH5FilePath.append(h5DataFilePath)
                        self.edPluginMXWaitFile = self.loadPlugin(
                            self.strPluginMXWaitFileName)
                        xsDataInputMXWaitFile.file = XSDataFile(
                            XSDataString(h5DataFilePath))
                        xsDataInputMXWaitFile.setSize(
                            XSDataInteger(self.minImageSize))
                        xsDataInputMXWaitFile.setTimeOut(
                            XSDataTime(self.fMXWaitFileTimeOut))
                        self.screen(
                            "Waiting for file {0}".format(h5DataFilePath))
                        self.DEBUG("Wait file timeOut set to %f" %
                                   self.fMXWaitFileTimeOut)
                        self.edPluginMXWaitFile.setDataInput(
                            xsDataInputMXWaitFile)
                        self.edPluginMXWaitFile.executeSynchronous()
                        #                    hdf5FilePath = strPathToImage.replace(".cbf", ".h5")
                        time.sleep(1)
                    if not os.path.exists(h5DataFilePath):
                        strError = "Time-out while waiting for image %s" % h5DataFilePath
                        self.error(strError)
                        self.addErrorMessage(strError)
                        self.setFailure()
                else:
                    if not os.path.exists(strPathToImage):
                        # self.screen("Waiting for file {0}".format(strPathToImage))
                        self.edPluginMXWaitFile = self.loadPlugin(
                            self.strPluginMXWaitFileName)
                        xsDataInputMXWaitFile.file = XSDataFile(
                            XSDataString(strPathToImage))
                        xsDataInputMXWaitFile.setSize(
                            XSDataInteger(self.minImageSize))
                        xsDataInputMXWaitFile.setTimeOut(
                            XSDataTime(self.fMXWaitFileTimeOut))
                        self.screen("Wait file timeOut set to %.0f s" %
                                    self.fMXWaitFileTimeOut)
                        self.edPluginMXWaitFile.setDataInput(
                            xsDataInputMXWaitFile)
                        self.edPluginMXWaitFile.executeSynchronous()
                    if not os.path.exists(strPathToImage):
                        strError = "Time-out while waiting for image %s" % strPathToImage
                        self.error(strError)
                        self.addErrorMessage(strError)
                        self.setFailure()
            if not self.isFailure():
                strPathToFirstImage = listOfImagesInBatch[0].path.value
                if strPathToImage.endswith(".h5"):
                    indexLoop = 1
                    continueLoop = True
                    while continueLoop:
                        directory = os.path.dirname(strPathToFirstImage)
                        firstImage = EDUtilsImage.getImageNumber(
                            listOfImagesInBatch[0].path.value)
                        lastImage = EDUtilsImage.getImageNumber(
                            listOfImagesInBatch[-1].path.value)
                        xsDataInputH5ToCBF = XSDataInputH5ToCBF()
                        xsDataInputH5ToCBF.hdf5File = XSDataFile(
                            listOfImagesInBatch[0].path)
                        xsDataInputH5ToCBF.hdf5ImageNumber = XSDataInteger(1)
                        xsDataInputH5ToCBF.startImageNumber = XSDataInteger(
                            firstImage)
                        xsDataInputH5ToCBF.endImageNumber = XSDataInteger(
                            lastImage)
                        xsDataInputH5ToCBF.forcedOutputDirectory = XSDataFile(
                            XSDataString(directory))
                        edPluginH5ToCBF = self.loadPlugin(
                            "EDPluginH5ToCBFv1_1")
                        edPluginH5ToCBF.dataInput = xsDataInputH5ToCBF
                        edPluginH5ToCBF.execute()
                        edPluginH5ToCBF.synchronize()
                        outputCBFFileTemplate = edPluginH5ToCBF.dataOutput.outputCBFFileTemplate
                        if outputCBFFileTemplate is not None:
                            lastCbfFile = outputCBFFileTemplate.path.value.replace(
                                "######", "{0:06d}".format(
                                    EDUtilsImage.getImageNumber(
                                        listOfImagesInBatch[-1].path.value)))
                            strPathToImage = os.path.join(
                                directory, lastCbfFile)
                            #                        print(cbfFile.path.value)
                            if os.path.exists(strPathToImage):
                                # Rename all images
                                for image in listOfImagesInBatch:
                                    image.path.value = image.path.value.replace(
                                        ".h5", ".cbf")
                                    imageNumber = EDUtilsImage.getImageNumber(
                                        image.path.value)
                                    oldPath = os.path.join(
                                        directory,
                                        outputCBFFileTemplate.path.value.
                                        replace("######",
                                                "{0:06d}".format(imageNumber)))
                                    newPath = os.path.join(
                                        directory,
                                        outputCBFFileTemplate.path.value.
                                        replace("######",
                                                "{0:04d}".format(imageNumber)))
                                    os.rename(oldPath, newPath)
                                lastCbfFile = outputCBFFileTemplate.path.value.replace(
                                    "######", "{0:04d}".format(
                                        EDUtilsImage.getImageNumber(
                                            listOfImagesInBatch[-1].path.value)
                                    ))
                                strPathToImage = os.path.join(
                                    directory, lastCbfFile)
                                self.screen(
                                    "Image has been converted to CBF file: {0}"
                                    .format(strPathToImage))
                                continueLoop = False
    #                    print(continueLoop)
                        if continueLoop:
                            self.screen(
                                "Still waiting for converting to CBF file: {0}"
                                .format(strPathToImage))
                            indexLoop += 1
                            time.sleep(5)
                            if indexLoop > 10:
                                continueLoop = False

                for image in listOfImagesInBatch:
                    strPathToImage = image.path.value
                    # Check if we should run distl.signalStrength
                    xsDataImageNew = XSDataImage(XSDataString(strPathToImage))
                    xsDataImageNew.number = XSDataInteger(
                        EDUtilsImage.getImageNumber(image.path.value))
                    edPluginPluginExecImageQualityIndicator = None
                    if bDoDistlSignalStrength:
                        if self.bUseThinClient:
                            strPluginName = self.strPluginNameThinClient
                        else:
                            strPluginName = self.strPluginName
                        edPluginPluginExecImageQualityIndicator = self.loadPlugin(
                            strPluginName)
                        self.listPluginExecImageQualityIndicator.append(
                            edPluginPluginExecImageQualityIndicator)
                        xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength(
                        )
                        xsDataInputDistlSignalStrength.setReferenceImage(
                            xsDataImageNew)
                        edPluginPluginExecImageQualityIndicator.setDataInput(
                            xsDataInputDistlSignalStrength)
                        edPluginPluginExecImageQualityIndicator.execute()
                    listPluginDistl.append(
                        (xsDataImageNew.copy(),
                         edPluginPluginExecImageQualityIndicator))

                edPluginControlDozor = self.loadPlugin(
                    self.strPluginNameControlDozor, "ControlDozor_{0}".format(
                        os.path.splitext(
                            os.path.basename(strPathToFirstImage))[0]))
                xsDataInputControlDozor = XSDataInputControlDozor()
                for image in listOfImagesInBatch:
                    xsDataInputControlDozor.addImage(XSDataFile(image.path))
                xsDataInputControlDozor.batchSize = XSDataInteger(
                    len(listOfImagesInBatch))
                edPluginControlDozor.dataInput = xsDataInputControlDozor
                edPluginControlDozor.execute()
                listPluginDozor.append(
                    (edPluginControlDozor, list(listOfImagesInBatch)))

        if not self.isFailure():
            listIndexing = []
            # Synchronize all image quality indicator plugins and upload to ISPyB
            xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators(
            )

            for (xsDataImage,
                 edPluginPluginExecImageQualityIndicator) in listPluginDistl:
                xsDataImageQualityIndicators = XSDataImageQualityIndicators()
                xsDataImageQualityIndicators.image = xsDataImage.copy()
                if edPluginPluginExecImageQualityIndicator is not None:
                    edPluginPluginExecImageQualityIndicator.synchronize()
                    if edPluginPluginExecImageQualityIndicator.dataOutput is not None:
                        if edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators is not None:
                            xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\
                                    edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
                self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(
                    xsDataImageQualityIndicators)

            for (edPluginControlDozor, listBatch) in listPluginDozor:
                edPluginControlDozor.synchronize()
                # Check that we got at least one result
                if len(edPluginControlDozor.dataOutput.imageDozor) == 0:
                    # Run the dozor plugin again, this time synchronously
                    firstImage = os.path.basename(listBatch[0].path.value)
                    lastImage = os.path.basename(listBatch[-1].path.value)
                    self.screen(
                        "No dozor results! Re-executing Dozor for images {0} to {1}"
                        .format(firstImage, lastImage))
                    time.sleep(5)
                    edPluginControlDozor = self.loadPlugin(
                        self.strPluginNameControlDozor,
                        "ControlDozor_reexecution_{0}".format(
                            os.path.splitext(firstImage)[0]))
                    xsDataInputControlDozor = XSDataInputControlDozor()
                    for image in listBatch:
                        xsDataInputControlDozor.addImage(XSDataFile(
                            image.path))
                    xsDataInputControlDozor.batchSize = XSDataInteger(
                        batchSize)
                    edPluginControlDozor.dataInput = xsDataInputControlDozor
                    edPluginControlDozor.executeSynchronous()
                for imageDozor in edPluginControlDozor.dataOutput.imageDozor:
                    for xsDataImageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                        if xsDataImageQualityIndicators.image.path.value == imageDozor.image.path.value:
                            xsDataImageQualityIndicators.dozor_score = imageDozor.mainScore
                            xsDataImageQualityIndicators.dozorSpotFile = imageDozor.spotFile
                            if imageDozor.spotFile is not None:
                                if os.path.exists(
                                        imageDozor.spotFile.path.value):
                                    numpyArray = numpy.loadtxt(
                                        imageDozor.spotFile.path.value,
                                        skiprows=3)
                                    xsDataImageQualityIndicators.dozorSpotList = XSDataString(
                                        base64.b64encode(
                                            numpyArray.tostring()))
                                    xsDataImageQualityIndicators.addDozorSpotListShape(
                                        XSDataInteger(numpyArray.shape[0]))
                                    if len(numpyArray.shape) > 1:
                                        xsDataImageQualityIndicators.addDozorSpotListShape(
                                            XSDataInteger(numpyArray.shape[1]))
                            xsDataImageQualityIndicators.dozorSpotsIntAver = imageDozor.spotsIntAver
                            xsDataImageQualityIndicators.dozorSpotsResolution = imageDozor.spotsResolution
                            xsDataImageQualityIndicators.dozorVisibleResolution = imageDozor.visibleResolution
                            if self.xsDataResultControlImageQualityIndicators.inputDozor is None:
                                if edPluginControlDozor.dataOutput.inputDozor is not None:
                                    self.xsDataResultControlImageQualityIndicators.inputDozor = XSDataDozorInput(
                                    ).parseString(
                                        edPluginControlDozor.dataOutput.
                                        inputDozor.marshal())
                if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                    xsDataISPyBImageQualityIndicators = \
                        XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
                    xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(
                        xsDataISPyBImageQualityIndicators)

    #        print xsDataInputStoreListOfImageQualityIndicators.marshal()
            if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
                self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
                self.edPluginISPyB.execute()
            #
            if bDoIndexing:
                # Find the 5 most intensive images (TIS):
                listImage = []
                # Check that we have dozor_score from all images:
                has_dozor_score = True
                for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                    if imageQualityIndicators.dozor_score is None:
                        has_dozor_score = False
                if has_dozor_score:
                    listSorted = sorted(
                        self.xsDataResultControlImageQualityIndicators.
                        imageQualityIndicators,
                        key=lambda imageQualityIndicators:
                        imageQualityIndicators.dozor_score.value)
                else:
                    listSorted = sorted(
                        self.xsDataResultControlImageQualityIndicators.
                        imageQualityIndicators,
                        key=lambda imageQualityIndicators:
                        imageQualityIndicators.totalIntegratedSignal.value)
                for xsDataResultControlImageQualityIndicator in listSorted[
                        -5:]:
                    if xsDataResultControlImageQualityIndicator.dozor_score.value > 1:
                        xsDataInputReadImageHeader = XSDataInputReadImageHeader(
                        )
                        xsDataInputReadImageHeader.image = XSDataFile(
                            xsDataResultControlImageQualityIndicator.image.path
                        )
                        self.edPluginReadImageHeader = self.loadPlugin(
                            self.strPluginReadImageHeaderName)
                        self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                        self.edPluginReadImageHeader.executeSynchronous()
                        xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                        if xsDataResultReadImageHeader is not None:
                            edPluginLabelitIndexing = self.loadPlugin(
                                self.strIndexingLabelitPluginName)
                            xsDataInputLabelitIndexing = XSDataInputLabelitIndexing(
                            )
                            xsDataInputLabelitIndexing.image.append(
                                XSDataImage(
                                    xsDataResultControlImageQualityIndicator.
                                    image.path))
                            edPluginLabelitIndexing.setDataInput(
                                xsDataInputLabelitIndexing)
                            self.listPluginLabelit.append([
                                edPluginLabelitIndexing,
                                xsDataResultControlImageQualityIndicator
                            ])
                            edPluginLabelitIndexing.execute()
                for tupleLabelit in self.listPluginLabelit:
                    edPluginLabelitIndexing = tupleLabelit[0]
                    xsDataResultControlImageQualityIndicator = tupleLabelit[1]
                    edPluginLabelitIndexing.synchronize()
                    if not edPluginLabelitIndexing.isFailure(
                    ) and edPluginLabelitIndexing.dataOutput is not None:
                        xsDataResultLabelitIndexing = edPluginLabelitIndexing.getDataOutput(
                        )
                        xsDataIndexingResult = EDHandlerXSDataPhenixv1_1.generateXSDataIndexingResult(
                            xsDataResultLabelitIndexing)
                        selectedSolution = xsDataIndexingResult.selectedSolution
                        if selectedSolution is not None:
                            xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
예제 #54
0
    def generateCommands(self, _xsDataInputH5ToCBF):
        """
        This method creates a list of commands for the converter
        """
        self.DEBUG("EDPluginH5ToCBFv1_1.generateCommands")

        hdf5File = _xsDataInputH5ToCBF.hdf5File.path.value
        directory = os.path.dirname(hdf5File)
        prefix = EDUtilsImage.getPrefix(hdf5File)

        if _xsDataInputH5ToCBF.imageNumber is not None:
            imageNumber = _xsDataInputH5ToCBF.imageNumber.value

            if _xsDataInputH5ToCBF.hdf5ImageNumber is None:
                hdf5ImageNumber = imageNumber
            else:
                hdf5ImageNumber = _xsDataInputH5ToCBF.hdf5ImageNumber.value

            if "master" in hdf5File:
                masterFile = hdf5File
            else:
                if EDUtilsPath.isEMBL():
                    masterFile = os.path.join(directory, prefix + "_master.h5".format(hdf5ImageNumber))
                else:
                    masterFile = os.path.join(directory, prefix + "_{0}_master.h5".format(hdf5ImageNumber))

            if _xsDataInputH5ToCBF.forcedOutputImageNumber is not None:
                CBFFileName = prefix + "_%04d" % _xsDataInputH5ToCBF.forcedOutputImageNumber.value + ".cbf"
                imageNumberInHdf5File = imageNumber
            else:
                CBFFileName = prefix + "_%04d" % imageNumber + ".cbf"
                imageNumberInHdf5File = imageNumber - hdf5ImageNumber + 1

            tmpCBFFileName = "tmp_" + CBFFileName

            if _xsDataInputH5ToCBF.forcedOutputDirectory is None:
                self.CBFFile = os.path.join(directory, CBFFileName)
            else:
                forcedOutputDirectory = self.dataInput.forcedOutputDirectory.path.value
                if not os.path.exists(forcedOutputDirectory):
                    os.makedirs(forcedOutputDirectory, 0o755)
                self.CBFFile = os.path.join(forcedOutputDirectory, CBFFileName)

            scriptCommandLine = "{0} {1} {2}".format(masterFile, imageNumberInHdf5File, self.CBFFile)

        elif _xsDataInputH5ToCBF.startImageNumber is not None and _xsDataInputH5ToCBF.endImageNumber is not None:

            startImageNumber = _xsDataInputH5ToCBF.startImageNumber.value
            endImageNumber = _xsDataInputH5ToCBF.endImageNumber.value

            if _xsDataInputH5ToCBF.hdf5ImageNumber is None:
                hdf5ImageNumber = startImageNumber
            else:
                hdf5ImageNumber = _xsDataInputH5ToCBF.hdf5ImageNumber.value

            if "master" in hdf5File:
                masterFile = hdf5File
            else:
                masterFile = os.path.join(directory, prefix + "_{0}_master.h5".format(hdf5ImageNumber))

            CBFFileNamePrefix = prefix + "_"

            if _xsDataInputH5ToCBF.forcedOutputDirectory is None:
                CBFFilePath = os.path.join(directory, CBFFileNamePrefix)
            else:
                forcedOutputDirectory = self.dataInput.forcedOutputDirectory.path.value
                if not os.path.exists(forcedOutputDirectory):
                    os.makedirs(forcedOutputDirectory, 0o755)
                CBFFilePath = os.path.join(forcedOutputDirectory, CBFFileNamePrefix)

            scriptCommandLine = "{0} {1}:{2} {3}".format(masterFile, startImageNumber, endImageNumber, CBFFilePath)

            self.CBFFileTemplate = CBFFilePath + "######.cbf"

        return scriptCommandLine
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_4.process")
        EDUtilsParallel.initializeNbThread()
        # Check batch size
        if self.dataInput.batchSize is None:
            batchSize = 1
        else:
            batchSize = self.dataInput.batchSize.value
        self.screen("Batch size: {0}".format(batchSize))
        # Check if we should do distlSignalStrength:
        bDoDistlSignalStrength = True
        if self.dataInput.doDistlSignalStrength is not None:
            if not self.dataInput.doDistlSignalStrength.value:
                bDoDistlSignalStrength = False
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                 bDoIndexing = True
        # Loop through all the incoming reference images
        listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators()
        listPluginDistl = []
        listPluginDozor = []
        listBatch = []
        indexBatch = 0
        listH5FilePath = []
        ispybDataCollection = None
        for xsDataImage in listXSDataImage:
            strPathToImage = xsDataImage.path.value
            # If Eiger, just wait for the h5 file
            if "id30a3" in strPathToImage:
                h5MasterFilePath, h5DataFilePath, hdf5ImageNumber = self.getH5FilePath(strPathToImage, batchSize)
#                print(h5FilePath)
#                print(hdf5ImageNumber)
                if not h5DataFilePath in listH5FilePath:
                    self.screen("ID30a3 Eiger data, waiting for master and data files...")
                    listH5FilePath.append(h5DataFilePath)
                    self.edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                    xsDataInputMXWaitFile.file = XSDataFile(XSDataString(h5DataFilePath))
                    xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                    xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                    self.screen("Waiting for file {0}".format(h5DataFilePath))
                    self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
                    self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                    self.edPluginMXWaitFile.executeSynchronous()
#                    hdf5FilePath = strPathToImage.replace(".cbf", ".h5")
                    ispybDataCollection = None
                    time.sleep(1)
                indexLoop = 1
                continueLoop = True
                while continueLoop:
                    xsDataInputControlH5ToCBF = XSDataInputControlH5ToCBF()
                    xsDataInputControlH5ToCBF.hdf5File = XSDataFile(XSDataString(strPathToImage))
                    imageNumber = EDUtilsImage.getImageNumber(strPathToImage)
                    xsDataInputControlH5ToCBF.imageNumber = XSDataInteger(imageNumber)
                    xsDataInputControlH5ToCBF.hdf5ImageNumber = XSDataInteger(hdf5ImageNumber)
                    xsDataInputControlH5ToCBF.ispybDataCollection = ispybDataCollection
                    edPluginControlH5ToCBF = self.loadPlugin(self.strPluginControlH5ToCBF, "ControlH5ToCBF_%04d_%02d" % (imageNumber, indexLoop))
                    edPluginControlH5ToCBF.dataInput = xsDataInputControlH5ToCBF
                    edPluginControlH5ToCBF.executeSynchronous()
                    cbfFile = edPluginControlH5ToCBF.dataOutput.outputCBFFile
#                    print(cbfFile)
#                    print(indexLoop)
                    if cbfFile is not None:
                        strPathToImage = cbfFile.path.value
#                        print(cbfFile.path.value)
                        if os.path.exists(strPathToImage):
                            self.screen("Image has been converted to CBF file: {0}".format(strPathToImage))
                            continueLoop = False
#                    print(continueLoop)
                    if continueLoop:
                        self.screen("Still waiting for converting to CBF file: {0}".format(strPathToImage))
                        indexLoop += 1
                        time.sleep(5)
                        if indexLoop > 10:
                            continueLoop = False

                ispybDataCollection = edPluginControlH5ToCBF.dataOutput.ispybDataCollection


            elif not os.path.exists(strPathToImage):
                self.screen("Waiting for file {0}".format(strPathToImage))
                self.edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                xsDataInputMXWaitFile.file = XSDataFile(XSDataString(strPathToImage))
                xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
                self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                self.edPluginMXWaitFile.executeSynchronous()
            if not os.path.exists(strPathToImage):
                strError = "Time-out while waiting for image %s" % strPathToImage
                self.error(strError)
                self.addErrorMessage(strError)
                self.setFailure()
            else:
                # Check if we should run distl.signalStrength
                xsDataImageNew = XSDataImage(XSDataString(strPathToImage))
                edPluginPluginExecImageQualityIndicator = None
                if bDoDistlSignalStrength:
                    if self.bUseThinClient:
                        strPluginName = self.strPluginNameThinClient
                    else:
                        strPluginName = self.strPluginName
                    edPluginPluginExecImageQualityIndicator = self.loadPlugin(strPluginName)
                    self.listPluginExecImageQualityIndicator.append(edPluginPluginExecImageQualityIndicator)
                    xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength()
                    xsDataInputDistlSignalStrength.setReferenceImage(xsDataImageNew)
                    edPluginPluginExecImageQualityIndicator.setDataInput(xsDataInputDistlSignalStrength)
                    edPluginPluginExecImageQualityIndicator.execute()
                listPluginDistl.append((xsDataImageNew.copy(), edPluginPluginExecImageQualityIndicator))
                listBatch.append(xsDataImageNew.copy())
                if len(listBatch) == batchSize:
                    edPluginControlDozor = self.loadPlugin(self.strPluginNameControlDozor)
                    xsDataInputControlDozor = XSDataInputControlDozor()
                    for image in listBatch:
                        xsDataInputControlDozor.addImage(XSDataFile(image.path))
                    xsDataInputControlDozor.batchSize = XSDataInteger(batchSize)
                    edPluginControlDozor.dataInput = xsDataInputControlDozor
                    edPluginControlDozor.execute()
                    listPluginDozor.append((edPluginControlDozor, listBatch))
                    listBatch = []
        if len(listBatch) > 0:
            # Process the remaining images...
            edPluginControlDozor = self.loadPlugin(self.strPluginNameControlDozor)
            xsDataInputControlDozor = XSDataInputControlDozor()
            for image in listBatch:
                xsDataInputControlDozor.addImage(XSDataFile(image.path))
            xsDataInputControlDozor.batchSize = XSDataInteger(batchSize)
            edPluginControlDozor.dataInput = xsDataInputControlDozor
            edPluginControlDozor.execute()
            listPluginDozor.append([edPluginControlDozor, listBatch])
        listIndexing = []
        # Synchronize all image quality indicator plugins and upload to ISPyB
        xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators()

        for (xsDataImage, edPluginPluginExecImageQualityIndicator) in listPluginDistl:
            xsDataImageQualityIndicators = XSDataImageQualityIndicators()
            xsDataImageQualityIndicators.image = xsDataImage.copy()
            if edPluginPluginExecImageQualityIndicator is not None:
                edPluginPluginExecImageQualityIndicator.synchronize()
                if edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators is not None:
                    xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\
                            edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
            self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(xsDataImageQualityIndicators)

        for (edPluginControlDozor, listBatch) in listPluginDozor:
            edPluginControlDozor.synchronize()
            for imageDozor in edPluginControlDozor.dataOutput.imageDozor:
                for xsDataImageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                    if xsDataImageQualityIndicators.image.path.value == imageDozor.image.path.value:
                        xsDataImageQualityIndicators.dozor_score = imageDozor.mainScore
                        xsDataImageQualityIndicators.dozorSpotFile = imageDozor.spotFile
                        if imageDozor.spotFile is not None:
                            if os.path.exists(imageDozor.spotFile.path.value):
                                numpyArray = numpy.loadtxt(imageDozor.spotFile.path.value, skiprows=3)
                                xsDataImageQualityIndicators.dozorSpotList = XSDataString(base64.b64encode(numpyArray.tostring()))
                                xsDataImageQualityIndicators.addDozorSpotListShape(XSDataInteger(numpyArray.shape[0]))
                                if len(numpyArray.shape) > 1:
                                    xsDataImageQualityIndicators.addDozorSpotListShape(XSDataInteger(numpyArray.shape[1]))
                        xsDataImageQualityIndicators.dozorSpotsIntAver = imageDozor.spotsIntAver
                        xsDataImageQualityIndicators.dozorSpotsResolution = imageDozor.spotsResolution
                        if self.xsDataResultControlImageQualityIndicators.inputDozor is None:
                            if edPluginControlDozor.dataOutput.inputDozor is not None:
                                self.xsDataResultControlImageQualityIndicators.inputDozor = XSDataDozorInput().parseString(
                                               edPluginControlDozor.dataOutput.inputDozor.marshal())
            if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                xsDataISPyBImageQualityIndicators = \
                    XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
                xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(xsDataISPyBImageQualityIndicators)
#        print xsDataInputStoreListOfImageQualityIndicators.marshal()
        if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
            self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
            self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
            self.edPluginISPyB.execute()
        #
        if bDoIndexing:
            # Find the 5 most intensive images (TIS):
            listImage = []
            # Check that we have dozor_score from all images:
            has_dozor_score = True
            for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                if imageQualityIndicators.dozor_score is None:
                    has_dozor_score = False
            if has_dozor_score:
                listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators,
                                    key=lambda imageQualityIndicators: imageQualityIndicators.dozor_score.value)
            else:
                listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators,
                                    key=lambda imageQualityIndicators: imageQualityIndicators.totalIntegratedSignal.value)
            for xsDataResultControlImageQualityIndicator in listSorted[-5:]:
                if xsDataResultControlImageQualityIndicator.goodBraggCandidates.value > 30:
                    xsDataInputReadImageHeader = XSDataInputReadImageHeader()
                    xsDataInputReadImageHeader.image = XSDataFile(xsDataResultControlImageQualityIndicator.image.path)
                    self.edPluginReadImageHeader = self.loadPlugin(self.strPluginReadImageHeaderName)
                    self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                    self.edPluginReadImageHeader.executeSynchronous()
                    xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                    if xsDataResultReadImageHeader is not None:
                        xsDataSubWedge = xsDataResultReadImageHeader.subWedge
                        self.xsDataCollection = XSDataCollection()
                        self.xsDataCollection.addSubWedge(xsDataSubWedge)
                        xsDataIndexingInput = XSDataIndexingInput()
                        xsDataIndexingInput.setDataCollection(self.xsDataCollection)
                        xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
                        edPluginMOSFLMIndexing = self.loadPlugin(self.strIndexingMOSFLMPluginName)
                        self.listPluginMOSFLM.append([edPluginMOSFLMIndexing, xsDataResultControlImageQualityIndicator])
                        edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
                        edPluginMOSFLMIndexing.execute()
            for tupleMOSFLM in self.listPluginMOSFLM:
                edPluginMOSFLMIndexing = tupleMOSFLM[0]
                xsDataResultControlImageQualityIndicator = tupleMOSFLM[1]
                edPluginMOSFLMIndexing.synchronize()
                if not edPluginMOSFLMIndexing.isFailure():
                    xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput
                    xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(xsDataMOSFLMOutput)
                    selectedSolution = xsDataIndexingResult.selectedSolution
                    if selectedSolution is not None:
                        xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution