Beispiel #1
0
def update():
    global p4, z, index, count
    index -= 1
    p4.setData(z=z[index % z.shape[0]])
    count += 1
    if count == 20:
        p1.setData(z=pg.gaussianFilter(np.random.normal(size=(50, 50)), (1.5, 2)))
        p3.setData(z=pg.gaussianFilter(np.random.normal(size=(50, 50)), (1.5, 1)))
        count = 0
Beispiel #2
0
def mkData():
    with pg.BusyCursor():
        global data, cache, ui, xp
        frames = ui.framesSpin.value()
        width = ui.widthSpin.value()
        height = ui.heightSpin.value()
        cacheKey = (ui.dtypeCombo.currentText(), ui.rgbCheck.isChecked(),
                    frames, width, height)
        if cacheKey not in cache:
            if cacheKey[0] == 'uint8':
                dt = xp.uint8
                loc = 128
                scale = 64
                mx = 255
            elif cacheKey[0] == 'uint16':
                dt = xp.uint16
                loc = 4096
                scale = 1024
                mx = 2**16
            elif cacheKey[0] == 'float':
                dt = xp.float
                loc = 1.0
                scale = 0.1
                mx = 1.0
            else:
                raise ValueError(f"unable to handle dtype: {cacheKey[0]}")

            if ui.rgbCheck.isChecked():
                data = xp.random.normal(size=(frames, width, height, 3),
                                        loc=loc,
                                        scale=scale)
                data = pg.gaussianFilter(data, (0, 6, 6, 0))
            else:
                data = xp.random.normal(size=(frames, width, height),
                                        loc=loc,
                                        scale=scale)
                data = pg.gaussianFilter(data, (0, 6, 6))
            if cacheKey[0] != 'float':
                data = xp.clip(data, 0, mx)
            data = data.astype(dt)
            data[:, 10, 10:50] = mx
            data[:, 9:12, 48] = mx
            data[:, 8:13, 47] = mx
            cache = {
                cacheKey: data
            }  # clear to save memory (but keep one to prevent unnecessary regeneration)

        data = cache[cacheKey]
        updateLUT()
        updateSize()
    def __init__( self, parent=None):
        super(PlotFrame, self).__init__(parent)
        self.area = pg_dock.DockArea()

        layout = QtGui.QHBoxLayout()
        layout.addWidget(self.area)
        self.setLayout(layout)

        self.sketchDock = pg_dock.Dock("Skecthing", size=(500, 500))     ## give this dock the minimum possible size
        self.measureDock = pg_dock.Dock("Measuring", size=(500,200))

        self.area.addDock(self.sketchDock, 'top')
        self.area.addDock(self.measureDock, 'bottom')

        data = pg.gaussianFilter(np.random.normal(size=(256, 256)), (20, 20))
        self.afmIm = pg.ImageItem(data)
        self.afmIm.setZValue(-1000)

        self.sketchPlot = pg.PlotWidget()
        self.sketchPlot.enableAutoRange('x', True)
        self.sketchPlot.enableAutoRange('y', True)
        self.sketchPlot.setAspectLocked(lock=True, ratio=1)
        self.sketchPlot.showGrid(x=1, y=1, alpha=0.8)
        self.sketchDock.addWidget(self.sketchPlot, 0, 0)


        self.histWidget = pg.HistogramLUTWidget()
        self.sketchDock.addWidget(self.histWidget, 0, 1)

        self.histWidget.setImageItem(self.afmIm)
        self.sketchPlot.addItem(self.afmIm)

        self.measurePlot = pg.PlotWidget()
        self.measureDock.addWidget(self.measurePlot)
Beispiel #4
0
 def updatePlot_after_remove_point():  #not implemented for PXRD
     #global data
     try:
         selected = roi.getArrayRegion(self.app_ctr.bkg_sub.img,
                                       self.img_pyqtgraph)
     except:
         pass
     p2.plot(selected.sum(axis=0), clear=True)
     x, y = [int(each) for each in self.roi.pos()]
     w, h = [int(each) for each in self.roi.size()]
     self.iso.setData(
         pg.gaussianFilter(
             self.app_ctr.bkg_sub.img[y:(y + h), x:(x + w)], (2, 2)))
     self.iso.setPos(x, y)
     if self.app_ctr.img_loader.frame_number == 0:
         isoLine.setValue(self.app_ctr.bkg_sub.img[y:(y + h),
                                                   x:(x + w)].mean())
     else:
         pass
     #print(isoLine.value(),self.current_image_no)
     #plot others
     plot_bkg_fit_gui_pyqtgraph(self.p2, self.p3, self.p4,
                                self.app_ctr.data, self.app_ctr.bkg_sub)
     self.lcdNumber_potential.display(
         self.app_ctr.data['potential'][-2])
     self.lcdNumber_current.display(self.app_ctr.data['current'][-2])
     self.lcdNumber_intensity.display(
         self.app_ctr.data['peak_intensity'][-2])
     self.lcdNumber_iso.display(isoLine.value())
    def __init__(self):
        ## Create window with ImageView widget
        super(RasterScan, self).__init__()
        self.resize(800,800)
        self.show()
        ## Create random 3D data set with noisy signals
        img = pg.gaussianFilter(np.random.normal(size=(200, 200)), (5, 5)) * 20 + 100
        img = img[np.newaxis,:,:]
        decay = np.exp(-np.linspace(0,0.3,100))[:,np.newaxis,np.newaxis]
        data = np.random.normal(size=(100, 200, 200))
        data += img * decay
        data += 2

        ## Add time-varying signal
        sig = np.zeros(data.shape[0])
        sig[30:] += np.exp(-np.linspace(1,10, 70))
        sig[40:] += np.exp(-np.linspace(1,10, 60))
        sig[70:] += np.exp(-np.linspace(1,10, 30))

        sig = sig[:,np.newaxis,np.newaxis] * 3
        data[:,50:60,50:60] += sig


        ## Display the data and assign each frame a time value from 1.0 to 3.0
        self.setImage(data, xvals=np.linspace(1., 3., data.shape[0]))
