예제 #1
0
def simple_2d_plot():
    app = QtGui.QApplication([])
    win = PlotWindow()
    plot = AutoPlot(parent=win)
    win.plot.setPlotWidget(plot)
    win.show()

    # plotting 1d traces
    if False:
        logger.info(f"1D trace")
        t0 = time.perf_counter()
        nsamples = 30
        for i in range(nsamples):
            data = datadict_to_meshgrid(
                testdata.get_1d_scalar_cos_data(201, 2)
            )
            win.plot.setData(data)
        t1 = time.perf_counter()
        fps = nsamples/(t1-t0)
        logger.info(f"Performance: {fps} FPS")

    # plotting images
    if True:
        logger.info(f"2D image")
        t0 = time.perf_counter()
        nsamples = 30
        for i in range(nsamples):
            data = datadict_to_meshgrid(
                testdata.get_2d_scalar_cos_data(201, 101, 1)
            )
            win.plot.setData(data)
        t1 = time.perf_counter()
        fps = nsamples/(t1-t0)
        logger.info(f"Performance: {fps} FPS")

    # plotting 2d scatter
    if False:
        logger.info(f"2D scatter")
        t0 = time.perf_counter()
        nsamples = 30
        for i in range(nsamples):
            data = testdata.get_2d_scalar_cos_data(21, 21, 1)
            win.plot.setData(data)
        t1 = time.perf_counter()
        fps = nsamples/(t1-t0)
        logger.info(f"Performance: {fps} FPS")

    return app.exec_()
예제 #2
0
def test_meshgrid_conversion():
    """Test making a meshgrid from a dataset"""

    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']),
        __info__='some info',
    )

    dd2 = datadict_to_meshgrid(dd, target_shape=(11, 5))
    assert DataDictBase.same_structure(dd, dd2)
    assert num.arrays_equal(dd2.data_vals('a'), aa)
    assert num.arrays_equal(dd2.data_vals('z'), zz)

    dd2 = datadict_to_meshgrid(dd, target_shape=None)
    assert DataDictBase.same_structure(dd, dd2)
    assert num.arrays_equal(dd2.data_vals('a'), aa)
    assert num.arrays_equal(dd2.data_vals('z'), zz)

    # test the case where inner/outer
    aa, bb = np.meshgrid(a, b, indexing='xy')
    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']),
        __info__='some info',
    )

    dd2 = datadict_to_meshgrid(dd,
                               target_shape=(5, 11),
                               inner_axis_order=['b', 'a'])
    assert DataDictBase.same_structure(dd, dd2)
    assert num.arrays_equal(dd2.data_vals('a'), np.transpose(aa, (1, 0)))
    assert num.arrays_equal(dd2.data_vals('z'), np.transpose(zz, (1, 0)))

    dd2 = datadict_to_meshgrid(dd, target_shape=None)
    assert DataDictBase.same_structure(dd, dd2)
    assert num.arrays_equal(dd2.data_vals('a'), np.transpose(aa, (1, 0)))
    assert num.arrays_equal(dd2.data_vals('z'), np.transpose(zz, (1, 0)))
def xySelection(interactive=False):
    if not interactive:
        app = QtGui.QApplication([])

    fc = linearFlowchart(('xysel', XYSelector))
    selector = fc.nodes()['xysel']
    dialog = widgetDialog(selector.ui, 'xysel')

    data = datadict_to_meshgrid(testdata.three_compatible_3d_sets(4, 4, 4))
    fc.setInput(dataIn=data)

    if not interactive:
        app.exec_()
    else:
        return dialog, fc
def dimReduction(interactive=False):
    if not interactive:
        app = QtGui.QApplication([])

    fc = linearFlowchart(('reducer', DimensionReducer))
    reducer = fc.nodes()['reducer']
    dialog = widgetDialog(reducer.ui, 'reducer')

    data = datadict_to_meshgrid(testdata.three_compatible_3d_sets(2, 2, 2))
    fc.setInput(dataIn=data)

    if not interactive:
        app.exec_()
    else:
        return dialog, fc
