Load python data structure from either a YAML or numpy file.
339316
def load_data(infile, workdir=None):
    
    infile = resolve_path(infile, workdir=workdir)
    infile, ext = os.path.splitext(infile)

    if os.path.isfile(infile + '.npy'):
        infile += '.npy'
    elif os.path.isfile(infile + '.yaml'):
        infile += '.yaml'
    else:
        raise Exception('Input file does not exist.')

    ext = os.path.splitext(infile)[1]

    if ext == '.npy':
        return infile, load_npy(infile)
    elif ext == '.yaml':
        return infile, load_yaml(infile)
    else:
        raise Exception('Unrecognized extension.')
1250635
def _load(content_or_fp):
    
    try:
        data = yaml.load(content_or_fp, Loader=yaml.loader.BaseLoader)
    except Exception as e:
        raise type(e)('Malformed yaml file:\n%r' % format_exc())

    try:
        ver = data['spec']
    except:
        raise ValueError('The file does not specify a spec version')

    try:
        ver = tuple(map(int, (ver.split("."))))
    except:
        raise ValueError("Invalid spec version format. Expect 'X.Y'"
                         " (X and Y integers), found %s" % ver)

    if ver > SPEC_VERSION_TUPLE:
        raise ValueError('The spec version of the file is '
                         '%s but the parser is %s. '
                         'Please update pyvisa-sim.' % (ver, SPEC_VERSION))

    return data
1245981
def parse_yaml_file(self, path):
        """"""
        with open(path, 'r') as fp:
            data = yaml.safe_load(fp)

        if not data:
            return {}

        def traverse(namespace, d):
            cfg = {}
            for key, val in d.items():
                if isinstance(d[key], dict):
                    cfg.update(traverse(namespace + [key], d[key]))
                else:
                    if not isinstance(val, str):
                        # All values should be double-quoted strings so they
                        # parse as strings; anything else is a configuration
                        # error at parse-time
                        raise ConfigurationError(
                            'Invalid value %r in file %s: values must be double-quoted strings' % (
                                val, path
                            )
                        )

                    cfg['_'.join(namespace + [key]).upper()] = val

            return cfg

        return traverse([], data)
306357
def load_yaml_file(filename):
    
    try:
        with open(filename, 'r') as f:
            return yaml.safe_load(f)
    except IOError as e:
        raise ParserError('Error opening ' + filename + ': ' + e.message)
    except ValueError as e:
        raise ParserError('Error parsing processes in {}: {}'
                          .format(filename, e.message))
358971
def _load(self, data_path, ignore_missing=False):
        '''
        '''
        if data_path.endswith(".npz"):
            data_dict = np.load(data_path)
            keys = sorted(data_dict.keys())
            for i, k in enumerate(keys):
                data = data_dict[k]
                op_name = "_".join(k.split("_")[:-1])
                param_name = "weights" if k.split("_")[-1] == "W" else "biases"
                if self.verbose:
                    print("Loaded: {} {}".format(op_name, param_name))
                if op_name not in self.weights:
                    self.weights[op_name] = {}
                self.weights[op_name][param_name] = data
        elif data_path.endswith(".npy"):
            data_dict = np.load(data_path).item()
            for op_name in data_dict:
                with tf.variable_scope(op_name, reuse=True):
                    for param_name, data in data_dict[op_name].iteritems():
                        if self.verbose:
                            print("Loaded: {} {}".format(op_name, param_name))
                        if op_name not in self.weights:
                            self.weights[op_name] = {}
                        self.weights[op_name][param_name] = data
        else:
            raise RuntimeError("Invalid file type.")
1253771
def load(self):
        """"""
        try:
            with open(self.config_file) as configfile:
                self.config = yaml.load(configfile)
        except TypeError:
            # no config file (use environment variables)
            pass
        if self.config:
            self.prefix = self.config.get('config_prefix', None)
        if not self.prefix:
            if os.getenv(self.config_prefix):
                self.prefix = os.getenv(self.config_prefix)
            else:
                for path in [
                    os.path.join(self.basepath, self.default_file),
                    os.path.join(self.config_root, self.default_file)
                ]:
                    if os.path.exists(path):
                        with open(path) as conf:
                            config = yaml.load(conf)
                            prefix = config.get(
                                self.config_prefix.lower(), None
                            )
                            if prefix:
                                self.prefix = prefix
                                break
142356
def load_parameters(self, source):
        """"""
        with open(source) as parameters_source:
            loaded = yaml.safe_load(parameters_source.read())
            for k, v in loaded.items():
                if isinstance(v, str):
                    loaded[k] = "'"+v+"'"
            return loaded
