Exemplo n.º 1
0
    def close(self):
        """ Close the file.  All open objects become invalid """
        with phil:
            # We have to explicitly murder all open objects related to the file

            # Close file-resident objects first, then the files.
            # Otherwise we get errors in MPI mode.
            id_list = h5f.get_obj_ids(self.id, ~h5f.OBJ_FILE)
            file_list = h5f.get_obj_ids(self.id, h5f.OBJ_FILE)

            id_list = [
                x for x in id_list if h5i.get_file_id(x).id == self.id.id
            ]
            file_list = [
                x for x in file_list if h5i.get_file_id(x).id == self.id.id
            ]

            for id_ in id_list:
                while id_.valid:
                    h5i.dec_ref(id_)

            for id_ in file_list:
                while id_.valid:
                    h5i.dec_ref(id_)

            self.id.close()
            _objects.nonlocal_close()
Exemplo n.º 2
0
    def __init__(self, name, mode=None, driver=None, libver=None, userblock_size=None, **kwds):
        """Create a new file object.

        See the h5py user guide for a detailed explanation of the options.

        name
            Name of the file on disk.  Note: for files created with the 'core'
            driver, HDF5 still requires this be non-empty.
        driver
            Name of the driver to use.  Legal values are None (default,
            recommended), 'core', 'sec2', 'stdio', 'mpio'.
        libver
            Library version bounds.  Currently only the strings 'earliest'
            and 'latest' are defined.
        userblock
            Desired size of user block.  Only allowed when creating a new
            file (mode w or w-).
        Additional keywords
            Passed on to the selected file driver.
        """
        if isinstance(name, _objects.ObjectID):
            fid = h5i.get_file_id(name)
        else:
            try:
                # If the byte string doesn't match the default
                # encoding, just pass it on as-is.  Note Unicode
                # objects can always be encoded.
                name = name.encode(sys.getfilesystemencoding())
            except (UnicodeError, LookupError):
                pass

            fapl = make_fapl(driver, libver, **kwds)
            fid = make_fid(name, mode, userblock_size, fapl)

        Group.__init__(self, fid)
Exemplo n.º 3
0
    def __init__(self, _id):
        # super __init__ is handled by DatasetID.__cinit__ automatically
        self._data_dict = None
        with phil:
            sid = self.get_space()
            self._shape = sid.get_simple_extent_dims()
        self._reshaped = False

        attr = h5a.open(self, b'raw_data')
        htype = h5t.py_create(attr.dtype)
        _arr = np.ndarray(attr.shape, dtype=attr.dtype, order='C')
        attr.read(_arr, mtype=htype)
        raw_data_name = _arr[()]
        if isinstance(raw_data_name, bytes):
            raw_data_name = raw_data_name.decode('utf-8')

        fid = h5i.get_file_id(self)
        g = Group(fid)
        self.raw_data = g[raw_data_name]
        self.chunks = tuple(self.raw_data.attrs['chunks'])

        fillvalue_a = np.empty((1,), dtype=self.dtype)
        dcpl = self.get_create_plist()
        dcpl.get_fill_value(fillvalue_a)
        self.fillvalue = fillvalue_a[0]
Exemplo n.º 4
0
Arquivo: files.py Projeto: B-Rich/h5py
 def close(self):
     """ Close the file.  All open objects become invalid """
     with phil:
         # We have to explicitly murder all open objects related to the file
         idlist = h5f.get_obj_ids(self.id)
         idlist = [x for x in idlist if h5i.get_file_id(x).id == self.id.id]
         self.id.close()
         for id_ in idlist:
             while id_.valid:
                 h5i.dec_ref(id_)
         _objects.nonlocal_close()
Exemplo n.º 5
0
 def close(self):
     """ Close the file.  All open objects become invalid """
     with phil:
         # We have to explicitly murder all open objects related to the file
         idlist = h5f.get_obj_ids(self.id)
         idlist = [x for x in idlist if h5i.get_file_id(x).id == self.id.id]
         self.id.close()
         for id_ in idlist:
             while id_.valid:
                 h5i.dec_ref(id_)
         _objects.nonlocal_close()
