示例#1
0
def test_nested_busy_cursors_clear_after_all_exit():
    with pg.BusyCursor():
        wait_cursor = pg.Qt.QtCore.Qt.CursorShape.WaitCursor
        with pg.BusyCursor():
            assert pg.Qt.QtGui.QApplication.overrideCursor().shape(
            ) == wait_cursor, "Cursor should be waiting"
        assert pg.Qt.QtGui.QApplication.overrideCursor().shape(
        ) == wait_cursor, "Cursor should be waiting"
    assert pg.Qt.QtGui.QApplication.overrideCursor(
    ) is None, "No override cursor should be set"
示例#2
0
    def plot_all(self):
        with pg.BusyCursor():
            self.clear()
            show_spikes = self.params['show spikes']

            for i, stim_key in enumerate(self.stim_keys):
                if self.params['stimulus filter', str(stim_key)] is False:
                    continue

                plt = DynamicsPlot()
                self.plots.append(plt)
                self.view.addItem(plt)
                self.view.nextRow()
                plt.set_title("%s  %0.0f Hz  %0.2f s" % stim_key)
                prs = self.sorted_recs[stim_key]
                plt.set_data(
                    prs,
                    show_spikes=show_spikes,
                    subtract_baseline=self.params['subtract baseline'])

            plt_height = max(400 if show_spikes else 250,
                             self.scroll_area.height() / len(self.stim_keys))
            self.view.setFixedHeight(plt_height * len(self.plots))
            self.view.setFixedWidth(
                self.scroll_area.width() -
                self.scroll_area.verticalScrollBar().width())
    def run():
        global results  # allow inspection from console
        n_types = params['n_types']
        Wab = np.array(
            [[float(str(wab_table.item(i, j).text())) for j in range(n_types)]
             for i in range(n_types)])
        with pg.BusyCursor():
            results = run_expt(Wab,
                               n_cells=params['n_cells'],
                               n_expts=params['n_expts'],
                               n_trials=params['n_trials'])

        cprobs = results['conn'].sum(axis=1) / results['probed'].sum(axis=1)
        rprobs = results['recip'].sum(axis=1) / results['probed'].sum(axis=1)
        ex_rprobs = cprobs**2
        ratios = rprobs / ex_rprobs

        y = pg.pseudoScatter(cprobs)
        c_plt.plot(cprobs, y, clear=True, pen=None, symbol='o')
        c_plt.addLine(x=Wab.mean())

        y = pg.pseudoScatter(rprobs)
        r_plt.plot(rprobs, y, clear=True, pen=None, symbol='o')

        y = pg.pseudoScatter(ratios)
        ratio_plt.plot(ratios, y, clear=True, pen=None, symbol='o')
        ratio_plt.addLine(x=1)

        rr_plt.plot(ex_rprobs, rprobs, clear=True, pen=None, symbol='o')
        l = pg.InfiniteLine(angle=45)
        rr_plt.addItem(l)
