Esempio n. 1
0
 def mergeTwoSubWedgesAdjascentInRotationAxis(self, _subWedge1, _subWedge2):
     """
     This method takes as input two sub wedges and merges them to an unique subwedge, if possible,
     and returns the resulting merged sub wedge. If the merge is not possible a None is returned.
     """
     EDVerbose.DEBUG(
         "EDPluginSubWedgeMergev1_1.mergeTwoSubWedgesAdjascentInRotationAxis"
     )
     xsDataSubWedgeMerged = None
     # First check that the two sub wedges have identical experimental conditions
     if (self.isSameExperimentalConditionInSubWedge(_subWedge1,
                                                    _subWedge2)):
         # Check if sub wedges are adjascent:
         dRoationAxisEnd1 = _subWedge1.getExperimentalCondition(
         ).getGoniostat().getRotationAxisEnd().getValue()
         dRoationAxisStart2 = _subWedge2.getExperimentalCondition(
         ).getGoniostat().getRotationAxisStart().getValue()
         #print dRoationAxisEnd1, dRoationAxisStart2
         if (self.compareTwoValues(dRoationAxisEnd1, dRoationAxisStart2,
                                   0.001)):
             # Same sub wedge! Let's merge them
             xsDataSubWedgeMerged = XSDataSubWedge.parseString(
                 _subWedge1.marshal())
             xsDataSubWedge2 = XSDataSubWedge.parseString(
                 _subWedge2.marshal())
             dRoationAxisEnd2 = xsDataSubWedge2.getExperimentalCondition(
             ).getGoniostat().getRotationAxisEnd().getValue()
             xsDataSubWedgeMerged.getExperimentalCondition().getGoniostat(
             ).setRotationAxisEnd(XSDataAngle(dRoationAxisEnd2))
             for xsDataImage in xsDataSubWedge2.getImage():
                 xsDataSubWedgeMerged.addImage(xsDataImage)
     return xsDataSubWedgeMerged
 def mergeListOfSubWedgesWithAdjascentRotationAxis(self, _listOfSubWedgesWithIdenticalExperimentalConditions):
     """
     This method merges sub wedges in a list if they are adjascent in phi.
     """
     self.DEBUG("EDPluginSubWedgeMergev1_1.mergeSubWedgesWithAdjascentRotationAxis")
     # Copy the incoming list to a new list
     listOfSubWedgesWithIdenticalExperimentalConditions = []
     for xsDataSubWedge in _listOfSubWedgesWithIdenticalExperimentalConditions:
         listOfSubWedgesWithIdenticalExperimentalConditions.append(XSDataSubWedge.parseString(xsDataSubWedge.marshal()))
     listOfMergedSubWedges = []
     if (len(listOfSubWedgesWithIdenticalExperimentalConditions) == 0):
         pass
     elif (len(listOfSubWedgesWithIdenticalExperimentalConditions) == 1):
         listOfMergedSubWedges = listOfSubWedgesWithIdenticalExperimentalConditions
     else:
         # First sort the list as function of rotation axis start
         listOfSubWedgesWithIdenticalExperimentalConditions.sort(lambda x, y: cmp(x.getExperimentalCondition().getGoniostat().getRotationAxisStart().getValue(), \
                                                                                     y.getExperimentalCondition().getGoniostat().getRotationAxisStart().getValue()))
         # Then loop through the subwedges and merge them if possible
         listRemainingSubWedges = listOfSubWedgesWithIdenticalExperimentalConditions
         oCurrentSubWedge = listRemainingSubWedges[0]
         listRemainingSubWedges = listRemainingSubWedges[1:]
         while (len(listRemainingSubWedges) > 0):
             oNextSubWedge = listRemainingSubWedges[0]
             listRemainingSubWedges = listRemainingSubWedges[1:]
             xsDataSubWedgeMerged = self.mergeTwoSubWedgesAdjascentInRotationAxis(oCurrentSubWedge, oNextSubWedge)
             if (xsDataSubWedgeMerged is None):
                 listOfMergedSubWedges.append(oCurrentSubWedge)
                 oCurrentSubWedge = oNextSubWedge
             else:
                 oCurrentSubWedge = xsDataSubWedgeMerged
         listOfMergedSubWedges.append(oCurrentSubWedge)
     return listOfMergedSubWedges
