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 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
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
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 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)
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