示例#4
0
文件: ui.py 项目: afcarl/ccfviewer
    def update_image_data(self):
        if self.atlas_data.image is None or self.atlas_data.label is None:
            return
        axis = self.display_ctrl.params['Orientation']
        axes = {
            'right': ('right', 'anterior', 'dorsal'),
            'dorsal': ('dorsal', 'right', 'anterior'),
            'anterior': ('anterior', 'right', 'dorsal')
        }[axis]
        order = [self.atlas_data.image._interpretAxis(ax) for ax in axes]

        # transpose, flip, downsample images
        ds = self.display_ctrl.params['Downsample']
        self.display_atlas = self.atlas_data.image.view(
            np.ndarray).transpose(order)
        with pg.BusyCursor():
            for ax in (0, 1, 2):
                self.display_atlas = pg.downsample(self.display_atlas,
                                                   ds,
                                                   axis=ax)
        self.display_label = self.atlas_data.label.view(
            np.ndarray).transpose(order)[::ds, ::ds, ::ds]

        # make sure atlas/label have the same size after downsampling

        scale = self.atlas_data.image._info[-1]['vxsize'] * ds
        self.scale = (scale, scale)

        self.zslider.setMaximum(self.display_atlas.shape[0])
        self.zslider.setValue(self.display_atlas.shape[0] // 2)
        self.angle_slider.setValue(0)
        self.update_ortho_image()
        self.update_slice_image()
        self.lut.setLevels(self.display_atlas.min(), self.display_atlas.max())
示例#5
0
 def selected_pair(self):
     with pg.BusyCursor():
         self.fit_compare.hide()
         self.meta_compare.hide()
         selected = self.experiment_browser.selectedItems()
         if len(selected) != 1:
             return
         item = selected[0]
         if hasattr(item, 'pair') is False:
             return
         pair = item.pair
         ## check to see if the pair has already been analyzed
         expt_id = pair.experiment.ext_id
         pre_cell_id = pair.pre_cell.ext_id
         post_cell_id = pair.post_cell.ext_id
         record = notes_db.get_pair_notes_record(expt_id, pre_cell_id, post_cell_id, session=self.notes_session)
         
         self.pair_param.setValue(pair)
         if record is None:
             self.pair_analyzer.load_pair(pair, self.default_session)
             self.pair_analyzer.analyze_responses()
             # self.pair_analyzer.fit_responses()
         else:
             self.pair_analyzer.load_pair(pair, self.default_session, record=record)
             self.pair_analyzer.analyze_responses()
             self.pair_analyzer.load_saved_fit(record)
示例#6
0
    def load_pair(self, pair, default_session, record=None):
        self.record = record
        self.initial_fit_parameters = OrderedDict([
            ('vc', {'-55': {}, '-70': {}}), 
            ('ic', {'-55': {}, '-70': {}}),
        ])
        self.output_fit_parameters = OrderedDict([
            ('vc', {'-55': {}, '-70': {}}), 
            ('ic', {'-55': {}, '-70': {}}),
        ])
        self.fit_params = {'initial': self.initial_fit_parameters, 'fit': self.output_fit_parameters}

        with pg.BusyCursor():
            self.reset_display()
            self.pair = pair
            print ('loading responses for %s...' % pair)
            q = response_query(default_session, pair)
            self.pulse_responses = [q.PulseResponse for q in q.all()]
            print('got %d pulse responses' % len(self.pulse_responses))
                
            if pair.has_synapse is True:
                synapse_type = pair.synapse.synapse_type
            else:
                synapse_type = None
            pair_params = {'Synapse call': synapse_type, 'Gap junction call': pair.has_electrical}
            self.ctrl_panel.update_user_params(**pair_params)
            self.ctrl_panel.update_fit_params(self.fit_params['fit'], fit_pass=True)
示例#7
0
    def updateImage(self):
        if self.atlas is None or self.label is None:
            return
        axis = self.displayCtrl.params['Orientation']
        axes = {
            'right': ('right', 'anterior', 'dorsal'),
            'dorsal': ('dorsal', 'right', 'anterior'),
            'anterior': ('anterior', 'right', 'dorsal')
        }[axis]
        order = [self.atlas._interpretAxis(ax) for ax in axes]

        # transpose, flip, downsample images
        ds = self.displayCtrl.params['Downsample']
        self.displayAtlas = self.atlas.view(np.ndarray).transpose(order)
        with pg.BusyCursor():
            for ax in (0, 1, 2):
                self.displayAtlas = pg.downsample(self.displayAtlas,
                                                  ds,
                                                  axis=ax)
        self.displayLabel = self.label.view(
            np.ndarray).transpose(order)[::ds, ::ds, ::ds]

        # make sure atlas/label have the same size after downsampling

        self.view.setData(self.displayAtlas,
                          self.displayLabel,
                          scale=self.atlas._info[-1]['vxsize'] * ds)
示例#8
0
    def load_pair(self, pair=None):
        pair = pair or self.pair
        if pair is None:
            return

        limit = self.params['data', 'limit']
        with pg.BusyCursor():

            pre_prec = db.aliased(db.PatchClampRecording)
            post_prec = db.aliased(db.PatchClampRecording)
            q = db.query(db.PulseResponse).join(db.StimPulse).join(db.Pair)
            q = q.join(pre_prec,
                       db.PulseResponse.recording_id == pre_prec.recording_id)
            q = q.join(post_prec,
                       db.StimPulse.recording_id == post_prec.recording_id)
            q = q.filter(db.Pair.id == pair.id)
            q = q.filter(pre_prec.clamp_mode == self.params['data',
                                                            'pre mode'])
            q = q.filter(post_prec.clamp_mode == self.params['data',
                                                             'post mode'])
            prs = q.limit(limit).all()

            # preload pulse response data
            ids = [pr.id for pr in prs]
            db.query(db.PulseResponse.data).filter(
                db.PulseResponse.id.in_(ids)).all()

            self.response_list = StimResponseList(prs)
            self.update_analysis()
示例#9
0
    def display_matrix_element_data(self, matrix_item, event, row, col):
        with pg.BusyCursor():
            field_name = self.matrix_display.matrix_display_filter.get_colormap_field()
            pre_class, post_class = [k for k, v in self.matrix_display.matrix_map.items() if v==[row, col]][0]

            #element = self.results.groupby(['pre_class', 'post_class']).get_group((pre_class, post_class))
            element = self.results.loc[self.pair_groups[(pre_class, post_class)]]
            if len(element) == 0:
                print ('%s->%s has no data, please select another element' % (pre_class, post_class))
                return
            analyzer = self.field_map[field_name]
            analyzer.print_element_info(pre_class, post_class, element, field_name)
            # from here row and col are tuples (row, pre_class) and (col, post_class) respectively
            row = (row, pre_class)
            col = (col, post_class)
            if int(event.modifiers() & pg.QtCore.Qt.ControlModifier)>0:
                self.selected += 1
                if self.selected >= len(self.colors):
                    self.selected = 0
                color = self.colors[self.selected]
                self.matrix_display.color_element(row, col, color)
                self.hist_plot.plot_element_data(element, analyzer, color, self.trace_panel)
                self.distance_plot.element_distance(element, color)
                self.element_scatter.color_selected_element(color, pre_class, post_class)
                self.pair_scatter.color_selected_element(color, pre_class, post_class)
                # self.pair_scatter.filter_selected_element(pre_class, post_class)
            else:
                self.display_matrix_element_reset() 
                color = self.colors[self.selected]
                self.matrix_display.color_element(row, col, color)
                self.hist_plot.plot_element_data(element, analyzer, color, self.trace_panel)
                self.distance_plot.element_distance(element, color)
                self.element_scatter.color_selected_element(color, pre_class, post_class)
                self.pair_scatter.color_selected_element(color, pre_class, post_class)
示例#10
0
def select_complete_clicked(param):
    with pg.BusyCursor():
        n_frames = raw_imgs.shape[2]
        for child in p_cell_selection.children()[0]:
            cell_id = int(child.name())
            visibility = (len(cell_frame_presence[cell_id]) == n_frames)
            child.setValue(visibility)
示例#11
0
 def update_clicked(self):
     p = cProfile.Profile()
     # p.enable()
     try:
         with pg.BusyCursor():
             # self.analyzers_needed()
             self.update_results()
             pre_cell_classes = self.cell_class_filter.get_pre_or_post_classes(
                 'presynaptic')
             post_cell_classes = self.cell_class_filter.get_pre_or_post_classes(
                 'postsynaptic')
             self.matrix_display.update_matrix_display(
                 self.results,
                 self.group_results,
                 self.cell_groups,
                 self.field_map,
                 pre_cell_classes=pre_cell_classes,
                 post_cell_classes=post_cell_classes)
             self.hist_plot.matrix_histogram(
                 self.results, self.group_results,
                 self.matrix_display.matrix_display_filter.colorMap,
                 self.field_map)
             self.element_scatter.set_data(self.group_results)
             self.pair_scatter.set_data(self.results)
             self.dist_plot = self.distance_plot.plot_distance(
                 self.results,
                 color=(128, 128, 128),
                 name='All Connections',
                 suppress_scatter=True)
             if self.main_window.matrix_widget.matrix is not None:
                 self.display_matrix_element_reset()
     finally:
         p.disable()
    def load_conn(self, pair):
        with pg.BusyCursor():
            amp_recs = get_amps(self.session, pair)
            base_recs = get_baseline_amps(self.session, pair, limit=len(amp_recs))

            for analyzer in self.analyzers:
                analyzer.load_conn(pair, amp_recs, base_recs)
 def deploy(self):
     with pg.BusyCursor():
         # Calculate detector translation required in x and y
         dx = self.parent.pixelSize * 1e6 * (self.parent.roi.centreX - self.parent.cx)  # microns
         dy = self.parent.pixelSize * 1e6 * (self.parent.roi.centreY - self.parent.cy)  # microns
         dz = np.mean(-self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6 # microns
         geo = self.parent.det.geometry(self.parent.evt)
         top = geo.get_top_geo()
         children = top.get_list_of_children()[0]
         geo.move_geo(children.oname, 0, dx=-dy, dy=-dx, dz=dz)
         fname =  self.parent.psocakeRunDir + "/"+str(self.parent.runNumber)+'-end.data'
         geo.save_pars_in_file(fname)
         print("#################################################")
         print("Deploying psana detector geometry: ", fname)
         print("#################################################")
         cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'recentred geometry'}
         if self.parent.args.localCalib:
             calibDir = './calib'
         elif self.parent.args.outDir is None:
             calibDir = self.parent.rootDir + '/calib'
         else:
             calibDir = self.parent.dir + '/' + self.parent.experimentName[:3] + '/' + \
                        self.parent.experimentName + '/calib'
         deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry',
                           run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0)
         # Reload new psana geometry
         self.parent.exp.setupExperiment()
         self.parent.img.getDetImage(self.parent.eventNumber)
         self.updateRings()
         self.parent.index.updateIndex()
         self.drawCentre()
         # Show mask
         self.parent.mk.updatePsanaMaskOn()