Beispiel #6
0
    def __init__(self, parent, **kwargs):
        super(AppWindow,
              self).__init__(parent)  #, QtCore.Qt.WindowStaysOnTopHint)
        self.addshortcut = QtWidgets.QShortcut(QtGui.QKeySequence("3"), self)
        self.addshortcut.activated.connect(self.make3D)
        self.regions = kwargs.get('regions', None)

        self.short2d = QtWidgets.QShortcut(QtGui.QKeySequence("2"), self)
        self.short2d.activated.connect(self.make2D)

        self.saveShortcut = QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+S"),
                                                self)
        self.saveShortcut.activated.connect(self.saveAll)

        self.setupUi(self)
        self.plot = pg.PlotWidget()
        self.curve = pg.PlotCurveItem(
        )  #name = name);C.setPen(color=col, width=3)
        self.plot.addItem(self.curve)
        self.exporter = PQG_ImageExporter(self.plot.plotItem)
        #3D Plot
        try:
            self.plot3D = plot3DTools.AppWindow()
        except:
            pass

        #2D plot (surface)
        self.win = QtGui.QMainWindow()
        self.win.resize(800, 800)
        imv = pg.ImageView()
        self.win.setCentralWidget(imv)

        ## Create random 3D data set with noisy signals
        img = pg.gaussianFilter(np.random.normal(size=(200, 200)),
                                (5, 5)) * 20 + 100
        img = img[np.newaxis, :, :]
        decay = np.exp(-np.linspace(0, 0.3, 100))[:, np.newaxis, np.newaxis]
        data = np.random.normal(size=(100, 200, 200))
        data += img * decay
        data += 2

        ## Add time-varying signal
        sig = np.zeros(data.shape[0])
        sig[30:] += np.exp(-np.linspace(1, 10, 70))
        sig[40:] += np.exp(-np.linspace(1, 10, 60))
        sig[70:] += np.exp(-np.linspace(1, 10, 30))

        sig = sig[:, np.newaxis, np.newaxis] * 3
        data[:, 50:60, 30:40] += sig

        ## Display the data and assign each frame a time value from 1.0 to 3.0
        imv.setImage(data, xvals=np.linspace(1., 3., data.shape[0]))

        ## Set a custom color map
        colors = [(0, 0, 0), (45, 5, 61), (84, 42, 55), (150, 87, 60),
                  (208, 171, 141), (255, 255, 255)]
        cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
        imv.setColorMap(cmap)

        self.makeMenu()
Beispiel #7
0
def testHistogramLUTWidget():
    pg.mkQApp()
    
    win = QtGui.QMainWindow()
    win.show()

    cw = QtGui.QWidget()
    win.setCentralWidget(cw)

    l = QtGui.QGridLayout()
    cw.setLayout(l)
    l.setSpacing(0)

    v = pg.GraphicsView()
    vb = pg.ViewBox()
    vb.setAspectLocked()
    v.setCentralItem(vb)
    l.addWidget(v, 0, 0, 3, 1)

    w = pg.HistogramLUTWidget(background='w')
    l.addWidget(w, 0, 1)

    data = pg.gaussianFilter(np.random.normal(size=(256, 256, 3)), (20, 20, 0))
    for i in range(32):
        for j in range(32):
            data[i*8, j*8] += .1
    img = pg.ImageItem(data)
    vb.addItem(img)
    vb.autoRange()

    w.setImageItem(img)
    
    QtGui.QApplication.processEvents()
    win.close()
Beispiel #8
0
    def createView(self):
        z, y, x = 300, 200, 100
        data = np.random.normal(size=(z, y, x))
        data = pg.gaussianFilter(data, (5, 5, 5))

        return dv.views.VolumeView(dv.models.VolumeModel(data), toolBar=True,
                                   slicesMode=dv.models.AXIS_XYZ)
 def process(self, dataIn, display=True):
     # CtrlNode has created self.ctrls, which is a dict containing {ctrlName: widget}
     sigma = self.ctrls['sigma'].value()
     strength = self.ctrls['strength'].value()
     output = dataIn - (strength *
                        pg.gaussianFilter(dataIn, (sigma, sigma)))
     return {'dataOut': output}
Beispiel #10
0
    def addIsocurve(self, level=0.):
        iso = pg.IsocurveItem(level=level, pen='g')
        iso.setZValue(1000)
        iso.setData(pg.gaussianFilter(self.data, (5, 5)))
        iso.setParentItem(self.image)

        self.iso = iso
    def init_data(self):
        # Generate image data
        data = np.random.normal(size=(200, 100))
        data[20:80, 20:80] += 2.
        data = pg.gaussianFilter(data, (3, 3))
        data += np.random.normal(size=(200, 100)) * 0.1

        self.set_data(data)
Beispiel #12
0
    def __init__(self, parent=None):
        # initialization of the superclass
        super(VideoMainWindow, self).__init__(parent)
        # setup the GUI
        self.setupUi(self)
        pg.setConfigOptions(background=pg.mkColor(0.5))
        pg.setConfigOptions(foreground=pg.mkColor(0.3))
        self.setWindowTitle('pyqtgraph example: Image Analysis')

        # Preserve plot area's aspect ration so image always scales correctly
        self.graphicsView.p1.setAspectLocked(True)

        # Use a file dialog to choose tiff stack
        file, mask = QFileDialog.getOpenFileName(self, 'Open a .tif/.tiff stack')
        # Read image data
        self.img_data_raw = volread(file)
        frames = self.img_data_raw.shape[0]

        # Transpose second and third axes (y, x) to correct orientation (x, y)
        self.img_data = np.transpose(self.img_data_raw, (0, 2, 1))
        # Flip each frame in the left/right direction, expected to be up/down
        for i in range(frames):
            self.img_data[i] = np.fliplr(self.img_data[i])

        self.ptr = 0
        self.lastTime = ptime.time()
        self.fps = None
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(50)    # 50 ms =~ 20 fps

        # Levels/color control with a histogram
        # TODO try with a HistogramLUTWidget
        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.graphicsView.img)
        self.graphicsView.widget.addItem(self.hist)

        # Isocurve drawing
        self.iso = pg.IsocurveItem(level=0.8, pen='g')
        self.iso.setParentItem(self.graphicsView.img)
        self.iso.setZValue(5)

        # Draggable line for setting isocurve level
        self.isoLine = pg.InfiniteLine(angle=0, movable=True, pen='g')
        self.hist.vb.addItem(self.isoLine)
        self.hist.vb.setMouseEnabled(y=False)  # makes user interaction a little easier
        self.isoLine.setValue(0.8)
        self.isoLine.setZValue(1000)  # bring iso line above contrast controls
        self.isoLine.sigDragged.connect(self.updateIsocurve)

        # Generate image data
        self.graphicsView.img.setImage(self.img_data[0])
        # self.graphicsView.img.scale(self.img_data.shape[1], self.img_data.shape[2])
        self.hist.setLevels(self.img_data.min(), self.img_data.max())

        # build isocurves from smoothed data
        self.isoLine.setValue(self.img_data.max() / 2)
        self.iso.setData(pg.gaussianFilter(self.img_data[0], (2, 2)))