Esempio n. 3
0
 def mergeListOfSubWedgesWithAdjascentRotationAxis(self, _listOfSubWedgesWithIdenticalExperimentalConditions):
     """
     This method merges sub wedges in a list if they are adjascent in phi.
     """
     EDVerbose.DEBUG("EDPluginSubWedgeMergev10.mergeSubWedgesWithAdjascentRotationAxis")
     # Copy the incoming list to a new list
     listOfSubWedgesWithIdenticalExperimentalConditions = []
     for xsDataSubWedge in _listOfSubWedgesWithIdenticalExperimentalConditions:
         listOfSubWedgesWithIdenticalExperimentalConditions.append(XSDataSubWedge.parseString(xsDataSubWedge.marshal()))
     listOfMergedSubWedges = []
     if (len(listOfSubWedgesWithIdenticalExperimentalConditions) == 0):
         pass
     elif (len(listOfSubWedgesWithIdenticalExperimentalConditions) == 1):
         listOfMergedSubWedges = listOfSubWedgesWithIdenticalExperimentalConditions
     else:
         # First sort the list as function of rotation axis start
         listOfSubWedgesWithIdenticalExperimentalConditions.sort(lambda x, y: cmp(x.getExperimentalCondition().getGoniostat().getRotationAxisStart().getValue(), \
                                                                                     y.getExperimentalCondition().getGoniostat().getRotationAxisStart().getValue()))
         # Then loop through the subwedges and merge them if possible
         listRemainingSubWedges = listOfSubWedgesWithIdenticalExperimentalConditions
         oCurrentSubWedge = listRemainingSubWedges[0]
         listRemainingSubWedges = listRemainingSubWedges[1:]
         while (len(listRemainingSubWedges) > 0):
             oNextSubWedge = listRemainingSubWedges[0]
             listRemainingSubWedges = listRemainingSubWedges[1:]
             xsDataSubWedgeMerged = self.mergeTwoSubWedgesAdjascentInRotationAxis(oCurrentSubWedge, oNextSubWedge)
             if (xsDataSubWedgeMerged is None):
                 listOfMergedSubWedges.append(oCurrentSubWedge)
                 oCurrentSubWedge = oNextSubWedge
             else:
                 oCurrentSubWedge = xsDataSubWedgeMerged
         listOfMergedSubWedges.append(oCurrentSubWedge)
     return listOfMergedSubWedges
 def testMergeTwoSubWedgesAdjascentInRotationAxis(self):
     # First check two sub wedges which shouldn't be merged
     edPluginSubWedgeMergev10 = self.createPlugin()
     edPluginSubWedgeMergev10.configure()
     xsDataInputSubWedgeMerge = XSDataInputSubWedgeMerge.parseFile(
         self.__strPathToReferenceInput)
     xsDataSubWedge1 = xsDataInputSubWedgeMerge.getSubWedge()[0]
     xsDataSubWedge2 = xsDataInputSubWedgeMerge.getSubWedge()[1]
     xsDataSubWedgeMerged = edPluginSubWedgeMergev10.mergeTwoSubWedgesAdjascentInRotationAxis(
         xsDataSubWedge1, xsDataSubWedge2)
     EDAssert.equal(xsDataSubWedgeMerged, None)
     # Then check two adjascent images
     strPathToInputTwoAdjascentImages = os.path.join(
         self.getPluginTestsDataHome(),
         "XSDataInputSubWedgeMerge_twoAdjascentImages.xml")
     xsDataInputSubWedgeMerge2 = XSDataInputSubWedgeMerge.parseFile(
         strPathToInputTwoAdjascentImages)
     xsDataSubWedge1 = xsDataInputSubWedgeMerge2.getSubWedge()[0]
     xsDataSubWedge2 = xsDataInputSubWedgeMerge2.getSubWedge()[1]
     xsDataSubWedgeMerged = edPluginSubWedgeMergev10.mergeTwoSubWedgesAdjascentInRotationAxis(
         xsDataSubWedge1, xsDataSubWedge2)
     xsDataSubWedgeMergedReference = XSDataSubWedge.parseFile(
         os.path.join(self.getPluginTestsDataHome(),
                      "XSDataSubWedgeMerged_twoImages.xml"))
     EDAssert.equal(xsDataSubWedgeMerged.marshal(),
                    xsDataSubWedgeMergedReference.marshal())
 def testMergeListOfSubWedgesWithAdjascentRotationAxis(self):
     edPluginSubWedgeMergev10 = self.createPlugin()
     edPluginSubWedgeMergev10.configure()
     # Check a list of nine adjascent images
     strPathToInputNineAdjascentImages = os.path.join(self.getPluginTestsDataHome(), "XSDataInputSubWedgeMerge_nineAdjascentImages.xml")
     xsDataInputSubWedgeMergeNine = XSDataInputSubWedgeMerge.parseFile(strPathToInputNineAdjascentImages)
     xsDataSubWedgeMerged = edPluginSubWedgeMergev10.mergeListOfSubWedgesWithAdjascentRotationAxis(xsDataInputSubWedgeMergeNine.getSubWedge())
     xsDataSubWedgeMergedReference = XSDataSubWedge.parseFile(os.path.join(self.getPluginTestsDataHome(), "XSDataSubWedgeMerged_nineImages.xml"))
     EDAssert.equal(xsDataSubWedgeMerged[0].marshal(), xsDataSubWedgeMergedReference.marshal())