示例#14
0
 def _dbl_clicked(self, index):
     """Item double clicked; load in NWB viewer
     """
     with pg.BusyCursor():
         item = self.browser.itemFromIndex(index)[0]
         self.nwb_viewer.load_nwb(item.expt.nwb_file)
         self.nwb_viewer.show()
示例#15
0
    def clicked(self, points):
        with pg.BusyCursor():
            if self.parent.args.v >= 1:
                print("curve clicked", points)
                from pprint import pprint
                pprint(vars(points.scatter))
            for i in range(len(points.scatter.data)):
                if points.scatter.ptsClicked[0] == points.scatter.data[i][7]:
                    ind = i
                    break
            indX = points.scatter.data[i][0]
            indY = points.scatter.data[i][1]
            if self.parent.args.v >= 1: print "x,y: ", indX, indY
            if self.quantifier_sort:
                ind = self.quantifierIndSorted[ind]

            if self.parent.eventNumber != self.quantifierEvent[ind]:
                self.parent.eventNumber = self.quantifierEvent[ind]
                self.parent.calib, self.parent.data = self.parent.img.getDetImage(
                    self.parent.eventNumber)
                self.parent.img.win.setImage(self.parent.data,
                                             autoRange=False,
                                             autoLevels=False,
                                             autoHistogramRange=False)
                self.parent.exp.p.param(self.parent.exp.exp_grp,
                                        self.parent.exp.exp_evt_str).setValue(
                                            self.parent.eventNumber)