Beispiel #13
0
    def __init__(self):
        self.graph = GraphicsLayoutWidget()
        self.graph.setObjectName("stock UI")
        self.label = pg.LabelItem(justify='right')
        self.graph.addItem(self.label)
        self.p1 = self.graph.addPlot(row=1, col=0)
        self.p2 = self.graph.addPlot(row=2, col=0)
        self.p1.showGrid(x=True, y=True, alpha=0.5)
        self.region = pg.LinearRegionItem()
        self.region.setZValue(10)
        # Add the LinearRegionItem to the ViewBox, but tell the ViewBox to exclude this
        # item when doing auto-range calculations.
        self.p2.addItem(self.region, ignoreBounds=True)

        #pg.dbg()
        self.p1.setAutoVisible(y=True)

        #create numpy arrays
        #make the numbers large to show that the xrange shows data from 10000 to all the way 0
        self.data1 = 10000 + 15000 * pg.gaussianFilter(
            np.random.random(size=10000),
            10) + 3000 * np.random.random(size=10000)
        self.data2 = 15000 + 15000 * pg.gaussianFilter(
            np.random.random(size=10000),
            10) + 3000 * np.random.random(size=10000)

        self.p1.plot(self.data1, pen="r")
        self.p1.plot(self.data2, pen="g")

        self.p2.plot(self.data1, pen="w")
        self.region.sigRegionChanged.connect(self.update)
        self.p1.sigRangeChanged.connect(self.updateRegion)

        self.region.setRegion([1000, 2000])

        #cross hair
        self.vLine = pg.InfiniteLine(angle=90, movable=False)
        self.hLine = pg.InfiniteLine(angle=0, movable=False)
        self.p1.addItem(self.vLine, ignoreBounds=True)
        self.p1.addItem(self.hLine, ignoreBounds=True)

        self.vb = self.p1.vb
        self.proxy = pg.SignalProxy(self.p1.scene().sigMouseMoved,
                                    rateLimit=60,
                                    slot=self.mouseMoved)
Beispiel #14
0
    def process(self, view, display=True):
        if view is not None:
            self.view = view
            self.view.addItem(self.iso)
            self.view.addHistItem(self.isoLine)

            self.iso.setData(pg.gaussianFilter(self.view.getImage(), (2, 2)))

            return {'level': self.iso.level}
Beispiel #15
0
	def process(self, view, display=True):
		if view is not None:
			self.view = view
			self.view.addItem(self.iso)
			self.view.addHistItem(self.isoLine)

			self.iso.setData(pg.gaussianFilter(self.view.getImage(), (2, 2)))

			return {'level': self.iso.level}
Beispiel #16
0
 def read_image(self):
     """ Acts like the device is measuring random images
             """
     noise = np.random.normal(size=(self._size,
                                    self._size)) * self._amplitude
     img = pg.gaussianFilter(
         np.random.normal(size=(self._size, self._size)), (5, 5)) * 20 + 100
     tot = img + noise
     return np.uint16(tot)
Beispiel #17
0
 def createView(self):
     data = pg.gaussianFilter(np.random.normal(size=(64, 64, 64)), (5, 5, 5))
     volModel = dv.models.VolumeModel(data)
     msv = dv.views.MultiSliceView(
         None, {axis: {'model': volModel.getSlicesModel(axis),
                       'normalize': True}
                for axis in [dv.models.AXIS_X, dv.models.AXIS_Y,
                             dv.models.AXIS_Z]})
     return msv
Beispiel #18
0
 def add_sea(self):
     self.removeItem(self.grid)
     z = pg.gaussianFilter(np.random.normal(size=(100, 100)), (1, 1))
     self.sea = gl.GLSurfacePlotItem(z=z,
                                     shader='shaded',
                                     color=(0.5, 0.5, 1, 1),
                                     smooth=True)
     self.sea.translate(-50, -50, -1)
     self.addItem(self.sea)
 def updateIsocurve(self):
     # #old
     # cur_data = pg.gaussianFilter(self.imv.getImageItem().image, (4, 4))
     # self.iso.setParentItem(self.imv.getImageItem())
     cur_data = pg.gaussianFilter(self.img.image, (4, 4))
     # self.iso.setParentItem(self.img)
     self.iso.setData(cur_data)  # this line takes too much process time
     self.iso.setLevel(cur_data.max() / np.e)
     self.iso.setZValue(1000)
Beispiel #20
0
def mkData():
    with pg.BusyCursor():
        global data, cache, ui
        frames = ui.framesSpin.value()
        width = ui.widthSpin.value()
        height = ui.heightSpin.value()
        dtype = (ui.dtypeCombo.currentText(), ui.rgbCheck.isChecked(), frames,
                 width, height)
        if dtype not in cache:
            if dtype[0] == 'uint8':
                dt = np.uint8
                loc = 128
                scale = 64
                mx = 255
            elif dtype[0] == 'uint16':
                dt = np.uint16
                loc = 4096
                scale = 1024
                mx = 2**16
            elif dtype[0] == 'float':
                dt = np.float
                loc = 1.0
                scale = 0.1

            if ui.rgbCheck.isChecked():
                data = np.random.normal(size=(frames, width, height, 3),
                                        loc=loc,
                                        scale=scale)
                data = pg.gaussianFilter(data, (0, 6, 6, 0))
            else:
                data = np.random.normal(size=(frames, width, height),
                                        loc=loc,
                                        scale=scale)
                data = pg.gaussianFilter(data, (0, 6, 6))
            if dtype[0] != 'float':
                data = np.clip(data, 0, mx)
            data = data.astype(dt)
            cache = {
                dtype: data
            }  # clear to save memory (but keep one to prevent unnecessary regeneration)

        data = cache[dtype]
        updateLUT()
        updateSize()
    def set_data(self, data):
        self.data = data

        # build isocurves from smoothed data
        self.iso_curve.setData(pg.gaussianFilter(self.data, (2, 2)))

        self.image_view.setImage(self.data)
        self.update_roi()

        print(self.hist.getLevels())
