예제 #1
0
 def createNewProject(shell):
     import ilastik.workflows
     from ilastik.workflow import getWorkflowFromName
     workflow_class = getWorkflowFromName(parsed_args.workflow)
     if workflow_class is None:
         raise Exception("'{}' is not a valid workflow type.".format( parsed_args.workflow ))
     # This should work for both the IlastikShell and the HeadlessShell
     shell.createAndLoadNewProject(path, workflow_class)
예제 #2
0
 def createNewProject(shell):
     import ilastik.workflows
     from ilastik.workflow import getWorkflowFromName
     workflow_class = getWorkflowFromName(parsed_args.workflow)
     if workflow_class is None:
         raise Exception("'{}' is not a valid workflow type.".format( parsed_args.workflow ))
     # This should work for both the IlastikShell and the HeadlessShell
     shell.createAndLoadNewProject(path, workflow_class)
예제 #3
0
    def openProjectFile(cls, projectFilePath, forceReadOnly=False):
        """
        Class method.
        Attempt to open the given path to an existing project file.
        If it doesn't exist, raise a ``ProjectManager.FileMissingError``.
        If its version is outdated, raise a ``ProjectManager.ProjectVersionError.``
        """
        projectFilePath = os.path.expanduser(projectFilePath)
        logger.info("Opening Project: " + projectFilePath)

        if not os.path.exists(projectFilePath):
            raise ProjectManager.FileMissingError(projectFilePath)

        # Open the file as an HDF5 file
        try:
            if forceReadOnly:
                mode = "r"
            else:
                mode = "r+"
            hdf5File = h5py.File(projectFilePath, mode)
        except IOError:
            # Maybe we tried 'r+', but the project is read-only
            hdf5File = h5py.File(projectFilePath, "r")
        readOnly = hdf5File.mode == "r"

        projectVersion = "0.5"
        if "ilastikVersion" in list(hdf5File.keys()):
            projectVersion = hdf5File["ilastikVersion"].value.decode("utf-8")

        # FIXME: version comparison
        if not isVersionCompatible(projectVersion):
            # Must use _importProject() for old project files.
            raise ProjectManager.ProjectVersionError(projectVersion,
                                                     ilastik.__version__)

        workflow_class = None
        if "workflowName" in list(hdf5File.keys()):
            # if workflow is found in file, take it
            workflowName = hdf5File["workflowName"].value.decode("utf-8")
            workflow_class = getWorkflowFromName(workflowName)

        return (hdf5File, workflow_class, readOnly)
예제 #4
0
    def openProjectFile(cls, projectFilePath, forceReadOnly=False):
        """
        Class method.
        Attempt to open the given path to an existing project file.
        If it doesn't exist, raise a ``ProjectManager.FileMissingError``.
        If its version is outdated, raise a ``ProjectManager.ProjectVersionError.``
        """
        projectFilePath = os.path.expanduser(projectFilePath)
        logger.info("Opening Project: " + projectFilePath)

        if not os.path.exists(projectFilePath):
            raise ProjectManager.FileMissingError(projectFilePath)

        # Open the file as an HDF5 file
        try:
            if forceReadOnly:
                mode = 'r'
            else:
                mode = 'r+'
            hdf5File = h5py.File(projectFilePath, mode)
        except IOError:
            # Maybe we tried 'r+', but the project is read-only
            hdf5File = h5py.File(projectFilePath, 'r')
        readOnly = (hdf5File.mode == 'r')

        projectVersion = "0.5"
        if "ilastikVersion" in hdf5File.keys():
            projectVersion = hdf5File["ilastikVersion"].value
        
        # FIXME: version comparison
        if not isVersionCompatible(projectVersion):
            # Must use _importProject() for old project files.
            raise ProjectManager.ProjectVersionError(projectVersion, ilastik.__version__)
        
        workflow_class = None
        if "workflowName" in hdf5File.keys():
            #if workflow is found in file, take it
            workflowName = hdf5File["workflowName"].value
            workflow_class = getWorkflowFromName(workflowName)
        
        return (hdf5File, workflow_class, readOnly)
예제 #5
0
    def openProjectFile(cls, projectFilePath):
        """
        Class method.
        Attempt to open the given path to an existing project file.
        If it doesn't exist, raise a ``ProjectManager.FileMissingError``.
        If its version is outdated, raise a ``ProjectManager.ProjectVersionError.``
        """
        logger.info("Opening Project: " + projectFilePath)

        if not os.path.exists(projectFilePath):
            raise ProjectManager.FileMissingError()

        # Open the file as an HDF5 file
        try:
            hdf5File = h5py.File(projectFilePath)
            readOnly = False
        except IOError:
            # Maybe the project is read-only
            hdf5File = h5py.File(projectFilePath, 'r')
            readOnly = True

        projectVersion = "0.5"
        if "ilastikVersion" in hdf5File.keys():
            projectVersion = hdf5File["ilastikVersion"].value

        # FIXME: version comparison
        if not isVersionCompatible(projectVersion):
            # Must use _importProject() for old project files.
            raise ProjectManager.ProjectVersionError(projectVersion,
                                                     ilastik.__version__)

        workflow_class = None
        if "workflowName" in hdf5File.keys():
            #if workflow is found in file, take it
            workflowName = hdf5File["workflowName"].value
            workflow_class = getWorkflowFromName(workflowName)

        return (hdf5File, workflow_class, readOnly)
예제 #6
0
파일: ilastik.py 프로젝트: thorbenk/ilastik
#!/usr/bin/env python

from ilastik.shell.gui.startShellGui import startShellGui
from optparse import OptionParser
import ilastik.workflows
from ilastik.workflow import getWorkflowFromName

usage = "%prog [options] <project file>"
parser = OptionParser(usage)
parser.add_option("--workflow",
              dest="workflow", default=None,
              help="specify a workflow that should be loaded")
options, args = parser.parse_args()

if len(args)==0:
    startShellGui(workflowClass=options.workflow)

elif len(args)==1:
    def loadProject(shell):
        shell.openProjectFile(args[0])
    workflowClass = getWorkflowFromName(options.workflow)
    startShellGui(workflowClass,loadProject)