How to use the plottr.data.datadict.DataDict 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 / gui / lineplot.py View on Github external
def processData(self):
        _data = self.getInputData()

        data = DataDict()
        for k in self.traceNames:
            data[k] = _data.get(k)
        if self.xaxisName in _data:
            data[self.xaxisName] = _data[self.xaxisName]

        return data
github data-plottr / plottr / test / gui / test_data.py View on Github external
def two_compatible_noisy_2d_sets(nx=10, ny=10):
    x = np.linspace(0, 10, nx)
    y = np.arange(ny)

    xx, yy = np.meshgrid(x, y, indexing='ij')
    dd = np.cos(xx) + (-0.05 + 0.1 * np.random.rand(*yy.shape))
    dd2 = np.sin(xx) + (-0.5 + 1 * np.random.rand(*yy.shape))

    d = DataDict(
        x = dict(values=xx.reshape(-1)),
        y = dict(values=yy.reshape(-1)),
        cos_data = dict(values=dd.reshape(-1), axes=['x', 'y']),
        sin_data = dict(values=dd2.reshape(-1), axes=['x', 'y']),
    )
    return d
github data-plottr / plottr / test / pytest / test_data_dict.py View on Github external
def test_shape_guessing_simple():
    """test whether we can infer shapes correctly"""

    a = np.linspace(0, 1, 11)
    b = np.arange(5)
    aa, bb = np.meshgrid(a, b, indexing='ij')
    zz = aa * bb

    dd = DataDict(
        a=dict(values=aa.reshape(-1)),
        b=dict(values=bb.reshape(-1)),
        z=dict(values=zz.reshape(-1), axes=['a', 'b'])
    )

    assert guess_shape_from_datadict(dd) == dict(z=(['a', 'b'], (11, 5)))

    dd['a']['values'][5] = None
    dd['a']['values'][10] = np.nan
    assert guess_shape_from_datadict(dd) == dict(z=(['a', 'b'], (11, 5)))

    # non-uniform
    # noise on the coordinates should not result in failing as long as it
    # keeps monotonicity in the sweep axes
    dd['a']['values'] = (aa + np.random.rand(a.size).reshape(a.size, 1)
                         * 1e-3).reshape(-1)
github data-plottr / plottr / test / gui / test_data.py View on Github external
def three_compatible_3d_sets(nx=3, ny=3, nz=3, rand_factor=1):
    x = np.linspace(0, 10, nx)
    y = np.linspace(-5, 5, ny)
    z = np.arange(nz)
    xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
    dd = np.cos(xx) * np.sin(yy) + rand_factor * np.random.rand(*zz.shape)
    dd2 = np.sin(xx) * np.cos(yy) + rand_factor * np.random.rand(*zz.shape)
    dd3 = np.cos(xx)**2 * np.cos(yy)**2 + rand_factor * np.random.rand(*zz.shape)

    d = DataDict(
        x = dict(values=xx.reshape(-1), unit='mA'),
        y = dict(values=yy.reshape(-1), unit='uC'),
        z = dict(values=zz.reshape(-1), unit='nF'),
        data = dict(values=dd.reshape(-1), axes=['x', 'y', 'z'], unit='kW'),
        more_data = dict(values=dd2.reshape(-1), axes=['x', 'y', 'z'], unit='MV'),
        different_data = dict(values=dd3.reshape(-1), axes=['x', 'y', 'z'], unit='TS')
    )
    return d
github data-plottr / plottr / test / pytest / test_ddh5.py View on Github external
def test_basic_storage_and_retrieval():
    x = np.arange(3)
    y = np.repeat(np.linspace(0, 1, 5).reshape(1, -1), 3, 0)
    z = np.arange(y.size).reshape(y.shape)

    data = dd.DataDict(
        x=dict(values=x, unit='A',
               __info__='careful!',
               __moreinfo__='more words in here'),
        y=dict(values=y, unit='B'),
        z=dict(values=z, axes=['x', 'y'], unit='C'),
        __desc__='some description',
    )
    assert data.validate()

    dds.datadict_to_hdf5(data, FN, append_mode=dds.AppendMode.none)
    datafromfile = dds.datadict_from_hdf5(FN)

    # hdf5 saving added a few extra metas that we need to ignore when
    # comparing
    datafromfile = _clean_from_file(datafromfile)
    assert(data == datafromfile)
