示例#1
0
    def validate(
            self, pos=None, text=None, anchor=None, data_bounds=None, **kwargs):
        """Validate the requested data before passing it to set_data()."""

        if text is None:
            text = []
        if isinstance(text, str):
            text = [text]
        if pos is None:
            pos = np.zeros((len(text), 2))

        assert pos is not None
        pos = np.atleast_2d(pos)
        assert pos.ndim == 2
        assert pos.shape[1] == 2
        n_text = pos.shape[0]
        assert len(text) == n_text

        anchor = anchor if anchor is not None else (0., 0.)
        anchor = np.atleast_2d(anchor)
        if anchor.shape[0] == 1:
            anchor = np.repeat(anchor, n_text, axis=0)
        assert anchor.ndim == 2
        assert anchor.shape == (n_text, 2)

        data_bounds = data_bounds if data_bounds is not None else NDC
        data_bounds = _get_data_bounds(data_bounds, pos)
        assert data_bounds.shape[0] == n_text
        data_bounds = data_bounds.astype(np.float64)
        assert data_bounds.shape == (n_text, 4)

        return Bunch(
            pos=pos, text=text, anchor=anchor, data_bounds=data_bounds,
            _n_items=n_text, _n_vertices=self.vertex_count(text=text))
示例#2
0
    def validate(
            self, x=None, y=None, color=None, depth=None, masks=None, data_bounds=None, **kwargs):
        """Validate the requested data before passing it to set_data()."""

        assert y is not None
        y = _as_list(y)

        if x is None:
            x = [np.linspace(-1., 1., len(_)) for _ in y]
        x = _as_list(x)

        # Remove empty elements.
        assert len(x) == len(y)

        assert [len(_) for _ in x] == [len(_) for _ in y]

        n_signals = len(x)

        if isinstance(data_bounds, str) and data_bounds == 'auto':
            xmin = [_min(_) for _ in x]
            ymin = [_min(_) for _ in y]
            xmax = [_max(_) for _ in x]
            ymax = [_max(_) for _ in y]
            data_bounds = np.c_[xmin, ymin, xmax, ymax]

        color = _get_array(color, (n_signals, 4),
                           PlotVisual.default_color,
                           dtype=np.float32,
                           )
        assert color.shape == (n_signals, 4)

        masks = _get_array(masks, (n_signals, 1), 1., np.float32)
        # The mask is clu_idx + fractional mask
        masks *= .99999
        assert masks.shape == (n_signals, 1)

        depth = _get_array(depth, (n_signals, 1), 0)
        assert depth.shape == (n_signals, 1)

        if data_bounds is not None:
            data_bounds = _get_data_bounds(data_bounds, length=n_signals)
            data_bounds = data_bounds.astype(np.float64)
            assert data_bounds.shape == (n_signals, 4)

        return Bunch(
            x=x, y=y, color=color, depth=depth, data_bounds=data_bounds, masks=masks,
            _n_items=n_signals, _n_vertices=self.vertex_count(y=y))
示例#3
0
    def validate(self, pos=None, data_bounds=None, **kwargs):
        """Validate the requested data before passing it to set_data()."""
        assert pos is not None
        pos = np.atleast_2d(pos)
        assert pos.ndim == 2
        assert pos.shape[1] == 2

        # By default, we assume that the coordinates are in NDC.
        if data_bounds is None:
            data_bounds = NDC
        data_bounds = _get_data_bounds(data_bounds)
        data_bounds = data_bounds.astype(np.float64)
        assert data_bounds.shape == (1, 4)

        return Bunch(
            pos=pos, data_bounds=data_bounds,
            _n_items=pos.shape[0], _n_vertices=self.vertex_count(pos=pos))
示例#4
0
    def validate(self, pos=None, color=None, data_bounds=None, **kwargs):
        """Validate the requested data before passing it to set_data()."""
        assert pos is not None
        pos = _as_array(pos)
        pos = np.atleast_2d(pos)
        assert pos.ndim == 2
        n_lines = pos.shape[0]
        assert pos.shape[1] == 4

        # Color.
        color = _get_array(color, (n_lines, 4), LineVisual.default_color)

        # By default, we assume that the coordinates are in NDC.
        if data_bounds is None:
            data_bounds = NDC
        data_bounds = _get_data_bounds(data_bounds, length=n_lines)
        data_bounds = data_bounds.astype(np.float64)
        assert data_bounds.shape == (n_lines, 4)

        return Bunch(
            pos=pos, color=color, data_bounds=data_bounds,
            _n_items=n_lines, _n_vertices=self.vertex_count(pos=pos))
示例#5
0
    def validate(self, x=None, y=None, pos=None, masks=None, data_bounds=None, **kwargs):
        """Validate the requested data before passing it to set_data()."""
        if pos is None:
            x, y = _get_pos(x, y)
            pos = np.c_[x, y]
        pos = np.asarray(pos)
        assert pos.ndim == 2
        assert pos.shape[1] == 2
        n = pos.shape[0]

        masks = _get_array(masks, (n, 1), 1., np.float32)
        assert masks.shape == (n, 1)

        # The mask is clu_idx + fractional mask
        masks *= .99999

        # Validate the data.
        if data_bounds is not None:
            data_bounds = _get_data_bounds(data_bounds, pos)
            assert data_bounds.shape[0] == n

        return Bunch(pos=pos, masks=masks, data_bounds=data_bounds, _n_items=n, _n_vertices=n)
示例#6
0
def test_get_data_bounds():
    ae(_get_data_bounds(None), [[-1., -1., 1., 1.]])

    db0 = np.array([[0, 1, 4, 5],
                    [0, 1, 4, 5],
                    [0, 1, 4, 5]])
    arr = np.arange(6).reshape((3, 2))
    assert np.all(_get_data_bounds(None, arr) == [[0, 1, 4, 5]])

    db = db0.copy()
    assert np.all(_get_data_bounds(db, arr) == [[0, 1, 4, 5]])

    db = db0.copy()
    db[2, :] = [1, 1, 1, 1]
    assert np.all(_get_data_bounds(db, arr)[:2, :] == [[0, 1, 4, 5]])
    assert np.all(_get_data_bounds(db, arr)[2, :] == [0, 0, 2, 2])

    db = db0.copy()
    db[:2, :] = [1, 1, 1, 1]
    assert np.all(_get_data_bounds(db, arr)[:2, :] == [[0, 0, 2, 2]])
    assert np.all(_get_data_bounds(db, arr)[2, :] == [0, 1, 4, 5])
示例#7
0
    def validate(
            self, x=None, y=None, pos=None, color=None, size=None, depth=None,
            data_bounds=None, **kwargs):
        """Validate the requested data before passing it to set_data()."""
        if pos is None:
            x, y = _get_pos(x, y)
            pos = np.c_[x, y]
        pos = np.asarray(pos)
        assert pos.ndim == 2
        assert pos.shape[1] == 2
        n = pos.shape[0]

        # Validate the data.
        color = _get_array(color, (n, 4), ScatterVisual.default_color, dtype=np.float32)
        size = _get_array(size, (n, 1), ScatterVisual.default_marker_size)
        depth = _get_array(depth, (n, 1), 0)
        if data_bounds is not None:
            data_bounds = _get_data_bounds(data_bounds, pos)
            assert data_bounds.shape[0] == n

        return Bunch(
            pos=pos, color=color, size=size, depth=depth, data_bounds=data_bounds,
            _n_items=n, _n_vertices=n)