How to use the gr.__init__.floatarray function in gr

To help you get started, we’ve selected a few gr 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 sciapp / python-gr / gr / __init__.py View on Github external
def gridit(xd, yd, zd, nx, ny):
    nd = _assertEqualLength(xd, yd, zd)
    _xd = floatarray(nd, xd)
    _yd = floatarray(nd, yd)
    _zd = floatarray(nd, zd)
    x = (c_double * nx)()
    y = (c_double * ny)()
    z = (c_double * (nx * ny))()
    __gr.gr_gridit(c_int(nd), _xd.data, _yd.data, _zd.data,
                   c_int(nx), c_int(ny), x, y, z)
    return [x[:], y[:], z[:]]
github sciapp / python-gr / gr / __init__.py View on Github external
`colors` :
        A list of RGB tuples containing the normalized color intensities
    `positions` :
        An optional list of length `len(colors)` containing the normalized positions where the corresponding colors
        are applied. The first element must be 0.0, the last element 1.0.

    If no `positions` are given the `colors` are evenly distributed in the linear interpolated colormap.
    Otherwise the values of `positions` define the particular position of the color in the colormap.
    """
    if positions:
        n = _assertEqualLength(colors, positions)
        _positions = floatarray(n, positions)
    else:
        n = len(colors)
        _positions = None
    _red = floatarray(n, [c[0] for c in colors])
    _green = floatarray(n, [c[1] for c in colors])
    _blue = floatarray(n, [c[2] for c in colors])
    __gr.gr_setcolormapfromrgb(c_int(n), _red.data, _green.data, _blue.data, _positions.data if _positions else None)
github sciapp / python-gr / gr / __init__.py View on Github external
| INTERP2_LINEAR  | 1 | Linear interpolation                      |
    +-----------------+---+-------------------------------------------+
    | INTERP_2_SPLINE | 2 | Interpolation using natural cubic splines |
    +-----------------+---+-------------------------------------------+
    | INTERP2_CUBIC   | 3 | Cubic interpolation                       |
    +-----------------+---+-------------------------------------------+

    """
    nx = len(x)
    ny = len(y)
    nz = len(z)
    nxq = len(xq)
    nyq = len(yq)
    _x = floatarray(nx, x)
    _y = floatarray(ny, y)
    _z = floatarray(nz, z)
    _xq = floatarray(nxq, xq)
    _yq = floatarray(nyq, yq)
    zq = empty([nxq, nyq], dtype=float64)
    __gr.gr_interp2(c_int(nx), c_int(ny), _x.data, _y.data, _z.data, c_int(nxq), c_int(nyq), _xq.data, _yq.data, zq.ctypes.data_as(POINTER(c_double)), c_int(method), c_double(extrapval))
    if flatten:
        zq.shape = prod(zq.shape)
    return zq
github sciapp / python-gr / gr / __init__.py View on Github external
+-----------------+---+-------------------------------------------+
    | INTERP2_LINEAR  | 1 | Linear interpolation                      |
    +-----------------+---+-------------------------------------------+
    | INTERP_2_SPLINE | 2 | Interpolation using natural cubic splines |
    +-----------------+---+-------------------------------------------+
    | INTERP2_CUBIC   | 3 | Cubic interpolation                       |
    +-----------------+---+-------------------------------------------+

    """
    nx = len(x)
    ny = len(y)
    nz = len(z)
    nxq = len(xq)
    nyq = len(yq)
    _x = floatarray(nx, x)
    _y = floatarray(ny, y)
    _z = floatarray(nz, z)
    _xq = floatarray(nxq, xq)
    _yq = floatarray(nyq, yq)
    zq = empty([nxq, nyq], dtype=float64)
    __gr.gr_interp2(c_int(nx), c_int(ny), _x.data, _y.data, _z.data, c_int(nxq), c_int(nyq), _xq.data, _yq.data, zq.ctypes.data_as(POINTER(c_double)), c_int(method), c_double(extrapval))
    if flatten:
        zq.shape = prod(zq.shape)
    return zq
github sciapp / python-gr / gr / __init__.py View on Github external
`x` :
        A list containing the X coordinates
    `y` :
        A list containing the Y coordinates
    `z` :
        A list containing the Z coordinates
    `levels` :
        A list containing the contour levels

    """
    nx = len(px)
    ny = len(py)
    nz = len(pz)
    nlevels = len(levels)
    _px = floatarray(nx, px)
    _py = floatarray(ny, py)
    _pz = floatarray(nz, pz)
    _levels = floatarray(nlevels, levels)
    n = min(nx, ny, nz)
    __gr.gr_tricontour(c_int(n), _px.data, _py.data, _pz.data, c_int(nlevels), _levels.data)
