當前位置: 首頁>>代碼示例>>Python>>正文


Python h5py.is_hdf5方法代碼示例

本文整理匯總了Python中h5py.is_hdf5方法的典型用法代碼示例。如果您正苦於以下問題:Python h5py.is_hdf5方法的具體用法?Python h5py.is_hdf5怎麽用?Python h5py.is_hdf5使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在h5py的用法示例。


在下文中一共展示了h5py.is_hdf5方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_valid_backend

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def is_valid_backend(path: Union[Path, str]) -> bool:
        if isinstance(path, str):
            path = Path(path)

        if not isinstance(path, Path):
            return False

        if not path.is_file():
            return False

        if not path.suffix == ".h5":
            return False

        if not h5.is_hdf5(path):
            return False

        with h5.File(path, mode="r") as f:
            if ("TYPE" in f.attrs) and ("LABELS" not in f.attrs):
                type_ = f.attrs["TYPE"].astype(str)[0]

                if type_ == "particles":
                    return True

        return False 
開發者ID:GoLP-IST,項目名稱:nata,代碼行數:26,代碼來源:hdf5.py

示例2: is_multires_file

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def is_multires_file(filepath, min_version=1):
    """
    Determine if a file is a multi-res cooler file.
    Returns False if the file doesn't exist.

    """
    if not h5py.is_hdf5(filepath):
        return False

    with h5py.File(filepath) as f:
        fmt = f.attrs.get("format", None)
        if "resolutions" in f.keys() and len(f["resolutions"].keys()) > 0:
            name = next(iter(f["resolutions"].keys()))
            if fmt == "HDF5::MCOOL" and _is_cooler(f["resolutions"][name]):
                return True
        elif "0" in f.keys() and _is_cooler(f["0"]) and min_version < 2:
            return True

    return False 
開發者ID:mirnylab,項目名稱:cooler,代碼行數:21,代碼來源:fileops.py

示例3: __init__

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def __init__(self, store, root=None, **kwargs):
        if isinstance(store, six.string_types):
            if root is None:
                self.filename, self.root = parse_cooler_uri(store)
            elif h5py.is_hdf5(store):
                with open_hdf5(store, **kwargs) as h5:
                    self.filename = h5.file.filename
                    self.root = root
            else:
                raise ValueError("Not a valid path to a Cooler file")
            self.uri = self.filename + "::" + self.root
            self.store = self.filename
            self.open_kws = kwargs
        else:
            # Assume an open HDF5 handle, ignore open_kws
            self.filename = store.file.filename
            self.root = store.name
            self.uri = self.filename + "::" + self.root
            self.store = store.file
            self.open_kws = {}
        self._refresh() 
開發者ID:mirnylab,項目名稱:cooler,代碼行數:23,代碼來源:api.py

示例4: dump_scf

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def dump_scf(mol, chkfile, e_tot, mo_energy, mo_coeff, mo_occ,
             overwrite_mol=True):
    '''save temporary results'''
    if h5py.is_hdf5(chkfile) and not overwrite_mol:
        with h5py.File(chkfile, 'a') as fh5:
            if 'mol' not in fh5:
                fh5['mol'] = mol.dumps()
    else:
        save_mol(mol, chkfile)

    scf_dic = {'e_tot'    : e_tot,
               'mo_energy': mo_energy,
               'mo_occ'   : mo_occ,
               'mo_coeff' : mo_coeff}
    save(chkfile, 'scf', scf_dic) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:17,代碼來源:chkfile.py

示例5: _create_h5file

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def _create_h5file(erifile, dataname):
    if h5py.is_hdf5(erifile):
        feri = h5py.File(erifile, 'a')
        if dataname in feri:
            del(feri[dataname])
    else:
        feri = h5py.File(erifile, 'w')
    return feri 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:10,代碼來源:outcore.py

