def process(self, _edObject=None): EDPluginExec.process(self) EDVerbose.DEBUG("*** EDPluginEDFReadHeaderv1_0.process") # Read the header contents and put it into an dictionary edStringPathToInputFile = self.getDataInput().getEdfFile().getPath( ).getValue() pyFileDescriptor = open(edStringPathToInputFile, "r") edfFile = EdfFile(pyFileDescriptor) pyFileDescriptor.close() iNumberOfImages = edfFile.GetNumImages() if (iNumberOfImages == 0): edStringErrorMessage = EDMessage.ERROR_UNEXPECTED_01 % ( self.getPluginName() + ".preProcess: No images in file " + edStringPathToInputFile) EDVerbose.error(edStringErrorMessage) self.addErrorMessage(edStringErrorMessage) raise RuntimeError, edStringErrorMessage #if ( iNumberOfImages > 1 ): # pass #EDVerbose.warning( "Warning! More than one image in file " + edStringPathToInputFile ", reading header from first image" ) self.m_edDictionaryHeader = edfFile.GetHeader(0)
def process(self, _edObject=None): EDPluginControl.process(self) EDVerbose.DEBUG("EDPluginBioSaxsMetadatav1_0.process") if not os.path.isfile(self.strInputImage): EDVerbose.WARNING("The given input file does not exist !!!") header = {} else: header = EdfFile(self.strInputImage).GetHeader(0) for key in EDUtilsBioSaxs.TRANSLATION: if key in dir(self) and self.__getattribute__(key) is None: if EDUtilsBioSaxs.TRANSLATION[key] in header: if key in EDUtilsBioSaxs.FLOAT_KEYS: setattr( self, key, float(header[EDUtilsBioSaxs.TRANSLATION[key]])) else: setattr(self, key, header[EDUtilsBioSaxs.TRANSLATION[key]]) if self.strOutputImage is not None: if os.path.abspath(self.strOutputImage) != os.path.abspath( self.strInputImage): shutil.copy(self.strInputImage, self.strOutputImage) keyToUpgrade = [] for key in EDUtilsBioSaxs.TRANSLATION: if key in dir(self) and self.__getattribute__(key) is None: if EDUtilsBioSaxs.TRANSLATION[key] not in header: keyToUpgrade.append(key) else: if key in EDUtilsBioSaxs.FLOAT_KEYS: oneHeader = float( header[EDUtilsBioSaxs.TRANSLATION[key]]) else: oneHeader = header[EDUtilsBioSaxs.TRANSLATION[key]] oneValue = eval("self.%s" % key) EDVerbose.DEBUG( "key: %s value_header=%s(%s) value_extra=%s(%s)" % (key, oneHeader, oneHeader.__class__, eval("self.%s" % key), eval( "self.%s" % key).__class__)) if oneHeader != oneValue: keyToUpgrade.append(key) for key in keyToUpgrade: if not self.__bSaxsMetadataFailed: xsdi = XSDataInputSaxsAddMetadatav1_0() xsdi.setInputImage(self.xsdInputData.getOutputImage()) xsdi.setKey(XSDataString(EDUtilsBioSaxs.TRANSLATION[key])) xsdi.setValue(XSDataString("%s" % eval("self.%s" % key))) edPlugin = self.loadPlugin( self.__strControlledPluginMetadata) edPlugin.setDataInput(xsdi) edPlugin.connectSUCCESS(self.doSuccessMetadata) edPlugin.connectFAILURE(self.doFailureMetadata) edPlugin.executeSynchronous() if self.__bSaxsMetadataFailed: EDVerbose.screen( "EDPluginBioSaxsMetadatav1_0.process: writeMetadata using EdfFile " ) edf = EdfFile(self.strOutputImage) headers = [ edf.GetHeader(i) for i in xrange(edf.GetNumImages()) ] data = [edf.GetData(i) for i in xrange(edf.GetNumImages())] del edf for key in EDUtilsBioSaxs.TRANSLATION: if key in dir(self) and self.__getattribute__(key) is None: header[EDUtilsBioSaxs.TRANSLATION[key]] = eval( "self.%s" % key) edf = EdfFile(self.strOutputImage) if len(data) == 1: edf.WriteImage(header, data[0], Append=0) elif len(data) > 1: edf.WriteImage(header, data[0], Append=0) for datum in data[1:]: edf.WriteImage({}, datum, Append=1) else: EDVerbose.WARNING("There are not data in %s !!!" % self.strInputImage)