Beispiel #22
0
def main_controller():
    app = QtWidgets.QApplication(sys.argv)
    form = QtWidgets.QWidget()
    Nx = 100
    Ny = 200
    data_random = np.random.normal(size=(Ny, Nx))
    x = np.linspace(0, Nx - 1, Nx)
    y = np.linspace(0, Ny - 1, Ny)
    from pymodaq.daq_utils.daq_utils import gauss2D

    data_red = 3 * gauss2D(x, 0.2 * Nx, Nx / 5, y, 0.3 * Ny, Ny / 5, 1,
                           90) * np.sin(x / 5)**2 + 0.1 * data_random
    # data_red = pg.gaussianFilter(data_red, (2, 2))
    data_green = 24 * gauss2D(x, 0.2 * Nx, Nx / 5, y, 0.3 * Ny, Ny / 5, 1, 0)
    # data_green = pg.gaussianFilter(data_green, (2, 2))
    data_green[70:80, 7:12] = np.nan

    data_blue = 10 * gauss2D(x, 0.7 * Nx, Nx / 5, y, 0.2 * Ny, Ny / 5, 1)
    data_blue = pg.gaussianFilter(data_blue, (2, 2))

    prog = Viewer2D(form)
    # prog.set_axis_scaling(scaling_options=utils.ScalingOptions(
    #     scaled_xaxis=utils.ScaledAxis(label="eV", units=None, offset=100, scaling=0.1),
    #     scaled_yaxis=utils.ScaledAxis(label="time", units='s', offset=-20, scaling=2)))
    form.show()
    #prog.auto_levels_action_sym.trigger()
    #prog.view.actions['autolevels'].trigger()

    data_spread = np.load('../../../resources/triangulation_data.npy')
    # data_shuffled = data
    # np.random.shuffle(data_shuffled)
    # prog.show_data(utils.DataFromPlugins(name='mydata', distribution='spread',
    #                                      data=[data, data_shuffled]))
    prog.view.get_action('histo').trigger()
    prog.view.get_action('autolevels').trigger()

    prog.show_data(
        utils.DataFromPlugins(name='mydata',
                              distribution='uniform',
                              data=[data_red, data_green]))
    #prog.show_data(utils.DataFromPlugins(name='mydata', distribution='spread', data=[data_spread]))

    #prog.ROI_select_signal.connect(print_roi_select)
    #prog.view.get_action('ROIselect').trigger()
    #prog.view.ROIselect.setSize((20, 35))
    #prog.view.ROIselect.setPos((45, 123))
    prog.show_roi_target(True)
    prog.move_scale_roi_target((50, 40), (20, 20))

    QtWidgets.QApplication.processEvents()

    # prog.setImage(data_spread=data)
    #app.processEvents()

    sys.exit(app.exec_())
 def show_hide_iso(self):
     if self.ui.isocurve_pb.isChecked():
         self.ui.iso.show()
         self.ui.isoLine.show()
         self.ui.Show_histogram.setChecked(True)
         self.show_hide_histogram()
         if self.ui.isocurve_pb.isChecked() and self.image.red is not None:
             self.ui.iso.setData(pg.gaussianFilter(self.image.red, (2, 2)))
     else:
         self.ui.iso.hide()
         self.ui.isoLine.hide()
Beispiel #24
0
    def do_stuff(self):

        p = Parameter.create(name='params', type='group', children=self.params)

        def change(param, changes):
            print("tree changes:")
            for param, change, data in changes:
                path = p.childPath(param)
                if path is not None:
                    childName = '.'.join(path)
                else:
                    childName = param.name()
                print('  parameter: %s' % childName)
                print('  change:    %s' % change)
                print('  data:      %s' % str(data))
                print('  ----------')

        p.sigTreeStateChanged.connect(change)

        # create a parameter tree widget
        t = ParameterTree()
        t.setParameters(p, showTop=False)
        t.setWindowTitle('pyqtgraph example: Parameter Tree')

        # plot some data
        plot = pg.PlotWidget()
        n = 1000
        xv = np.arange(n)
        yv = 1 * pg.gaussianFilter(np.random.random(size=n), 10)
        plot.plot(xv, yv, pen='r')

        # make a second plot
        plot2 = pg.PlotWidget()
        plot2.plot(xv, yv, pen='g')

        # set the layout of the widget
        layout = QtGui.QGridLayout()

        # layout.columnStretch(5)
        layout.setColumnStretch(2, 2)

        # NOTE: (widget, # y_row, x_row, y_span, x_span)
        # layout.addWidget(QtGui.QLabel("Data monitor thing"), 0, 0, 1, 2)

        layout.addWidget(t, 0, 0, 2, 1)

        layout.addWidget(plot, 0, 2)
        layout.addWidget(plot2, 1, 2)

        self.setLayout(layout)

        # test save/restore
        s = p.saveState()
        p.restoreState(s)
Beispiel #25
0
def createSlicesModel(imgSize, size):
    """
    Creates an SlicesModel, generating random images of the given image size,
    having size elements.
    :param imgSize: (tupple) The image size
    :param size: (int) The number of slices(images)
    :return: (SlicesModel)
    """
    s = size, imgSize[1], imgSize[0]
    data = pg.gaussianFilter(np.random.normal(size=s), (5, 5, 5))
    return dv.models.SlicesModel(data)
Beispiel #26
0
    def getData(self, micId):
        """
        Return the micrograph image data
        :param micId: (int) The micrograph id
        :return: The micrograph image data
        """
        if micId not in self._cache:
            c, r = self._imageSize
            self._cache[micId] = pg.gaussianFilter(
                np.random.normal(size=(r, c)), (5, 5))

        return self._cache[micId]
Beispiel #27
0
def mkData():
    with pg.BusyCursor():
        global data, cache, ui
        frames = ui.framesSpin.value()
        width = ui.widthSpin.value()
        height = ui.heightSpin.value()
        dtype = (ui.dtypeCombo.currentText(), ui.rgbCheck.isChecked(), frames, width, height)
        if dtype not in cache:
            if dtype[0] == 'uint8':
                dt = np.uint8
                loc = 128
                scale = 64
                mx = 255
            elif dtype[0] == 'uint16':
                dt = np.uint16
                loc = 4096
                scale = 1024
                mx = 2**16
            elif dtype[0] == 'float':
                dt = np.float
                loc = 1.0
                scale = 0.1
            
            if ui.rgbCheck.isChecked():
                data = np.random.normal(size=(frames,width,height,3), loc=loc, scale=scale)
                data = pg.gaussianFilter(data, (0, 6, 6, 0))
            else:
                data = np.random.normal(size=(frames,width,height), loc=loc, scale=scale)
                data = pg.gaussianFilter(data, (0, 6, 6))
            if dtype[0] != 'float':
                data = np.clip(data, 0, mx)
            data = data.astype(dt)
            data[:, 10, 10:50] = mx
            data[:, 9:12, 48] = mx
            data[:, 8:13, 47] = mx
            cache = {dtype: data} # clear to save memory (but keep one to prevent unnecessary regeneration)
            
        data = cache[dtype]
        updateLUT()
        updateSize()
