def createWidget(self, parent): from silx.gui.plot3d import ScalarFieldView from silx.gui.plot3d import SFViewParamTree plot = ScalarFieldView.ScalarFieldView(parent) plot.setAxesLabels(*reversed(self.axesNames(None, None))) def computeIsolevel(data): data = data[numpy.isfinite(data)] if len(data) == 0: return 0 else: return numpy.mean(data) + numpy.std(data) plot.addIsosurface(computeIsolevel, '#FF0000FF') # Create a parameter tree for the scalar field view options = SFViewParamTree.TreeView(plot) options.setSfView(plot) # Add the parameter tree to the main window in a dock widget dock = qt.QDockWidget() dock.setWidget(options) plot.addDockWidget(qt.Qt.RightDockWidgetArea, dock) return plot
def __init__(self, parent=None): """ :param parent: Parent QWidget """ super(ArrayVolumePlot, self).__init__(parent) self.__signal = None self.__signal_name = None # the Z, Y, X axes apply to the last three dimensions of the signal # (in that order) self.__z_axis = None self.__z_axis_name = None self.__y_axis = None self.__y_axis_name = None self.__x_axis = None self.__x_axis_name = None from silx.gui.plot3d.ScalarFieldView import ScalarFieldView from silx.gui.plot3d import SFViewParamTree self._view = ScalarFieldView(self) def computeIsolevel(data): data = data[numpy.isfinite(data)] if len(data) == 0: return 0 else: return numpy.mean(data) + numpy.std(data) self._view.addIsosurface(computeIsolevel, '#FF0000FF') # Create a parameter tree for the scalar field view options = SFViewParamTree.TreeView(self._view) options.setSfView(self._view) # Add the parameter tree to the main window in a dock widget dock = qt.QDockWidget() dock.setWidget(options) self._view.addDockWidget(qt.Qt.RightDockWidgetArea, dock) self._hline = qt.QFrame(self) self._hline.setFrameStyle(qt.QFrame.HLine) self._hline.setFrameShadow(qt.QFrame.Sunken) self._legend = qt.QLabel(self) self._selector = NumpyAxesSelector(self) self._selector.setNamedAxesSelectorVisibility(False) self.__selector_is_connected = False layout = qt.QVBoxLayout() layout.addWidget(self._view) layout.addWidget(self._hline) layout.addWidget(self._legend) layout.addWidget(self._selector) self.setLayout(layout)
3D data set as a subset by providing the indices along the first n-3 dimensions with '#': <filename>::<path_in_file>#<1st_dim_index>...#<n-3th_dim_index> E.g.: data.h5::/data_5D#1#1 """) args = parser.parse_args(args=sys.argv[1:]) # Start GUI app = qt.QApplication([]) # Create the viewer main window window = ScalarFieldView() # Create a parameter tree for the scalar field view treeView = SFViewParamTree.TreeView(window) treeView.setSfView(window) # Attach the parameter tree to the view # Add the parameter tree to the main window in a dock widget dock = qt.QDockWidget() dock.setWindowTitle('Parameters') dock.setWidget(treeView) window.addDockWidget(qt.Qt.RightDockWidgetArea, dock) # Load data from file if args.filename is not None: data = load(args.filename) _logger.info('Data:\n\tShape: %s\n\tRange: [%f, %f]', str(data.shape), data.min(), data.max()) else: # Create dummy data
def main(argv=None): # Parse input arguments parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-l', '--level', nargs='?', type=float, default=float('nan'), help="The value at which to generate the iso-surface") parser.add_argument('-sx', '--xscale', nargs='?', type=float, default=1., help="The scale of the data on the X axis") parser.add_argument('-sy', '--yscale', nargs='?', type=float, default=1., help="The scale of the data on the Y axis") parser.add_argument('-sz', '--zscale', nargs='?', type=float, default=1., help="The scale of the data on the Z axis") parser.add_argument('-ox', '--xoffset', nargs='?', type=float, default=0., help="The offset of the data on the X axis") parser.add_argument('-oy', '--yoffset', nargs='?', type=float, default=0., help="The offset of the data on the Y axis") parser.add_argument('-oz', '--zoffset', nargs='?', type=float, default=0., help="The offset of the data on the Z axis") parser.add_argument('filename', nargs='?', default=None, help="""Filename to open. It supports 3D volume saved as .npy or in .h5 files. It also support nD data set (n>=3) stored in a HDF5 file. For HDF5, provide the filename and path as: <filename>::<path_in_file>. If the data set has more than 3 dimensions, it is possible to choose a 3D data set as a subset by providing the indices along the first n-3 dimensions with '#': <filename>::<path_in_file>#<1st_dim_index>...#<n-3th_dim_index> E.g.: data.h5::/data_5D#1#1 """) args = parser.parse_args(args=argv) # Start GUI global app # QApplication must be global to avoid seg fault on quit app = qt.QApplication([]) # Create the viewer main window window = ScalarFieldView() window.setAttribute(qt.Qt.WA_DeleteOnClose) # Create a parameter tree for the scalar field view treeView = SFViewParamTree.TreeView(window) treeView.setSfView(window) # Attach the parameter tree to the view # Add the parameter tree to the main window in a dock widget dock = qt.QDockWidget() dock.setWindowTitle('Parameters') dock.setWidget(treeView) window.addDockWidget(qt.Qt.RightDockWidgetArea, dock) # Load data from file if args.filename is not None: data = load(args.filename) _logger.info('Data:\n\tShape: %s\n\tRange: [%f, %f]', str(data.shape), data.min(), data.max()) else: # Create dummy data _logger.warning('Not data file provided, creating dummy data') coords = numpy.linspace(-10, 10, 64) z = coords.reshape(-1, 1, 1) y = coords.reshape(1, -1, 1) x = coords.reshape(1, 1, -1) data = numpy.sin(x * y * z) / (x * y * z) # Set ScalarFieldView data window.setData(data) # Set scale of the data window.setScale(args.xscale, args.yscale, args.zscale) # Set offset of the data window.setTranslation(args.xoffset, args.yoffset, args.zoffset) # Set axes labels window.setAxesLabels('X', 'Y', 'Z') # Add an iso-surface if not numpy.isnan(args.level): # Add an iso-surface at the given iso-level window.addIsosurface(args.level, '#FF0000FF') else: # Add an iso-surface from a function window.addIsosurface(default_isolevel, '#FF0000FF') window.show() return app.exec_()