Esempio n. 6
0
    def getXSDataResultStrategy(self, _xsDataResultBest, _xsDataExperimentalCondition, _xsDataSample):
        xsDataResultStrategy = XSDataResultStrategy()


        #xsDataCollectionRunsBest = _xsDataResultBest.getCollectionRun()
        xsDataCollectionPlansBest = _xsDataResultBest.getCollectionPlan()

        for xsDataCollectionPlanBest in xsDataCollectionPlansBest:

            xsDataCollectionPlan = XSDataCollectionPlan()
            xsDataCollectionStrategy = XSDataCollection()

            xsDataDoubleTransmission = xsDataCollectionPlanBest.getStrategySummary().getAttenuation()

            for xsDataCollectionRunBest in xsDataCollectionPlanBest.getCollectionRun():
                xsDataSubWedge = XSDataSubWedge()
                strXmlStringDataExperimentalCondition = _xsDataExperimentalCondition.marshal()
                xsDataExperimentalCondition = XSDataExperimentalCondition.parseString(strXmlStringDataExperimentalCondition)
                xsDataExperimentalCondition.getBeam().setExposureTime(xsDataCollectionRunBest.getExposureTime())
                xsDataExperimentalCondition.getBeam().setTransmission(xsDataDoubleTransmission)
                xsDataExperimentalCondition.getDetector().setDistance(xsDataCollectionRunBest.getDistance())
                xsDataExperimentalCondition.getGoniostat().setRotationAxisStart(xsDataCollectionRunBest.getPhiStart())
                xsDataExperimentalCondition.getGoniostat().setOscillationWidth(xsDataCollectionRunBest.getPhiWidth())
                fRotationAxisEnd = xsDataCollectionRunBest.getPhiStart().getValue() + xsDataCollectionRunBest.getNumberOfImages().getValue() * xsDataCollectionRunBest.getPhiWidth().getValue()
                xsDataExperimentalCondition.getGoniostat().setRotationAxisEnd(XSDataAngle(fRotationAxisEnd))
                xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
                xsDataSubWedge.setSubWedgeNumber(xsDataCollectionRunBest.getCollectionRunNumber())
                xsDataCollectionStrategy.addSubWedge(xsDataSubWedge)

            xsDataCollectionStrategy.setSample(_xsDataSample)

            xsDataCollectionPlan.setCollectionStrategy(xsDataCollectionStrategy)
            xsDataStrategySummary = xsDataCollectionPlanBest.getStrategySummary()
            xsDataCollectionPlan.setStrategySummary(xsDataStrategySummary)

            xsDataStatistics = xsDataCollectionPlanBest.getStatisticalPrediction()
            xsDataCollectionPlan.setStatistics(xsDataStatistics)

            xsDataCollectionPlan.setCollectionPlanNumber(xsDataCollectionPlanBest.getCollectionPlanNumber())

            xsDataResultStrategy.addCollectionPlan(xsDataCollectionPlan)

        return xsDataResultStrategy
 def mergeTwoSubWedgesAdjascentInRotationAxis(self, _subWedge1, _subWedge2):
     """
     This method takes as input two sub wedges and merges them to an unique subwedge, if possible,
     and returns the resulting merged sub wedge. If the merge is not possible a None is returned.
     """
     self.DEBUG("EDPluginSubWedgeMergev1_1.mergeTwoSubWedgesAdjascentInRotationAxis")
     xsDataSubWedgeMerged = None
     # First check that the two sub wedges have identical experimental conditions
     if (self.isSameExperimentalConditionInSubWedge(_subWedge1, _subWedge2)):
         # Check if sub wedges are adjascent:
         dRoationAxisEnd1 = _subWedge1.getExperimentalCondition().getGoniostat().getRotationAxisEnd().getValue()
         dRoationAxisStart2 = _subWedge2.getExperimentalCondition().getGoniostat().getRotationAxisStart().getValue()
         #print dRoationAxisEnd1, dRoationAxisStart2
         if (self.compareTwoValues(dRoationAxisEnd1, dRoationAxisStart2, 0.001)):
             # Same sub wedge! Let's merge them
             xsDataSubWedgeMerged = XSDataSubWedge.parseString(_subWedge1.marshal())
             xsDataSubWedge2 = XSDataSubWedge.parseString(_subWedge2.marshal())
             dRoationAxisEnd2 = xsDataSubWedge2.getExperimentalCondition().getGoniostat().getRotationAxisEnd().getValue()
             xsDataSubWedgeMerged.getExperimentalCondition().getGoniostat().setRotationAxisEnd(XSDataAngle(dRoationAxisEnd2))
             for xsDataImage in xsDataSubWedge2.getImage():
                 xsDataSubWedgeMerged.addImage(xsDataImage)
     return xsDataSubWedgeMerged
