当前位置: 首页>>代码示例>>Python>>正文


Python h5py.Group方法代码示例

本文整理汇总了Python中h5py.Group方法的典型用法代码示例。如果您正苦于以下问题:Python h5py.Group方法的具体用法?Python h5py.Group怎么用?Python h5py.Group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在h5py的用法示例。


在下文中一共展示了h5py.Group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_naoaux

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def get_naoaux(self):
        '''The dimension of auxiliary basis at gamma point'''
# determine naoaux with self._cderi, because DF object may be used as CD
# object when self._cderi is provided.
        if self._cderi is None:
            self.build()
        # self._cderi['j3c/k_id/seg_id']
        with addons.load(self._cderi, 'j3c/0') as feri:
            if isinstance(feri, h5py.Group):
                naux = feri['0'].shape[0]
            else:
                naux = feri.shape[0]

        cell = self.cell
        if (cell.dimension == 2 and cell.low_dim_ft_type != 'inf_vacuum' and
            not isinstance(self._cderi, numpy.ndarray)):
            with h5py.File(self._cderi, 'r') as feri:
                if 'j3c-/0' in feri:
                    dat = feri['j3c-/0']
                    if isinstance(dat, h5py.Group):
                        naux += dat['0'].shape[0]
                    else:
                        naux += dat.shape[0]
        return naux 
开发者ID:pyscf,项目名称:pyscf,代码行数:26,代码来源:df.py

示例2: __enter__

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def __enter__(self):
        if isinstance(self.eri, str):
            feri = self.feri = h5py.File(self.eri, 'r')
        elif isinstance(self.eri, h5py.Group):
            feri = self.eri
        elif isinstance(getattr(self.eri, 'name', None), str):
            feri = self.feri = h5py.File(self.eri.name, 'r')
        elif isinstance(self.eri, numpy.ndarray):
            return self.eri
        else:
            raise RuntimeError('Unknown eri type %s', type(self.eri))

        if self.dataname is None:
            return feri
        else:
            return feri[self.dataname] 
开发者ID:pyscf,项目名称:pyscf,代码行数:18,代码来源:addons.py

示例3: h5py_dataset_iterator

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def h5py_dataset_iterator(self, g, prefix=''):
    for key in g.keys():
      item = g[key]
      path = '{}/{}'.format(prefix, key)
      keys = [i for i in item.keys()]
      if isinstance(item[keys[0]], h5py.Dataset):  # test for dataset
        data = {'path': path}
        for k in keys:
          if not isinstance(item[k], h5py.Group):
            dataset = np.array(item[k].value)

            if type(dataset) is np.ndarray:
              if dataset.size != 0:
                if type(dataset[0]) is np.bytes_:
                  dataset = [a.decode('ascii') for a in dataset]

            data.update({k: dataset})

        yield data
      else:  # test for group (go down)
        for s in self.h5py_dataset_iterator(item, path):
          yield s 
开发者ID:deepchem,项目名称:deepchem,代码行数:24,代码来源:pyanitools.py

示例4: get_data

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def get_data(self, path, prefix=''):
    item = self.store[path]
    path = '{}/{}'.format(prefix, path)
    keys = [i for i in item.keys()]
    data = {'path': path}
    # print(path)
    for k in keys:
      if not isinstance(item[k], h5py.Group):
        dataset = np.array(item[k].value)

        if type(dataset) is np.ndarray:
          if dataset.size != 0:
            if type(dataset[0]) is np.bytes_:
              dataset = [a.decode('ascii') for a in dataset]

        data.update({k: dataset})
    return data 
开发者ID:deepchem,项目名称:deepchem,代码行数:19,代码来源:pyanitools.py

示例5: _parse_units

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def _parse_units(file, _units):
    import h5py

    t_units = {}
    if isinstance(_units, h5py.Group):
        for name in _units.keys():
            value = _units[name]
            dict_val = []
            for val in value:
                if isinstance(file[val[0]], h5py.Dataset):
                    dict_val.append(file[val[0]][()])
                    t_units[name] = dict_val
                else:
                    break
        out = [dict(zip(t_units, col)) for col in zip(*t_units.values())]
    else:
        out = []
        for unit in _units:
            group = file[unit[()][0]]
            unit_dict = {}
            for k in group.keys():
                unit_dict[k] = group[k][()]
            out.append(unit_dict)

    return out 
