def __init__(self): QtGui.QWidget.__init__(self) self.resize(800, 1000) self.layout = QtGui.QGridLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.layout) self.gw = pg.GraphicsLayoutWidget() self.layout.addWidget(self.gw) self.vb1 = self.gw.addViewBox() self.img1 = pg.ImageItem() self.vb1.addItem(self.img1) self.vb2 = self.gw.addViewBox(row=1, col=0) self.img2 = pg.ImageItem() self.vb2.addItem(self.img2) for vb in (self.vb1, self.vb2): vb.invertY() vb.setAspectLocked(True) self.plt1 = self.gw.addPlot(row=2, col=0) self.plt1.setLabels(bottom=('time', 's')) self.plt1_items = [] self.rois = [ pg.RectROI([0, 0], [10, 10], pen=(i, 4)) for i in range(2) ] for roi in self.rois: self.vb1.addItem(roi) roi.sigRegionChangeFinished.connect(self.roi_changed) self.ignore_roi_change = False self.plt2 = self.gw.addPlot(row=3, col=0) self.plt2.setXLink(self.plt1) self.plt2.setLabels(bottom=('time', 's')) self.base_time_rgn = pg.LinearRegionItem([0.0, 0.1]) self.test_time_rgn = pg.LinearRegionItem([0.1, 0.11]) for time_rgn in (self.base_time_rgn, self.test_time_rgn): self.plt1.addItem(time_rgn) time_rgn.sigRegionChangeFinished.connect(self.time_rgn_changed) time_rgn.sigRegionChangeFinished.connect( self.update_sequence_analysis) self.clamp_plots = [] self.plt3 = self.gw.addPlot(row=4, col=0) self.plt3.setLabels(left="dF / F", bottom="trial") self.show()
def addPinnedFrame(self): """Make a copy of the current camera frame and pin it to the view background""" data = self.frameDisplay.visibleImage() if data is None: return hist = self.frameDisplay.contrastCtrl.ui.histogram im = pg.ImageItem(data, levels=hist.getLevels(), lut=hist.getLookupTable(img=data), removable=True) im.sigRemoveRequested.connect(self.removePinnedFrame) if len(self.pinnedFrames) == 0: z = -10000 else: z = self.pinnedFrames[-1].zValue() + 1 im.setZValue(z) self.pinnedFrames.append(im) view = self.frameDisplay.imageItem().getViewBox() if view is not None: view.addItem(im) im.setTransform( self.frameDisplay.currentFrame.globalTransform().as2D())
def __init__(self, parent=None): Qt.QWidget.__init__(self, parent) self.layout = Qt.QGridLayout() self.setLayout(self.layout) self.view = pg.ImageView() self.layout.addWidget(self.view, 0, 0) self.ctrlWidget = Qt.QWidget() self.layout.addWidget(self.ctrlWidget, 0, 1) self.maskItem = pg.ImageItem() self.maskItem.setZValue(10) self.maskItem.setCompositionMode(Qt.QPainter.CompositionMode_Multiply) lut = np.zeros((256, 3), dtype='ubyte') lut[:, 0:2] = np.arange(256).reshape(256, 1) self.maskItem.setLookupTable(lut) kern = np.fromfunction( lambda x, y: np.clip(((5 - (x - 5)**2 + (y - 5)**2)**0.5 * 255), 0, 255), (11, 11)) self.maskItem.setDrawKernel(kern, mask=kern, center=(5, 5), mode='add') self.view.addItem(self.maskItem) self.view.sigTimeChanged.connect(self.updateMaskImage)
def errorSurface(axes=[3, 0], v1=None, v2=None, bounds=None, noise=0.0, n=5000): ## compute sum of squares error between two templates over a range of differences in v ## the two templates are generated from the parameters in v1 and v2 ## the error surface is computed by varying v2[axis[n]] from bounds[axis[n]][0] to bounds[axis[n]][1] on ## each axis of the surface. ## displays and returns the error surface, ## also returns an array of all the v2 parameters used for each point in the surface. x = np.linspace(0, 0.5, 5000) v = [1.0, 0.05, 0.05, 0.1] ## defaults used if v1 / v2 are not given if v1 is None: v1 = v[:] if v2 is None: v2 = v1[:] if bounds is None: bounds = [(0.0, 2.0), (0.0, 0.1), (0.01, 0.1), (0.01, 0.5)] template1 = pspFunc(v1, x) + np.random.normal(size=len(x), scale=noise) ## number of iterations per axis n = int(n**(1.0 / len(axes))) axv = [] for ax in axes: axv.append(np.linspace(bounds[ax][0], bounds[ax][1], n)) err = np.empty((n, ) * len(axes)) vals = np.empty(err.shape, dtype=object) inds = np.indices(err.shape).reshape((len(axes), err.size)) for i in xrange(inds.shape[1]): ind = tuple(inds[:, i]) v2a = v2[:] for j in range(len(axes)): v2a[axes[j]] = axv[j][ind[j]] template2 = pspFunc(v2a, x) err[ind] = np.sum((template2 - template1)**2) vals[ind] = v2a if len(axes) == 2: p = pg.plot() img = pg.ImageItem(err) p.addItem(img) b1 = bounds[axes[0]] b2 = bounds[axes[1]] img.setRect(QtCore.QRectF(b1[0], b2[0], b1[1] - b1[0], b2[1] - b2[0])) elif len(axes) == 3: pg.image(err) return err, vals
def __init__(self, *args): AnalysisModule.__init__(self, *args) self.layout = Qt.QGridLayout() self.setLayout(self.layout) self.splitter = Qt.QSplitter() self.layout.addWidget(self.splitter) self.ptree = ParameterTree() self.splitter.addWidget(self.ptree) self.imageView = pg.ImageView() self.splitter.addWidget(self.imageView) self.params = Parameter(name='imager', children=[ dict(name='scanner', type='interface', interfaceTypes=['scanner']), dict(name='detectors', type='group', addText="Add detector.."), dict(name='decomb', type='float', readonly=False, value=20e-6, suffix='s', siPrefix=True, bounds=[0, 1e-3], step=1e-6, decimals=5, children=[ dict(name='auto', type='action'), dict(name='subpixel', type='bool', value=False), ]), dict(name='downsample', type='int', value=1, suffix='x', bounds=[1,None]), dict(name='display', type='bool', value=True), dict(name='scanProgram', type='list', values=[]), dict(name='Objective', type='str', value='Unknown', readonly=True), dict(name='Filter', type='str', value='Unknown', readonly=True), ]) self.ptree.setParameters(self.params, showTop=False) self.params.sigTreeStateChanged.connect(self.update) self.params.child('detectors').sigAddNew.connect(self.addDetectorClicked) self.params.child('decomb', 'auto').sigActivated.connect(self.autoDecomb) self.man = getManager() self.scannerDev = self.man.getDevice(self.params['scanner']) # find first scope device that is parent of scanner dev = self.scannerDev while dev is not None and not isinstance(dev, Microscope): dev = dev.parentDevice() self.scopeDev = dev self.lastFrame = None # self.SUF = SUFA.ScannerUtilities() # self.ui.alphaSlider.valueChanged.connect(self.imageAlphaAdjust) self.img = pg.ImageItem() ## image shown in camera module self.img.setLookupTable(self.imageView.ui.histogram.getLookupTable) # image fetches LUT from the ImageView self.imageView.ui.histogram.sigLevelsChanged.connect(self._updateCamModImage) self.imageView.imageItem.setAutoDownsample(True)
def __init__(self): Qt.QObject.__init__(self) self._imageItem = pg.ImageItem() self.contrastCtrl = self.contrastClass() self.contrastCtrl.setImageItem(self._imageItem) self.bgCtrl = self.bgSubtractClass() self.bgCtrl.needFrameUpdate.connect(self.updateFrame) self.nextFrame = None self._updateFrame = False self.currentFrame = None self.lastDrawTime = None self.displayFps = None self.hasQuit = False ## Check for new frame updates every 16ms ## Some checks may be skipped even if there is a new frame waiting to avoid drawing more than ## 60fps. self.frameTimer = Qt.QTimer() self.frameTimer.timeout.connect(self.drawFrame) self.frameTimer.start(30) ## draw frames no faster than 60Hz
def __init__(self, image=None, **opts): ## If no image was specified, check for a file handle.. if image is None: image = opts.get('handle', None) item = None self.data = None if isinstance(image, QtGui.QGraphicsItem): item = image elif isinstance(image, np.ndarray): self.data = image elif isinstance(image, DataManager.FileHandle): opts['handle'] = image self.handle = image self.data = self.handle.read() if 'name' not in opts: opts['name'] = self.handle.shortName() try: if 'transform' in self.handle.info(): tr = pg.SRTTransform3D(self.handle.info()['transform']) tr = pg.SRTTransform(tr) ## convert to 2D opts['pos'] = tr.getTranslation() opts['scale'] = tr.getScale() opts['angle'] = tr.getRotation() else: ## check for older info formats if 'imagePosition' in self.handle.info(): opts['scale'] = self.handle.info()['pixelSize'] opts['pos'] = self.handle.info()['imagePosition'] elif 'Downsample' in self.handle.info(): ### Needed to support an older format stored by 2p imager if 'pixelSize' in self.handle.info(): opts['scale'] = self.handle.info()['pixelSize'] if 'microscope' in self.handle.info(): m = self.handle.info()['microscope'] opts['pos'] = m['position'][0:2] else: info = self.data._info[-1] opts['pos'] = info.get('imagePosition', None) elif hasattr(self.data, '_info'): info = self.data._info[-1] opts['scale'] = info.get('pixelSize', None) opts['pos'] = info.get('imagePosition', None) else: opts['defaultUserTransform'] = {'scale': (1e-5, 1e-5)} opts['scalable'] = True except: debug.printExc( 'Error reading transformation for image file %s:' % image.name()) if item is None: item = pg.ImageItem() CanvasItem.__init__(self, item, **opts) self.splitter = QtGui.QSplitter() self.splitter.setOrientation(QtCore.Qt.Vertical) self.layout.addWidget(self.splitter, self.layout.rowCount(), 0, 1, 2) self.filterGroup = pg.GroupBox("Image Filter") fgl = QtGui.QGridLayout() fgl.setContentsMargins(3, 3, 3, 3) fgl.setSpacing(1) self.filterGroup.setLayout(fgl) self.filter = ImageFilterWidget() self.filter.sigStateChanged.connect(self.filterStateChanged) fgl.addWidget(self.filter) self.splitter.addWidget(self.filterGroup) self.histogram = pg.HistogramLUTWidget() self.histogram.setImageItem(self.graphicsItem()) # addWidget arguments: row, column, rowspan, colspan self.splitter.addWidget(self.histogram) self.imgModeCombo = QtGui.QComboBox() self.imgModeCombo.addItems( ['SourceOver', 'Overlay', 'Plus', 'Multiply']) self.layout.addWidget(self.imgModeCombo, self.layout.rowCount(), 0, 1, 1) self.imgModeCombo.currentIndexChanged.connect(self.imgModeChanged) self.autoBtn = QtGui.QPushButton("Auto") self.autoBtn.setCheckable(True) self.autoBtn.setChecked(True) self.layout.addWidget(self.autoBtn, self.layout.rowCount() - 1, 1, 1, 1) self.timeSlider = QtGui.QSlider(QtCore.Qt.Horizontal) self.layout.addWidget(self.timeSlider, self.layout.rowCount(), 0, 1, 2) self.timeSlider.valueChanged.connect(self.timeChanged) # ## controls that only appear if there is a time axis self.timeControls = [self.timeSlider] if self.data is not None: if isinstance(self.data, pg.metaarray.MetaArray): self.filter.setInput(self.data.asarray()) else: self.filter.setInput(self.data) self.updateImage() # Needed to ensure selection box wraps the image properly tr = self.saveTransform() self.resetUserTransform() self.restoreTransform(tr)
def show(dh=None): """ Display a graphic of the currently selected slice / cell """ global v, g, atlas if dh is None: dh = man.currentFile v.clear() if 'cell' in dh.shortName().lower(): cd = dh sd = cd.parent() else: sd = dh cd = None atlas.loadState(sd) g = atlas.schematicGraphicsItems() v.addItem(g) if cd is not None: ## small image to go over slice schematic imgf = cd['morphology.png'] imgd = pg.colorToAlpha(imgf.read(), np.array([255,255,255])) mimg1 = pg.ImageItem(imgd) tr = pg.SRTTransform(imgf.info()['userTransform']) mimg1.setTransform(tr) mimg1.setParentItem(g.sliceGroup) g.cellImg1 = mimg1 ## larger image to be displayed above cellGroup = pg.ItemGroup() g.cellGroup = cellGroup mimg2 = pg.ImageItem(imgd) mimg2.setParentItem(cellGroup) mimg2.setTransform(tr * g.sliceGroup.transform()) mimg2.scale(1.0 / g.sliceScaleFactor, 1.0 / g.sliceScaleFactor) #angle = pg.SRTTransform(g.sliceGroup.transform()).getRotation() #mimg2.rotate(angle) cellScale = 50. cellGroup.scale(cellScale, cellScale) g.cellImg2 = mimg2 ## reposition image above slice schematic b1 = g.atlasGroup.mapRectToParent(g.atlasGroup.childrenBoundingRect()) b2 = g.sliceClip.mapRectToParent(g.sliceClip.boundingRect()) bounds = b1 | b2 cellGroup.setParentItem(g) imgBounds = g.mapRectFromItem(mimg2, mimg2.boundingRect()) pos = pg.Point(bounds.center().x() - imgBounds.center().x(), bounds.top()-imgBounds.bottom()) cellGroup.setPos(pos) ## add scale bar sbLength = 25e-6 g.cellScale = Qt.QGraphicsLineItem(0.0, 0.0, sbLength, 0.0) g.cellScale.setPen(pg.mkPen(color=0.0, width=100e-6/cellScale, cosmetic=False)) g.cellScale.setParentItem(cellGroup) g.cellScale.setZValue(10) g.cellScale.text = pg.TextItem(u"25 µm", anchor=(0.5, 1), color=(0,0,0)) g.cellScale.text.setParentItem(g.cellScale) g.cellScale.text.setPos(sbLength*0.5, -50e-6/cellScale) corner = mimg2.mapToParent(mimg2.boundingRect()).boundingRect().bottomRight() g.cellScale.setPos(corner + pg.Point(-sbLength/2., -sbLength/3.)) cell = dh sl = cell.parent() day = sl.parent() name = day.shortName() + "_" + sl.shortName() + "_" + cell.shortName() g.cellName = pg.TextItem(name, color=(0,0,0)) g.cellName.setParentItem(cellGroup) g.cellName.setPos(corner + pg.Point(-sbLength*4,-sbLength/4.))
def showMap(dh=None): """ Display a graphic of an input map for the currently selected cell """ global v, g, atlas if dh is None: dh = man.currentFile db = man.getModule('Data Manager').currentDatabase() v.clear() cd = dh sd = cd.parent() atlas.loadState(sd) g = atlas.schematicGraphicsItems(contours=False, sliceScale=10, cellDir=cd) v.addItem(g) cellGroup = pg.ItemGroup() g.cellGroup = cellGroup cellScale = 10. cellGroup.scale(cellScale, cellScale) cellGroup.setParentItem(g) g.atlasScale.hide() g.arrowGroup.hide() ## reposition/rescale atlas group b1 = g.atlasGroup.mapRectToParent(g.atlasGroup.childrenBoundingRect()) b2 = g.sliceClip.mapRectToParent(g.sliceClip.boundingRect()) g.atlasGroup.setPos(b2.right()-b1.left()+0.001, b2.top()-b1.top()) b1 = g.atlasGroup.mapRectToParent(g.atlasGroup.childrenBoundingRect()) bounds = b1 | b2 if cd.exists('morphology.png'): ## small image to go over slice schematic imgf = cd['morphology.png'] imgd = pg.colorToAlpha(imgf.read(), np.array([255,255,255])) mimg1 = pg.ImageItem(imgd) tr = pg.SRTTransform(imgf.info()['userTransform']) mimg1.setTransform(tr) mimg1.setParentItem(g.sliceGroup) mimg1.setZValue(100) g.cellImg1 = mimg1 ## larger image to be displayed above mimg2 = pg.ImageItem(imgd) mimg2.setParentItem(cellGroup) mimg2.setTransform(tr * g.sliceGroup.transform()) mimg2.scale(1.0 / g.sliceScaleFactor, 1.0 / g.sliceScaleFactor) #angle = pg.SRTTransform(g.sliceGroup.transform()).getRotation() #mimg2.rotate(angle) g.cellImg2 = mimg2 cellGroup.scale(5,5) ## reposition next to slice schematic imgBounds = g.mapRectFromItem(mimg2, mimg2.boundingRect()) pos = pg.Point(bounds.right()-imgBounds.left(), bounds.bottom()-imgBounds.bottom()) cellGroup.setPos(pos) ## add scale bar sbLength = 50e-6 g.cellScale = Qt.QGraphicsLineItem(0.0, 0.0, sbLength, 0.0) g.cellScale.setPen(pg.mkPen(color=0.0, width=5)) g.cellScale.setZValue(10) g.cellScale.text = pg.TextItem(u"%d µm" % int(sbLength*1e6), anchor=(0.5, 1), color=(0,0,0)) g.cellScale.text.setParentItem(g.cellScale) g.cellScale.text.setPos(sbLength*0.5, -50e-6/cellScale) #g.cellScale = pg.ScaleBar(sbLength) g.cellScale.setParentItem(cellGroup) corner = mimg2.mapToParent(mimg2.boundingRect()).boundingRect().bottomRight() g.cellScale.setPos(corner + pg.Point(-sbLength/2., -sbLength/3.)) pos = pg.SRTTransform(cd.info()['userTransform']).map(pg.Point(0,0)) size = pg.Point(30e-6, 30e-6) g.cellMarker = Qt.QGraphicsEllipseItem(Qt.QRectF(pos-size, pos+size)) g.cellMarker.setBrush(pg.mkBrush(100,100,255,150)) g.cellMarker.setPen(pg.mkPen('k', width=0.5)) g.cellMarker.setParentItem(g.sliceGroup) g.cellMarker.setZValue(90) sites = db.select('map_site_view', ['ProtocolDir', 'HasInput'], where={'CellDir': cd}) if len(sites) > 0: tr = sites[0]['ProtocolDir'].parent().info().get('userTransform', None) if tr is None: tr = pg.SRTTransform() else: tr = pg.SRTTransform(tr) pos = [] size = sites[0]['ProtocolDir'].info()['Scanner']['spotSize'] brushes = [] for site in sites: pd = site['ProtocolDir'] x,y = pd.info()['Scanner']['position'] p2 = tr.map(pg.Point(x,y)) pos.append((p2.x(), p2.y())) if site['HasInput']: brushes.append(pg.mkBrush('w')) else: brushes.append(pg.mkBrush(None)) inputMap = pg.ScatterPlotItem(pos=np.array(pos), size=size, brush=brushes, pen=(0,0,0,50), pxMode=False, antialias=True) g.sliceGroup.addItem(inputMap) g.inputMap = inputMap inputMap.setZValue(50) cell = dh sl = cell.parent() day = sl.parent() name = day.shortName() + "_" + sl.shortName() + "_" + cell.shortName() rec = db.select('DirTable_Cell', '*', where={'Dir': cd})[0] name += "\nType: " + str(rec['CellType']) + " Temp: " + str(rec['Temperature']) + " Internal: " + str(rec['Internal']) + " Age:" + str(rec['Age']) + " Raccess: " + str(rec['AccessResistance']) name += "\nDirect Area: %s>0pA %s>20pA %s>100pA" % (str(rec['DirectAreaGt0']), str(rec['DirectAreaGt20']), str(rec['DirectAreaGt100'])) name += " Direct n spikes: " + str(rec['DirectNSpikes']) name += "\nSpont Ex Decay: %s Spont In Decay: %s" % (str(rec['SpontExDecay1']), str(rec['SpontInDecay'])) name += "\nExcitatory input" if (rec['EvokedExDecay'] is not None or rec['EvokedExAmp'] is not None) else "" print(rec) #name += '\nDirect Slow Decay: %s %s' % (str(rec['DirectAreaGT0']), str(rec['DirectAreaGT0'])) g.cellName = pg.TextItem(name, color=(0,0,0)) g.cellName.setParentItem(g) g.cellName.setPos(0, bounds.bottom())
def __init__(self): QtGui.QSplitter.__init__(self, QtCore.Qt.Horizontal) self.resize(800, 1000) self.params = pg.parametertree.Parameter( name='params', type='group', children=[ dict(name='sequence', type='group', children=[ dict(name='analysis', type='list', values=['dF / F', 'SNR', 'noise']), ]), ]) self.ptree = pg.parametertree.ParameterTree() self.ptree.setParameters(self.params) self.params.child('sequence').sigTreeStateChanged.connect( self.update_sequence_analysis) self.leftPanel = QtGui.QWidget() self.addWidget(self.leftPanel) self.layout = QtGui.QGridLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.leftPanel.setLayout(self.layout) self.layout.addWidget(self.ptree, 0, 0) self.gw = pg.GraphicsLayoutWidget() self.addWidget(self.gw) self.vb1 = self.gw.addViewBox() self.img1 = pg.ImageItem() self.vb1.addItem(self.img1) self.vb2 = self.gw.addViewBox(row=1, col=0) self.img2 = pg.ImageItem() self.vb2.addItem(self.img2) for vb in (self.vb1, self.vb2): vb.invertY() vb.setAspectLocked(True) self.plt1 = self.gw.addPlot(row=2, col=0) self.plt1.setLabels(bottom=('time', 's')) self.plt1_items = [] self.rois = [ pg.EllipseROI([0, 0], [10, 10], pen=(i, 4)) for i in range(2) ] for roi in self.rois: self.vb1.addItem(roi) roi.sigRegionChangeFinished.connect(self.roi_changed) self.ignore_roi_change = False self.plt2 = self.gw.addPlot(row=3, col=0) self.plt2.setXLink(self.plt1) self.plt2.setLabels(bottom=('time', 's')) self.noise_time_rgn = pg.LinearRegionItem([0.01, 0.02], brush=(255, 0, 0, 30)) self.base_time_rgn = pg.LinearRegionItem([0.025, 0.95], brush=(0, 255, 0, 30)) self.test_time_rgn = pg.LinearRegionItem([0.1, 0.11], brush=(0, 0, 255, 30)) for time_rgn in (self.base_time_rgn, self.test_time_rgn, self.noise_time_rgn): self.plt1.addItem(time_rgn) time_rgn.sigRegionChangeFinished.connect(self.time_rgn_changed) time_rgn.sigRegionChangeFinished.connect( self.update_sequence_analysis) self.clamp_plots = [] self.plt3 = self.gw.addPlot(row=4, col=0) self.plt3.setLabels(left="dF / F", bottom="trial") self.show()
'labels': {} }]) label.write(labelFile, mappable=True) label = metaarray.MetaArray(file=labelFile, mmap=True, writable=True) labelCache = None labelInfo = {} #ui.view.enableMouse() #ui.view.setAspectLocked(True) vb = pg.ViewBox() ui.view.setCentralItem(vb) vb.setAspectLocked(True) vb.invertY(False) dataImg = pg.ImageItem() labelImg = pg.ImageItem() # mode=Qt.QPainter.CompositionMode_Plus) #labelImg.setCompositionMode(Qt.QPainter.CompositionMode_Overlay) labelImg.setZValue(10) labelImg.setOpacity(1) vb.addItem(dataImg) vb.addItem(labelImg) def connectSignals(): for r in [ui.rightRadio, ui.dorsalRadio, ui.rostralRadio]: r.toggled.connect(imageChanged) ui.zSlider.valueChanged.connect(updateImage) ui.radiusSpin.valueChanged.connect(updateKernel) ui.greyCheck.toggled.connect(updateImage) ui.labelSlider.valueChanged.connect(imageChanged)
pw1.setLabel('bottom', 'Decay Tau', 's') spl2 = Qt.QSplitter() spl2.setOrientation(Qt.Qt.Horizontal) spl1.addWidget(spl2) pw2 = pg.PlotWidget(labels={'bottom': ('time', 's')}) spl2.addWidget(pw2) tab = Qt.QTabWidget() spl2.addWidget(tab) ## For viewing cell morphology gv = pg.GraphicsView() gv.setBackgroundBrush(pg.mkBrush('w')) image = pg.ImageItem() gv.addItem(image) gv.enableMouse() gv.setAspectLocked(True) tab.addTab(gv, 'Morphology') ## 3D atlas import acq4.analysis.atlas.CochlearNucleus as CN atlas = CN.CNAtlasDisplayWidget() atlas.showLabel('DCN') atlas.showLabel('AVCN') atlas.showLabel('PVCN') tab.addTab(atlas, 'Atlas') atlasPoints = gl.GLScatterPlotItem() atlas.addItem(atlasPoints)
def __init__(self, image=None, **opts): """ CanvasItem displaying an image. The image may be 2 or 3-dimensional. Options: image: May be a fileHandle, ndarray, or GraphicsItem. handle: May optionally be specified in place of image """ ## If no image was specified, check for a file handle.. if image is None: image = opts.get('handle', None) item = None self.data = None self.currentT = None if isinstance(image, QtGui.QGraphicsItem): item = image elif isinstance(image, np.ndarray): self.data = image elif isinstance(image, DataManager.FileHandle): opts['handle'] = image self.handle = image self.data = self.handle.read() if 'name' not in opts: opts['name'] = self.handle.shortName() try: if 'transform' in self.handle.info(): tr = pg.SRTTransform3D(self.handle.info()['transform']) tr = pg.SRTTransform(tr) ## convert to 2D opts['pos'] = tr.getTranslation() opts['scale'] = tr.getScale() opts['angle'] = tr.getRotation() else: ## check for older info formats if 'imagePosition' in self.handle.info(): opts['scale'] = self.handle.info()['pixelSize'] opts['pos'] = self.handle.info()['imagePosition'] elif 'Downsample' in self.handle.info(): ### Needed to support an older format stored by 2p imager if 'pixelSize' in self.handle.info(): opts['scale'] = self.handle.info()['pixelSize'] if 'microscope' in self.handle.info(): m = self.handle.info()['microscope'] print 'm: ', m print 'mpos: ', m['position'] opts['pos'] = m['position'][0:2] else: info = self.data._info[-1] opts['pos'] = info.get('imagePosition', None) elif hasattr(self.data, '_info'): info = self.data._info[-1] opts['scale'] = info.get('pixelSize', None) opts['pos'] = info.get('imagePosition', None) else: opts['defaultUserTransform'] = {'scale': (1e-5, 1e-5)} opts['scalable'] = True except: debug.printExc( 'Error reading transformation for image file %s:' % image.name()) if item is None: item = pg.ImageItem() CanvasItem.__init__(self, item, **opts) self.histogram = pg.PlotWidget() self.blockHistogram = False self.histogram.setMaximumHeight(100) self.levelRgn = pg.LinearRegionItem() self.histogram.addItem(self.levelRgn) self.updateHistogram(autoLevels=True) # addWidget arguments: row, column, rowspan, colspan self.layout.addWidget(self.histogram, self.layout.rowCount(), 0, 1, 3) self.timeSlider = QtGui.QSlider(QtCore.Qt.Horizontal) #self.timeSlider.setMinimum(0) #self.timeSlider.setMaximum(self.data.shape[0]-1) self.layout.addWidget(self.timeSlider, self.layout.rowCount(), 0, 1, 3) self.timeSlider.valueChanged.connect(self.timeChanged) self.timeSlider.sliderPressed.connect(self.timeSliderPressed) self.timeSlider.sliderReleased.connect(self.timeSliderReleased) thisRow = self.layout.rowCount() self.edgeBtn = QtGui.QPushButton('Edge') self.edgeBtn.clicked.connect(self.edgeClicked) self.layout.addWidget(self.edgeBtn, thisRow, 0, 1, 1) self.meanBtn = QtGui.QPushButton('Mean') self.meanBtn.clicked.connect(self.meanClicked) self.layout.addWidget(self.meanBtn, thisRow + 1, 0, 1, 1) self.tvBtn = QtGui.QPushButton('tv denoise') self.tvBtn.clicked.connect(self.tvClicked) self.layout.addWidget(self.tvBtn, thisRow + 2, 0, 1, 1) self.maxBtn = QtGui.QPushButton('Max no Filter') self.maxBtn.clicked.connect(self.maxClicked) self.layout.addWidget(self.maxBtn, thisRow, 1, 1, 1) self.maxBtn2 = QtGui.QPushButton('Max w/Gaussian') self.maxBtn2.clicked.connect(self.max2Clicked) self.layout.addWidget(self.maxBtn2, thisRow + 1, 1, 1, 1) self.maxMedianBtn = QtGui.QPushButton('Max w/Median') self.maxMedianBtn.clicked.connect(self.maxMedianClicked) self.layout.addWidget(self.maxMedianBtn, thisRow + 2, 1, 1, 1) self.filterOrder = QtGui.QComboBox() self.filterLabel = QtGui.QLabel('Order') for n in range(1, 11): self.filterOrder.addItem("%d" % n) self.layout.addWidget(self.filterLabel, thisRow + 3, 2, 1, 1) self.layout.addWidget(self.filterOrder, thisRow + 3, 3, 1, 1) self.zPlanes = QtGui.QComboBox() self.zPlanesLabel = QtGui.QLabel('# planes') for s in ['All', '1', '2', '3', '4', '5']: self.zPlanes.addItem("%s" % s) self.layout.addWidget(self.zPlanesLabel, thisRow + 3, 0, 1, 1) self.layout.addWidget(self.zPlanes, thisRow + 3, 1, 1, 1) ## controls that only appear if there is a time axis self.timeControls = [ self.timeSlider, self.edgeBtn, self.maxBtn, self.meanBtn, self.maxBtn2, self.maxMedianBtn, self.filterOrder, self.zPlanes ] if self.data is not None: self.updateImage(self.data) self.graphicsItem().sigImageChanged.connect(self.updateHistogram) self.levelRgn.sigRegionChanged.connect(self.levelsChanged) self.levelRgn.sigRegionChangeFinished.connect( self.levelsChangeFinished)