本文整理汇总了Python中ilastik.shell.projectManager.ProjectManager类的典型用法代码示例。如果您正苦于以下问题:Python ProjectManager类的具体用法?Python ProjectManager怎么用?Python ProjectManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: openProjectFile
def openProjectFile(self, projectFilePath):
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, _ = ProjectManager.openProjectFile(projectFilePath)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly = False)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# For now, we assume that any imported projects are pixel classification workflow projects.
import ilastik.workflows
default_workflow = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( default_workflow,
importFromPath=oldProjectFilePath,
headless=True )
self.projectManager._importProject(oldProjectFilePath, hdf5File, projectFilePath,readOnly = False)
示例2: createAndLoadNewProject
def createAndLoadNewProject(self, newProjectFilePath, workflow_class):
hdf5File = ProjectManager.createBlankProjectFile(newProjectFilePath)
readOnly = False
self.projectManager = ProjectManager(
self, workflow_class, headless=True, workflow_cmdline_args=self._workflow_cmdline_args
)
self.projectManager._loadProject(hdf5File, newProjectFilePath, readOnly)
示例3: openProjectFile
def openProjectFile(self, projectFilePath, force_readonly=False):
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, readOnly = ProjectManager.openProjectFile(projectFilePath, force_readonly)
# If there are any "creation-time" command-line args saved to the project file,
# load them so that the workflow can be instantiated with the same settings
# that were used when the project was first created.
project_creation_args = []
if "workflow_cmdline_args" in hdf5File.keys():
if len(hdf5File["workflow_cmdline_args"]) > 0:
project_creation_args = map(str, hdf5File["workflow_cmdline_args"][...])
if workflow_class is None:
# If the project file has no known workflow, we assume pixel classification
import ilastik.workflows
workflow_class = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
import warnings
warnings.warn( "Your project file ({}) does not specify a workflow type. "
"Assuming Pixel Classification".format( projectFilePath ) )
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( self,
workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args,
project_creation_args=project_creation_args )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly)
except ProjectManager.FileMissingError:
logger.error("Couldn't find project file: {}".format( projectFilePath ))
raise
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# For now, we assume that any imported projects are pixel classification workflow projects.
import ilastik.workflows
default_workflow = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( self,
default_workflow,
importFromPath=oldProjectFilePath,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args,
project_creation_args=self._workflow_cmdline_args )
self.projectManager._importProject(oldProjectFilePath, hdf5File, projectFilePath,readOnly = False)
示例4: HeadlessShell
class HeadlessShell(object):
"""
For now, this class is just a stand-in for the GUI shell (used when running from the command line).
"""
def __init__(self):
self._applets = []
self.projectManager = ProjectManager()
self.currentImageIndex = -1
def addApplet(self, aplt):
self._applets.append(aplt)
self.projectManager.addApplet(aplt)
def changeCurrentInputImageIndex(self, newImageIndex):
if newImageIndex != self.currentImageIndex:
# Alert each central widget and viewer control widget that the image selection changed
for i in range(len(self._applets)):
self._applets[i].gui.setImageIndex(newImageIndex)
self.currentImageIndex = newImageIndex
def openProjectPath(self, projectFilePath):
try:
hdf5File, readOnly = self.projectManager.openProjectFile(projectFilePath)
self.projectManager.loadProject(hdf5File, projectFilePath, readOnly)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
projectFile = self.projectManager.createBlankProjectFile(projectFilePath)
self.projectManager.importProject(oldProjectFilePath, projectFile, projectFilePath)
示例5: HeadlessShell
class HeadlessShell(object):
"""
For now, this class is just a stand-in for the GUI shell (used when running from the command line).
"""
def __init__(self, workflowClass):
self._workflowClass = workflowClass
self.projectManager = None
@property
def workflow(self):
return self.projectManager.workflow
def createBlankProjectFile(self, projectFilePath):
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
readOnly = False
self.projectManager = ProjectManager( self._workflowClass, headless=True )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly)
def openProjectPath(self, projectFilePath):
try:
# Open the project file
hdf5File, readOnly = ProjectManager.openProjectFile(projectFilePath)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( self._workflowClass, headless=True )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly = False)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( self._workflowClass, importFromPath=oldProjectFilePath, headless=True )
self.projectManager._importProject(importFromPath, hdf5File, projectFilePath,readOnly = False)
def closeCurrentProject(self):
self.projectManager._closeCurrentProject()
self.projectManager.cleanUp()
self.projectManager = None
示例6: create_new_tst_project
def create_new_tst_project(cls):
# Instantiate 'shell'
shell = HeadlessShell( )
# Create a blank project file and load it.
newProjectFilePath = cls.PROJECT_FILE
newProjectFile = ProjectManager.createBlankProjectFile(newProjectFilePath, PixelClassificationWorkflow, [])
newProjectFile.close()
shell.openProjectFile(newProjectFilePath)
workflow = shell.workflow
# Add a file
from ilastik.applets.dataSelection.opDataSelection import DatasetInfo
info = DatasetInfo()
info.filePath = cls.SAMPLE_DATA
opDataSelection = workflow.dataSelectionApplet.topLevelOperator
opDataSelection.DatasetGroup.resize(1)
opDataSelection.DatasetGroup[0][0].setValue(info)
# Set some features
ScalesList = [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0]
FeatureIds = [ 'GaussianSmoothing',
'LaplacianOfGaussian',
'StructureTensorEigenvalues',
'HessianOfGaussianEigenvalues',
'GaussianGradientMagnitude',
'DifferenceOfGaussians' ]
opFeatures = workflow.featureSelectionApplet.topLevelOperator
opFeatures.Scales.setValue( ScalesList )
opFeatures.FeatureIds.setValue( FeatureIds )
# sigma: 0.3 0.7 1.0 1.6 3.5 5.0 10.0
selections = numpy.array( [[True, False, False, False, False, False, False],
[True, False, False, False, False, False, False],
[True, False, False, False, False, False, False],
[False, False, False, False, False, False, False],
[False, False, False, False, False, False, False],
[False, False, False, False, False, False, False]] )
opFeatures.SelectionMatrix.setValue(selections)
# Add some labels directly to the operator
opPixelClass = workflow.pcApplet.topLevelOperator
opPixelClass.LabelNames.setValue(['Label 1', 'Label 2'])
slicing1 = sl[0:1,0:10,0:10,0:1,0:1]
labels1 = 1 * numpy.ones(slicing2shape(slicing1), dtype=numpy.uint8)
opPixelClass.LabelInputs[0][slicing1] = labels1
slicing2 = sl[0:1,0:10,10:20,0:1,0:1]
labels2 = 2 * numpy.ones(slicing2shape(slicing2), dtype=numpy.uint8)
opPixelClass.LabelInputs[0][slicing2] = labels2
# Save and close
shell.projectManager.saveProject()
del shell
示例7: __init__
def __init__( self, workflow = [], parent = None, flags = QtCore.Qt.WindowFlags(0), sideSplitterSizePolicy=SideSplitterSizePolicy.Manual ):
QMainWindow.__init__(self, parent = parent, flags = flags )
# Register for thunk events (easy UI calls from non-GUI threads)
self.thunkEventHandler = ThunkEventHandler(self)
self._sideSplitterSizePolicy = sideSplitterSizePolicy
self.projectManager = ProjectManager()
import inspect, os
ilastikShellFilePath = os.path.dirname(inspect.getfile(inspect.currentframe()))
uic.loadUi( ilastikShellFilePath + "/ui/ilastikShell.ui", self )
self._applets = []
self.appletBarMapping = {}
self.setAttribute(Qt.WA_AlwaysShowToolTips)
if 'Ubuntu' in platform.platform():
# Native menus are prettier, but aren't working on Ubuntu at this time (Qt 4.7, Ubuntu 11)
self.menuBar().setNativeMenuBar(False)
(self._projectMenu, self._shellActions) = self._createProjectMenu()
self._settingsMenu = self._createSettingsMenu()
self.menuBar().addMenu( self._projectMenu )
self.menuBar().addMenu( self._settingsMenu )
self.updateShellProjectDisplay()
self.progressDisplayManager = ProgressDisplayManager(self.statusBar)
self.appletBar.expanded.connect(self.handleAppleBarItemExpanded)
self.appletBar.clicked.connect(self.handleAppletBarClick)
self.appletBar.setVerticalScrollMode( QAbstractItemView.ScrollPerPixel )
# By default, make the splitter control expose a reasonable width of the applet bar
self.mainSplitter.setSizes([300,1])
self.currentAppletIndex = 0
self.currentImageIndex = -1
self.populatingImageSelectionCombo = False
self.imageSelectionCombo.currentIndexChanged.connect( self.changeCurrentInputImageIndex )
self.enableWorkflow = False # Global mask applied to all applets
self._controlCmds = [] # Track the control commands that have been issued by each applet so they can be popped.
self._disableCounts = [] # Controls for each applet can be disabled by his peers.
# No applet can be enabled unless his disableCount == 0
# Add all the applets from the workflow
for app in workflow.applets:
self.addApplet(app)
self.workflow = workflow
示例8: openProjectPath
def openProjectPath(self, projectFilePath):
try:
# Open the project file
hdf5File, readOnly = ProjectManager.openProjectFile(projectFilePath)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( self._workflowClass, hdf5File, projectFilePath, readOnly, headless=True )
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( self._workflowClass, hdf5File, projectFilePath, readOnly=False, importFromPath=oldProjectFilePath, headless=True )
示例9: downloadProjectFromDvid
def downloadProjectFromDvid(cls, dvid_key_url):
# By convention, command-line users specify the location of the project
# keyvalue data using the same format that the DVID API itself uses.
url_format = "^protocol://hostname/api/node/uuid/kv_instance_name(\\?/key/keyname)?"
for field in ['protocol', 'hostname', 'uuid', 'kv_instance_name', 'keyname']:
url_format = url_format.replace( field, '(?P<' + field + '>[^?]+)' )
match = re.match( url_format, dvid_key_url )
if not match:
# DVID is the only url-based format we support right now.
# So if it looks like the user gave a URL that isn't a valid DVID node, then error.
raise RuntimeError("Invalid URL format for DVID key-value data: {}".format(projectFilePath))
fields = match.groupdict()
projectFilePath = ProjectManager.downloadProjectFromDvid( fields['hostname'],
fields['uuid'],
fields['kv_instance_name'],
fields['keyname'] )
return projectFilePath
示例10: create_project_file
def create_project_file(self, workflow_class, project_file_name):
newProjectFile = ProjectManager.createBlankProjectFile(project_file_name, workflow_class, [])
newProjectFile.close()
示例11: IlastikShell
class IlastikShell( QMainWindow ):
"""
The GUI's main window. Simply a standard 'container' GUI for one or more applets.
"""
def __init__( self, workflow = [], parent = None, flags = QtCore.Qt.WindowFlags(0), sideSplitterSizePolicy=SideSplitterSizePolicy.Manual ):
QMainWindow.__init__(self, parent = parent, flags = flags )
# Register for thunk events (easy UI calls from non-GUI threads)
self.thunkEventHandler = ThunkEventHandler(self)
self._sideSplitterSizePolicy = sideSplitterSizePolicy
self.projectManager = ProjectManager()
import inspect, os
ilastikShellFilePath = os.path.dirname(inspect.getfile(inspect.currentframe()))
uic.loadUi( ilastikShellFilePath + "/ui/ilastikShell.ui", self )
self._applets = []
self.appletBarMapping = {}
self.setAttribute(Qt.WA_AlwaysShowToolTips)
if 'Ubuntu' in platform.platform():
# Native menus are prettier, but aren't working on Ubuntu at this time (Qt 4.7, Ubuntu 11)
self.menuBar().setNativeMenuBar(False)
(self._projectMenu, self._shellActions) = self._createProjectMenu()
self._settingsMenu = self._createSettingsMenu()
self.menuBar().addMenu( self._projectMenu )
self.menuBar().addMenu( self._settingsMenu )
self.updateShellProjectDisplay()
self.progressDisplayManager = ProgressDisplayManager(self.statusBar)
for applet in workflow:
self.addApplet(applet)
self.appletBar.expanded.connect(self.handleAppleBarItemExpanded)
self.appletBar.clicked.connect(self.handleAppletBarClick)
self.appletBar.setVerticalScrollMode( QAbstractItemView.ScrollPerPixel )
# By default, make the splitter control expose a reasonable width of the applet bar
self.mainSplitter.setSizes([300,1])
self.currentAppletIndex = 0
self.currentImageIndex = -1
self.populatingImageSelectionCombo = False
self.imageSelectionCombo.currentIndexChanged.connect( self.changeCurrentInputImageIndex )
self.enableWorkflow = False # Global mask applied to all applets
self._controlCmds = [] # Track the control commands that have been issued by each applet so they can be popped.
self._disableCounts = [] # Controls for each applet can be disabled by his peers.
# No applet can be enabled unless his disableCount == 0
def _createProjectMenu(self):
# Create a menu for "General" (non-applet) actions
menu = QMenu("&Project", self)
shellActions = ShellActions()
# Menu item: New Project
shellActions.newProjectAction = menu.addAction("&New Project...")
shellActions.newProjectAction.setShortcuts( QKeySequence.New )
shellActions.newProjectAction.triggered.connect(self.onNewProjectActionTriggered)
# Menu item: Open Project
shellActions.openProjectAction = menu.addAction("&Open Project...")
shellActions.openProjectAction.setShortcuts( QKeySequence.Open )
shellActions.openProjectAction.triggered.connect(self.onOpenProjectActionTriggered)
# Menu item: Save Project
shellActions.saveProjectAction = menu.addAction("&Save Project")
shellActions.saveProjectAction.setShortcuts( QKeySequence.Save )
shellActions.saveProjectAction.triggered.connect(self.onSaveProjectActionTriggered)
# Menu item: Save Project As
shellActions.saveProjectAsAction = menu.addAction("&Save Project As...")
shellActions.saveProjectAsAction.setShortcuts( QKeySequence.SaveAs )
shellActions.saveProjectAsAction.triggered.connect(self.onSaveProjectAsActionTriggered)
# Menu item: Save Project Snapshot
shellActions.saveProjectSnapshotAction = menu.addAction("&Take Snapshot...")
shellActions.saveProjectSnapshotAction.triggered.connect(self.onSaveProjectSnapshotActionTriggered)
# Menu item: Import Project
shellActions.importProjectAction = menu.addAction("&Import Project...")
shellActions.importProjectAction.triggered.connect(self.onImportProjectActionTriggered)
# Menu item: Quit
shellActions.quitAction = menu.addAction("&Quit")
shellActions.quitAction.setShortcuts( QKeySequence.Quit )
shellActions.quitAction.triggered.connect(self.onQuitActionTriggered)
shellActions.quitAction.setShortcut( QKeySequence.Quit )
return (menu, shellActions)
#.........这里部分代码省略.........
示例12: HeadlessShell
class HeadlessShell(object):
"""
For now, this class is just a stand-in for the GUI shell (used when running from the command line).
"""
def __init__(self, workflow_cmdline_args=None):
self._workflow_cmdline_args = workflow_cmdline_args or []
self.projectManager = None
@property
def workflow(self):
return self.projectManager.workflow
def createAndLoadNewProject(self, newProjectFilePath, workflow_class):
hdf5File = ProjectManager.createBlankProjectFile(newProjectFilePath)
readOnly = False
self.projectManager = ProjectManager(
self, workflow_class, headless=True, workflow_cmdline_args=self._workflow_cmdline_args
)
self.projectManager._loadProject(hdf5File, newProjectFilePath, readOnly)
def openProjectFile(self, projectFilePath):
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, _ = ProjectManager.openProjectFile(projectFilePath)
if workflow_class is None:
# If the project file has no known workflow, we assume pixel classification
import ilastik.workflows
workflow_class = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
import warnings
warnings.warn(
"Your project file ({}) does not specify a workflow type. "
"Assuming Pixel Classification".format(projectFilePath)
)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager(
self, workflow_class, headless=True, workflow_cmdline_args=self._workflow_cmdline_args
)
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly=False)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# For now, we assume that any imported projects are pixel classification workflow projects.
import ilastik.workflows
default_workflow = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager(
self, default_workflow, importFromPath=oldProjectFilePath, headless=True
)
self.projectManager._importProject(oldProjectFilePath, hdf5File, projectFilePath, readOnly=False)
def setAppletEnabled(self, applet, enabled):
"""
Provided here to satisfy the ShellABC.
For now, HeadlessShell has no concept of "enabled" or "disabled" applets.
"""
pass
def enableProjectChanges(self, enabled):
"""
Provided here to satisfy the ShellABC.
For now, HeadlessShell has no mechanism for closing projects.
"""
pass
def closeCurrentProject(self):
self.projectManager._closeCurrentProject()
self.projectManager.cleanUp()
self.projectManager = None
示例13: createBlankProjectFile
def createBlankProjectFile(self, projectFilePath):
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
readOnly = False
self.projectManager = ProjectManager( self._workflowClass, headless=True )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly)
示例14: HeadlessShell
class HeadlessShell(object):
"""
For now, this class is just a stand-in for the GUI shell (used when running from the command line).
"""
def __init__(self, workflow_cmdline_args=None):
self._workflow_cmdline_args = workflow_cmdline_args or []
self.projectManager = None
@property
def workflow(self):
return self.projectManager.workflow
@property
def currentImageIndex(self):
return -1
def createAndLoadNewProject(self, newProjectFilePath, workflow_class):
hdf5File = ProjectManager.createBlankProjectFile(newProjectFilePath)
readOnly = False
self.projectManager = ProjectManager( self,
workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args )
self.projectManager._loadProject(hdf5File, newProjectFilePath, readOnly)
self.projectManager.saveProject()
@classmethod
def downloadProjectFromDvid(cls, dvid_key_url):
dvid_key_url = str(dvid_key_url)
# By convention, command-line users specify the location of the project
# keyvalue data using the same format that the DVID API itself uses.
url_format = "^protocol://hostname/api/node/uuid/kv_instance_name(/key/keyname)?"
for field in ['protocol', 'hostname', 'uuid', 'kv_instance_name', 'keyname']:
url_format = url_format.replace( field, '(?P<' + field + '>[^?/]+)' )
match = re.match( url_format, dvid_key_url )
if not match:
# DVID is the only url-based format we support right now.
# So if it looks like the user gave a URL that isn't a valid DVID node, then error.
raise RuntimeError("Invalid URL format for DVID key-value data: {}".format(projectFilePath))
fields = match.groupdict()
projectFilePath = ProjectManager.downloadProjectFromDvid( fields['hostname'],
fields['uuid'],
fields['kv_instance_name'],
fields['keyname'] )
return projectFilePath
def openProjectFile(self, projectFilePath, force_readonly=False):
# If the user gave a URL to a DVID key, then download the project file from dvid first.
# (So far, DVID is the only type of URL access we support for project files.)
if isUrl(projectFilePath):
projectFilePath = HeadlessShell.downloadProjectFromDvid(projectFilePath)
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, readOnly = ProjectManager.openProjectFile(projectFilePath, force_readonly)
# If there are any "creation-time" command-line args saved to the project file,
# load them so that the workflow can be instantiated with the same settings
# that were used when the project was first created.
project_creation_args = []
if "workflow_cmdline_args" in hdf5File.keys():
if len(hdf5File["workflow_cmdline_args"]) > 0:
project_creation_args = map(str, hdf5File["workflow_cmdline_args"][...])
if workflow_class is None:
# If the project file has no known workflow, we assume pixel classification
import ilastik.workflows
workflow_class = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
import warnings
warnings.warn( "Your project file ({}) does not specify a workflow type. "
"Assuming Pixel Classification".format( projectFilePath ) )
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( self,
workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args,
project_creation_args=project_creation_args )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly)
except ProjectManager.FileMissingError:
logger.error("Couldn't find project file: {}".format( projectFilePath ))
raise
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
#.........这里部分代码省略.........
示例15: HeadlessShell
class HeadlessShell(object):
"""
For now, this class is just a stand-in for the GUI shell (used when running from the command line).
"""
def __init__(self, workflow_cmdline_args=None):
self._workflow_cmdline_args = workflow_cmdline_args or []
self.projectManager = None
@property
def workflow(self):
return self.projectManager.workflow
def createAndLoadNewProject(self, newProjectFilePath, workflow_class):
hdf5File = ProjectManager.createBlankProjectFile(newProjectFilePath)
readOnly = False
self.projectManager = ProjectManager( workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args )
self.projectManager._loadProject(hdf5File, newProjectFilePath, readOnly)
def openProjectFile(self, projectFilePath):
# Make sure all workflow sub-classes have been loaded,
# so we can detect the workflow type in the project.
import ilastik.workflows
try:
# Open the project file
hdf5File, workflow_class, _ = ProjectManager.openProjectFile(projectFilePath)
# Create our project manager
# This instantiates the workflow and applies all settings from the project.
self.projectManager = ProjectManager( workflow_class,
headless=True,
workflow_cmdline_args=self._workflow_cmdline_args )
self.projectManager._loadProject(hdf5File, projectFilePath, readOnly = False)
except ProjectManager.ProjectVersionError:
# Couldn't open project. Try importing it.
oldProjectFilePath = projectFilePath
name, ext = os.path.splitext(oldProjectFilePath)
# Create a brand new project file.
projectFilePath = name + "_imported" + ext
logger.info("Importing project as '" + projectFilePath + "'")
hdf5File = ProjectManager.createBlankProjectFile(projectFilePath)
# For now, we assume that any imported projects are pixel classification workflow projects.
import ilastik.workflows
default_workflow = ilastik.workflows.pixelClassification.PixelClassificationWorkflow
# Create the project manager.
# Here, we provide an additional parameter: the path of the project we're importing from.
self.projectManager = ProjectManager( default_workflow,
importFromPath=oldProjectFilePath,
headless=True )
self.projectManager._importProject(oldProjectFilePath, hdf5File, projectFilePath,readOnly = False)
def closeCurrentProject(self):
self.projectManager._closeCurrentProject()
self.projectManager.cleanUp()
self.projectManager = None