def updateData():
    global updateTime, fps
    ## Display the data
    img = pg.gaussianFilter(np.random.normal(size=(200, 200)),
                            (5, 5)) * 20 + 100
    imview.setImage(img, autoLevels=False, autoHistogramRange=False
                    )  # Display new image and stop range from jumping around
    QtCore.QTimer.singleShot(1, updateData)  # Recursive call here
    now = pg.ptime.time()
    fps2 = 1.0 / (now - updateTime)
    updateTime = now
    fps = fps * 0.9 + fps2 * 0.1
    imview.setWindowTitle('%0.1f fps (close window to stop)' % fps)
Beispiel #29
0
 def createView(self):
     imageView = dv.views.ImageView(parent=None, border_color='#FFAA33')
     data = pg.gaussianFilter(np.random.normal(size=(512, 512)),
                              (5, 5))
     imgModel = dv.models.ImageModel(data)
     imageView.setModel(imgModel)
     dim_x, dim_y = imgModel.getDim()
     desc = ("<html><head/><body><p>"
             "<span style=\" color:#0055ff;\">Dimensions: </span>"
             "<span style=\" color:#000000;\">(%d,%d)</span></p>"
             "</html>" % (dim_x, dim_y))
     imageView.setImageInfo(text=desc)
     return imageView
Beispiel #30
0
    def set_data(self, data, slit_shape=None, pix_scale=0.1):
        self.image_item.setImage(np.swapaxes(data.data, 0, 1))

        self.hist.setLevels(np.nanmin(data.data.compressed().value),
                            np.nanmax(data.data.compressed().value))
        self.iso.setData(pg.gaussianFilter(data.data.data.value, (2, 2)))
        self.iso_line.setValue(np.median(data.data.compressed().value))

        self.plot.setLabel('bottom',
                           text="X [{}]".format(
                               u.Unit(data.dispersion_unit.to_string())))
        self.plot.setLabel('left',
                           text="Y [{}]".format(
                               u.Unit(data.cross_dispersion_unit.to_string())))
Beispiel #31
0
    def getData(self, row, col=0):
        """ Return the data (array like) for the item in this row, column.
         Used by rendering of images in a given cell of the table.
        """
        data = self._imgData.get(row)
        if len(self._imgSize) == 2:  # 2D Image
            s = (self._imgSize[1], self._imgSize[0])
        else:  # Volume
            s = (self._imgSize[2], self._imgSize[1], self._imgSize[0])
        if data is None:
            data = pg.gaussianFilter(np.random.normal(size=s),
                                     [5 for _ in range(len(self._imgSize))])
            self._imgData[row] = data

        return data
Beispiel #32
0
    def _setDataToNoise(self):
        """ Sets image data to noise
        """
        logger.debug("_setDataToNoise")

        # img = np.random.randint(100, 150, size=(1216, 1936), dtype=np.uint16)
        img = pg.gaussianFilter(np.random.normal(size=(300, 200)), (5, 5)) * 20
        # img = np.random.normal(size=(300, 200)) * 100

        # For testing issue 792
        # maxVal = 1.0
        # img = np.random.uniform(0.0, 1.0, size=(300, 300)) * maxVal
        # img[200:205, :] = maxVal

        self.setImage(img)
Beispiel #33
0
def init_data():
    Nx = 100
    Ny = 200
    data_random = np.random.normal(size=(Ny, Nx))
    x = np.linspace(0, Nx - 1, Nx)
    y = np.linspace(0, Ny - 1, Ny)
    from pymodaq.daq_utils.daq_utils import gauss2D

    data_red = 3 * gauss2D(x, 0.2 * Nx, Nx / 5, y, 0.3 * Ny, Ny / 5, 1,
                           90) * np.sin(x / 5)**2
    data_green = 24 * gauss2D(x, 0.2 * Nx, Nx / 5, y, 0.3 * Ny, Ny / 5, 1, 0)
    data_blue = 10 * gauss2D(x, 0.7 * Nx, Nx / 5, y, 0.2 * Ny, Ny / 5, 1)
    data_blue = pg.gaussianFilter(data_blue, (2, 2))
    here = Path(__file__).parent
    data_spread = np.load(str(here.joinpath('triangulation_data.npy')))
    return data_red, data_green, data_blue, data_spread
Beispiel #34
0
    def make_testdata(self):  #create numpy arrays
        #make the numbers large to show that the xrange shows data from 10000 to all the way 0
        ntr = 1
        npts = 10000
        dt = 1e-2
        dataX = np.linspace(0, dt, npts)
        self.dt = np.mean(np.diff(dataX))
        shortx = dataX[1500:5000]
        t0 = shortx[0]

        d = -200. + 10 * pg.gaussianFilter(np.random.random(
            size=npts), 10)  #  + 10 * np.random.random(size=npts)
        d[1500:5000] += -20 * (np.exp(-(shortx - t0) / 1e-3) -
                               np.exp(-(shortx - t0) / 0.25e-3))
        dataY = d

        # dataX = 10000 + 15000 * pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * np.random.random(size=10000)
        return (dataX, dataY)
Beispiel #35
0
hist.vb.setMouseEnabled(y=False) # makes user interaction a little easier
isoLine.setValue(0.8)
isoLine.setZValue(1000) # bring iso line above contrast controls

# Another plot area for displaying ROI data
win.nextRow()
p2 = win.addPlot(colspan=2)
p2.setMaximumHeight(250)
win.resize(800, 800)
win.show()


# Generate image data
data = np.random.normal(size=(100, 200))
data[20:80, 20:80] += 2.
data = pg.gaussianFilter(data, (3, 3))
data += np.random.normal(size=(100, 200)) * 0.1
img.setImage(data)
hist.setLevels(data.min(), data.max())

# build isocurves from smoothed data
iso.setData(pg.gaussianFilter(data, (2, 2)))

# set position and scale of image
img.scale(0.2, 0.2)
img.translate(-50, 0)

# zoom to fit imageo
p1.autoRange()  

Beispiel #36
0
 def update():
     z = self.amp * pg.gaussianFilter(np.random.normal(size=(self.x_size, self.y_size)), (1,1))
     if self.rand_noise:
         for x in range(20):
             z[random.randint(0, self.x_size - 1), random.randint(0, self.y_size - 1)] = self.amp * 2
     curve.setData(z=z)
 def process(self, dataIn, display=True):
     # CtrlNode has created self.ctrls, which is a dict containing {ctrlName: widget}
     sigma = self.ctrls['sigma'].value()
     strength = self.ctrls['strength'].value()
     output = dataIn - (strength * pg.gaussianFilter(dataIn, (sigma,sigma)))
     return {'dataOut': output}
