Esempio n. 1
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,
                )
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)