Esempio n. 8
0
    def getXSDataStrategyResult(self, _xsDataBestOutput, _xsDataExperimentalCondition, _xsDataSample):
        xsDataStrategyResult = XSDataStrategyResult()


        #xsDataCollectionRunsBest = _xsDataBestOutput.getCollectionRun()
        xsDataCollectionPlansBest = _xsDataBestOutput.getCollectionPlan()

        for xsDataCollectionPlanBest in xsDataCollectionPlansBest:

            xsDataCollectionPlan = XSDataCollectionPlan()
            xsDataCollectionStrategy = XSDataCollection()

            for xsDataCollectionRunBest in xsDataCollectionPlanBest.getCollectionRun():
                xsDataSubWedge = XSDataSubWedge()
                strXmlStringDataExperimentalCondition = _xsDataExperimentalCondition.marshal()
                xsDataExperimentalCondition = XSDataExperimentalCondition.parseString(strXmlStringDataExperimentalCondition)
                xsDataExperimentalCondition.getBeam().setExposureTime(xsDataCollectionRunBest.getExposureTime())
                xsDataExperimentalCondition.getDetector().setDistance(xsDataCollectionRunBest.getDistance())
                xsDataExperimentalCondition.getGoniostat().setRotationAxisStart(xsDataCollectionRunBest.getPhiStart())
                xsDataExperimentalCondition.getGoniostat().setOscillationWidth(xsDataCollectionRunBest.getPhiWidth())
                fRotationAxisEnd = xsDataCollectionRunBest.getPhiStart().getValue() + xsDataCollectionRunBest.getNumberOfImages().getValue() * xsDataCollectionRunBest.getPhiWidth().getValue()
                xsDataExperimentalCondition.getGoniostat().setRotationAxisEnd(XSDataAngle(fRotationAxisEnd))
                xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
                xsDataCollectionStrategy.addSubWedge(xsDataSubWedge)

            xsDataCollectionStrategy.setSample(_xsDataSample)

            xsDataCollectionPlan.setCollectionStrategy(xsDataCollectionStrategy)
            xsDataStrategySummary = xsDataCollectionPlanBest.getStrategySummary()
            xsDataCollectionPlan.setStrategySummary(xsDataStrategySummary)

            xsDataStatistics = xsDataCollectionPlanBest.getStatisticalPrediction()
            xsDataCollectionPlan.setStatistics(xsDataStatistics)

            xsDataStrategyResult.addCollectionPlan(xsDataCollectionPlan)

        return xsDataStrategyResult
 def testMergeListOfSubWedgesWithAdjascentRotationAxis(self):
     edPluginSubWedgeMergev10 = self.createPlugin()
     edPluginSubWedgeMergev10.configure()
     # Check a list of nine adjascent images
     strPathToInputNineAdjascentImages = os.path.join(
         self.getPluginTestsDataHome(),
         "XSDataInputSubWedgeMerge_nineAdjascentImages.xml")
     xsDataInputSubWedgeMergeNine = XSDataInputSubWedgeMerge.parseFile(
         strPathToInputNineAdjascentImages)
     xsDataSubWedgeMerged = edPluginSubWedgeMergev10.mergeListOfSubWedgesWithAdjascentRotationAxis(
         xsDataInputSubWedgeMergeNine.getSubWedge())
     xsDataSubWedgeMergedReference = XSDataSubWedge.parseFile(
         os.path.join(self.getPluginTestsDataHome(),
                      "XSDataSubWedgeMerged_nineImages.xml"))
     EDAssert.equal(xsDataSubWedgeMerged[0].marshal(),
                    xsDataSubWedgeMergedReference.marshal())
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        self.DEBUG("EDPluginControlGeneratePredictionv10.preProcess...")

        xsDataGeneratePredictionInput = self.getDataInput()

        xsDataSelectedIndexingSolution = xsDataGeneratePredictionInput.getSelectedIndexingSolution()
        xsDataExperimentalConditionRefined = xsDataSelectedIndexingSolution.getExperimentalConditionRefined()
        xsDataCollection = xsDataGeneratePredictionInput.getDataCollection()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()

        # List containing instances of all the generate prediction plugins
        self.__listPluginGeneratePrediction = []

        # Loop through all subwedges
        iIndex = 0
        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            # 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
            # Then loop through all images in a sub wedge
            for xsDataImage in xsDataImageList:
                iIndex += 1
                edPluginGeneratePrediction = self.loadPlugin(self.__strPluginGeneratePredictionName,
                                                              "%s-%02d" % (self.__strPluginGeneratePredictionName, iIndex))
                xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
                xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(xsDataSelectedIndexingSolution.marshal()))
                xsDataCollectionNew = XSDataCollection()
                xsDataSubWedgeNew = XSDataSubWedge()
                xsDataSubWedgeNew.addImage(XSDataImage.parseString(xsDataImage.marshal()))
                xsDataSubWedgeNew.setExperimentalCondition(XSDataExperimentalCondition.parseString(xsDataSubWedge.getExperimentalCondition().marshal()))
                # We must modify the rotationOscillationStart for the new subwedge
                xsDataGoniostatNew = xsDataSubWedgeNew.getExperimentalCondition().getGoniostat()
                fGoniostatRotationAxisStart = xsDataGoniostatNew.getRotationAxisStart().getValue()
                fGonioStatOscillationRange = xsDataGoniostatNew.getOscillationWidth().getValue()
                iImageNumber = xsDataImage.getNumber().getValue()
                fGoniostatRotationAxisStartNew = fGoniostatRotationAxisStart + (iImageNumber - iLowestImageNumber) * fGonioStatOscillationRange
                xsDataGoniostatNew.setRotationAxisStart(XSDataAngle(fGoniostatRotationAxisStartNew))
                # 
                xsDataCollectionNew.addSubWedge(xsDataSubWedgeNew)
                xsDataGeneratePredictionInput.setDataCollection(xsDataCollectionNew)
                from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
                xsDataMOSFLMInputGeneratePrediction = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputGeneratePrediction(xsDataGeneratePredictionInput)
                edPluginGeneratePrediction.setDataInput(xsDataMOSFLMInputGeneratePrediction)
                self.__listPluginGeneratePrediction.append(edPluginGeneratePrediction)
 def testMergeTwoSubWedgesAdjascentInRotationAxis(self):
     # First check two sub wedges which shouldn't be merged
     edPluginSubWedgeMergev10 = self.createPlugin()
     edPluginSubWedgeMergev10.configure()
     xsDataInputSubWedgeMerge = XSDataInputSubWedgeMerge.parseFile(self.__strPathToReferenceInput)
     xsDataSubWedge1 = xsDataInputSubWedgeMerge.getSubWedge()[0]
     xsDataSubWedge2 = xsDataInputSubWedgeMerge.getSubWedge()[1]
     xsDataSubWedgeMerged = edPluginSubWedgeMergev10.mergeTwoSubWedgesAdjascentInRotationAxis(xsDataSubWedge1, xsDataSubWedge2)
     EDAssert.equal(xsDataSubWedgeMerged, None)
     # Then check two adjascent images
     strPathToInputTwoAdjascentImages = os.path.join(self.getPluginTestsDataHome(), "XSDataInputSubWedgeMerge_twoAdjascentImages.xml")
     xsDataInputSubWedgeMerge2 = XSDataInputSubWedgeMerge.parseFile(strPathToInputTwoAdjascentImages)
     xsDataSubWedge1 = xsDataInputSubWedgeMerge2.getSubWedge()[0]
     xsDataSubWedge2 = xsDataInputSubWedgeMerge2.getSubWedge()[1]
     xsDataSubWedgeMerged = edPluginSubWedgeMergev10.mergeTwoSubWedgesAdjascentInRotationAxis(xsDataSubWedge1, xsDataSubWedge2)
     xsDataSubWedgeMergedReference = XSDataSubWedge.parseFile(os.path.join(self.getPluginTestsDataHome(), "XSDataSubWedgeMerged_twoImages.xml"))
     EDAssert.equal(xsDataSubWedgeMerged.marshal(), xsDataSubWedgeMergedReference.marshal())
    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)