示例6: dump_mcscf

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def dump_mcscf(mc, chkfile=None, key='mcscf',
               e_tot=None, mo_coeff=None, ncore=None, ncas=None,
               mo_occ=None, mo_energy=None, e_cas=None, ci_vector=None,
               casdm1=None, overwrite_mol=True):
    '''Save CASCI/CASSCF calculation results or intermediates in chkfile.
    '''
    if chkfile is None: chkfile = mc.chkfile
    if ncore is None: ncore = mc.ncore
    if ncas is None: ncas = mc.ncas
    if e_tot is None: e_tot = mc.e_tot
    if e_cas is None: e_cas = mc.e_cas
    if mo_coeff is None: mo_coeff = mc.mo_coeff
    #if ci_vector is None: ci_vector = mc.ci

    if h5py.is_hdf5(chkfile):
        fh5 = h5py.File(chkfile, 'a')
        if key in fh5:
            del(fh5[key])
    else:
        fh5 = h5py.File(chkfile, 'w')

    if 'mol' not in fh5:
        fh5['mol'] = mc.mol.dumps()
    elif overwrite_mol:
        del(fh5['mol'])
        fh5['mol'] = mc.mol.dumps()

    fh5[key+'/mo_coeff'] = mo_coeff

    def store(subkey, val):
        if val is not None:
            fh5[key+'/'+subkey] = val
    store('e_tot', e_tot)
    store('e_cas', e_cas)
    store('ci', ci_vector)
    store('ncore', ncore)
    store('ncas', ncas)
    store('mo_occ', mo_occ)
    store('mo_energy', mo_energy)
    store('casdm1', casdm1)
    fh5.close() 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:43,代碼來源:chkfile.py

示例7: is_cooler

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def is_cooler(uri):
    """
    Determine if a URI string references a cooler data collection.
    Returns False if the file or group path doesn't exist.

    """
    filepath, grouppath = parse_cooler_uri(uri)
    if not h5py.is_hdf5(filepath):
        return False
    with h5py.File(filepath) as f:
        return _is_cooler(f[grouppath]) 
開發者ID:mirnylab,項目名稱:cooler,代碼行數:13,代碼來源:fileops.py

示例8: list_coolers

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def list_coolers(filepath):
    """
    List group paths to all cooler data collections in a file.

    Parameters
    ----------
    filepath : str

    Returns
    -------
    list
        Cooler group paths in the file.

    """
    if not h5py.is_hdf5(filepath):
        raise OSError("'{}' is not an HDF5 file.".format(filepath))

    listing = []

    def _check_cooler(pth, grp):
        if _is_cooler(grp):
            listing.append("/" + pth if not pth.startswith("/") else pth)

    with h5py.File(filepath, "r") as f:
        _check_cooler("/", f)
        visititems(f, _check_cooler)

    return natsorted(listing) 
開發者ID:mirnylab,項目名稱:cooler,代碼行數:30,代碼來源:fileops.py

示例9: ls

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def ls(uri):
    """
    Get all groups and datasets in an HDF5 file.

    Parameters
    ----------
    uri : str

    Returns
    -------
    list
        Group and dataset paths.

    """
    filepath, grouppath = parse_cooler_uri(uri)
    if not h5py.is_hdf5(filepath):
        raise OSError("'{}' is not an HDF5 file.".format(filepath))

    listing = []

    def _check_all(pth, grp):
        listing.append("/" + pth if not pth.startswith("/") else pth)

    with h5py.File(filepath, "r") as f:
        _check_all(grouppath, f)
        visititems(f[grouppath], _check_all)

    return listing 
開發者ID:mirnylab,項目名稱:cooler,代碼行數:30,代碼來源:fileops.py

示例10: flow_from_fname

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def flow_from_fname(self, fname, datasets=None):
        """ Returns an specific iterator given the filename

        # Arguments
            datasets: str or list. If str will return one iterator; otherwise
            will return len(dataset) iterators for each dataset

        # Inputs
            fname: path to a file.
                *.h5 (HDF5 format)
                *json (JSON format)

        # Outputs
            If fname is:
                HDF5 format: H5Iterator
                JSON format: JSONIterator
        """
        out = None
        datasets = datasets or ['/']
        if type(datasets) not in (set, list):
            datasets = [datasets]

        if h5py.is_hdf5(fname):
            h5_f = h5py.File(fname, 'r')
            out = [self.flow_from_h5_group(h5_f[dataset])
                   for dataset in datasets]

        ext = os.path.splitext(fname)[1]
        if ext == '.json':
            out = [self.flow_from_json(fname, dataset) for dataset in datasets]

        if out is None:
            raise ValueError("Extension not recognized")

        if len(out) == 1:
            return out[0]
        return out 
