當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleSignal.emit方法代碼示例

本文整理匯總了Python中ilastik.utility.simpleSignal.SimpleSignal.emit方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleSignal.emit方法的具體用法?Python SimpleSignal.emit怎麽用?Python SimpleSignal.emit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ilastik.utility.simpleSignal.SimpleSignal的用法示例。


在下文中一共展示了SimpleSignal.emit方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SerialPredictionSlot

# 需要導入模塊: from ilastik.utility.simpleSignal import SimpleSignal [as 別名]
# 或者: from ilastik.utility.simpleSignal.SimpleSignal import emit [as 別名]
class SerialPredictionSlot(SerialSlot):

    def __init__(self, slot, operator, inslot=None, name=None,
                 subname=None, default=None, depends=None,
                 selfdepends=True):
        super(SerialPredictionSlot, self).__init__(
            slot, inslot, name, subname, default, depends, selfdepends
        )
        self.operator = operator
        self.progressSignal = SimpleSignal() # Signature: emit(percentComplete)

        self._predictionStorageEnabled = False
        self._predictionStorageRequest = None
        self._predictionsPresent = False

    def setDirty(self, *args, **kwargs):
        self.dirty = True
        self._predictionsPresent = False

    @property
    def predictionStorageEnabled(self):
        return self._predictionStorageEnabled

    @predictionStorageEnabled.setter
    def predictionStorageEnabled(self, value):
        self._predictionStorageEnabled = value
        if not self._predictionsPresent:
            self.dirty = True

    def cancel(self):
        if self._predictionStorageRequest is not None:
            self.predictionStorageEnabled = False
            self._predictionStorageRequest.cancel()

    def shouldSerialize(self, group):
        result = super(SerialPredictionSlot,self).shouldSerialize(group)
        result &= self.predictionStorageEnabled
        return result

    def _disconnect(self):
        for i,slot in enumerate(self.operator.PredictionsFromDisk):
            slot.disconnect()

    def serialize(self, group):
        if not self.shouldSerialize(group):
            return

        self._disconnect()
        super(SerialPredictionSlot, self).serialize(group)
        self.deserialize(group)

    def _serialize(self, group, name, slot):
        """Called when the currently stored predictions are dirty. If
        prediction storage is currently enabled, store them to the
        file. Otherwise, just delete them/

        (Avoid inconsistent project states, e.g. don't allow old
        predictions to be stored with a new classifier.)

        """
        predictionDir = group.create_group(self.name)

        # Disconnect the operators that might be using the old data.
        self.deserialize(group)
        
        failedToSave = False
        opWriter = None
        try:
            num = len(slot)
            if num > 0:
                increment = 100 / float(num)

            progress = 0
            for imageIndex in range(num):
                # Have we been cancelled?
                if not self.predictionStorageEnabled:
                    break

                datasetName = self.subname.format(imageIndex)

                # Use a big dataset writer to do this in chunks
                opWriter = OpH5WriterBigDataset(graph=self.operator.graph, parent = self.operator.parent)
                opWriter.hdf5File.setValue(predictionDir)
                opWriter.hdf5Path.setValue(datasetName)
                opWriter.Image.connect(slot[imageIndex])

                def handleProgress(percent):
                    # Stop sending progress if we were cancelled
                    if self.predictionStorageEnabled:
                        curprogress = progress + percent * (increment / 100.0)
                        self.progressSignal.emit(curprogress)
                opWriter.progressSignal.subscribe(handleProgress)

                # Create the request
                self._predictionStorageRequest = opWriter.WriteImage[...]

                # Must use a threading event here because if we wait on the 
                # request from within a "real" thread, it refuses to be cancelled.
                finishedEvent = threading.Event()
                def handleFinish(result):
#.........這裏部分代碼省略.........
開發者ID:JensNRAD,項目名稱:ilastik_public,代碼行數:103,代碼來源:countingSerializer.py

示例2: AppletSerializer