Esempio n. 13
0
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlGeneratePredictionv10.preProcess...")

        xsDataGeneratePredictionInput = self.getDataInput()

        xsDataSelectedIndexingSolution = xsDataGeneratePredictionInput.getSelectedIndexingSolution(
        )
        xsDataExperimentalConditionRefined = xsDataSelectedIndexingSolution.getExperimentalConditionRefined(
        )
        xsDataCollection = xsDataGeneratePredictionInput.getDataCollection()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()

        # List containing instances of all the generate prediction plugins
        self.__listPluginGeneratePrediction = []

        # Loop through all subwedges
        iIndex = 0
        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            # 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
            # Then loop through all images in a sub wedge
            for xsDataImage in xsDataImageList:
                iIndex += 1
                edPluginGeneratePrediction = self.loadPlugin(
                    self.__strPluginGeneratePredictionName, "%s-%02d" %
                    (self.__strPluginGeneratePredictionName, iIndex))
                xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
                xsDataGeneratePredictionInput.setSelectedIndexingSolution(
                    XSDataIndexingSolutionSelected.parseString(
                        xsDataSelectedIndexingSolution.marshal()))
                xsDataCollectionNew = XSDataCollection()
                xsDataSubWedgeNew = XSDataSubWedge()
                xsDataSubWedgeNew.addImage(
                    XSDataImage.parseString(xsDataImage.marshal()))
                xsDataSubWedgeNew.setExperimentalCondition(
                    XSDataExperimentalCondition.parseString(
                        xsDataSubWedge.getExperimentalCondition().marshal()))
                # We must modify the rotationOscillationStart for the new subwedge
                xsDataGoniostatNew = xsDataSubWedgeNew.getExperimentalCondition(
                ).getGoniostat()
                fGoniostatRotationAxisStart = xsDataGoniostatNew.getRotationAxisStart(
                ).getValue()
                fGonioStatOscillationRange = xsDataGoniostatNew.getOscillationWidth(
                ).getValue()
                iImageNumber = xsDataImage.getNumber().getValue()
                fGoniostatRotationAxisStartNew = fGoniostatRotationAxisStart + (
                    iImageNumber -
                    iLowestImageNumber) * fGonioStatOscillationRange
                xsDataGoniostatNew.setRotationAxisStart(
                    XSDataAngle(fGoniostatRotationAxisStartNew))
                #
                xsDataCollectionNew.addSubWedge(xsDataSubWedgeNew)
                xsDataGeneratePredictionInput.setDataCollection(
                    xsDataCollectionNew)
                from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
                xsDataMOSFLMInputGeneratePrediction = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputGeneratePrediction(
                    xsDataGeneratePredictionInput)
                edPluginGeneratePrediction.setDataInput(
                    xsDataMOSFLMInputGeneratePrediction)
                self.__listPluginGeneratePrediction.append(
                    edPluginGeneratePrediction)
    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)