Beispiel #38
0
## Add path to library (just for examples; you do not need this)

import numpy as np
import pyqtgraph as pg
import pyqtgraph.opengl as gl
from pyqtgraph.Qt import QtCore, QtGui

app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 200
w.show()
w.setWindowTitle('pyqtgraph example: GLImageItem')

## create volume data set to slice three images from
shape = (100,100,70)
data = pg.gaussianFilter(np.random.normal(size=shape), (4,4,4))
data += pg.gaussianFilter(np.random.normal(size=shape), (15,15,15))*15

## slice out three planes, convert to RGBA for OpenGL texture
levels = (-0.08, 0.08)
tex1 = pg.makeRGBA(data[shape[0]/2], levels=levels)[0]       # yz plane
tex2 = pg.makeRGBA(data[:,shape[1]/2], levels=levels)[0]     # xz plane
tex3 = pg.makeRGBA(data[:,:,shape[2]/2], levels=levels)[0]   # xy plane
#tex1[:,:,3] = 128
#tex2[:,:,3] = 128
#tex3[:,:,3] = 128

## Create three image items from textures, add to view
v1 = gl.GLImageItem(tex1)
v1.translate(-shape[1]/2, -shape[2]/2, 0)
v1.rotate(90, 0,0,1)
Beispiel #39
0
# Interpret image data as row-major instead of col-major
pg.setConfigOptions(imageAxisOrder="row-major")

app = QtGui.QApplication([])

## Create window with ImageView widget
win = QtGui.QMainWindow()
win.resize(800, 800)
imv = pg.ImageView()
win.setCentralWidget(imv)
win.show()
win.setWindowTitle("pyqtgraph example: ImageView")

## Create random 3D data set with noisy signals
img = pg.gaussianFilter(np.random.normal(size=(200, 200)), (5, 5)) * 20 + 100
img = img[np.newaxis, :, :]
decay = np.exp(-np.linspace(0, 0.3, 100))[:, np.newaxis, np.newaxis]
data = np.random.normal(size=(100, 200, 200))
data += img * decay
data += 2

## Add time-varying signal
sig = np.zeros(data.shape[0])
sig[30:] += np.exp(-np.linspace(1, 10, 70))
sig[40:] += np.exp(-np.linspace(1, 10, 60))
sig[70:] += np.exp(-np.linspace(1, 10, 30))

sig = sig[:, np.newaxis, np.newaxis] * 3
data[:, 50:60, 30:40] += sig
Beispiel #40
0
# -*- coding: utf-8 -*-
"""
Tests use of IsoCurve item displayed with image
"""

import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore

app = QtGui.QApplication([])

## make pretty looping data
frames = 200
data = np.random.normal(size=(frames,30,30), loc=0, scale=100)
data = np.concatenate([data, data], axis=0)
data = pg.gaussianFilter(data, (10, 10, 10))[frames/2:frames + frames/2]
data[:, 15:16, 15:17] += 1

win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: Isocurve')
vb = win.addViewBox()
img = pg.ImageItem(data[0])
vb.addItem(img)
vb.setAspectLocked()

## generate empty curves
curves = []
levels = np.linspace(data.min(), data.max(), 10)
for i in range(len(levels)):
    v = levels[i]
    ## generate isocurve with automatic color selection
