How to use the h5py.h5s function in h5py

To help you get started, we’ve selected a few h5py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yt-project / yt / yt / frontends / enzo / io.py View on Github external
for g in chunk.objs:
                if g.filename is None: continue
                if fid is None:
                    fid = h5py.h5f.open(g.filename.encode('ascii'), h5py.h5f.ACC_RDONLY)
                data = np.empty(g.ActiveDimensions[::-1], dtype="float64")
                data_view = data.swapaxes(0,2)
                nd = 0
                for field in fields:
                    ftype, fname = field
                    try:
                        node = "/Grid%08i/%s" % (g.id, fname)
                        dg = h5py.h5d.open(fid, node.encode('ascii'))
                    except KeyError:
                        if fname == "Dark_Matter_Density": continue
                        raise
                    dg.read(h5py.h5s.ALL, h5py.h5s.ALL, data)
                    nd = g.select(selector, data_view, rv[field], ind) # caches
                ind += nd
            if fid: fid.close()
        return rv
github h5py / h5py / h5py / _hl / selections.py View on Github external
def append(self, points):
        """ Add the sequence of points to the end of the current selection """
        self._perform_selection(points, h5s.SELECT_APPEND)
github HDFGroup / h5serv / server / hdf5db.py View on Github external
objid = h5py.h5r.dereference(regionRef, self.f.file.file.id)
        if objid:
            item['id'] = self.getUUIDByAddress(h5py.h5o.get_info(objid).addr)
        else:
                log.info("region reference unable able to find item with objid: " + objid)
                return item
            
        sel = h5py.h5r.get_region(regionRef, objid)  
        select_type = sel.get_select_type()
        if select_type not in selectionEnums:
            msg = "Unexpected selection type: " + regionRef.typecode
            self.log.error(msg)
            raise IOError(errno.EIO, msg)
        item['select_type'] = selectionEnums[select_type]
        pointlist = None
        if select_type == h5py.h5s.SEL_POINTS:
            # retrieve a numpy array of selection points
            points = sel.get_select_elem_pointlist()   
            pointlist = points.tolist()   
        elif select_type == h5py.h5s.SEL_HYPERSLABS:
            points = sel.get_select_hyper_blocklist()        
            if points is not None:
                pointlist = points[...].tolist()
                # bump up the second coordinate by one to match api spec
                for point in pointlist:
                    coord2 = point[1]
                    for i in range(len(coord2)):
                        coord2[i] = coord2[i] + 1
                    
        item['selection'] = pointlist    
        
        return item
github h5py / h5py / h5py / _hl / selections.py View on Github external
def __init__(self, shape, spaceid=None):
        """ Create a selection.  Shape may be None if spaceid is given. """
        if spaceid is not None:
            self._id = spaceid
            self._shape = spaceid.shape
        else:
            shape = tuple(shape)
            self._shape = shape
            self._id = h5s.create_simple(shape, (h5s.UNLIMITED,)*len(shape))
            self._id.select_all()
github HDFGroup / h5serv / server / hdf5db.py View on Github external
def createRegionReference(self, item):
        selectionEnums = { 'H5S_SEL_NONE': h5py.h5s.SEL_NONE,
                           'H5S_SEL_ALL': h5py.h5s.SEL_ALL, 
                           'H5S_SEL_POINTS': h5py.h5s.SEL_POINTS,
                           'H5S_SEL_HYPERSLABS': h5py.h5s.SEL_HYPERSLABS 
                          }
        region_ref = None
                          
        if 'select_type' not in item:
            msg = "select_type not provided for region selection"
            self.log.info(msg)
            raise IOError(errno.EINVAL, msg)
        select_type = item['select_type']
        if select_type not in selectionEnums.keys():
            msg = "selection type: [" + select_type + "] is not valid"
            self.log.info(msg)
            raise IOError(errno.EINVAL, msg)
        dset = None