github data-plottr / plottr / plottr / utils / testdata.py View on Github external
def one_2d_set(nx=10, ny=10):
    x = np.linspace(0, 10, nx)
    y = np.arange(ny)

    xx, yy = np.meshgrid(x, y, indexing='ij')
    dd = np.cos(xx) + (-0.05 + 0.1 * np.random.rand(*yy.shape))

    d = DataDict(
        x=dict(values=xx.reshape(-1)),
        y=dict(values=yy.reshape(-1)),
        cos_data=dict(values=dd.reshape(-1), axes=['x', 'y']),
    )
    d.validate()
    return d
github data-plottr / plottr / test / pytest / test_gridder.py View on Github external
DataGridder.uiClass = None

    fc = linearFlowchart(('grid', DataGridder))
    node = fc.nodes()['grid']

    x = np.arange(5.0)
    y = np.linspace(0, 1, 5)
    z = np.arange(4.0, 6.0, 1.0)
    xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
    vv = xx * yy * zz
    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()
github data-plottr / plottr / plottr / node / grid.py View on Github external
def process(self, **kw):
        data = kw['dataIn']
        if data is None:
            return None

        data = super().process(**kw)
        if data is None:
            return None
        data = data['dataOut'].copy()
        self.axesList.emit(data.axes())

        dout = None
        method, opts = self._grid

        if isinstance(data, DataDict):
            if method is GridOption.noGrid:
                dout = data.expand()
            elif method is GridOption.guessShape:
                dout = dd.datadict_to_meshgrid(data)
            elif method is GridOption.specifyShape:
                dout = dd.datadict_to_meshgrid(data, target_shape=opts['shape'])

        elif isinstance(data, MeshgridDataDict):
            if method is GridOption.noGrid:
                dout = dd.meshgrid_to_datadict(data)
            elif method is GridOption.guessShape:
                dout = data
            elif method is GridOption.specifyShape:
                self.logger().warning(
                    f"Data is already on grid. Ignore shape.")
                dout = data
github data-plottr / plottr / doc / examples / data.py View on Github external
def two_compatible_noisy_2d_sets(nx=10, ny=10):
    x = np.linspace(0, 10, nx)
    y = np.arange(ny)

    xx, yy = np.meshgrid(x, y, indexing='ij')
    dd = np.cos(xx) + (-0.05 + 0.1 * np.random.rand(*yy.shape))
    dd2 = np.sin(xx) + (-0.5 + 1 * np.random.rand(*yy.shape))

    d = DataDict(
        x = dict(values=xx.reshape(-1)),
        y = dict(values=yy.reshape(-1)),
        cos_data = dict(values=dd.reshape(-1), axes=['x', 'y']),
        sin_data = dict(values=dd2.reshape(-1), axes=['x', 'y']),
    )
    return d
github data-plottr / plottr / plottr / plot / mpl.py View on Github external
# * too few or too many independents
    if len(data.axes()) < 1 or len(data.axes()) > 2:
        return PlotDataType.unknown

    # * no data to plot
    if len(data.dependents()) == 0:
        return PlotDataType.unknown

    if isinstance(data, MeshgridDataDict):
        if len(data.axes()) == 2:
            return PlotDataType.grid2d
        else:
            return PlotDataType.line1d

    elif isinstance(data, DataDict):
        if len(data.axes()) == 2:
            return PlotDataType.scatter2d
        else:
            return PlotDataType.scatter1d

    return PlotDataType.unknown