開發者ID:igormq,項目名稱:asr-study,代碼行數:39,代碼來源:dataset_generator.py

示例11: as_scanner

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def as_scanner(mf):
    import copy
    if isinstance(mf, lib.SinglePointScanner):
        return mf

    logger.info(mf, 'Create scanner for %s', mf.__class__)

    class SCF_Scanner(mf.__class__, lib.SinglePointScanner):
        def __init__(self, mf_obj):
            self.__dict__.update(mf_obj.__dict__)

        def __call__(self, cell_or_geom, **kwargs):
            from pyscf.pbc import gto
            if isinstance(cell_or_geom, gto.Cell):
                cell = cell_or_geom
            else:
                cell = self.cell.set_geom_(cell_or_geom, inplace=False)

            # Cleanup intermediates associated to the pervious mol object
            self.reset(cell)

            if 'dm0' in kwargs:
                dm0 = kwargs.pop('dm0')
            elif self.mo_coeff is None:
                dm0 = None
            elif self.chkfile and h5py.is_hdf5(self.chkfile):
                dm0 = self.from_chk(self.chkfile)
            else:
                dm0 = self.make_rdm1()
                # dm0 form last calculation cannot be used in the current
                # calculation if a completely different system is given.
                # Obviously, the systems are very different if the number of
                # basis functions are different.
                # TODO: A robust check should include more comparison on
                # various attributes between current `mol` and the `mol` in
                # last calculation.
                if dm0.shape[-1] != cell.nao_nr():
                    #TODO:
                    #from pyscf.scf import addons
                    #if numpy.any(last_mol.atom_charges() != mol.atom_charges()):
                    #    dm0 = None
                    #elif non-relativistic:
                    #    addons.project_dm_nr2nr(last_mol, dm0, last_mol)
                    #else:
                    #    addons.project_dm_r2r(last_mol, dm0, last_mol)
                    dm0 = None
            self.mo_coeff = None  # To avoid last mo_coeff being used by SOSCF
            e_tot = self.kernel(dm0=dm0, **kwargs)
            return e_tot

    return SCF_Scanner(mf) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:53,代碼來源:khf.py

示例12: __init__

# 需要導入模塊: import h5py [as 別名]
# 或者: from h5py import is_hdf5 [as 別名]
def __init__(self, filename=None, size_limit=SIZE_LIM, out_dir='./', n_coarse_chan=None, coarse_chans=None):
        """
        :param filename:        string,      name of file (.h5 or .fil)
        :param size_limit:      float,       maximum size in MB that the file is allowed to be
        :param out_dir:         string,      directory where output files should be saved
        """

        if filename and os.path.isfile(filename):
            self.filename = filename
            self.out_dir = out_dir
            self.n_coarse_chan = n_coarse_chan
            self.coarse_chans = coarse_chans

            if not h5py.is_hdf5(filename):
                if not sigproc.is_filterbank(filename):
                    raise IOError('No correct format, need .h5. Try again...')
                else:
                    logger.info("File .fil detected. Attempting to create .h5 file in current directory...")
                    try:
                        self.__make_h5_file()
                    except:
                        raise IOError('Unable to create .h5 file. Please, try again with correct format.')

            self.filestat = os.stat(filename)
            self.filesize = self.filestat.st_size/(1024.0**2)

            # Make sure file is not larger than limit. If it is, we must split the file
            if self.filesize > size_limit:
                logger.info("The file is of size %f MB, exceeding our size limit %f MB. Split needed..."%(self.filesize, size_limit))
                self.data_list = self.__split_h5()
            else:
                #EE This is here mainly for testing. Since need to keep in mind the band pass shape.
                logger.debug("File size %f MB within range %f MB, okay..."%(self.filesize, size_limit))
                data_obj = DATAH5(filename)
                self.data_list = [data_obj]

            self.status = True

        else:
            self.status = False
            errmsg = "File {} doesn\'t exist, please check!".format(filename)
            logger.error(errmsg)
            raise IOError(errmsg) 
開發者ID:UCBerkeleySETI,項目名稱:turbo_seti,代碼行數:45,代碼來源:data_handler.py


注:本文中的h5py.is_hdf5方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。