github HDFGroup / hdf5-json / h5json / hdf5db.py View on Github external
if strLength < len(value):
            self.log.warning("makeNullTermStringAttribute: value string longer than length")
            #value = value[:strLength]  # truncate to length
        
        
        if six.PY3 and type(attr_name) is str:    
            try:
                attr_name = attr_name.encode('ascii')
            except UnicodeDecodeError:
                raise TypeError("non-ascii attribute name not allowed")

        # create the attribute
        tid = h5py.h5t.TypeID.copy(h5py.h5t.C_S1)
        tid.set_size(strLength)
        tid.set_strpad(h5py.h5t.STR_NULLTERM)
        sid = h5py.h5s.create(h5py.h5s.SCALAR)
        aid = h5py.h5a.create(obj.id, attr_name, tid, sid)
        # write the value
        dtype_code = 'S' + str(strLength)
        ndarr = np.array(value, dtype=np.dtype(dtype_code))
        aid.write(ndarr)
github h5py / h5py / h5py / _hl / dataset.py View on Github external
dcpl.set_obj_track_times(track_times)
    elif track_times is not None:
        raise TypeError("track_times must be either True or False")
    if track_order == True:
        dcpl.set_attr_creation_order(
            h5p.CRT_ORDER_TRACKED | h5p.CRT_ORDER_INDEXED)
    elif track_order == False:
        dcpl.set_attr_creation_order(0)
    elif track_order is not None:
        raise TypeError("track_order must be either True or False")

    if maxshape is not None:
        maxshape = tuple(m if m is not None else h5s.UNLIMITED for m in maxshape)

    if isinstance(data, Empty):
        sid = h5s.create(h5s.NULL)
    else:
        sid = h5s.create_simple(shape, maxshape)


    dset_id = h5d.create(parent.id, None, tid, sid, dcpl=dcpl)

    if (data is not None) and (not isinstance(data, Empty)):
        dset_id.write(h5s.ALL, h5s.ALL, data)

    return dset_id
github HDFGroup / h5serv / server / hdf5db.py View on Github external
log.info("region reference unable able to find item with objid: " + objid)
                return item
            
        sel = h5py.h5r.get_region(regionRef, objid)  
        select_type = sel.get_select_type()
        if select_type not in selectionEnums:
            msg = "Unexpected selection type: " + regionRef.typecode
            self.log.error(msg)
            raise IOError(errno.EIO, msg)
        item['select_type'] = selectionEnums[select_type]
        pointlist = None
        if select_type == h5py.h5s.SEL_POINTS:
            # retrieve a numpy array of selection points
            points = sel.get_select_elem_pointlist()   
            pointlist = points.tolist()   
        elif select_type == h5py.h5s.SEL_HYPERSLABS:
            points = sel.get_select_hyper_blocklist()        
            if points is not None:
                pointlist = points[...].tolist()
                # bump up the second coordinate by one to match api spec
                for point in pointlist:
                    coord2 = point[1]
                    for i in range(len(coord2)):
                        coord2[i] = coord2[i] + 1
                    
        item['selection'] = pointlist    
        
        return item
github ratschlab / spladder / matlab / modules / hdf5.py View on Github external
else:
                    ret[i, j] = sp.empty(dref.shape, dtype=dref.dtype)
                    dref.read(h5py.h5s.ALL, h5py.h5s.ALL, ret[i, j])
                    ret[i, j] = ret[i, j].T
                if isinstance(ret[i, j], sp.ndarray):
                    shp = ret[i, j].shape
                    if len(shp) == 2 and isinstance(ret[i, j][0, 0], h5py.h5r.Reference):
                        ret[i, j] = deref_array(ret[i, j], file)
                    elif len(shp) == 1 and isinstance(ret[i, j][0], h5py.h5r.Reference):
                        ret[i, j] = deref_array(ret[i, j], file)
    else:
        for i in xrange(data.shape[0]):
            ref = data[i]
            dref = h5py.h5r.dereference(ref, file._id)
            ret[i] = sp.empty(dref.shape, dtype=dref.dtype)
            dref.read(h5py.h5s.ALL, h5py.h5s.ALL, ret[i])
            ret[i] = ret[i].T
            if isinstance(ret[i], sp.ndarray):
                shp = ret[i].shape
                if len(shp) == 2 and isinstance(ret[i][0, 0], h5py.h5r.Reference):
                    ret[i] = deref_array(ret[i], file)
                elif len(shp) == 1 and isinstance(ret[i][0], h5py.h5r.Reference):
                    ret[i] = deref_array(ret[i], file)
    return ret