# 需要導入模塊: from ilastik.utility.simpleSignal import SimpleSignal [as 別名]
# 或者: from ilastik.utility.simpleSignal.SimpleSignal import emit [as 別名]
class AppletSerializer(object):
    """
    Base class for all AppletSerializers.
    """
    # Force subclasses to override abstract methods and properties
    __metaclass__ = ABCMeta
    base_initialized = False

    # override if necessary
    version = "0.1"

    #########################
    # Semi-abstract methods #
    #########################

    def _serializeToHdf5(self, topGroup, hdf5File, projectFilePath):

        """Child classes should override this function, if
        necessary.

        """
        pass

    def _deserializeFromHdf5(self, topGroup, groupVersion, hdf5File,
                             projectFilePath, headless = False):
        """Child classes should override this function, if
        necessary.

        """
        pass

    #############################
    # Base class implementation #
    #############################

    def __init__(self, topGroupName, slots=None, operator=None):
        """Constructor. Subclasses must call this method in their own
        __init__ functions. If they fail to do so, the shell raises an
        exception.

        Parameters:
        :param topGroupName: name of this applet's data group in the file.
            Defaults to the name of the operator.
        :param slots: a list of SerialSlots

        """
        self.progressSignal = SimpleSignal() # Signature: emit(percentComplete)
        self.base_initialized = True
        self.topGroupName = topGroupName
        self.serialSlots = maybe(slots, [])
        self.operator = operator
        self.caresOfHeadless = False # should _deserializeFromHdf5 should be called with headless-argument?
        self._ignoreDirty = False

    def isDirty(self):
        """Returns true if the current state of this item (in memory)
        does not match the state of the HDF5 group on disk.

        Subclasses only need override this method if ORing the flags
        is not enough.

        """
        return any(list(ss.dirty for ss in self.serialSlots))

    @property
    def ignoreDirty(self):
        return self._ignoreDirty

    @ignoreDirty.setter
    def ignoreDirty(self, value):
        self._ignoreDirty = value
        for ss in self.serialSlots:
            ss.ignoreDirty = value

    def unload(self):
        """Called if either

        (1) the user closed the project or

        (2) the project opening process needs to be aborted for some
            reason (e.g. not all items could be deserialized
            properly due to a corrupted ilp)

        This way we can avoid invalid state due to a partially loaded
        project.

        """
        for ss in self.serialSlots:
            ss.unload()

    def progressIncrement(self, group=None):
        """Get the percentage progress for each slot.

        :param group: If None, all all slots are assumed to be
            processed. Otherwise, decides for each slot by calling
            slot.shouldSerialize(group).

        """
        if group is None:
            nslots = len(self.serialSlots)
#.........這裏部分代碼省略.........
開發者ID:christophdecker,項目名稱:ilastik,代碼行數:103,代碼來源:appletSerializer.py

示例3: AppletSerializer

# 需要導入模塊: from ilastik.utility.simpleSignal import SimpleSignal [as 別名]
# 或者: from ilastik.utility.simpleSignal.SimpleSignal import emit [as 別名]

#.........這裏部分代碼省略.........
        Convenience helper.
        Returns parentGorup[groupName], creating first it if necessary.
        """
        try:
            return parentGroup[groupName]
        except KeyError:
            return parentGroup.create_group(groupName)

    @classmethod
    def deleteIfPresent(cls, parentGroup, name):
        """
        Convenience helper.
        Deletes parentGorup[groupName], if it exists.
        """
        try:
            del parentGroup[name]
        except KeyError:
            pass

    @property
    def version(self):
        """
        Return the version of the serializer itself.
        """
        return self._version
    
    @property
    def topGroupName(self):
        return self._topGroupName

    #############################
    # Base class implementation #
    #############################

    def __init__(self, topGroupName, version):
        self._version = version
        self._topGroupName = topGroupName
        
        self.progressSignal = SimpleSignal() # Signature: emit(percentComplete)

        self._base_initialized = True

    def serializeToHdf5(self, hdf5File, projectFilePath):
        # Check the overall file version
        ilastikVersion = hdf5File["ilastikVersion"].value

        # Make sure we can find our way around the project tree
        if not VersionManager.isProjectFileVersionCompatible(ilastikVersion):
            return

        self.progressSignal.emit(0)
        
        topGroup = self.getOrCreateGroup(hdf5File, self.topGroupName)
        
        # Set the version
        if 'StorageVersion' not in topGroup.keys():
            topGroup.create_dataset('StorageVersion', data=self._version)
        else:
            topGroup['StorageVersion'][()] = self._version

        try:
            # Call the subclass to do the actual work
            self._serializeToHdf5(topGroup, hdf5File, projectFilePath)
        finally:
            self.progressSignal.emit(100)

    def deserializeFromHdf5(self, hdf5File, projectFilePath):
        # Check the overall file version
        ilastikVersion = hdf5File["ilastikVersion"].value

        # Make sure we can find our way around the project tree
        if not VersionManager.isProjectFileVersionCompatible(ilastikVersion):
            return

        self.progressSignal.emit(0)

        # If the top group isn't there, call initWithoutTopGroup
        try:
            topGroup = hdf5File[self.topGroupName]
            groupVersion = topGroup['StorageVersion'][()]
        except KeyError:
            topGroup = None
            groupVersion = None

        try:
            if topGroup is not None:
                # Call the subclass to do the actual work
                self._deserializeFromHdf5(topGroup, groupVersion, hdf5File, projectFilePath)
            else:
                self.initWithoutTopGroup(hdf5File, projectFilePath)
        finally:
            self.progressSignal.emit(100)

    @property
    def base_initialized(self):
        """
        Do not override this property.
        Used by the shell to ensure that Applet.__init__ was called by your subclass.
        """
        return self._base_initialized
開發者ID:LimpingTwerp,項目名稱:applet-workflows,代碼行數:104,代碼來源:appletSerializer.py


注:本文中的ilastik.utility.simpleSignal.SimpleSignal.emit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。