Return the h5features version of a given HDF5 `group`.

    Look for a 'version' attribute in the `group` and return its
    value. Return '0.1' if the version is not found. Raises an IOError
    if it is not supported.
352134
def read_version(group):
    
    version = ('0.1' if 'version' not in group.attrs
               else group.attrs['version'])

    # decode from bytes to str if needed
    if isinstance(version, bytes):
        version = version.decode()

    if not is_supported_version(version):
        raise IOError('version {} is not supported'.format(version))

    return version
133913
def _get_version(name, results):
    '''
    
    '''
    for line in salt.utils.itertools.split(results, '\n'):
        if not line:
            continue
        try:
            pkgname, pkgver = line.rsplit('-', 1)
        except ValueError:
            continue
        if pkgname == name:
            return pkgver
    return None
858794
def convert2hdf5(ClassIn, platform_name, bandnames, scale=1e-06):
    
    import h5py

    instr = ClassIn(bandnames[0], platform_name)
    instr_name = instr.instrument.replace('/', '')
    filename = os.path.join(instr.output_dir,
                            "rsr_{0}_{1}.h5".format(instr_name,
                                                    platform_name))

    with h5py.File(filename, "w") as h5f:
        h5f.attrs['description'] = ('Relative Spectral Responses for ' +
                                    instr.instrument.upper())
        h5f.attrs['platform_name'] = platform_name
        h5f.attrs['band_names'] = bandnames

        for chname in bandnames:
            sensor = ClassIn(chname, platform_name)
            grp = h5f.create_group(chname)
            wvl = sensor.rsr['wavelength'][~np.isnan(sensor.rsr['wavelength'])]
            rsp = sensor.rsr['response'][~np.isnan(sensor.rsr['wavelength'])]
            grp.attrs['central_wavelength'] = get_central_wave(wvl, rsp)
            arr = sensor.rsr['wavelength']
            dset = grp.create_dataset('wavelength', arr.shape, dtype='f')
            dset.attrs['unit'] = 'm'
            dset.attrs['scale'] = scale
            dset[...] = arr
            arr = sensor.rsr['response']
            dset = grp.create_dataset('response', arr.shape, dtype='f')
            dset[...] = arr
409658
def load_version(fname: str) -> str:
    
    if not os.path.exists(fname):
        logger.warning("No version file found. Defaulting to 1.0.3")
        return "1.0.3"
    with open(fname) as inp:
        return inp.read().strip()
873918
def h5features_convert(self, infile):
        """"""
        with h5py.File(infile, 'r') as f:
            groups = list(f.keys())
        for group in groups:
            self._writer.write(
                Reader(infile, group).read(),
                self.groupname, append=True)
495830
def with_read_hdf5(func):
    
    @wraps(func)
    def decorated_func(fobj, *args, **kwargs):
        # pylint: disable=missing-docstring
        if not isinstance(fobj, h5py.HLObject):
            if isinstance(fobj, FILE_LIKE):
                fobj = fobj.name
            with h5py.File(fobj, 'r') as h5f:
                return func(h5f, *args, **kwargs)
        return func(fobj, *args, **kwargs)

    return decorated_func
621939
def read_hdf5_flag(h5f, path=None, gpstype=LIGOTimeGPS):
    
    # extract correct group
    dataset = _get_flag_group(h5f, path)

    # read dataset
    active = SegmentList.read(dataset['active'], format='hdf5',
                              gpstype=gpstype)
    try:
        known = SegmentList.read(dataset['known'], format='hdf5',
                                 gpstype=gpstype)
    except KeyError as first_keyerror:
        try:
            known = SegmentList.read(dataset['valid'], format='hdf5',
                                     gpstype=gpstype)
        except KeyError:
            raise first_keyerror

    return DataQualityFlag(active=active, known=known, **dict(dataset.attrs))
8427
def read_version():
    
    with open('./oi/version.py') as fh:
        for line in fh:
            if line.startswith('VERSION'):
                return line.split('=')[1].strip().strip("'")
