How to use the plottr.utils.num.arrays_equal function in plottr

To help you get started, we’ve selected a few plottr 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 data-plottr / plottr / test / pytest / test_data_dict.py View on Github external
a[4:6] = None
    b = np.arange(10).astype(complex)
    b[4] = np.nan

    a_clean = np.hstack((a[:4], a[5:]))
    b_clean = np.hstack((b[:4], b[5:]))

    dd = DataDict(
        a=dict(values=a),
        b=dict(values=b, axes=['a']),
    )

    assert dd.validate()
    dd2 = dd.remove_invalid_entries()
    assert dd2.validate()
    assert num.arrays_equal(dd2.data_vals('a'), a_clean)
    assert num.arrays_equal(dd2.data_vals('b'), b_clean)
github data-plottr / plottr / test / pytest / test_gridder.py View on Github external
assert data.validate()

    fc.setInput(dataIn=data)
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        v1d,
    )

    node.grid = GridOption.guessShape, dict()
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        vv,
    )

    node.grid = GridOption.specifyShape, dict(shape=(5, 5, 2))
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        vv,
    )
github data-plottr / plottr / test / pytest / test_data_dict.py View on Github external
b[3, 0] = np.nan

    a_clean = np.vstack((a[0:1, :], a[2:, :]))
    b_clean = np.vstack((b[0:1, :], b[2:, :]))

    dd = DataDict(
        a=dict(values=a),
        b=dict(values=b, axes=['a']),
    )

    assert dd.validate()
    dd2 = dd.remove_invalid_entries()
    assert dd2.validate()
    assert dd2.shapes() == {'a': (3, 2), 'b': (3, 2)}
    assert num.arrays_equal(dd2.data_vals('a'), a_clean)
    assert num.arrays_equal(dd2.data_vals('b'), b_clean)
github data-plottr / plottr / test / pytest / test_gridder.py View on Github external
x1d, y1d, z1d = xx.flatten(), yy.flatten(), zz.flatten()
    v1d = vv.flatten()

    # construct data dict, with axes for vals not conforming to the
    # correct order with which we've generated the data
    data = DataDict(
        x=dict(values=x1d),
        y=dict(values=y1d),
        z=dict(values=z1d),
        vals=dict(values=v1d, axes=['y', 'z', 'x'])
    )
    assert data.validate()

    # in the 1-d data, nothing unusual should happen
    fc.setInput(dataIn=data)
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        v1d,
    )

    # guessing the grid should work, and fix the wrong order
    node.grid = GridOption.guessShape, dict()
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        vv.transpose((1,2,0)),
    )
    assert fc.outputValues()['dataOut']['vals']['axes'] == ['y', 'z', 'x']

    # finally, specify manually. omitting inner shape doesn't work
    node.grid = GridOption.specifyShape, dict(shape=(5, 2, 5))
    assert fc.outputValues()['dataOut'].data_vals('vals').shape == (5,2,5)
    assert not num.arrays_equal(
github data-plottr / plottr / test / pytest / test_dim_reducer.py View on Github external
fc.setInput(dataIn=data)

    # this should return None, because no x/y axes were set.
    assert fc.outputValues()['dataOut'] is None

    # now select two axes, and test that the other one is correctly selected
    node.xyAxes = ('x', 'y')
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        vals[:,:,0]
    )

    # try a different reduction on the third axis
    node.reductions = {'z': (ReductionMethod.average, [], {})}
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        vals.mean(axis=-1)
    )

    # Test transposing the data by flipping x/y
    node.xyAxes = ('y', 'x')
    assert num.arrays_equal(
        fc.outputValues()['dataOut'].data_vals('vals'),
        vals.mean(axis=-1).transpose((1, 0))
    )
github data-plottr / plottr / test / pytest / test_numtools.py View on Github external
def test_cropping2d():
    """Test basic data cropping of 2d grids"""
    arr = np.arange(16.).reshape(4, 4)
    arr[2:] = np.nan
    data = np.random.rand(4, 4)

    x, y, z = num.crop2d(arr, arr.T, data)
    assert num.arrays_equal(x, arr[:2, :2])
    assert num.arrays_equal(y, arr.T[:2, :2])
    assert num.arrays_equal(z, data[:2, :2])
github data-plottr / plottr / plottr / data / datadict.py View on Github external
# need to revert the type to DataDictBase
            if hasattr(d, 'nrecords') and hasattr(ret, 'nrecords'):
                if d.nrecords() != ret.nrecords():
                    rettype = DataDictBase
            else:
                rettype = DataDictBase
            ret = rettype(**ret)

            # First, parse the axes in the to-be-added ddict.
            # if dimensions with same names are present already in the current
            # return ddict and are not compatible with what's to be added,
            # rename the incoming dimension.
            ax_map = {}
            for d_ax in d.axes():
                if d_ax in ret.axes():
                    if num.arrays_equal(d.data_vals(d_ax), ret.data_vals(d_ax)):
                        ax_map[d_ax] = d_ax
                    else:
                        newax = _find_replacement_name(ret, d_ax)
                        ax_map[d_ax] = newax
                        ret[newax] = d[d_ax]
                elif d_ax in ret.dependents():
                    newax = _find_replacement_name(ret, d_ax)
                    ax_map[d_ax] = newax
                    ret[newax] = d[d_ax]
                else:
                    ax_map[d_ax] = d_ax
                    ret[d_ax] = d[d_ax]

            for d_dep in d.dependents():
                if d_dep in ret:
                    newdep = _find_replacement_name(ret, d_dep)