示例#16
0
 def set_expts(self, expts):
     with pg.BusyCursor():
         self.experiment_browser.clear()
         has_data = self.data_type['Pairs with data']
         if not has_data:
             self.experiment_browser.populate(experiments=expts, all_pairs=True)
         else:
             self.experiment_browser.populate(experiments=expts)
示例#17
0
 def deploy(self):
     with pg.BusyCursor():
         # Calculate detector translation in x and y
         dx = self.parent.pixelSize * 1e6 * (
             self.parent.cx - self.parent.roi.centreX)  # microns
         dy = self.parent.pixelSize * 1e6 * (
             self.parent.cy - self.parent.roi.centreY)  # microns
         dz = np.mean(self.parent.det.coords_z(self.parent.evt)
                      ) - self.parent.detectorDistance * 1e6  # microns
         geo = self.parent.det.geometry(self.parent.evt)
         if 'cspad' in self.parent.detInfo.lower(
         ) and 'cxi' in self.parent.experimentName:
             geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=-dz)
         elif 'rayonix' in self.parent.detInfo.lower(
         ) and 'mfx' in self.parent.experimentName:
             top = geo.get_top_geo()
             children = top.get_list_of_children()[0]
             geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz)
         elif 'rayonix' in self.parent.detInfo.lower(
         ) and 'xpp' in self.parent.experimentName:
             top = geo.get_top_geo()
             children = top.get_list_of_children()[0]
             geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz)
         else:
             print "deploy not implemented"
         fname = self.parent.psocakeRunDir + "/" + str(
             self.parent.runNumber) + '-end.data'
         geo.save_pars_in_file(fname)
         print "#################################################"
         print "Deploying psana detector geometry: ", fname
         print "#################################################"
         cmts = {
             'exp': self.parent.experimentName,
             'app': 'psocake',
             'comment': 'recentred geometry'
         }
         if self.parent.args.localCalib:
             calibDir = './calib'
         elif self.parent.args.outDir is None:
             calibDir = self.parent.rootDir + '/calib'
         else:
             calibDir = '/reg/d/psdm/' + self.parent.experimentName[:
                                                                    3] + '/' + self.parent.experimentName + '/calib'
         deploy_calib_file(cdir=calibDir,
                           src=str(self.parent.det.name),
                           type='geometry',
                           run_start=self.parent.runNumber,
                           run_end=None,
                           ifname=fname,
                           dcmts=cmts,
                           pbits=0)
         # Reload new psana geometry
         self.parent.exp.setupExperiment()
         self.parent.img.getDetImage(self.parent.eventNumber)
         self.updateRings()
         self.parent.index.updateIndex()
         self.drawCentre()
