How to use the h5pyd._hl.selections.Selection function in h5pyd

To help you get started, we’ve selected a few h5pyd 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 HDFGroup / h5pyd / h5pyd / _hl / selections.py View on Github external
return N//N_leftover


    shape = tuple(get_n_axis(sid, x) for x in range(rank))

    if np.product(shape) != N:
        # This means multiple hyperslab selections are in effect,
        # so we fall back to a 1D shape
        return (N,)

    return shape




class ScalarSelection(Selection):

    """
        Implements slicing for scalar datasets.
    """

    @property
    def mshape(self):
        return self._mshape


    def __init__(self, shape,  *args, **kwds):
        Selection.__init__(self, shape, *args, **kwds)
        arg = None
        if len(args) > 0:
            arg = args[0]
        if arg == ():
github HDFGroup / h5pyd / h5pyd / _hl / selections.py View on Github external
def __init__(self, shape,  *args, **kwds):
        Selection.__init__(self, shape, *args, **kwds)
        arg = None
        if len(args) > 0:
            arg = args[0]
        if arg == ():
            self._mshape = None
            self._select_type = H5S_SELECT_ALL
        elif arg == (Ellipsis,):
            self._mshape = ()
            self._select_type = H5S_SELECT_ALL
        else:
            raise ValueError("Illegal slicing argument for scalar dataspace")
github HDFGroup / h5pyd / h5pyd / _hl / selections.py View on Github external
chunks = tuple(x//y for x, y in zip(count, tshape))
        nchunks = int(np.product(chunks))

        if nchunks == 1:
            yield self._id
        else:
            sid = self._id.copy()
            sid.select_hyperslab((0,)*rank, tshape, step)
            for idx in range(nchunks):
                offset = tuple(x*y*z + s for x, y, z, s in zip(np.unravel_index(idx, chunks), tshape, step, start))
                sid.offset_simple(offset)
                yield sid


class FancySelection(Selection):

    """
        Implements advanced NumPy-style selection operations in addition to
        the standard slice-and-int behavior.

        Indexing arguments may be ints, slices, lists of indicies, or
        per-axis (1D) boolean arrays.

        Broadcasting is not supported for these selections.
    """

    @property
    def mshape(self):
        return self._mshape

    @property
github HDFGroup / h5pyd / h5pyd / _hl / selections.py View on Github external
# TBD - handle NULL Space object

    if obj.shape == ():
        # scalar object
        sel = ScalarSelection(obj.shape, args)
        return sel


    #print("select, len(args):", len(args))
    # "Special" indexing objects
    if len(args) == 1:

        arg = args[0]

        if isinstance(arg, Selection):
            if arg.shape != obj.shape:
                raise TypeError("Mismatched selection shape")
            return arg

        elif isinstance(arg, np.ndarray) or isinstance(arg, list):
            sel = PointSelection(obj.shape)
            sel[arg]
            return sel
        """
        #todo - RegionReference
        elif isinstance(arg, h5r.RegionReference):
            sid = h5r.get_region(arg, dsid)
            if shape != sid.shape:
                raise TypeError("Reference shape does not match dataset shape")

            return Selection(shape, spaceid=sid)
github HDFGroup / h5pyd / h5pyd / _hl / selections.py View on Github external
npoints *= nextent
        else:
            raise IOError("Unsupported select type")
        return npoints


    def broadcast(self, target_shape):
        """ Get an iterable for broadcasting """
        if np.product(target_shape) != self.nselect:
            raise TypeError("Broadcasting is not supported for point-wise selections")
        yield self._id

    def __getitem__(self, args):
        raise NotImplementedError("This class does not support indexing")

class PointSelection(Selection):

    """
        Represents a point-wise selection.  You can supply sequences of
        points to the three methods append(), prepend() and set(), or a
        single boolean array to __getitem__.
    """
    def __init__(self, shape,  *args, **kwds):
        """ Create a Point selection.   """
        Selection.__init__(self, shape, *args, **kwds)
        self._points = []

    @property
    def points(self):
        """ selection points """
        return self._points
github HDFGroup / h5pyd / h5pyd / _hl / selections.py View on Github external
self._perform_selection(points, H5S_SELECT_PREPEND)

    def set(self, points):
        """ Replace the current selection with the given sequence of points"""
        """
        if isinstance(points, list):
            # selection with list of points
            self._perform_list_selection(points, H5S_SELECT_SET)

        else:
            # selection with boolean ndarray
        """
        self._perform_selection(points, H5S_SELECT_SET)


class SimpleSelection(Selection):

    """ A single "rectangular" (regular) selection composed of only slices
        and integer arguments.  Can participate in broadcasting.
    """

    @property
    def mshape(self):
        """ Shape of current selection """
        return self._mshape

    @property
    def start(self):
        return self._sel[0]

    @property
    def count(self):