本文整理匯總了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):
#.........這裏部分代碼省略.........
示例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)
#.........這裏部分代碼省略.........
示例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