示例#18
0
    def createMuliColorAndList(self):
        """ Finally Load Images and poplulate the list widget from the dictionary"""
        with pg.BusyCursor(): # gives the circle showing gui is doing something
            self.generateImageDictionary()
            if self.image_dict:
                self.createMultiColorView(self.image_dict)
                self.displayImageNames(self.image_dict)

            else:
                pass
示例#19
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 - 1
            elif cacheKey[0] == 'float':
                dt = xp.float32
                loc = 1.0
                scale = 0.1
                mx = 1.0
            else:
                raise ValueError(f"unable to handle dtype: {cacheKey[0]}")

            chan_shape = (height, width)
            if ui.rgbCheck.isChecked():
                frame_shape = chan_shape + (3, )
            else:
                frame_shape = chan_shape
            data = xp.empty((frames, ) + frame_shape, dtype=dt)
            view = data.reshape((-1, ) + chan_shape)
            for idx in range(view.shape[0]):
                subdata = xp.random.normal(loc=loc,
                                           scale=scale,
                                           size=chan_shape)
                # note: gaussian filtering has been removed as it slows down array
                #       creation greatly.
                if cacheKey[0] != 'float':
                    xp.clip(subdata, 0, mx, out=subdata)
                view[idx] = subdata

            data[:, 10:50, 10] = mx
            data[:, 48, 9:12] = mx
            data[:, 47, 8:13] = mx
            cache = {
                cacheKey: data
            }  # clear to save memory (but keep one to prevent unnecessary regeneration)

        data = cache[cacheKey]
        updateLUT()
        updateSize()
    def browser_item_selected(self):
        with pg.BusyCursor():
            selected = self.browser.selectedItems()
            if len(selected) != 1:
                return
            item = selected[0]
            if not hasattr(item, 'pair'):
                return
            pair = item.pair

            self.load_pair(pair)
 def syncGeom(self):
     with pg.BusyCursor():
         print "#################################################"
         print "Updating psana geometry with CrystFEL geometry"
         print "#################################################"
         self.parent.geom.findPsanaGeometry()
         psanaGeom = self.parent.psocakeRunDir + "/.temp.data"
         if self.parent.args.localCalib:
             cmd = [
                 "crystfel2psana", "-e", self.parent.experimentName, "-r",
                 str(self.parent.runNumber), "-d",
                 str(self.parent.det.name), "--rootDir", '.', "-c",
                 self.geom, "-p", psanaGeom, "-z",
                 str(self.parent.clen)
             ]
         else:
             cmd = [
                 "crystfel2psana", "-e", self.parent.experimentName, "-r",
                 str(self.parent.runNumber), "-d",
                 str(self.parent.det.name), "--rootDir",
                 self.parent.rootDir, "-c", self.geom, "-p", psanaGeom,
                 "-z",
                 str(self.parent.clen)
             ]
         if self.parent.args.v >= 0: print "cmd: ", cmd
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
         output = p.communicate()[0]
         p.stdout.close()
         # Reload new psana geometry
         cmts = {
             'exp': self.parent.experimentName,
             'app': 'psocake',
             'comment': 'converted from crystfel geometry'
         }
         if self.parent.args.localCalib:
             calibDir = './calib'
         elif self.parent.args.outDir is None:
             calibDir = self.parent.rootDir + '/calib'
         else:
             calibDir = '/reg/d/psdm/' + self.parent.experimentName[:
                                                                    3] + '/' + self.parent.experimentName + '/calib'
         deploy_calib_file(cdir=calibDir,
                           src=str(self.parent.det.name),
                           type='geometry',
                           run_start=self.parent.runNumber,
                           run_end=None,
                           ifname=psanaGeom,
                           dcmts=cmts,
                           pbits=0)
         self.parent.exp.setupExperiment()
         self.parent.img.getDetImage(self.parent.eventNumber)
         self.parent.geom.updateRings()
         self.parent.index.updateIndex()
         self.parent.geom.drawCentre()