Beispiel #41
0
    def createLayout(self):
        print 'Creating layout...'
        self.setWindowTitle('Interferometry Acquisition GUI')  
        #self.widget = QtGui.QWidget()
        #self.setCentralWidget(self.widget)
        self.layout = pg.LayoutWidget()
        #self.widget.setLayout(self.layout)
        self.setCentralWidget(self.layout)
        
        #Create GUI
        sizePolicyBt = QtGui.QSizePolicy(1, 1)
        sizePolicyBt.setHorizontalStretch(0)
        sizePolicyBt.setVerticalStretch(0)
        
        self.btOpen = QtGui.QPushButton("Open\nprevious results")
        sizePolicyBt.setHeightForWidth(self.btOpen.sizePolicy().hasHeightForWidth())
        self.btOpen.setSizePolicy(sizePolicyBt);
        self.btOpen.setStyleSheet("background-color: yellow; font-size: 16px; font: bold")
        
        self.btStart = QtGui.QPushButton("Start\nacquisition")
        sizePolicyBt.setHeightForWidth(self.btStart.sizePolicy().hasHeightForWidth())
        self.btStart.setSizePolicy(sizePolicyBt);
        self.btStart.setStyleSheet("background-color: green; font-size: 16px; font: bold")
        self.btStart.clicked.connect(self.startAcquisition)
        
        self.btStop = QtGui.QPushButton("Stop\nacquisition")
        sizePolicyBt.setHeightForWidth(self.btStop.sizePolicy().hasHeightForWidth())
        self.btStop.setSizePolicy(sizePolicyBt);
        self.btStop.setStyleSheet("background-color: red; font-size: 16px; font: bold")
        self.btStop.clicked.connect(self.stopAcquisition)
        self.btStop.setEnabled(False)
        
        self.paramTree = ParameterTree()
        self.paramTree.setParameters(Parameters.paramObject, showTop=False)
        self.paramTree.setWindowTitle('pyqtgraph example: Parameter Tree')
        self.paramTree.setMinimumWidth(350)
        self.paramTree.setMaximumWidth(350)
        sizePolicyPt = QtGui.QSizePolicy(1,1)
        sizePolicyPt.setHorizontalStretch(QtGui.QSizePolicy.Fixed)
        sizePolicyPt.setVerticalStretch(1)
        self.paramTree.setSizePolicy(sizePolicyPt);


        ## Create random 2D data
        data = np.random.normal(size=(512, 512)) + pg.gaussianFilter(np.random.normal(size=(512, 512)), (5, 5)) * 20 + 100
        data = data[:,:,np.newaxis]
        data = data.repeat(3,2)

        self.plotTl = pg.GraphicsView()
        self.plotTlImage = pg.ImageItem(data[:,:,:]) #parent=self.plotTl
        self.plotTlViewBox = pg.ViewBox()         
        self.plotTl.setCentralWidget(self.plotTlViewBox)
        self.plotTlViewBox.addItem(self.plotTlImage)

    
        self.plotTr = pg.PlotWidget(title="Interferometry", labels={'left': 'Signal amplitude (A.U.)', 'bottom': 'Distance (mm)'})
        #self.plotTlViewBox2.addItem(self.plotTr)
        self.plotTrCurve = self.plotTr.plot(pen=(255,0,0),name='C1') #Red
        self.plotTrCurve2 = self.plotTr.plot(pen=(0,255,0),name='C2') #Green
        #self.plotTlViewBox2.enableAutoRange('xy', True)  ## stop auto-scaling after the first data set is plotted
        #self.plotTr.addLegend('Test')
        self.plotTr.setYRange(-1000, 1000)
 
        self.plotBl = pg.PlotWidget(title="Distance", labels={'left': 'Distance (mm)', 'bottom': 'Number of acquisitions'})
        
        self.plotBlCurve = self.plotBl.plot(pen=(255,0,0),name='C1')
        self.plotBl.enableAutoRange('xy', True)  ## stop auto-scaling after the first data set is plotted       
        self.plotBl.setMaximumWidth(3500)
        
        self.tbInfo = QtGui.QTextEdit()
        self.tbInfo.setEnabled(False)
        palette = self.tbInfo.palette()
        palette.setColor(QtGui.QPalette.Base, QtGui.QColor("white")) #White background
        self.tbInfo.setPalette(palette)
        self.tbInfo.setTextColor(QtGui.QColor("black"))
        self.tbInfo.insertPlainText("Useful information will appear here.")
        
        #Create list view of multiple items
        self.tbStatus = QtGui.QListView()
        self.tbStatus.setEnabled(False)
        palette = self.tbStatus.palette()
        palette.setColor(QtGui.QPalette.Base, QtGui.QColor("white")) #White background
        self.tbStatus.setPalette(palette)
        itemModelStatus = QtGui.QStandardItemModel(self.tbStatus)
        self.tbStatus.setModel(itemModelStatus)
        #Add system status
        self.itemStatus = QtGui.QStandardItem()
        self.setStatus(False)      
        itemModelStatus.appendRow(self.itemStatus)    
        #Add camera status
        self.itemCameraStatus = QtGui.QStandardItem()
        self.setCameraStatus(False)      
        itemModelStatus.appendRow(self.itemCameraStatus)           
        #Add memory usage
        self.itemMemory = QtGui.QStandardItem("Acquisition board memory usage: N/A")
        self.itemMemory.setForeground(QtGui.QColor("black"))  
        itemModelStatus.appendRow(self.itemMemory)
        #Add max value position
        self.itemMaxValPos = QtGui.QStandardItem("Maximum RF value position: N/A")
        self.itemMaxValPos.setForeground(QtGui.QColor("black"))  
        itemModelStatus.appendRow(self.itemMaxValPos)        
        
        
        #layout.addWidget(QtGui.QLabel("These are two views of the same data. They should always display the same values."), 0, 0, 1, 2)
        self.layout.addWidget(self.btOpen, 9, 6, 1, 1)
        self.layout.addWidget(self.btStart, 9, 7, 1, 1)
        self.layout.addWidget(self.btStop, 9, 8, 1, 1)
        self.layout.addWidget(self.paramTree, 0, 0, 10, 3)
        self.layout.addWidget(self.plotTl, 0, 3, 5, 3) 
        self.layout.addWidget(self.plotTr, 0, 6, 5, 3)
        self.layout.addWidget(self.plotBl, 5, 3, 5, 3)
        self.layout.addWidget(self.tbInfo, 5, 6, 2, 3)
        self.layout.addWidget(self.tbStatus, 7, 6, 2, 3)

        self.layout.layout.setColumnStretch(3,1)
        self.layout.layout.setColumnStretch(4,1)
        self.layout.layout.setColumnStretch(5,1)
        self.layout.layout.setColumnStretch(6,1)
        self.layout.layout.setColumnStretch(7,1)
        self.layout.layout.setColumnStretch(8,1)

        self.show()
        self.resize(1500,800)
        self.move(100,100)    
        
        Parameters.paramObject.param('Save/Restore functionality', 'Save State').sigActivated.connect(self.saveParam)
        Parameters.paramObject.param('Save/Restore functionality', 'Restore State').sigActivated.connect(self.restoreParam)
        
        Parameters.paramObject.child("Acquisition Parameters", "Rotation speed (%)").sigValueChanged.connect(self.motorSpeedChanged)
        Parameters.paramObject.child("Trigger Options", "Acquisition mode").sigValueChanged.connect(self.triggerChanged)
        Parameters.paramObject.child("Trigger Options", "Trigger amplitude").sigValueChanged.connect(self.triggerChanged)
        Parameters.paramObject.child("Trigger Options", "Trigger switch 1/2").sigActivated.connect(self.triggerHalfSwitch)
        
        # adding by emitting signal in different thread
        self.workThread = AcquisitionWorker()
        self.workThread.updateDataCamera.connect(self.setDataCurveTl)
        self.workThread.updateDataInterf.connect(self.setDataCurveTr)
        self.workThread.updateDataDistance.connect(self.setDataCurveBl)
        self.workThread.updateDataDistance2.connect(self.setDataCurveBl2)
        self.workThread.updateWire.connect(self.setWire)
        self.workThread.setStatus.connect(self.setStatus)
        self.workThread.setInfo.connect(self.setInfo)
        self.testCount = 0;
        
        #Fill the plots with dummy data
        self.data = np.random.normal(size=(10,1000))    
        self.plotTrXAxis = np.arange(1000) * (0.01)
        self.plotBlXAxis = np.arange(1000) * (1)
        self.plotTrCurve.setData(x=self.plotTrXAxis,y=self.data[2%10],name='C1')
        self.plotTrCurve2.setData(x=self.plotTrXAxis,y=self.data[3%10],name='C2')    
        self.plotBlCurve.setData(x=self.plotBlXAxis,y=self.data[4%10],name='C1')            
        
        self.valueTest = 1
Beispiel #42
0
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLSurfacePlot')
w.setCameraPosition(distance=50)

## Add a grid to the view
g = gl.GLGridItem()
g.scale(2,2,1)
g.setDepthValue(10)  # draw grid after surfaces since they may be translucent
w.addItem(g)


## Simple surface plot example
## x, y values are not specified, so assumed to be 0:50
z = pg.gaussianFilter(np.random.normal(size=(50,50)), (1,1))
p1 = gl.GLSurfacePlotItem(z=z, shader='shaded', color=(0.5, 0.5, 1, 1))
p1.scale(16./49., 16./49., 1.0)
p1.translate(-18, 2, 0)
w.addItem(p1)