Esempio n. 15
0
    def getXSDataResultStrategy(self, _xsDataResultBest,
                                _xsDataExperimentalCondition, _xsDataSample):
        xsDataResultStrategy = XSDataResultStrategy()

        listXSDataBestCollectionPlan = _xsDataResultBest.getCollectionPlan()

        for xsDataBestCollectionPlan in listXSDataBestCollectionPlan:

            xsDataCollectionPlan = XSDataCollectionPlan()
            xsDataCollectionStrategy = XSDataCollection()

            xsDataBestStrategySummary = xsDataBestCollectionPlan.getStrategySummary(
            )

            xsDataDoubleTransmission = xsDataBestStrategySummary.getTransmission(
            )

            for xsDataBestCollectionRun in xsDataBestCollectionPlan.getCollectionRun(
            ):
                xsDataSubWedge = XSDataSubWedge()
                strXmlStringDataExperimentalCondition = _xsDataExperimentalCondition.marshal(
                )
                xsDataExperimentalCondition = XSDataExperimentalCondition.parseString(
                    strXmlStringDataExperimentalCondition)
                xsDataExperimentalCondition.getBeam().setExposureTime(
                    xsDataBestCollectionRun.getExposureTime())
                if (xsDataBestCollectionRun.getTransmission() is None):
                    xsDataExperimentalCondition.getBeam().setTransmission(
                        xsDataDoubleTransmission)
                else:
                    xsDataExperimentalCondition.getBeam().setTransmission(
                        xsDataBestCollectionRun.getTransmission())
                xsDataExperimentalCondition.getDetector().setDistance(
                    xsDataBestStrategySummary.getDistance())
                xsDataExperimentalCondition.getGoniostat(
                ).setRotationAxisStart(xsDataBestCollectionRun.getPhiStart())
                xsDataExperimentalCondition.getGoniostat().setOscillationWidth(
                    xsDataBestCollectionRun.getPhiWidth())
                fRotationAxisEnd = xsDataBestCollectionRun.getPhiStart(
                ).getValue(
                ) + xsDataBestCollectionRun.getNumberOfImages().getValue(
                ) * xsDataBestCollectionRun.getPhiWidth().getValue()
                xsDataExperimentalCondition.getGoniostat().setRotationAxisEnd(
                    XSDataAngle(fRotationAxisEnd))
                xsDataSubWedge.setExperimentalCondition(
                    xsDataExperimentalCondition)
                xsDataSubWedge.setSubWedgeNumber(
                    xsDataBestCollectionRun.getCollectionRunNumber())
                if xsDataBestCollectionRun.getCrystalPosition():
                    xsDataSubWedge.setAction(
                        XSDataString("Crystal position: %d" %
                                     xsDataBestCollectionRun.
                                     getCrystalPosition().getValue()))
                else:
                    xsDataSubWedge.setAction(
                        xsDataBestCollectionRun.getAction())
                xsDataCollectionStrategy.addSubWedge(xsDataSubWedge)

            xsDataCollectionStrategy.setSample(_xsDataSample)

            xsDataCollectionPlan.setCollectionStrategy(
                xsDataCollectionStrategy)

            xsDataStrategySummary = XSDataStrategySummary()
            xsDataStrategySummary.setCompleteness(
                xsDataBestStrategySummary.getCompleteness())
            xsDataStrategySummary.setISigma(
                xsDataBestStrategySummary.getISigma())
            xsDataStrategySummary.setRankingResolution(
                xsDataBestStrategySummary.getRankingResolution())
            xsDataStrategySummary.setRedundancy(
                xsDataBestStrategySummary.getRedundancy())
            xsDataStrategySummary.setResolution(
                xsDataBestStrategySummary.getResolution())
            xsDataStrategySummary.setResolutionReasoning(
                xsDataBestStrategySummary.getResolutionReasoning())
            xsDataStrategySummary.setTotalDataCollectionTime(
                xsDataBestStrategySummary.getTotalDataCollectionTime())
            xsDataStrategySummary.setTotalExposureTime(
                xsDataBestStrategySummary.getTotalExposureTime())
            xsDataCollectionPlan.setStrategySummary(xsDataStrategySummary)

            if xsDataBestCollectionPlan.getStatisticalPrediction() is not None:
                xsDataStatisticsStrategy = XSDataStatisticsStrategy.parseString(
                    xsDataBestCollectionPlan.getStatisticalPrediction(
                    ).marshal())
                xsDataCollectionPlan.setStatistics(xsDataStatisticsStrategy)

            xsDataCollectionPlan.setCollectionPlanNumber(
                xsDataBestCollectionPlan.getCollectionPlanNumber())

            xsDataResultStrategy.addCollectionPlan(xsDataCollectionPlan)

        if _xsDataResultBest.getPathToLogFile() != None:
            xsDataResultStrategy.setBestLogFile(
                _xsDataResultBest.getPathToLogFile())

        return xsDataResultStrategy