github sciapp / python-gr / gr / __init__.py View on Github external
ny = len(py)
    nz = len(pz)
    nh = len(h)
    if isinstance(pz, ndarray):
        if len(pz.shape) == 1:
            out_of_bounds = nz != nx * ny
        elif len(pz.shape) == 2:
            out_of_bounds = pz.shape[0] != nx or pz.shape[1] != ny
        else:
            out_of_bounds = True
    else:
        out_of_bounds = nz != nx * ny
    if not out_of_bounds:
        _px = floatarray(nx, px)
        _py = floatarray(ny, py)
        _h = floatarray(nh, h)
        _pz = floatarray(nz, pz)
        __gr.gr_contour(c_int(nx), c_int(ny), c_int(nh),
                        _px.data, _py.data, _h.data, _pz.data, c_int(major_h))
    else:
        raise AttributeError("Sequences have incorrect length or dimension.")
github sciapp / python-gr / gr / __init__.py View on Github external
def hexbin(x, y, nbins):
    n = _assertEqualLength(x, y)
    _x = floatarray(n, x)
    _y = floatarray(n, y)
    return __gr.gr_hexbin(c_int(n), _x.data, _y.data, c_int(nbins))
github sciapp / python-gr / gr / __init__.py View on Github external
out_of_bounds = nz != nx * ny
        elif len(pz.shape) == 2:
            out_of_bounds = pz.shape[0] != nx or pz.shape[1] != ny
        else:
            out_of_bounds = True
    else:
        out_of_bounds = nz != nx * ny
    if not out_of_bounds:
        _px = floatarray(nx, px)
        _py = floatarray(ny, py)
        _pz = floatarray(nz, pz)
        if major_h:
            z_min, z_max, rotation, tilt = inqspace()
            setspace(np.min(pz), np.max(pz), 0, 90)
        if h:
            _h = floatarray(nh, h)
            __gr.gr_contourf(c_int(nx), c_int(ny), c_int(nh),
                             _px.data, _py.data, _h.data, _pz.data, c_int(major_h))
        else:
            __gr.gr_contourf(c_int(nx), c_int(ny), c_int(nh),
                             _px.data, _py.data, None, _pz.data, c_int(major_h))
        if major_h:
            setspace(z_min, z_max, rotation, tilt)
    else:
        raise AttributeError("Sequences have incorrect length or dimension.")
github sciapp / python-gr / gr / __init__.py View on Github external
def hexbin(x, y, nbins):
    n = _assertEqualLength(x, y)
    _x = floatarray(n, x)
    _y = floatarray(n, y)
    return __gr.gr_hexbin(c_int(n), _x.data, _y.data, c_int(nbins))
github sciapp / python-gr / gr / __init__.py View on Github external
`y` :
        A list containing the Y coordinates
    `u` :
        A list containing the U component for each point on the grid
    `v` :
        A list containing the V component for each point on the grid
    `color` :
        A bool to indicate whether or not the arrows should be colored using
        the current colormap

    The values for `x` and `y` are in world coordinates.
    """
    _x = floatarray(nx, x)
    _y = floatarray(ny, y)
    _u = floatarray(nx * ny, u)
    _v = floatarray(nx * ny, v)
    __gr.gr_quiver(c_int(nx), c_int(ny), _x.data, _y.data, _u.data, _v.data, c_int(1 if color else 0))