1191602
def find_version(fname):
    
    version = ""
    with open(fname, "r") as fp:
        reg = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
        for line in fp:
            m = reg.match(line)
            if m:
                version = m.group(1)
                break
    if not version:
        raise RuntimeError("Cannot find version information")
    return version
1056959
def _is_flag_group(obj):
    
    return (
        isinstance(obj, h5py.Group) and
        isinstance(obj.get("active"), h5py.Dataset) and
        isinstance(obj.get("known"), h5py.Dataset)
    )
342851
def _load_h5(filename):
    ''''''
    from neurom.io import hdf5
    return hdf5.read(filename,
                     remove_duplicates=False,
                     data_wrapper=DataWrapper)
395043
def version_from_branch(branch):
    
    try:
        return tuple(
            map(
                int,
                re.match(r"^.*(?P<version>\d+(\.\d+)+).*$", branch)
                .groupdict()["version"]
                .split("."),
            )
        )
    except AttributeError as attr_err:
        raise ValueError(
            f"Branch {branch} seems to not have a version in its name."
        ) from attr_err
860542
def write_hdf5_flag_group(flag, h5group, **kwargs):
    
    # write segmentlists
    flag.active.write(h5group, 'active', **kwargs)
    kwargs['append'] = True
    flag.known.write(h5group, 'known', **kwargs)

    # store metadata
    for attr in ['name', 'label', 'category', 'description', 'isgood',
                 'padding']:
        value = getattr(flag, attr)
        if value is None:
            continue
        elif isinstance(value, Quantity):
            h5group.attrs[attr] = value.value
        elif isinstance(value, UnitBase):
            h5group.attrs[attr] = str(value)
        else:
            h5group.attrs[attr] = value

    return h5group
1075385
def get_version():
        
        version_desc = open(os.path.join(os.path.abspath(APISettings.VERSION_FILE)))
        version_file = version_desc.read()

        try:
            version = re.search(r"version=['\"]([^'\"]+)['\"]", version_file).group(1)
            return version
        except FileNotFoundError:
            Shell.fail('File not found!')
            raise FileNotFoundError
        except ValueError:
            Shell.fail('Version not found in file ' + version_file + '!')
            raise ValueError
        finally:
            version_desc.close()
849727
def VERSION(self):
        """"""
        return int(re.match(r'^(\D+)(\d+)$', self.__class__.__name__).group(2))
975505
def read_hdf5_dict(h5f, names=None, path=None, on_missing='error', **kwargs):
    
    if path:
        h5f = h5f[path]

    # allow alternative keyword argument name (FIXME)
    if names is None:
        names = kwargs.pop('flags', None)

    # try and get list of names automatically
    if names is None:
        try:
            names = find_flag_groups(h5f, strict=True)
        except KeyError:
            names = None
        if not names:
            raise ValueError("Failed to automatically parse available flag "
                             "names from HDF5, please give a list of names "
                             "to read via the ``names=`` keyword")

    # read data
    out = DataQualityDict()
    for name in names:
        try:
            out[name] = read_hdf5_flag(h5f, name, **kwargs)
        except KeyError as exc:
            if on_missing == 'ignore':
                pass
            elif on_missing == 'warn':
                warnings.warn(str(exc))
            else:
                raise ValueError('no H5Group found for flag '
                                 '{0!r}'.format(name))

    return out
85270
def savehdf(filename, datadict, groupname="data", mode="a", metadata=None,
            as_dataframe=False, append=False):
    
    if as_dataframe:
        df = _pd.DataFrame(datadict)
        df.to_hdf(filename, groupname)
    else:
        if isinstance(datadict, _pd.DataFrame):
            datadict = datadict.to_dict("list")
        with _h5py.File(filename, mode) as f:
            for key, value in datadict.items():
                if append:
                    try:
                        f[groupname + "/" + key] = np.append(f[groupname + "/" + key], value)
                    except KeyError:
                        f[groupname + "/" + key] = value
                else:
                    f[groupname + "/" + key] = value
            if metadata:
                for key, value in metadata.items():
                    f[groupname].attrs[key] = value