421148
def extract_yaml(yaml_files):
    
    loaded_yaml = []
    for yaml_file in yaml_files:
        try:
            with open(yaml_file, 'r') as fd:
                loaded_yaml.append(yaml.safe_load(fd))
        except IOError as e:
            print('Error reading file', yaml_file)
            raise e
        except yaml.YAMLError as e:
            print('Error parsing file', yaml_file)
            raise e
        except Exception as e:
            print('General error')
            raise e
    return loaded_yaml
120440
def from_file(path):
        """"""
        with open(path) as stream:
            obj = yaml.safe_load(stream)
        Config.lint(obj)
        return Config(config_dict=obj)
1011613
def _load_yaml_config(path=None):
    """"""
    countour_yaml_path = path or find_contour_yaml()

    if countour_yaml_path is None:
        logging.debug("countour.yaml not found.")
        return None

    with open(countour_yaml_path) as yaml_file:
        return yaml_file.read()
776932
def yaml_load(path, input="", err_quit=False):
    
    try:
        if len(input) > 0:
            return yaml.safe_load(input)
        elif len(path) > 0:
            return yaml.safe_load(file_to_string(path))
    except Exception as err:
        file = os.path.basename(path)
        ui.error("",
                 c.MESSAGES["yaml_error"].replace("%file", file), err,
                 "")

        if err_quit:
            sys.exit(1)

        return False
395568
def load_all_yamls(cls, directories):
        
        yaml_files = []
        loaded_yamls = {}

        for d in directories:
            if d.startswith('/home') and not os.path.exists(d):
                os.makedirs(d)
            for dirname, subdirs, files in os.walk(d):
                yaml_files.extend(map(lambda x: os.path.join(dirname, x),
                                      filter(lambda x: x.endswith('.yaml'), files)))

        for f in yaml_files:
            loaded_yamls[f] = cls.load_yaml_by_path(f)

        return loaded_yamls
1189403
def load_manifest(data):
    
    if isinstance(data, dict):
        return data
    doc = yaml.safe_load(data)
    if not isinstance(doc, dict):
        raise Exception("Manifest didn't result in dict.")
    return doc
38970
def load_var_file(filename, obj):
    """"""
    rendered = render(filename, obj)
    ext = os.path.splitext(filename)[1][1:]
    v_obj = dict()
    if ext == 'json':
        v_obj = json.loads(rendered)
    elif ext == 'yaml' or ext == 'yml':
        v_obj = yaml.safe_load(rendered)
    else:
        LOG.warning("assuming yaml for unrecognized extension %s",
                    ext)
        v_obj = yaml.safe_load(rendered)

    return v_obj
40778
def _load(self, filename):
        """"""
        filename = pathlib.Path(filename)
        with filename.open() as fd:
            data = fd.readlines()

        # Get the strings that correspond to self.fileid
        bool_head = [l.strip().startswith("[") for l in data]

        int_head = np.squeeze(np.where(bool_head))
        int_head = np.atleast_1d(int_head)

        start = int_head[self.fileid]+1

        if len(int_head) > self.fileid+1:
            end = int_head[self.fileid+1]
        else:
            end = len(data)

        subdata = data[start:end]

        # separate all elements and strip them
        subdata = [[it.strip() for it in l.split("=")] for l in subdata]

        points = []

        for var, val in subdata:
            if var.lower() == "x axis":
                xaxis = val.lower()
            elif var.lower() == "y axis":
                yaxis = val.lower()
            elif var.lower() == "name":
                self.name = val
            elif var.lower() == "inverted":
                if val == "True":
                    self.inverted = True
            elif var.lower().startswith("point"):
                val = np.array(val.strip("[]").split(), dtype=float)
                points.append([int(var[5:]), val])
            else:
                raise KeyError("Unknown variable: {} = {}".
                               format(var, val))
        self.axes = (xaxis, yaxis)
        # sort points
        points.sort()
        # get only coordinates from points
        self.points = np.array([p[1] for p in points])

        # overwrite unique id
        unique_id = int(data[start-1].strip().strip("Polygon []"))
        self._set_unique_id(unique_id)
681997
def load_stream(cls, st):
        """"""
        y = yaml.load(st)
        return [ Automaton(k, v) for k, v in y.iteritems() ]
102711
def load_configuration(yaml: yaml.ruamel.yaml.YAML, filename: str) -> DictLike:
    
    with open(filename, "r") as f:
        config = yaml.load(f)

    return config