def postProcess(self, _edObject=None): EDPluginExecProcessScript.postProcess(self) self.DEBUG("EDPluginExecDatPorodv1_0.postProcess") # Create some output data logfile = os.path.join(self.getWorkingDirectory(), self.getScriptLogFileName()) out = open(logfile, "r").read().split() if self.atsasVersion < "2.6": try: res = float(out[0]) except (ValueError, IndexError): self.error("Unable to read porod log file: " + logfile) self.setFailure() else: xsDataResult = XSDataResultDatPorod( volume=XSDataDoubleWithUnit(value=res)) self.setDataOutput(xsDataResult) else: try: res = float(out[2]) except (ValueError, IndexError): self.error("Unable to read porod log file: " + logfile) self.setFailure() else: xsDataResult = XSDataResultDatPorod( volume=XSDataDoubleWithUnit(value=res)) self.setDataOutput(xsDataResult)
def fileName2xml(filename): """Here we create the XML string to be passed to the EDNA plugin from the input filename This can / should be modified by the final user @param filename: full path of the input file @type filename: python string representing the path @rtype: XML string @return: python string """ if filename.endswith(".jpg"): xm = None else: upperDir = os.path.dirname(os.path.dirname(filename)) if not os.path.isdir(os.path.join(upperDir, "Thumbnail")): os.makedirs(os.path.join(upperDir, "Thumbnail"), int("775", 8)) destinationPath = os.path.join(upperDir, "Thumbnail") xsd = XSDataInputExecThumbnail() xsdFile = XSDataFile() xsdFile.setPath(XSDataString(filename)) xsd.setInputImagePath(xsdFile) xsdPath = XSDataFile() xsdPath.setPath(XSDataString(destinationPath)) xsd.setOutputPath(xsdPath) # xsd.setLevelsColorize(XSDataBoolean(True)) # xsd.setLevelsNormalize(XSDataBoolean(True)) xsd.setLevelsEqualize(XSDataBoolean(True)) # xsd.setLevelsGamma(XSDataDouble(gamma)) xsd.setLevelsMin(XSDataDouble(0.0)) xsdMax = XSDataDoubleWithUnit() xsdMax.setValue(99.9) xsdMax.setUnit(XSDataString("""%""")) xsd.setLevelsMax(xsdMax) # xsd.setLevelsAutoContrast(XSDataDouble(1.0)) xsd.setFilterBlur([XSDataInteger(5)]) xsd.setFilterDilatation([XSDataInteger(10)]) # xsd.setCropBorders(XSDataInteger(), XSDataInteger()) xsd.setLevelsInvert(XSDataBoolean(True)) xsd.setThumbHeight(XSDataInteger(256)) xsd.setThumbWidth(XSDataInteger(256)) xml = xsd.marshal() return xml
def fileName2xml(filename): """Here we create the XML string to be passed to the EDNA plugin from the input filename This can / should be modified by the final user @param filename: full path of the input file @type filename: python string representing the path @rtype: XML string @return: python string """ if filename.endswith(".jpg"): xm = None else: upperDir = os.path.dirname(os.path.dirname(filename)) if not os.path.isdir(os.path.join(upperDir, "Thumbnail")): os.makedirs(os.path.join(upperDir, "Thumbnail"), int("775", 8)) destinationPath = os.path.join(upperDir, "Thumbnail") xsd = XSDataInputExecThumbnail() xsdFile = XSDataFile() xsdFile.setPath(XSDataString(filename)) xsd.setInputImagePath(xsdFile) xsdPath = XSDataFile() xsdPath.setPath(XSDataString(destinationPath)) xsd.setOutputPath(xsdPath) # xsd.setLevelsColorize(XSDataBoolean(True)) # xsd.setLevelsNormalize(XSDataBoolean(True)) xsd.setLevelsEqualize(XSDataBoolean(True)) # xsd.setLevelsGamma(XSDataDouble(gamma)) xsd.setLevelsMin(XSDataDouble(0.0)) xsdMax = XSDataDoubleWithUnit() xsdMax.setValue(99.9) xsdMax.setUnit(XSDataString("""%""")) xsd.setLevelsMax(xsdMax) # xsd.setLevelsAutoContrast(XSDataDouble(1.0)) xsd.setFilterBlur([XSDataInteger(5)]) xsd.setFilterDilatation([XSDataInteger(10)]) #xsd.setCropBorders(XSDataInteger(), XSDataInteger()) xsd.setLevelsInvert(XSDataBoolean(True)) xsd.setThumbHeight(XSDataInteger(256)) xsd.setThumbWidth(XSDataInteger(256)) xml = xsd.marshal() return xml
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) EDVerbose.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess") # Check that the input image exists and is of the expected type strPathToDiffractionImage = self.getDataInput().getDiffractionImage().getPath().getValue() strImageFileNameExtension = os.path.splitext(strPathToDiffractionImage)[1] if not strImageFileNameExtension in [".img", ".marccd", ".mccd", ".cbf"]: print strImageFileNameExtension EDVerbose.error("Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage) self.setFailure() else: # Load the waitFile plugin xsDataInputWaitFile = XSDataInputWaitFile() xsDataInputWaitFile.setExpectedSize(XSDataInteger(self.__iExpectedSize)) xsDataInputWaitFile.setExpectedFile(self.getDataInput().getDiffractionImage()) if self.getDataInput().getWaitForFileTimeOut(): xsDataInputWaitFile.setTimeOut(self.getDataInput().getWaitForFileTimeOut()) self.__edPluginWaitFile = EDPluginWaitFile() self.__edPluginWaitFile.setDataInput(xsDataInputWaitFile) # Load the execution plugin self.__edPluginExecThumbnail = self.loadPlugin(self.__strExecThumbnailPluginName) xsDataInputExecThumbnail = XSDataInputExecThumbnail() xsDataInputExecThumbnail.setInputImagePath(self.getDataInput().getDiffractionImage()) xsDataInputExecThumbnail.setLevelsInvert(XSDataBoolean(True)) xsDataInputExecThumbnail.setLevelsMin(XSDataDoubleWithUnit(0.0)) xsDataDoubleWithUnitLevelsMax = XSDataDoubleWithUnit(99.95) xsDataDoubleWithUnitLevelsMax.setUnit(XSDataString("%")) xsDataInputExecThumbnail.setLevelsMax(xsDataDoubleWithUnitLevelsMax) xsDataInputExecThumbnail.setFilterDilatation([XSDataInteger(4)]) xsDataInputExecThumbnail.setLevelsColorize(XSDataBoolean(False)) xsDataInputExecThumbnail.setThumbHeight(XSDataInteger(1024)) xsDataInputExecThumbnail.setThumbWidth(XSDataInteger(1024)) xsDataInputExecThumbnail.setKeepRatio(XSDataBoolean(False)) # 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): EDVerbose.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 BaseException, e: EDVerbose.WARNING("Couldn't create the directory %s" % strOutputDirname) elif os.access(strOutputDirname, os.W_OK): bIsOk = True if not bIsOk: EDVerbose.warning("Cannot write to pyarch directory: %s" % strOutputDirname) strOutputDirname = tempfile.mkdtemp("", "EDPluginPyarchThumbnailv10_", "/tmp") EDVerbose.warning("Writing thumbnail images to: %s" % strOutputDirname) self.strOutputPathWithoutExtension = os.path.join(strOutputDirname, strImageNameWithoutExt) self.strOutputPath = os.path.join(self.strOutputPathWithoutExtension + ".jpeg") xsDataInputExecThumbnail.setOutputPath(XSDataFile(XSDataString(self.strOutputPath))) self.__edPluginExecThumbnail.setDataInput(xsDataInputExecThumbnail)