开发者ID:SpikeInterface,项目名称:spikeextractors,代码行数:27,代码来源:hdsortsortingextractor.py

示例6: load_h5

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def load_h5(fname, key=None):
    """load h5 file"""
    try:
        hfile = h5py.File(fname,'r')
    except:
        assert 0, "\nload_h5()::ERROR: Cannot open <<"+str(fname)+">>\n"
    if key==None:
        try:
            key = hfile.keys()[0]
        except:
            assert 0, "\nload_h5()::ERROR: File is not h5 / is empty  <<"+str(fname)+">>\n"
    xx = hfile[key]
    if isinstance(xx, h5py.Group):
        xx=dict(xx)
        xx = xx[xx.keys()[0] if key==None else key]
    dat = np.asarray(xx, dtype = xx.dtype)
    hfile.close()
    return dat 
开发者ID:GUR9000,项目名称:Deep_MRI_brain_extraction,代码行数:20,代码来源:file_reading.py

示例7: save_parameters_as_hdf5

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def save_parameters_as_hdf5(model, filename='model.h5'):
    # Save the model parameters into a HDF5 archive
    chainer.serializers.save_hdf5(filename, model)
    print('model.h5 saved!\n')

    # Load the saved HDF5 using h5py
    print('--- The list of saved params in model.h5 ---')
    f = h5py.File('model.h5', 'r')
    for param_key, param in f.items():
        msg = '{}:'.format(param_key)
        if isinstance(param, h5py.Dataset):
            msg += ' {}'.format(param.shape)
        print(msg)
        if isinstance(param, h5py.Group):
            for child_key, child in param.items():
                print('  {}:{}'.format(child_key, child.shape))
    print('---------------------------------------------\n') 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:save.py

示例8: __init__

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def __init__(self, pop_name, pop_group, types_table):
        self._pop_name = pop_name
        self._pop_group = pop_group
        self._types_table = types_table
        self._nrows = 0

        # For storing individual groups
        self._group_map = {}  # grp-id --> h5py.Group object
        self._find_groups()
        self._group_cache = {}  # grp-id --> soneta.io.Group() object

        # Refrences to most of the population's primary dataset
        self._type_id_ds = pop_group[self.type_ids_column]
        self._group_id_ds = pop_group[self.group_id_column]
        self._group_index_ds = pop_group[self.group_index_column]

        self._group_indicies = {}  # grp-id --> list of rows indicies
        self._group_indicies_cache_built = False 
开发者ID:AllenInstitute,项目名称:sonata,代码行数:20,代码来源:population.py

示例9: __init__

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def __init__(self, root_name, h5_files, h5_mode, csv_files):
        """
        :param root_name: should either be 'nodes' or 'edges'
        :param h5_files: file (or list of files) containing nodes/edges
        :param h5_mode: currently only supporting 'r' mode in h5py
        :param csv_files: file (or list of files) containing node/edge types
        """
        self._root_name = root_name
        self._h5_handles = [utils.load_h5(f, h5_mode) for f in utils.listify(h5_files)]
        self._csv_handles = [(f, utils.load_csv(f)) for f in utils.listify(csv_files)]

        # merge and create a table of the types table(s)
        self._types_table = None
        self._build_types_table()

        # population_name->h5py.Group table (won't instantiate the population)
        self._populations_groups = {}
        self._store_groups()

        # A map between population_name -> Population object. Population objects aren't created until called, in the
        # case user wants to split populations among MPI nodes (instantiation will create node/edge indicies and other
        # overhead).
        self._populations_cache = {}

        self.check_format() 
开发者ID:AllenInstitute,项目名称:sonata,代码行数:27,代码来源:file_root.py

示例10: write_attributes

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def write_attributes(self, h5file_group):
        """
        Attribute data consists of

         1. `__init__` parameters that are of type str or numerical. These are directly written into `h5py.Group.attrs`
         2. lists are stored under `<h5py.Group>/__lists`
         3. dicts are stored under `<h5py.Group>/__dicts`

        Parameters
        ----------
        h5file_group: h5py.Group
        """
        h5file_group.attrs.create("__type", self.io_data.typename)    # Record the type of the current class instance
        attributes = self.io_data.attributes
        for attr_name, attr_value in attributes.items():
            if isinstance(attr_value, dict):  # h5py does not serialize dicts automatically, so have to do it manually
                group_name = "__dicts/" + attr_name
                h5file_group.create_group(group_name)
                io.write(attr_value, self.filename, file_handle=h5file_group[group_name])
            elif isinstance(attr_value, (list, tuple)):
                group_name = "__lists/" + attr_name
                h5file_group.create_group(group_name)
                io.write(attr_value, self.filename, file_handle=h5file_group[group_name])
            else:
                h5file_group.attrs[attr_name] = attr_value 
