def run_compute_feature_images(yamlfile):

    yparams = YamlParams(filename=yamlfile)
    params = yparams.get_params()

    # Logger stuff
    yparams.set_indent(1)
    yparams.startlogger(filename=params['resultfolder'] +
                        'compute_feature_images.log',
                        type='w',
                        name='ComputeFeatureImages')

    try:

        compute_feature_images(yparams)

        yparams.logging('')
        yparams.stoplogger()

    except:
        raise
        yparams.errout('Unexpected error')
Example #2
0
    yamlfile = args.ParameterFile
    resultfolder = None
    if args.ResultFolder is not None:
        resultfolder = args.ResultFolder[0]

    if resultfolder is not None:
        replace('./parameters.yml', '^resultfolder: .*$',
                "resultfolder: {}".format(resultfolder))
        replace('./parameters.yml', '^intermedfolder: .*$',
                'intermedfolder: {}{}'.format(resultfolder, 'intermed/'))
        replace('./parameters.yml', '^scriptsfolder: .*$',
                'scriptsfolder: {}{}'.format(resultfolder, 'scripts/'))
        if not os.path.exists(resultfolder):
            os.makedirs(resultfolder)

    yaml = YamlParams(filename=yamlfile)
    params = yaml.get_params()

    yaml.startlogger(filename=params['resultfolder'] + 'pipeline.log',
                     type='w',
                     name='Pipeline')

    yaml.logging('Starting script with:')
    yaml.logging('    ParameterFile = {}\n', yamlfile)

    # Create folder for scripts
    if not os.path.exists(params['scriptsfolder']):
        os.makedirs(params['scriptsfolder'])
    else:
        if params['overwriteresults']:
            yaml.logging(
def run_compute_paths(yamlfile, logging=True):

    yparams = YamlParams(filename=yamlfile)
    params = yparams.get_params()

    # Logger stuff
    yparams.set_indent(1)
    yparams.startlogger(filename=params['resultfolder'] + 'compute_paths.log',
                        type='w',
                        name='ComputePaths')

    try:

        compute_paths(yparams)

        yparams.logging('')
        yparams.stoplogger()

    except:

        yparams.errout('Unexpected error')
Example #4
0
def run_random_forest(yamlfile,
                      logging=True,
                      make_only_feature_array=False,
                      debug=False,
                      write=True):

    yparams = YamlParams(filename=yamlfile)
    params = yparams.get_params()

    # Logger stuff
    yparams.set_indent(1)
    yparams.startlogger(filename=params['resultfolder'] + 'random_forest.log',
                        type='w',
                        name='RandomForest')

    try:

        random_forest(yparams, debug)

        yparams.logging('')
        yparams.stoplogger()

    except:
        raise
        yparams.errout('Unexpected error')
Example #5
0
    def __init__(
        self,
        path=None,
        filename=None,
        filepath=None,
        data=None,
        skeys=None,
        tkeys=None,
        castkey=None,
        yaml=None,
        yamlspec=None,
        recursive_search=False,
        nodata=False,
    ):

        if type(yaml) is str:
            YamlParams.__init__(self, filename=yaml)
        elif isinstance(yaml, YamlParams):
            YamlParams.__init__(self, yaml=yaml)

        # self._sources = dict()

        if yaml is not None:

            yamldict = self.get_params()
            if yamlspec is None:
                if "filepath" in yamldict.keys():
                    filepath = yamldict["filepath"]
                if "path" in yamldict.keys():
                    filepath = yamldict["path"]
                if "filename" in yamldict.keys():
                    filepath = yamldict["filename"]
                if "castkey" in yamldict.keys():
                    castkey = yamldict["castkey"]
                if "skeys" in yamldict.keys():
                    if type(yamldict["skeys"]) is dict:
                        skeys = ()
                        for i in xrange(1, len(yamldict["skeys"])):
                            skeys += (yamldict[yamldict["skeys"][0]][yamldict["skeys"][i]],)
                    else:
                        skeys = yamldict["skeys"]

            else:
                if "filepath" in yamlspec.keys():
                    filepath = yamldict[yamlspec["filepath"]]
                if "path" in yamlspec.keys():
                    path = yamldict[yamlspec["path"]]
                if "filename" in yamlspec.keys():
                    filename = yamldict[yamlspec["filename"]]
                if "castkey" in yamlspec.keys():
                    castkey = yamldict[yamlspec["castkey"]]
                if "skeys" in yamlspec.keys():
                    if type(yamlspec["skeys"]) is dict:
                        skeys = ()
                        for key, val in yamlspec["skeys"].iteritems():
                            for i in val:
                                skeys += (yamldict[key][i],)

                        for i in xrange(1, len(yamlspec["skeys"])):
                            skeys += (yamldict[yamlspec["skeys"][0]][yamlspec["skeys"][i]],)
                    else:
                        skeys = yamldict[yamlspec["skeys"]]

        if data is not None:
            RecursiveDict.__init__(self, data=data, tkeys=tkeys)
        else:
            RecursiveDict.__init__(self)

            if path is not None:
                self.data_from_file(
                    path + filename,
                    skeys=skeys,
                    tkeys=tkeys,
                    castkey=castkey,
                    recursive_search=recursive_search,
                    nodata=nodata,
                )

            elif filepath is not None:
                self.data_from_file(
                    filepath,
                    skeys=skeys,
                    tkeys=tkeys,
                    castkey=castkey,
                    recursive_search=recursive_search,
                    nodata=nodata,
                )
Example #6
0
def run_find_border_contacts(yamlfile, logging=True):

    yparams = YamlParams(filename=yamlfile)
    params = yparams.get_params()

    # Logger stuff
    yparams.set_indent(1)
    yparams.startlogger(filename=params['resultfolder'] +
                        'find_border_contacts.log',
                        type='w',
                        name='FindBorderContacts')

    try:

        find_border_contacts(yparams)

        yparams.logging('')
        yparams.stoplogger()

    except:

        yparams.errout('Unexpected error')
Example #7
0
    def __init__(self,
                 image_path=None,
                 image_file=None,
                 image_names=None,
                 image_ids=None,
                 asdict=True,
                 keys=None,
                 yaml=None,
                 yamlspec=None):
        """
        :param image_path:
        :param image_file:
        :param image_names:
        :param image_ids:
        :param asdict:
        :param keys:

        :type yaml: str
        :param yaml: Filename of yaml configuration file
            Can contain the fields image_path, image_file, image_names, image_ids, asdict, or keys
            If other names for the respective fields are desired use yamlspec (see below)

        :type yamlspec: dict
        :param yamlspec: Translates field names in the configuration file to the respective variable names

            EXAMPLES:

            When using a yaml file like this:
            ---YAML---
            image_path: '~/data/'
            image_file: 'mydatafile.h5'
            ----------
            yamlspec can be set to None.

            If other keywords are desired within the yaml file yamlspec has to be set accordingly:
            ---YAML---
            datapath: '~/data/'
            datafile: 'mydatafile.h5'
            ----------
            yamlspec={'image_path': 'datapath', 'image_file': 'datafile'}

            Note that not every variable has to be set within the yaml file, it is then taken from the function
            arguments.

            If yamlspec is set, only the variables specified in yamlspec are actually read:
            ---YAML---
            datapath: '~/data/'
            datafile: 'mydatafile.h5'
            asdict: True
            ----------
            yamlspec={'image_path': 'datapath', 'image_file': 'datafile'}
            --> asdict will be ignored and derived from the function arguments
            solution:
            yamlspec={'image_path': 'datapath', 'image_file': 'datafile', 'asdict': 'asdict'}

        """

        if yaml is not None:
            YamlParams.__init__(self, filename=yaml)
            # self._yaml = yaml
            # yamldict = self.load_yaml(yaml)
            yamldict = self.get_params()
            if yamlspec is None:
                if 'image_path' in yamldict.keys():
                    image_path = yamldict['image_path']
                if 'image_file' in yamldict.keys():
                    image_file = yamldict['image_file']
                if 'image_names' in yamldict.keys():
                    image_names = yamldict['image_names']
                if 'image_ids' in yamldict.keys():
                    image_ids = yamldict['image_ids']
                if 'asdict' in yamldict.keys(): asdict = yamldict['asdict']
                if 'keys' in yamldict.keys(): keys = yamldict['keys']

            else:
                if 'image_path' in yamlspec.keys():
                    image_path = yamldict[yamlspec['image_path']]
                if 'image_file' in yamlspec.keys():
                    image_file = yamldict[yamlspec['image_file']]
                if 'image_names' in yamlspec.keys():
                    if type(yamlspec['image_names']) is tuple:
                        image_names = ()
                        for i in xrange(1, len(yamlspec['image_names'])):
                            image_names += (
                                yamldict[yamlspec['image_names'][0]][
                                    yamlspec['image_names'][i]], )
                    else:
                        image_names = yamldict[yamlspec['image_names']]
                if 'image_ids' in yamlspec.keys():
                    image_ids = yamldict[yamlspec['image_ids']]
                if 'asdict' in yamlspec.keys():
                    asdict = yamldict[yamlspec['asdict']]
                if 'keys' in yamlspec.keys(): keys = yamldict[yamlspec['keys']]
        else:
            YamlParams.__init__(self)

        if image_path is not None and image_file is not None:
            data = self.load_h5(image_path + image_file, image_ids,
                                image_names, asdict, keys)
        else:
            data = None

        ImageProcessing.__init__(self, data)

        self.set_file(image_path, image_file, image_names, image_ids)
Example #8
0
    def __init__(self, image_path=None, image_file=None, image_names=None, image_ids=None,
                 asdict=True, keys=None, yaml=None, yamlspec=None):
        """
        :param image_path:
        :param image_file:
        :param image_names:
        :param image_ids:
        :param asdict:
        :param keys:

        :type yaml: str
        :param yaml: Filename of yaml configuration file
            Can contain the fields image_path, image_file, image_names, image_ids, asdict, or keys
            If other names for the respective fields are desired use yamlspec (see below)

        :type yamlspec: dict
        :param yamlspec: Translates field names in the configuration file to the respective variable names

            EXAMPLES:

            When using a yaml file like this:
            ---YAML---
            image_path: '~/data/'
            image_file: 'mydatafile.h5'
            ----------
            yamlspec can be set to None.

            If other keywords are desired within the yaml file yamlspec has to be set accordingly:
            ---YAML---
            datapath: '~/data/'
            datafile: 'mydatafile.h5'
            ----------
            yamlspec={'image_path': 'datapath', 'image_file': 'datafile'}

            Note that not every variable has to be set within the yaml file, it is then taken from the function
            arguments.

            If yamlspec is set, only the variables specified in yamlspec are actually read:
            ---YAML---
            datapath: '~/data/'
            datafile: 'mydatafile.h5'
            asdict: True
            ----------
            yamlspec={'image_path': 'datapath', 'image_file': 'datafile'}
            --> asdict will be ignored and derived from the function arguments
            solution:
            yamlspec={'image_path': 'datapath', 'image_file': 'datafile', 'asdict': 'asdict'}

        """

        if yaml is not None:
            YamlParams.__init__(self, filename=yaml)
            # self._yaml = yaml
            # yamldict = self.load_yaml(yaml)
            yamldict = self.get_params()
            if yamlspec is None:
                if 'image_path' in yamldict.keys(): image_path = yamldict['image_path']
                if 'image_file' in yamldict.keys(): image_file = yamldict['image_file']
                if 'image_names' in yamldict.keys(): image_names = yamldict['image_names']
                if 'image_ids' in yamldict.keys(): image_ids = yamldict['image_ids']
                if 'asdict' in yamldict.keys(): asdict = yamldict['asdict']
                if 'keys' in yamldict.keys(): keys = yamldict['keys']

            else:
                if 'image_path' in yamlspec.keys(): image_path = yamldict[yamlspec['image_path']]
                if 'image_file' in yamlspec.keys(): image_file = yamldict[yamlspec['image_file']]
                if 'image_names' in yamlspec.keys():
                    if type(yamlspec['image_names']) is tuple:
                        image_names = ()
                        for i in xrange(1, len(yamlspec['image_names'])):
                            image_names += (yamldict[yamlspec['image_names'][0]][yamlspec['image_names'][i]],)
                    else:
                        image_names = yamldict[yamlspec['image_names']]
                if 'image_ids' in yamlspec.keys(): image_ids = yamldict[yamlspec['image_ids']]
                if 'asdict' in yamlspec.keys(): asdict = yamldict[yamlspec['asdict']]
                if 'keys' in yamlspec.keys(): keys = yamldict[yamlspec['keys']]
        else:
            YamlParams.__init__(self)

        if image_path is not None and image_file is not None:
            data = self.load_h5(image_path + image_file, image_ids, image_names,
                                asdict, keys)
        else:
            data = None

        ImageProcessing.__init__(self, data)

        self.set_file(image_path, image_file, image_names, image_ids)
Example #9
0
def run_remove_small_objects(yamlfile):

    yparams = YamlParams(filename=yamlfile)
    params = yparams.get_params()

    # Logger stuff
    yparams.set_indent(1)
    yparams.startlogger(filename=params['resultfolder'] +
                        'remove_small_objects.log',
                        type='w',
                        name='RemoveSmallObjects')

    try:

        remove_small_objects(yparams)

        yparams.logging('')
        yparams.stoplogger()

    except:

        yparams.errout('Unexpected error')
Example #10
0
    def __init__(self,
                 path=None,
                 filename=None,
                 filepath=None,
                 data=None,
                 skeys=None,
                 tkeys=None,
                 castkey=None,
                 yaml=None,
                 yamlspec=None,
                 recursive_search=False,
                 nodata=False):

        if type(yaml) is str:
            YamlParams.__init__(self, filename=yaml)
        elif isinstance(yaml, YamlParams):
            YamlParams.__init__(self, yaml=yaml)

        # self._sources = dict()

        if yaml is not None:

            yamldict = self.get_params()
            if yamlspec is None:
                if 'filepath' in yamldict.keys():
                    filepath = yamldict['filepath']
                if 'path' in yamldict.keys(): filepath = yamldict['path']
                if 'filename' in yamldict.keys():
                    filepath = yamldict['filename']
                if 'castkey' in yamldict.keys(): castkey = yamldict['castkey']
                if 'skeys' in yamldict.keys():
                    if type(yamldict['skeys']) is dict:
                        skeys = ()
                        for i in xrange(1, len(yamldict['skeys'])):
                            skeys += (yamldict[yamldict['skeys'][0]][
                                yamldict['skeys'][i]], )
                    else:
                        skeys = yamldict['skeys']

            else:
                if 'filepath' in yamlspec.keys():
                    filepath = yamldict[yamlspec['filepath']]
                if 'path' in yamlspec.keys(): path = yamldict[yamlspec['path']]
                if 'filename' in yamlspec.keys():
                    filename = yamldict[yamlspec['filename']]
                if 'castkey' in yamlspec.keys():
                    castkey = yamldict[yamlspec['castkey']]
                if 'skeys' in yamlspec.keys():
                    if type(yamlspec['skeys']) is dict:
                        skeys = ()
                        for key, val in yamlspec['skeys'].iteritems():
                            for i in val:
                                skeys += (yamldict[key][i], )

                        for i in xrange(1, len(yamlspec['skeys'])):
                            skeys += (yamldict[yamlspec['skeys'][0]][
                                yamlspec['skeys'][i]], )
                    else:
                        skeys = yamldict[yamlspec['skeys']]

        if data is not None:
            RecursiveDict.__init__(self, data=data, tkeys=tkeys)
        else:
            RecursiveDict.__init__(self)

            if path is not None:
                self.data_from_file(path + filename,
                                    skeys=skeys,
                                    tkeys=tkeys,
                                    castkey=castkey,
                                    recursive_search=recursive_search,
                                    nodata=nodata)

            elif filepath is not None:
                self.data_from_file(filepath,
                                    skeys=skeys,
                                    tkeys=tkeys,
                                    castkey=castkey,
                                    recursive_search=recursive_search,
                                    nodata=nodata)