示例#22
0
def save_selected_clicked(param):
    if not any(cell_visibility.values()):
        pg.Qt.QtGui.QMessageBox.error(
            b_save_selected, 'Save failed',
            'Please select at least one cell before saving')
        return
    with pg.BusyCursor():
        save_results(path_in, trj, col_tuple, col_weights, id_masks, cell_ids,
                     background_id, color_list, cell_color_idx,
                     cell_visibility, params['Pixel scale'][0],
                     params['Pixel scale'][3], params['Show id\'s'][0], True,
                     params['Show tracks'][0], params['Mask extension'][0])
 def autoDeploy(self):
     with pg.BusyCursor():
         powderHits = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxHits.npy')
         powderMisses = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxMisses.npy')
         powderImg = self.parent.det.image(self.parent.evt, np.maximum(powderHits,powderMisses))
         centreRow, centreCol = findDetectorCentre(np.log(abs(powderImg)), self.parent.cx, self.parent.cy, range=200)
         print("Current centre along row,centre along column: ", self.parent.cx, self.parent.cy)
         print("Optimum centre along row,centre along column: ", centreRow, centreCol)
         allowedDeviation = 175 # pixels
         if abs(self.parent.cx - centreRow) <= allowedDeviation and \
             abs(self.parent.cy - centreCol) <= allowedDeviation:
             deploy = True
         else:
             deploy = False
             print "Too far away from current centre. I will not deploy the auto centred geometry."
         if deploy:
             # Calculate detector translation in x and y
             dx = self.parent.pixelSize * 1e6 * (self.parent.cx - centreRow)  # microns
             dy = self.parent.pixelSize * 1e6 * (self.parent.cy - centreCol)  # microns
             dz = np.mean(self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6  # microns
             geo = self.parent.det.geometry(self.parent.evt)
             if 'cspad' in self.parent.detInfo.lower() and 'cxi' in self.parent.experimentName:
                 geo.move_geo('CSPAD:V1', 0, dx=dx, dy=dy, dz=-dz)
             elif 'rayonix' in self.parent.detInfo.lower() and 'mfx' in self.parent.experimentName:
                 top = geo.get_top_geo()
                 children = top.get_list_of_children()[0]
                 geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz)
             elif 'rayonix' in self.parent.detInfo.lower() and 'xpp' in self.parent.experimentName:
                 top = geo.get_top_geo()
                 children = top.get_list_of_children()[0]
                 geo.move_geo(children.oname, 0, dx=dx, dy=dy, dz=-dz)
             else:
                 print "autoDeploy not implemented"
             fname = self.parent.psocakeRunDir + "/" + str(self.parent.runNumber) + '-end.data'
             geo.save_pars_in_file(fname)
             print "#################################################"
             print "Deploying psana detector geometry: ", fname
             print "#################################################"
             cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'auto recentred geometry'}
             if self.parent.args.localCalib:
                 calibDir = './calib'
             elif self.parent.args.outDir is None:
                 calibDir = self.parent.rootDir + '/calib'
             else:
                 calibDir = '/reg/d/psdm/' + self.parent.experimentName[:3] + '/' + self.parent.experimentName + '/calib'
             deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry',
                               run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0)
             # Reload new psana geometry
             self.parent.exp.setupExperiment()
             self.parent.img.getDetImage(self.parent.eventNumber)
             self.updateRings()
             self.parent.index.updateIndex()
             self.drawCentre()
    def autoDeploy(self): #FIXME: yet to verify this works correctly on new lab coordinate
        with pg.BusyCursor():
            powderHits = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxHits.npy')
            powderMisses = np.load(self.parent.psocakeRunDir + '/' + self.parent.experimentName + '_' + str(self.parent.runNumber).zfill(4) + '_maxMisses.npy')
            powderImg = self.parent.det.image(self.parent.evt, np.maximum(powderHits,powderMisses))
            centreRow, centreCol = findDetectorCentre(np.log(abs(powderImg)), self.parent.cx, self.parent.cy, range=200)
            print("Current centre along row,centre along column: ", self.parent.cx, self.parent.cy)
            print("Optimum centre along row,centre along column: ", centreRow, centreCol)
            allowedDeviation = 175 # pixels
            if abs(self.parent.cx - centreRow) <= allowedDeviation and \
                abs(self.parent.cy - centreCol) <= allowedDeviation:
                deploy = True
            else:
                deploy = False
                print("Too far away from current centre. I will not deploy the auto centred geometry.")
            if deploy:
                # Calculate detector translation in x and y
                dx = self.parent.pixelSize * 1e6 * (self.parent.cx - centreRow)  # microns
                dy = self.parent.pixelSize * 1e6 * (self.parent.cy - centreCol)  # microns
                dz = np.mean(-self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6  # microns

                dx = self.parent.pixelSize * 1e6 * (self.parent.roi.centreX - self.parent.cx)  # microns
                dy = self.parent.pixelSize * 1e6 * (self.parent.roi.centreY - self.parent.cy)  # microns
                dz = np.mean(-self.parent.det.coords_z(self.parent.evt)) - self.parent.detectorDistance * 1e6  # microns

                geo = self.parent.det.geometry(self.parent.evt)
                top = geo.get_top_geo()
                children = top.get_list_of_children()[0]
                geo.move_geo(children.oname, 0, dx=-dy, dy=-dx, dz=dz)
                fname = self.parent.psocakeRunDir + "/" + str(self.parent.runNumber) + '-end.data'
                geo.save_pars_in_file(fname)
                print("#################################################")
                print("Deploying psana detector geometry: ", fname)
                print("#################################################")
                cmts = {'exp': self.parent.experimentName, 'app': 'psocake', 'comment': 'auto recentred geometry'}
                if self.parent.args.localCalib:
                    calibDir = './calib'
                elif self.parent.args.outDir is None:
                    calibDir = self.parent.rootDir + '/calib'
                else:
                    calibDir = self.parent.dir + '/' + self.parent.experimentName[:3] + '/' + self.parent.experimentName + \
                               '/calib'
                deploy_calib_file(cdir=calibDir, src=str(self.parent.det.name), type='geometry',
                                  run_start=self.parent.runNumber, run_end=None, ifname=fname, dcmts=cmts, pbits=0)
                # Reload new psana geometry
                self.parent.exp.setupExperiment()
                self.parent.img.getDetImage(self.parent.eventNumber)
                self.updateRings()
                self.parent.index.updateIndex()
                self.drawCentre()
                # Show mask
                self.parent.mk.updatePsanaMaskOn()
示例#25
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()
示例#26
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()
示例#27
0
def readNRRDAtlas(nrrdFile=None):
    """
    Download atlas files from:
      http://help.brain-map.org/display/mouseconnectivity/API#API-DownloadAtlas
    """
    import nrrd
    if nrrdFile is None:
        displayMessage('Please Select NRRD Atlas File')
        nrrdFile = QtGui.QFileDialog.getOpenFileName(None,
                                                     "Select NRRD atlas file")

    with pg.BusyCursor():
        data, header = nrrd.read(nrrdFile)

    # convert to ubyte to compress a bit
    np.multiply(data, 255. / data.max(), out=data, casting='unsafe')
    data = data.astype('ubyte')

    # data must have axes (anterior, dorsal, right)
    # rearrange axes to fit -- CCF data comes in (posterior, inferior, right) order.
    data = data[::-1, ::-1, :]

    # voxel size in um
    vxsize = 1e-6 * float(header['space directions'][0][0])

    info = [{
        'name': 'anterior',
        'values': np.arange(data.shape[0]) * vxsize,
        'units': 'm'
    }, {
        'name': 'dorsal',
        'values': np.arange(data.shape[1]) * vxsize,
        'units': 'm'
    }, {
        'name': 'right',
        'values': np.arange(data.shape[2]) * vxsize,
        'units': 'm'
    }, {
        'vxsize': vxsize
    }]
    ma = metaarray.MetaArray(data, info=info)
    return ma
示例#28
0
    def update_display(self):
        with pg.BusyCursor():
            align = 'pre' if self.params['display',
                                         'plot spike aligned'] else 'stim'

            self.clear_plots()

            rl = self.corrected_response_list
            if len(rl) == 0:
                return

            stim_ts = rl.get_tseries('stim', align=align)
            self._plot_ts(stim_ts, self.plt1)

            pre_ts = rl.get_tseries('pre', align=align)
            self._plot_ts(pre_ts, self.plt2)

            post_ts = rl.get_tseries('post', align=align)
            dvdt = self.params['display', 'plot dv/dt']
            lowpass = self.params['display', 'plot lowpass']
            self._plot_ts(post_ts, self.plt3, dvdt=dvdt, lowpass=lowpass)
示例#29
0
    def find_files(self):
        self.prev_item = None
        self.pattern_list.clear()
        name = self.path_edit.text()
        self.new = True

        if any([i in name for i in '[*?']):
            self.flist = glob.glob(name)
            if not self.flist:
                self.image_label.setText('no files found')
                return
        else:
            # use all files in folder
            dirname = os.path.dirname(name)
            self.flist = [
                os.path.join(dirname, i)
                for i in os.listdir(os.path.dirname(name))
            ]
            self.flist = list(
                filter(lambda x: x.endswith('.cbf') or x.endswith('.nxs'),
                       self.flist))

        self.flist = sorted(self.flist, key=self._sort_keys)

        #print(self.flist)
        with pg.BusyCursor():
            for f in self.flist:
                if f.endswith('.cbf'):
                    self._add_cbf(f)
                elif f.endswith('.nxs'):
                    m = self._lambda3m_regex.match(f)
                    if m:
                        self._add_lambda3m(f)
                    else:
                        self._add_lambda(f)
        try:
            self.pattern_list.setCurrentItem(self.pattern_list.topLevelItem(0),
                                             0, QItemSelectionModel.Select)
        except:
            pass
示例#30
0
    def selection_changed(self):
        with pg.BusyCursor():
            sel = self.syn_tree.selectedItems()[0]
            expt = sel.expt

            self.expt_info.set_experiment(expt)

            pre_cell = sel.cells[0].cell_id
            post_cell = sel.cells[1].cell_id

            key = (expt, pre_cell, post_cell)
            if key not in self.analyzers:
                self.analyzers[key] = DynamicsAnalyzer(*key)
            analyzer = self.analyzers[key]

            if len(analyzer.pulse_responses) == 0:
                raise Exception(
                    "No suitable data found for cell %d -> cell %d in expt %s"
                    % (pre_cell, post_cell, expt))

            # Plot all individual and averaged train responses for all sets of stimulus parameters
            self.train_plots.clear()
            analyzer.plot_train_responses(plot_grid=self.train_plots)