开发者ID:scqubits,项目名称:scqubits,代码行数:27,代码来源:fileio_backends.py

示例11: to_file

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def to_file(self, io_data, file_handle=None):
        """
        Takes the serialized IOData and writes it either to a new h5 file with file name given by `self.filename` to to
        the given h5py.Group of an open h5 file.

        Parameters
        ----------
        io_data: IOData
        file_handle: h5py.Group, optional
        """
        self.io_data = io_data
        if file_handle is None:
            h5file_group = h5py.File(self.filename, 'w')
        else:
            h5file_group = file_handle

        self.write_attributes(h5file_group)
        self.write_ndarrays(h5file_group)
        self.write_objects(h5file_group) 
开发者ID:scqubits,项目名称:scqubits,代码行数:21,代码来源:fileio_backends.py

示例12: read_objects

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def read_objects(self, h5file_group):
        """
        Read data from the given h5 file group that represents a Python object other than an ndarray, list, or dict.

        Parameters
        ----------
        h5file_group: h5py.Group

        Returns
        -------
        dict [str, IOData]
        """
        inner_objects = {}
        h5file_group = h5file_group["__objects"]
        for obj_name in h5file_group:
            inner_objects[obj_name] = io.read(self.filename, h5file_group[obj_name])
        return inner_objects 
开发者ID:scqubits,项目名称:scqubits,代码行数:19,代码来源:fileio_backends.py

示例13: from_file

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def from_file(self, filename, file_handle=None):
        """
        Either opens a new h5 file for reading or accesses an already opened file via the given h5.Group handle. Reads
        all data from the three categories of attributes (incl. lists and dicts), ndarrays, and objects.

        Parameters
        ----------
        filename: str
        file_handle: h5.Group, optional

        Returns
        -------
        IOData
        """
        if file_handle is None:
            h5file_group = h5py.File(filename, 'r')
        else:
            h5file_group = file_handle

        attributes = self.read_attributes(h5file_group)
        typename = attributes['__type']
        del attributes['__type']
        ndarrays = self.read_ndarrays(h5file_group)
        inner_objects = self.read_objects(h5file_group)
        return io.IOData(typename, attributes, ndarrays, inner_objects) 
开发者ID:scqubits,项目名称:scqubits,代码行数:27,代码来源:fileio_backends.py

示例14: __init__

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def __init__(self, path, mode='a'):
        if isinstance(path, h5py.Group):
            self.data = path
            self._is_file = False
        elif isinstance(path, str):
            self.data = h5py.File(path, mode=mode)
            self._is_file = True
        elif isinstance(path, dict):
            self.data = path
            self._is_file = False
            if mode == 'w':
                self.data.clear()
            # Flag to check if a dict is user defined data or a sub group:
            self.data['_is_group'] = True
        else:
            raise TypeError('Required Group, str or dict. '
                            'Received: {}.'.format(type(path)))
        self.read_only = mode == 'r' 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:io_utils.py

示例15: dump

# 需要导入模块: import h5py [as 别名]
# 或者: from h5py import Group [as 别名]
def dump(self, target):
        """Serializes MPArray to :code:`h5py.Group`. Recover using
        :func:`~load`.

        :param target: :code:`h5py.Group` the instance should be saved to or
            path to h5 file (it's then serialized to /)

        """
        if isinstance(target, str):
            import h5py
            with h5py.File(target, 'w') as outfile:
                return self.dump(outfile)

        for prop in ('ranks', 'shape'):
            # these are only saved for convenience
            target.attrs[prop] = str(getattr(self, prop))

        # these are actually used in MPArray.load
        target.attrs['len'] = len(self)
        target.attrs['canonical_form'] = self.canonical_form

        for site, lten in enumerate(self._lt):
            target[str(site)] = lten 
开发者ID:dsuess,项目名称:mpnum,代码行数:25,代码来源:mparray.py


注:本文中的h5py.Group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。