def xySelectionWidget():
    def selectionCb(selection):
        print(selection)

    app = QtGui.QApplication([])
    widget = XYSelectionWidget()
    widget.rolesChanged.connect(selectionCb)

    # set up the UI, feed data in
    data = datadict_to_meshgrid(testdata.three_compatible_3d_sets(5, 5, 5))
    dialog = widgetDialog(widget)
    widget.setData(data)
    widget.clear()
    widget.setData(data)
    return app.exec_()
예제 #6
0
def gridOptionWidget():
    def cb(val):
        print(val)

    app = QtGui.QApplication([])
    widget = GridOptionWidget()
    widget.optionSelected.connect(cb)

    # set up the UI, feed data in
    data = datadict_to_meshgrid(
        testdata.three_compatible_3d_sets(5, 5, 5)
    )
    dialog = widgetDialog(widget)
    widget.setAxes(data.axes())
    widget.setShape(data.shape())

    return app.exec_()
예제 #7
0
def test_gridOptionWidget():
    def cb(val):
        print(val)

    widget = GridOptionWidget()
    widget.optionSelected.connect(cb)

    # set up the UI, feed data in
    data = datadict_to_meshgrid(testdata.three_compatible_3d_sets(5, 5, 5))
    dialog = widgetDialog(widget)
    widget.setAxes(data.axes())

    widget.setShape({
        'order': ['x', 'y', 'z'],
        'shape': (5, 5, 5),
    })

    return dialog
def _make_testdata(complex: bool = False):
    x = np.linspace(-1, 1, 101)
    y = np.arange(7)
    z = np.linspace(0, 100, 16)
    xx, yy, zz = np.meshgrid(x, y, z, indexing='ij')
    rr = np.random.normal(loc=0, scale=1, size=xx.shape)
    if complex:
        ii = np.random.normal(loc=0, scale=1, size=xx.shape)
        nn = rr + 1j * ii
    else:
        nn = rr

    return datadict_to_meshgrid(
        DataDict(
            x=dict(values=xx),
            y=dict(values=yy),
            z=dict(values=zz),
            noise=dict(values=nn, axes=['x', 'y', 'z']),
        ))
def test_equality():
    """test whether direct comparison of datasets is working."""
    dd1 = DataDict(
        x=dict(values=np.arange(5), unit='A'),
        y=dict(values=np.arange(5)**2, axes=['x']),
    )
    assert dd1.validate()
    dd1.add_meta('some_info', 'some_value')
    dd2 = dd1.copy()
    assert datasets_are_equal(dd1, dd2)
    assert dd1 == dd2

    dd2 = dd1.copy()
    dd2.delete_meta('some_info')
    assert not datasets_are_equal(dd1, dd2)
    assert not dd1 == dd2
    assert datasets_are_equal(dd1, dd2, ignore_meta=True)

    dd2 = dd1.copy()
    dd2['x']['unit'] = 'B'
    assert not datasets_are_equal(dd1, dd2)

    dd2 = dd1.copy()
    dd2['y']['values'][-1] -= 1
    assert not datasets_are_equal(dd1, dd2)

    dd2 = DataDictBase(**dd1)
    assert not datasets_are_equal(dd1, dd2)

    dd2 = datadict_to_meshgrid(dd1)
    assert not datasets_are_equal(dd1, dd2)

    dd2 = dd1.copy()
    dd2['w'] = dict(values=np.arange(5), unit='C')
    dd2['y']['axes'] = ['w', 'x']
    assert not datasets_are_equal(dd1, dd2)

    assert not dd1 == 'abc'
예제 #10
0
 def from_dataset(cls, ds, gate_name, freq_name, magnitude_name, phase_name):
     meshgrid = datadict_to_meshgrid(ds_to_datadict(ds))
     return cls.from_meshgrid(meshgrid, gate_name, freq_name, magnitude_name, phase_name)