def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess") # Check that the input image exists and is of the expected type strPathToDiffractionImage = self.dataInput.diffractionImage.path.value strImageFileNameExtension = os.path.splitext( strPathToDiffractionImage)[1] if not strImageFileNameExtension in [ ".img", ".marccd", ".mccd", ".cbf", ".h5" ]: self.error( "Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage) self.setFailure() else: # Load the MXWaitFile plugin xsDataInputMXWaitFile = XSDataInputMXWaitFile() pathToImageFile = strPathToDiffractionImage # Quite ugly hack to avoid lag problems at the ESRF: if EDUtilsPath.isESRF() or EDUtilsPath.isALBA(): if any(beamline in strPathToDiffractionImage for beamline in ["id23eh1", "id29", "id30b"]): # Pilatus 6M self.minImageSize = 6000000 elif any(beamline in strPathToDiffractionImage for beamline in ["id23eh2", "id30a1"]): # Pilatus3 2M self.minImageSize = 2000000 elif strImageFileNameExtension == ".h5": self.h5MasterFilePath, self.h5DataFilePath, self.h5FileNumber = self.getH5FilePath( pathToImageFile) pathToImageFile = self.h5DataFilePath self.isH5 = True elif EDUtilsPath.isEMBL(): self.minImageSize = 10000 xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize)) xsDataInputMXWaitFile.setFile( XSDataFile(XSDataString(pathToImageFile))) if self.getDataInput().getWaitForFileTimeOut(): xsDataInputMXWaitFile.setTimeOut( self.getDataInput().getWaitForFileTimeOut()) self.edPluginMXWaitFile = self.loadPlugin( self.strMXWaitFilePluginName) self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile) # Load the execution plugin self.edPluginExecThumbnail = self.loadPlugin( self.strExecThumbnailPluginName) xsDataInputMXThumbnail = XSDataInputMXThumbnail() xsDataInputMXThumbnail.image = self.getDataInput( ).getDiffractionImage() xsDataInputMXThumbnail.height = XSDataInteger(1024) xsDataInputMXThumbnail.width = XSDataInteger(1024) xsDataInputMXThumbnail.format = self.dataInput.format # Output path strImageNameWithoutExt = os.path.basename( os.path.splitext(strPathToDiffractionImage)[0]) strImageDirname = os.path.dirname(strPathToDiffractionImage) if self.getDataInput().getForcedOutputDirectory(): strForcedOutputDirectory = self.getDataInput( ).getForcedOutputDirectory().getPath().getValue() if not os.access(strForcedOutputDirectory, os.W_OK): self.error("Cannot write to forced output directory : %s" % strForcedOutputDirectory) self.setFailure() else: self.strOutputPathWithoutExtension = os.path.join( strForcedOutputDirectory, strImageNameWithoutExt) else: # Try to store in the ESRF pyarch directory strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath( strImageDirname) # Check that output pyarch path exists and is writeable: bIsOk = False if strOutputDirname: if not os.path.exists(strOutputDirname): # Try to create the directory try: os.makedirs(strOutputDirname) bIsOk = True except Exception as e: self.WARNING("Couldn't create the directory %s" % strOutputDirname) elif os.access(strOutputDirname, os.W_OK): bIsOk = True if not bIsOk: self.warning("Cannot write to pyarch directory: %s" % strOutputDirname) strTmpUser = os.path.join("/tmp", os.environ["USER"]) if not os.path.exists(strTmpUser): os.mkdir(strTmpUser, 0o755) strOutputDirname = tempfile.mkdtemp( prefix="EDPluginPyarchThumbnailv10_", dir=strTmpUser) os.chmod(strOutputDirname, 0o755) self.warning("Writing thumbnail images to: %s" % strOutputDirname) self.strOutputPathWithoutExtension = os.path.join( strOutputDirname, strImageNameWithoutExt) if self.dataInput.format is not None: self.strSuffix = self.dataInput.format.value.lower() self.strImageFormat = self.dataInput.format.value.upper() self.strOutputPath = os.path.join( self.strOutputPathWithoutExtension + "." + self.strSuffix) xsDataInputMXThumbnail.setOutputPath( XSDataFile(XSDataString(self.strOutputPath))) self.edPluginExecThumbnail.setDataInput(xsDataInputMXThumbnail)
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlCharacterisationv1_4.preProcess") self._xsDataResultCharacterisation = XSDataResultCharacterisation() # Load the plugins self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \ "Indexing") self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \ "IndexingEvalualtionLABELIT") self._edPluginControlIndexingMOSFLM = self.loadPlugin(self._strPluginControlIndexingMOSFLM, \ "IndexingMOSFLM") self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \ "IndexingEvalualtionMOSFLM") self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \ "GeneratePrediction") self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \ "Integration") self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \ "ControlXDSGenerateBackgroundImage") self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \ "Strategy") if self._runKappa: self._edPluginControlKappa = self.loadPlugin( self._strPluginControlKappaName, "Kappa") if (self._edPluginControlIndexingIndicators is not None): self.DEBUG("EDPluginControlCharacterisationv1_4.preProcess: " + self._strPluginControlIndexingIndicators + " Found... setting Data Input") # create Data Input for indexing xsDataInputCharacterisation = self.getDataInput() self._xsDataCollection = xsDataInputCharacterisation.getDataCollection( ) # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0] xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition( ).getBeam() if xsDataBeam.getTransmission() is not None: fTransmission = xsDataBeam.getTransmission().getValue() if fTransmission < self._fMinTransmission: strWarningMessageBanner = "^" * 80 strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %" self.warning(strWarningMessageBanner) self.warning(strWarningMessage1) self.warning(strWarningMessage2) self.warning(strWarningMessageBanner) self.addWarningMessage(strWarningMessageBanner) self.addWarningMessage(strWarningMessage1) self.addWarningMessage(strWarningMessage2) self.addWarningMessage(strWarningMessageBanner) self.sendMessageToMXCuBE(strWarningMessage1, "warning") self.sendMessageToMXCuBE(strWarningMessage2, "warning") xsDataCrystal = None xsDataSubWedgeList = self._xsDataCollection.getSubWedge() if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])): strError = "EDPluginControlCharacterisationv1_4.preProcess: No subwedges in input data." self.ERROR(strError) self.setFailure() else: # Load the thumbnail plugins self._iNoReferenceImages = 0 for subWedge in xsDataInputCharacterisation.dataCollection.subWedge: for image in subWedge.image: self._iNoReferenceImages += 1 edPluginJpeg = self.loadPlugin( self._strPluginGenerateThumbnailName) xsDataInputMXThumbnail = XSDataInputMXThumbnail() xsDataInputMXThumbnail.image = XSDataFile(image.path) xsDataInputMXThumbnail.height = XSDataInteger(1024) xsDataInputMXThumbnail.width = XSDataInteger(1024) jpegFilename = os.path.splitext( os.path.basename(image.path.value))[0] + ".jpg" xsDataInputMXThumbnail.outputPath = XSDataFile( XSDataString( os.path.join(self.getWorkingDirectory(), jpegFilename))) edPluginJpeg.dataInput = xsDataInputMXThumbnail edPluginThumnail = self.loadPlugin( self._strPluginGenerateThumbnailName) xsDataInputMXThumbnail = XSDataInputMXThumbnail() xsDataInputMXThumbnail.image = XSDataFile(image.path) xsDataInputMXThumbnail.height = XSDataInteger(256) xsDataInputMXThumbnail.width = XSDataInteger(256) thumbnailFilename = os.path.splitext( os.path.basename( image.path.value))[0] + ".thumbnail.jpg" xsDataInputMXThumbnail.outputPath = XSDataFile( XSDataString( os.path.join(self.getWorkingDirectory(), thumbnailFilename))) edPluginThumnail.dataInput = xsDataInputMXThumbnail self._listPluginGenerateThumbnail.append( (image, edPluginJpeg, edPluginThumnail)) edPluginJpeg.execute() edPluginThumnail.execute() xsDataExperimentalCondition = xsDataSubWedgeList[ 0].getExperimentalCondition() # Fix for bug 431: if the flux is zero raise an error xsDataDoubleFlux = xsDataExperimentalCondition.getBeam( ).getFlux() if (xsDataDoubleFlux is not None): if (xsDataDoubleFlux.getValue() < 0.1): strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted." self.ERROR(strErrorMessage) self.sendMessageToMXCuBE(strErrorMessage, "error") self.addErrorMessage( "EDPluginControlCharacterisationv1_4.preProcess ERROR: " + strErrorMessage) # self.addComment(strErrorMessage) self.setFailure() xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan( ) xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup( ) if (xsDataStringForcedSpaceGroup is not None): self._xsDataCrystal = XSDataCrystal() xsDataSpaceGroup = XSDataSpaceGroup() xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup) self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup) self._edPluginControlIndexingIndicators.setDataInput( self._xsDataCollection, "dataCollection") if self._xsDataCrystal is not None: self._edPluginControlIndexingIndicators.setDataInput( self._xsDataCrystal, "crystal") # Populate characterisation object self._xsDataResultCharacterisation.setDataCollection( XSDataCollection.parseString( self._xsDataCollection.marshal()))