## Saddle example with x and y specified
x = np.linspace(-8, 8, 50)
y = np.linspace(-8, 8, 50)
z = 0.1 * ((x.reshape(50,1) ** 2) - (y.reshape(1,50) ** 2))
p2 = gl.GLSurfacePlotItem(x=x, y=y, z=z, shader='normalColor')
p2.translate(-10,-10,0)
w.addItem(p2)

Beispiel #43
0
    def __init__(self):
        super(Mainwindow, self).__init__()      
        self.exitAction = QtGui.QAction(QtGui.QIcon('close.png'), 'Exit', self)
        self.exitAction.setShortcut('Ctrl+Q')
        self.exitAction.setStatusTip('Exit application')
        self.exitAction.triggered.connect(self.close)
        self.statusBar()
        self.menubar = self.menuBar()
        self.fileMenu = self.menubar.addMenu('&File')
        self.exitMenu = self.menubar.addMenu('&Exit')
        #fileMenu.addAction(exitAction1)
        #toolbar = self.addToolBar('Exit')
        #toolbar.addAction(exitAction)
        self.setGeometry(100, 100, 1000, 500)
        self.setWindowTitle('BCI System Nanjing University Li Meng')
        self.setWindowIcon(QtGui.QIcon('Icon_system.png'))    
        
        #---Left  Docker
        
        dockWidgetleft =QtGui.QDockWidget("Direction",self)
        dockWidgetleft.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.Leftdocker = LeftDockerWidget()
        dockWidgetleft.setWidget(self.Leftdocker)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dockWidgetleft)
        
        #---Right Docker
        dockWidgetright =QtGui.QDockWidget("Status",self)
        dockWidgetright.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.Rightdocker = RightDockerWidget()
        dockWidgetright.setWidget(self.Rightdocker)
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dockWidgetright)
        
        #---Top Docker
        dockWidgettop =QtGui.QDockWidget("Tool",self)
        dockWidgettop.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
        self.Topdocker = TopDockerWidget()
        dockWidgettop.setWidget(self.Topdocker)
        self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dockWidgettop)

        w = gl.GLViewWidget()
        #w.resize(6,800)
        w.opts['distance'] = 200
        w.setWindowTitle('pyqtgraph example: GLImageItem')

        ## create volume data set to slice three images from
        shape = (100,100,70)
        data = pg.gaussianFilter(np.random.normal(size=shape), (4,4,4))
        data += pg.gaussianFilter(np.random.normal(size=shape), (15,15,15))*15

        ## slice out three planes, convert to RGBA for OpenGL texture
        levels = (-0.08, 0.08)
        tex1 = pg.makeRGBA(data[shape[0]/2], levels=levels)[0]       # yz plane
        tex2 = pg.makeRGBA(data[:,shape[1]/2], levels=levels)[0]     # xz plane
        tex3 = pg.makeRGBA(data[:,:,shape[2]/2], levels=levels)[0]   # xy plane

        v1 = gl.GLImageItem(tex1)
        v1.translate(-shape[1]/2, -shape[2]/2, 0)
        v1.rotate(90, 0,0,1)
        v1.rotate(-90, 0,1,0)
        w.addItem(v1)
        v2 = gl.GLImageItem(tex2)
        v2.translate(-shape[0]/2, -shape[2]/2, 0)
        v2.rotate(-90, 1,0,0)
        w.addItem(v2)
        v3 = gl.GLImageItem(tex3)
        v3.translate(-shape[0]/2, -shape[1]/2, 0)
        w.addItem(v3)
        ax = gl.GLAxisItem()
        w.addItem(ax)
        self.setCentralWidget(w);
        self.resize(1200,500)
w = fc.widget()

layout.addWidget(fc.widget(), 0, 0, 2, 1)

## Create two ImageView widgets to display the raw and processed data with contrast
## and color control.
v1 = pg.ImageView()
v2 = pg.ImageView()
layout.addWidget(v1, 0, 1)
layout.addWidget(v2, 1, 1)

win.show()

## generate random input data
data = np.random.normal(size=(100,100))
data = 25 * pg.gaussianFilter(data, (5,5))
data += np.random.normal(size=(100,100))
data[40:60, 40:60] += 15.0
data[30:50, 30:50] += 15.0
#data += np.sin(np.linspace(0, 100, 1000))
#data = metaarray.MetaArray(data, info=[{'name': 'Time', 'values': np.linspace(0, 1.0, len(data))}, {}])

## Set the raw data as the input value to the flowchart
fc.setInput(dataIn=data)


## At this point, we need some custom Node classes since those provided in the library
## are not sufficient. Each node will define a set of input/output terminals, a 
## processing function, and optionally a control widget (to be displayed in the 
## flowchart control panel)
Beispiel #45
0
win.setCentralWidget(cw)

l = QtGui.QGridLayout()
cw.setLayout(l)
l.setSpacing(0)

v = pg.GraphicsView()
vb = pg.ViewBox()
vb.setAspectLocked()
v.setCentralItem(vb)
l.addWidget(v, 0, 0)

w = pg.HistogramLUTWidget()
l.addWidget(w, 0, 1)

data = pg.gaussianFilter(np.random.normal(size=(256, 256)), (20, 20))
for i in range(32):
    for j in range(32):
        data[i*8, j*8] += .1
img = pg.ImageItem(data)
#data2 = np.zeros((2,) + data.shape + (2,))
#data2[0,:,:,0] = data  ## make non-contiguous array for testing purposes
#img = pg.ImageItem(data2[0,:,:,0])
vb.addItem(img)
vb.autoRange()

w.setImageItem(img)


## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
Beispiel #46
0
p1 = win.addPlot(row=1, col=0)
p2 = win.addPlot(row=2, col=0)

region = pg.LinearRegionItem()
region.setZValue(10)
# Add the LinearRegionItem to the ViewBox, but tell the ViewBox to exclude this 
# item when doing auto-range calculations.
p2.addItem(region, ignoreBounds=True)

#pg.dbg()
p1.setAutoVisible(y=True)


#create numpy arrays
#make the numbers large to show that the xrange shows data from 10000 to all the way 0
data1 = 10000 + 15000 * pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * np.random.random(size=10000)
data2 = 15000 + 15000 * pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * np.random.random(size=10000)

p1.plot(data1, pen="r")
p1.plot(data2, pen="g")

p2.plot(data1, pen="w")

def update():
    region.setZValue(10)
    minX, maxX = region.getRegion()
    p1.setXRange(minX, maxX, padding=0)    

region.sigRegionChanged.connect(update)

def updateRegion(window, viewRange):