def value(self, pos, grid=None, as_str=False): """ Return the data value at a point :param pos: Position as a 3D or 4D vector. If 4D last value is the volume index (0 for 3D). If ``grid`` not specified, position is in world space :param grid: If specified, interpret position in this ``DataGrid`` co-ordinate space. :param str: If True, return value as string to appropriate number of decimal places. """ if grid is None: grid = DataGrid([1, 1, 1], np.identity(4)) if len(pos) == 3: pos = list(pos) + [ 0, ] data_pos = [ int(math.floor(v + 0.5)) for v in self.grid.grid_to_grid(pos[:3], from_grid=grid) ] if min(data_pos) < 0: # Out of range but will be misinterpreted by indexing! value = 0 else: rawdata = self.volume(pos[3]) try: value = rawdata[tuple(data_pos)] except IndexError: value = 0 if as_str: return sf(value) else: return value
def _update_table(self): self.variance_model.clear() extra = self.ivm.extras.get( self._options.option("output-name").value + "_variance", None) if extra is not None: self.debug(str(extra)) for idx, header in enumerate(extra.col_headers): self.variance_model.setHorizontalHeaderItem( idx, QtGui.QStandardItem(header)) for idx, variance in enumerate(extra.arr): self.variance_model.setItem( idx, 0, QtGui.QStandardItem(str(variance[0]))) self.variance_model.setItem( idx, 1, QtGui.QStandardItem(sf(variance[1]))) self.variance_model.setItem( idx, 2, QtGui.QStandardItem(sf(variance[2])))
def _update_table(self): """ Set the data parameter values in the table based on the current point clicked """ self.values_table.clear() self.values_table.setHorizontalHeaderItem(0, QtGui.QStandardItem("Value")) data_vals = self.ivm.values(self.ivl.focus(), self.ivl.grid) for ii, ovl in enumerate(sorted(data_vals.keys())): if self.ivm.data[ovl].ndim == 3: self.values_table.setVerticalHeaderItem(ii, QtGui.QStandardItem(ovl)) self.values_table.setItem(ii, 0, QtGui.QStandardItem(sf(data_vals[ovl])))
def _focus_changed(self, focus): if self._qpdata is not None: value = self._qpdata.value(focus, self.ivl.grid) if self._qpdata.roi: region = int(value) if region == 0: text = "(outside ROI)" else: text = self._qpdata.regions.get(region, "") if text == "": text = "1" else: text = sf(value, 4) self._value_label.setText(text)
def _update_rms_table(self): try: self.updating = True # Hack to prevent plot being refreshed during table update self.rms_table.clear() self.rms_table.setHorizontalHeaderItem(0, QtGui.QStandardItem("Name")) self.rms_table.setHorizontalHeaderItem( 1, QtGui.QStandardItem("RMS (Position)")) pos = self.ivl.focus() sigs = self.ivm.timeseries(pos, self.ivl.grid) max_length = max([ 0, ] + [len(sig) for sig in sigs.values()]) if self.ivm.main is not None: main_curve = self.ivm.main.timeseries(pos, grid=self.ivl.grid) main_curve.extend([0] * max_length) main_curve = main_curve[:max_length] for idx, name in enumerate(sorted(sigs.keys())): # Make sure data curve is correct length data_curve = sigs[name] data_curve.extend([0] * max_length) data_curve = data_curve[:max_length] if self.ivm.main is not None: data_rms = np.sqrt( np.mean( np.square([ v1 - v2 for v1, v2 in zip(main_curve, data_curve) ]))) else: data_rms = 0 name_item = QtGui.QStandardItem(name) name_item.setCheckable(True) name_item.setEditable(False) if name not in self.data_enabled: self.data_enabled[name] = QtCore.Qt.Checked name_item.setCheckState(self.data_enabled[name]) self.rms_table.setItem(idx, 0, name_item) item = QtGui.QStandardItem(sf(data_rms)) item.setEditable(False) self.rms_table.setItem(idx, 1, item) finally: self.updating = False
def _update_pool_list(self): self._updating = True try: self.pools_table.clear() self.pools_table.setHorizontalHeaderItem( 0, QtGui.QStandardItem("Name")) self.pools_table.setHorizontalHeaderItem( 1, QtGui.QStandardItem("PPM offset")) self.pools_table.setHorizontalHeaderItem( 2, QtGui.QStandardItem("Exchange rate")) self.pools_table.setHorizontalHeaderItem(3, QtGui.QStandardItem("T1")) self.pools_table.setHorizontalHeaderItem(4, QtGui.QStandardItem("T2")) self.pools_table_view.horizontalHeader().setSectionResizeMode( 0, QtGui.QHeaderView.Stretch) for idx, pool in enumerate(self._pools): name_item = QtGui.QStandardItem(pool.name) name_item.setCheckable(True) name_item.setEditable(False) name_item.setCheckState( QtCore.Qt.Checked if pool.enabled else QtCore.Qt.Unchecked) name_item.setData(pool) self.pools_table.setItem(idx, 0, name_item) vals = pool.vals[self._b0_str] for col, val in enumerate(vals): item = QtGui.QStandardItem(sf(val)) item.setEditable(True) item.setData(pool) self.pools_table.setItem(idx, col + 1, item) self.pools_table_view.resizeColumnsToContents() finally: self._updating = False self.sig_pools_changed.emit(self.pools)
def _update_edit(self, value): if self.rtype == int: self.val_edit.setText(str(int(value))) else: self.val_edit.setText(sf(value, sig_fig=self.decimals))
def run(self, options): data_name = options.pop('data', None) output_name = options.pop('output-name', None) if data_name is None: data_items = self.ivm.data.keys() elif isinstance(data_name, six.string_types): data_items = [ data_name, ] if output_name is None: output_name = "%s_stats" % data_name else: data_items = data_name data_items = [self.ivm.data[name] for name in data_items] if output_name is None: output_name = "stats" roi_name = options.pop('roi', None) roi = None if roi_name is not None: roi = self.ivm.rois[roi_name] slice_dir = options.pop('slice-dir', None) slice_pos = options.pop('slice-pos', 0) sl = None if slice_dir is not None: sl = OrthoSlice(self.ivm.main.grid, slice_dir, slice_pos) vol = options.pop('vol', None) no_extra = options.pop('no-extras', False) exact_median = options.pop('exact-median', False) self.model.clear() self.model.setVerticalHeaderItem(0, QtGui.QStandardItem("Mean")) self.model.setVerticalHeaderItem(1, QtGui.QStandardItem("Median")) self.model.setVerticalHeaderItem(2, QtGui.QStandardItem("STD")) self.model.setVerticalHeaderItem(3, QtGui.QStandardItem("Min")) self.model.setVerticalHeaderItem(4, QtGui.QStandardItem("Max")) col = 0 for data in data_items: stats, roi_labels = self.get_summary_stats( data, roi, slice_loc=sl, vol=vol, exact_median=exact_median) for ii in range(len(stats['mean'])): self.model.setHorizontalHeaderItem( col, QtGui.QStandardItem("%s\n%s" % (data.name, roi_labels[ii]))) self.model.setItem(0, col, QtGui.QStandardItem(sf(stats['mean'][ii]))) self.model.setItem( 1, col, QtGui.QStandardItem(sf(stats['median'][ii]))) self.model.setItem(2, col, QtGui.QStandardItem(sf(stats['std'][ii]))) self.model.setItem(3, col, QtGui.QStandardItem(sf(stats['min'][ii]))) self.model.setItem(4, col, QtGui.QStandardItem(sf(stats['max'][ii]))) col += 1 if not no_extra: self.ivm.add_extra(output_name, table_to_extra(self.model, output_name))