Esempio n. 16
0
    def getXSDataResultStrategy(self, _xsDataResultBest, _xsDataExperimentalCondition, _xsDataSample):
        xsDataResultStrategy = XSDataResultStrategy()

        listXSDataBestCollectionPlan = _xsDataResultBest.getCollectionPlan()

        for xsDataBestCollectionPlan in listXSDataBestCollectionPlan:

            xsDataCollectionPlan = XSDataCollectionPlan()
            xsDataCollectionStrategy = XSDataCollection()

            xsDataBestStrategySummary = xsDataBestCollectionPlan.getStrategySummary()

            xsDataDoubleTransmission = xsDataBestStrategySummary.getTransmission()

            for xsDataBestCollectionRun in xsDataBestCollectionPlan.getCollectionRun():
                xsDataSubWedge = XSDataSubWedge()
                strXmlStringDataExperimentalCondition = _xsDataExperimentalCondition.marshal()
                xsDataExperimentalCondition = XSDataExperimentalCondition.parseString(
                    strXmlStringDataExperimentalCondition
                )
                xsDataExperimentalCondition.getBeam().setExposureTime(xsDataBestCollectionRun.getExposureTime())
                if xsDataBestCollectionRun.getTransmission() is None:
                    xsDataExperimentalCondition.getBeam().setTransmission(xsDataDoubleTransmission)
                else:
                    xsDataExperimentalCondition.getBeam().setTransmission(xsDataBestCollectionRun.getTransmission())
                xsDataExperimentalCondition.getDetector().setDistance(xsDataBestStrategySummary.getDistance())
                xsDataExperimentalCondition.getGoniostat().setRotationAxisStart(xsDataBestCollectionRun.getPhiStart())
                xsDataExperimentalCondition.getGoniostat().setOscillationWidth(xsDataBestCollectionRun.getPhiWidth())
                fRotationAxisEnd = (
                    xsDataBestCollectionRun.getPhiStart().getValue()
                    + xsDataBestCollectionRun.getNumberOfImages().getValue()
                    * xsDataBestCollectionRun.getPhiWidth().getValue()
                )
                xsDataExperimentalCondition.getGoniostat().setRotationAxisEnd(XSDataAngle(fRotationAxisEnd))
                xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
                xsDataSubWedge.setSubWedgeNumber(xsDataBestCollectionRun.getCollectionRunNumber())
                if xsDataBestCollectionRun.getCrystalPosition():
                    xsDataSubWedge.setAction(
                        XSDataString("Crystal position: %d" % xsDataBestCollectionRun.getCrystalPosition().getValue())
                    )
                else:
                    xsDataSubWedge.setAction(xsDataBestCollectionRun.getAction())
                xsDataCollectionStrategy.addSubWedge(xsDataSubWedge)

            xsDataCollectionStrategy.setSample(_xsDataSample)

            xsDataCollectionPlan.setCollectionStrategy(xsDataCollectionStrategy)

            xsDataStrategySummary = XSDataStrategySummary()
            xsDataStrategySummary.setCompleteness(xsDataBestStrategySummary.getCompleteness())
            xsDataStrategySummary.setISigma(xsDataBestStrategySummary.getISigma())
            xsDataStrategySummary.setRankingResolution(xsDataBestStrategySummary.getRankingResolution())
            xsDataStrategySummary.setRedundancy(xsDataBestStrategySummary.getRedundancy())
            xsDataStrategySummary.setResolution(xsDataBestStrategySummary.getResolution())
            xsDataStrategySummary.setResolutionReasoning(xsDataBestStrategySummary.getResolutionReasoning())
            xsDataStrategySummary.setTotalDataCollectionTime(xsDataBestStrategySummary.getTotalDataCollectionTime())
            xsDataStrategySummary.setTotalExposureTime(xsDataBestStrategySummary.getTotalExposureTime())
            xsDataCollectionPlan.setStrategySummary(xsDataStrategySummary)

            if xsDataBestCollectionPlan.getStatisticalPrediction() is not None:
                xsDataStatisticsStrategy = XSDataStatisticsStrategy.parseString(
                    xsDataBestCollectionPlan.getStatisticalPrediction().marshal()
                )
                xsDataCollectionPlan.setStatistics(xsDataStatisticsStrategy)

            xsDataCollectionPlan.setCollectionPlanNumber(xsDataBestCollectionPlan.getCollectionPlanNumber())

            xsDataResultStrategy.addCollectionPlan(xsDataCollectionPlan)

        if _xsDataResultBest.getPathToLogFile() != None:
            xsDataResultStrategy.setBestLogFile(_xsDataResultBest.getPathToLogFile())

        return xsDataResultStrategy
    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)
        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)
Esempio n. 19
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)