Exemplo n.º 6
0
    def close(self):
        """ Close the file.  All open objects become invalid """
        with phil:
            # We have to explicitly murder all open objects related to the file

            # Close file-resident objects first, then the files.
            # Otherwise we get errors in MPI mode.
            id_list = h5f.get_obj_ids(self.id, ~h5f.OBJ_FILE)
            file_list = h5f.get_obj_ids(self.id, h5f.OBJ_FILE)

            id_list = [x for x in id_list if h5i.get_file_id(x).id == self.id.id]
            file_list = [x for x in file_list if h5i.get_file_id(x).id == self.id.id]

            for id_ in id_list:
                while id_.valid:
                    h5i.dec_ref(id_)

            for id_ in file_list:
                while id_.valid:
                    h5i.dec_ref(id_)

            self.id.close()
            _objects.nonlocal_close()
Exemplo n.º 7
0
    def __init__(self,
                 name,
                 mode=None,
                 driver=None,
                 libver=None,
                 userblock_size=None,
                 **kwds):
        """Create a new file object.

        See the h5py user guide for a detailed explanation of the options.

        name
            Name of the file on disk.  Note: for files created with the 'core'
            driver, HDF5 still requires this be non-empty.
        driver
            Name of the driver to use.  Legal values are None (default,
            recommended), 'core', 'sec2', 'stdio', 'mpio'.
        libver
            Library version bounds.  Currently only the strings 'earliest'
            and 'latest' are defined.
        userblock
            Desired size of user block.  Only allowed when creating a new
            file (mode w or w-).
        Additional keywords
            Passed on to the selected file driver.
        """
        if isinstance(name, _objects.ObjectID):
            fid = h5i.get_file_id(name)
        else:
            try:
                # If the byte string doesn't match the default
                # encoding, just pass it on as-is.  Note Unicode
                # objects can always be encoded.
                name = name.encode(sys.getfilesystemencoding())
            except (UnicodeError, LookupError):
                pass

            # Read family member size from file when opening existing
            # files with the family driver
            if driver == 'family' and mode in (
                    'r', 'r+') and 'memb_size' not in kwds:
                kwds['memb_size'] = h5f.FAMILY_DEFAULT

            fapl = make_fapl(driver, libver, **kwds)
            fid = make_fid(name, mode, userblock_size, fapl)

        Group.__init__(self, fid)
Exemplo n.º 8
0
    def __init__(self, _id):
        # super __init__ is handled by DatasetID.__cinit__ automatically
        self.data_dict = {}
        with phil:
            sid = self.get_space()
            self._shape = sid.get_simple_extent_dims()

        dcpl = self.get_create_plist()
        # Same as dataset.get_virtual_sources
        virtual_sources = [
            VDSmap(dcpl.get_virtual_vspace(j), dcpl.get_virtual_filename(j),
                   dcpl.get_virtual_dsetname(j), dcpl.get_virtual_srcspace(j))
            for j in range(dcpl.get_virtual_count())
        ]

        slice_map = {
            spaceid_to_slice(i.vspace): spaceid_to_slice(i.src_space)
            for i in virtual_sources
        }

        # slice_map = {i.args[0]: j.args[0] for i, j in slice_map.items()}
        fid = h5i.get_file_id(self)
        g = Group(fid)
        raw_data_name = virtual_sources[0].dset_name
        assert all(i.dset_name == raw_data_name for i in virtual_sources)
        self.raw_data = g[raw_data_name]
        self.chunks = tuple(self.raw_data.attrs['chunks'])

        for s in slice_map:
            src_idx = slice_map[s]
            if isinstance(src_idx, Tuple):
                # The pointers to the raw data should only be slices, since
                # the raw data chunks are extended in the first dimension
                # only.
                assert src_idx != Tuple()
                assert len(src_idx.args) == len(self.chunks)
                src_idx = src_idx.args[0]
            assert isinstance(src_idx, Slice)
            self.data_dict[s] = src_idx

        fillvalue_a = np.empty((1, ), dtype=self.dtype)
        dcpl.get_fill_value(fillvalue_a)
        self.fillvalue = fillvalue_a[0]