Beispiel #1
0
    def load_clicked(self):
        """
        Checks that directory is pointed at a slice
        Check LIMS for 20x biocytin image and if 20x image is saved locally.
        If image not saved locally then copies file from LIMS.
        Enables button to create a JSON of the cell locations
        """
        if self.base_dir.info()['dirType'] != 'Slice':
            raise Exception('No Slice Selected')
        self.base_path = self.base_dir.name()

        aff_image_path = lims.specimen_20x_image(self.specimen_name,
                                                 treatment='Biocytin')
        if aff_image_path is None:
            raise Exception("No 20x biocytin image for specimen %s" %
                            self.specimen_name)

        if not os.path.exists(aff_image_path):
            raise Exception("No image found at path '%s'" % aff_image_path)

        aff_image_name = os.path.split(aff_image_path)[-1]
        save_path = os.path.join(self.base_path, aff_image_name)

        if not os.path.exists(save_path):
            with pg.BusyCursor():
                shutil.copy2(aff_image_path, save_path)
                self.base_dir.indexFile(aff_image_name)
Beispiel #2
0
    def storeDBScan(self, scan, storeEvents=True):
        """Store all data for a scan, using cached values if possible"""
        p = debug.Profiler("Photostim.storeDBScan", disabled=True)

        if storeEvents:
            self.clearDBScan(scan)

        with pg.BusyCursor():
            #dh = scan.source()
            #print "Store scan:", scan.source().name()
            events = []
            stats = []
            spots = scan.spots()
            with pg.ProgressDialog("Preparing data for %s" % scan.name(), 0,
                                   len(spots) + 1) as dlg:

                ## collect events and stats from all spots in the scan
                for i in xrange(len(spots)):
                    s = spots[i]
                    fh = self.dataModel.getClampFile(s.data())
                    try:
                        ev = scan.getEvents(fh)['events']
                        events.append(ev)
                    except:
                        print fh, scan.getEvents(fh)
                        raise
                    st = scan.getStats(s.data())
                    stats.append(st)
                    dlg.setValue(i)
                    if dlg.wasCanceled():
                        raise HelpfulException("Scan store canceled by user.",
                                               msgType='status')

                p.mark("Prepared data")

            dbui = self.getElement('Database')
            db = dbui.getDb()
            with db.transaction():
                ## Store all events for this scan
                if storeEvents:
                    events = [x for x in events if len(x) > 0]

                    if len(events) > 0:
                        ev = np.concatenate(events)
                        p.mark("concatenate events")
                        self.detector.storeToDB(ev)
                        p.mark("stored all events")

                ## Store spot data
                self.storeStats(stats)
                p.mark("stored all stats")
                p.finish()
Beispiel #3
0
    def __init__(self, **kwds):
        if not HAVE_AICCF:
            raise Exception(
                "This item requires the aiccf module, but it could not be imported."
            )
        kwds.pop('viewRect', None)

        self.atlas = CCFAtlasData()
        with pg.BusyCursor():
            self.atlasView = AtlasSliceView()
            self.atlasView.set_data(self.atlas)

        item = self.atlasView.img2
        opts = {'scalable': True, 'rotatable': True, 'movable': True}
        opts.update(kwds)
        CanvasItem.__init__(self, item, **opts)

        self.__ctrl = Qt.QWidget()
        self.__layout = Qt.QGridLayout()
        self.__ctrl.setLayout(self.__layout)
        self.__layout.setContentsMargins(0, 0, 0, 0)
        self.__layout.addWidget(self.atlasView.display_ctrl, 0, 0)
        self.__layout.addWidget(self.atlasView.label_tree, 1, 0)

        self.showSliceBtn = Qt.QPushButton("Show slice")
        self.showSliceBtn.setCheckable(True)
        self.__layout.addWidget(self.showSliceBtn, 2, 0)
        self.showSliceBtn.toggled.connect(self.showSliceToggled)

        self.layout.addWidget(self.__ctrl, self.layout.rowCount(), 0, 1, 2)

        # Set up window for selecting slice plane
        self.sliceWidget = Qt.QWidget()
        self.sliceLayout = Qt.QGridLayout()
        self.sliceWidget.setLayout(self.sliceLayout)
        self.sliceGraphicsView = pg.GraphicsLayoutWidget()
        self.sliceLayout.addWidget(self.sliceGraphicsView, 0, 0)
        self.sliceView = self.sliceGraphicsView.addViewBox()
        self.sliceView.addItem(self.atlasView.img1)
        self.sliceView.autoRange()
        self.sliceView.setAspectLocked(True)
        self.sliceView.addItem(self.atlasView.line_roi)
        self.sliceLayout.addWidget(self.atlasView.zslider, 1, 0)
        self.sliceLayout.addWidget(self.atlasView.angle_slider, 2, 0)
        self.sliceWidget.resize(800, 800)
Beispiel #4
0
    def setCurrentFile(self, file):
        #print "=============== set current file ============"
        if file is self.current:
            return

        ## What if we just want to update the data display?
        #self.clear()

        if file is None:
            self.current = None
            return

        if file.isDir():
            ## Sequence or not?
            return
        else:
            typ = file.fileType()
            if typ is None:
                return
            else:
                image = False
                with pg.BusyCursor():
                    data = file.read()
                if typ == 'ImageFile':
                    image = True
                elif typ == 'MetaArray':
                    if data.ndim == 2 and not data.axisHasColumns(
                            0) and not data.axisHasColumns(1):
                        image = True
                    elif data.ndim > 2:
                        image = True
                else:
                    return

        with pg.BusyCursor():
            if image:
                if self.currentType == 'image' and len(self.widgets) > 0:
                    try:
                        self.widgets[0].setImage(data, autoRange=False)
                    except:
                        print "widget types:", map(type, self.widgets)
                        raise
                else:
                    self.clear()
                    w = pg.ImageView(self)
                    #print "add image:", w.ui.roiPlot.plotItem
                    #self.plots = [weakref.ref(w.ui.roiPlot.plotItem)]
                    self.addWidget(w)
                    w.setImage(data)
                    self.widgets.append(w)
                self.currentType = 'image'
            else:
                self.clear()
                w = pg.MultiPlotWidget(self)
                self.addWidget(w)
                w.plot(data)
                self.currentType = 'plot'
                self.widgets.append(w)
                #print "add mplot:", w.mPlotItem.plots

                #self.plots = [weakref.ref(p[0]) for p in w.mPlotItem.plots]

        if (hasattr(data, 'implements') and data.implements('MetaArray')):
            if self.dictWidget is None:
                w = DictView(data._info)
                self.dictWidget = w
                #w.setText(str(data._info[-1]))
                self.addWidget(w)
                self.widgets.append(w)
                h = self.size().height()
                self.setSizes([h * 0.8, h * 0.2])
            else:
                self.dictWidget.setData(data._info)
 def load_data(self, seqDir):
     with pg.BusyCursor():
         self._load_data(seqDir)