Exemplo n.º 1
0
    def __init__(self, parent=None) -> None:
        super(ImageStack, self).__init__(parent)
        self.__n_prefetch = ImageStack.N_PRELOAD
        self._loadingThreads = []
        self.setWindowFlags(qt.Qt.Widget)
        self._current_url = None
        self._url_loader = UrlLoader
        "class to instantiate for loading urls"

        # main widget
        self._plot = _PlotWithWaitingLabel(parent=self)
        self._plot.setAttribute(qt.Qt.WA_DeleteOnClose, True)
        self.setWindowTitle("Image stack")
        self.setCentralWidget(self._plot)

        # dock widget: url table
        self._tableDockWidget = qt.QDockWidget(parent=self)
        self._urlsTable = _ToggleableUrlSelectionTable(parent=self)
        self._tableDockWidget.setWidget(self._urlsTable)
        self._tableDockWidget.setFeatures(qt.QDockWidget.DockWidgetMovable)
        self.addDockWidget(qt.Qt.RightDockWidgetArea, self._tableDockWidget)
        # dock widget: qslider
        self._sliderDockWidget = qt.QDockWidget(parent=self)
        self._slider = _HorizontalSlider(parent=self)
        self._sliderDockWidget.setWidget(self._slider)
        self.addDockWidget(qt.Qt.BottomDockWidgetArea, self._sliderDockWidget)
        self._sliderDockWidget.setFeatures(qt.QDockWidget.DockWidgetMovable)

        self.reset()

        # connect signal / slot
        self._urlsTable.sigCurrentUrlChanged.connect(self.setCurrentUrl)
        self._slider.sigCurrentUrlIndexChanged.connect(self.setCurrentUrlIndex)
Exemplo n.º 2
0
    def __init__(self, parent=None, plot=None, mode=None):
        assert plot is not None
        qt.QMainWindow.__init__(self, parent)
        self._roiStatsWindow = ROIStatsWidget(plot=plot)
        self.setCentralWidget(self._roiStatsWindow)

        # update mode docker
        self._updateModeControl = UpdateModeWidget(parent=self)
        self._docker = qt.QDockWidget(parent=self)
        self._docker.setWidget(self._updateModeControl)
        self.addDockWidget(qt.Qt.TopDockWidgetArea, self._docker)
        self.setWindowFlags(qt.Qt.Widget)

        # connect signal / slot
        self._updateModeControl.sigUpdateModeChanged.connect(
            self._roiStatsWindow._setUpdateMode)
        callback = functools.partial(self._roiStatsWindow._updateAllStats,
                                     is_request=True)
        self._updateModeControl.sigUpdateRequested.connect(callback)

        # expose API
        self.registerROI = self._roiStatsWindow.registerROI
        self.setStats = self._roiStatsWindow.setStats
        self.addItem = self._roiStatsWindow.addItem
        self.removeItem = self._roiStatsWindow.removeItem
        self.setUpdateMode = self._updateModeControl.setUpdateMode

        # setup
        self._updateModeControl.setUpdateMode('auto')
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def __init__(self, parent=None):
        """

        :param parent: Parent QWidget
        """
        super(ArrayCurvePlot, self).__init__(parent)

        self.__signals = None
        self.__signals_names = None
        self.__signal_errors = None
        self.__axis = None
        self.__axis_name = None
        self.__x_axis_errors = None
        self.__values = None

        self._plot = Plot1D(self)

        self.selectorDock = qt.QDockWidget("Data selector", self._plot)
        # not closable
        self.selectorDock.setFeatures(qt.QDockWidget.DockWidgetMovable
                                      | qt.QDockWidget.DockWidgetFloatable)
        self._selector = NumpyAxesSelector(self.selectorDock)
        self._selector.setNamedAxesSelectorVisibility(False)
        self.__selector_is_connected = False
        self.selectorDock.setWidget(self._selector)
        self._plot.addTabbedDockWidget(self.selectorDock)

        self._plot.sigActiveCurveChanged.connect(
            self._setYLabelFromActiveLegend)

        layout = qt.QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._plot, 0, 0)

        self.setLayout(layout)
Exemplo n.º 5
0
    def __init__(self, parent=None, logger=None):

        super(RixsMainWindow, self).__init__(parent=parent)

        self._logger = logger or _logger

        if parent is not None:
            #: behave as a widget
            self.setWindowFlags(qt.Qt.Widget)
        else:
            #: main window
            self.setWindowTitle('RIXS_VIEW')

        self.setGeometry(0, 0, 1280, 960)

        #: Model (= simple RixsData container)
        self._model = RixsListModel()

        #: View (= simply show list of loaded data)
        self._view = RixsListView(parent=self)
        self._view.setModel(self._model)

        #: View dock widget
        self._dockDataWidget = qt.QDockWidget(parent=self)
        self._dockDataWidget.setObjectName('Data View')
        self._dockDataWidget.setWidget(self._view)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockDataWidget)

        #: Plot Area
        self._plotArea = RixsPlotArea(self)
        self.setCentralWidget(self._plotArea)
        self.setMinimumSize(600, 600)
    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)
Exemplo n.º 7
0
    def __init__(self, parent=None, mode=None):
        qt.QMainWindow.__init__(self, parent)
        self.plot = Plot2D()
        self.setCentralWidget(self.plot)

        # 1D roi management
        self._curveRoiWidget = self.plot.getCurvesRoiDockWidget().widget()
        # hide last columns which are of no use now
        for index in (5, 6, 7, 8):
            self._curveRoiWidget.roiTable.setColumnHidden(index, True)

        # 2D - 3D roi manager
        self._regionManager = RegionOfInterestManager(parent=self.plot)

        # Create the table widget displaying
        self._2DRoiWidget = RegionOfInterestTableWidget()
        self._2DRoiWidget.setRegionOfInterestManager(self._regionManager)

        # tabWidget for displaying the rois
        self._roisTabWidget = qt.QTabWidget(parent=self)
        if hasattr(self._roisTabWidget, 'setTabBarAutoHide'):
            self._roisTabWidget.setTabBarAutoHide(True)

        # widget for displaying stats results and update mode
        self._statsWidget = _RoiStatsWidget(parent=self, plot=self.plot)

        # create Dock widgets
        self._roisTabWidgetDockWidget = qt.QDockWidget(parent=self)
        self._roisTabWidgetDockWidget.setWidget(self._roisTabWidget)
        self.addDockWidget(qt.Qt.RightDockWidgetArea,
                           self._roisTabWidgetDockWidget)

        # create Dock widgets
        self._roiStatsWindowDockWidget = qt.QDockWidget(parent=self)
        self._roiStatsWindowDockWidget.setWidget(self._statsWidget)
        # move the docker contain in the parent widget
        self.addDockWidget(qt.Qt.RightDockWidgetArea,
                           self._statsWidget._docker)
        self.addDockWidget(qt.Qt.RightDockWidgetArea,
                           self._roiStatsWindowDockWidget)

        # expose API
        self.setUpdateMode = self._statsWidget.setUpdateMode
    def setUp(self):
        super(TestScalarFieldView, self).setUp()
        self.widget = ScalarFieldView()
        self.widget.show()

        paramTreeWidget = TreeView()
        paramTreeWidget.setSfView(self.widget)

        dock = qt.QDockWidget()
        dock.setWidget(paramTreeWidget)
        self.widget.addDockWidget(qt.Qt.BottomDockWidgetArea, dock)
Exemplo n.º 9
0
    def setUp(self):
        super(TestRegionOfInterestManager, self).setUp()
        self.plot = PlotWindow()

        self.roiTableWidget = roi.RegionOfInterestTableWidget()
        dock = qt.QDockWidget()
        dock.setWidget(self.roiTableWidget)
        self.plot.addDockWidget(qt.Qt.BottomDockWidgetArea, dock)

        self.plot.show()
        self.qWaitForWindowExposed(self.plot)
Exemplo n.º 10
0
    def testDockWidgets(self):
        """Test add/remove dock widgets"""
        dock1 = qt.QDockWidget('Test 1')
        dock1.setWidget(qt.QLabel('Test 1'))

        self.plot.addTabbedDockWidget(dock1)
        self.qapp.processEvents()

        self.plot.removeDockWidget(dock1)
        self.qapp.processEvents()

        dock2 = qt.QDockWidget('Test 2')
        dock2.setWidget(qt.QLabel('Test 2'))

        self.plot.addTabbedDockWidget(dock2)
        self.qapp.processEvents()

        if qt.BINDING != 'PySide2':
            # Weird bug with PySide2 later upon gc.collect() when getting the layout
            self.assertNotEqual(self.plot.layout().indexOf(dock2), -1,
                                "dock2 not properly displayed")
Exemplo n.º 11
0
    def setUp(self):
        super(TestCurveLegendsWidget, self).setUp()
        self.plot = PlotWindow()

        self.legends = CurveLegendsWidget.CurveLegendsWidget()
        self.legends.setPlotWidget(self.plot)

        dock = qt.QDockWidget()
        dock.setWindowTitle('Curve Legends')
        dock.setWidget(self.legends)
        self.plot.addTabbedDockWidget(dock)

        self.plot.show()
        self.qWaitForWindowExposed(self.plot)
Exemplo n.º 12
0
    def __init__(self, backend):
        qt.QMainWindow.__init__(self, parent=None)
        self._plot = CompareImages(parent=self, backend=backend)

        self._selectionTable = UrlSelectionTable(parent=self)
        self._dockWidgetMenu = qt.QDockWidget(parent=self)
        self._dockWidgetMenu.layout().setContentsMargins(0, 0, 0, 0)
        self._dockWidgetMenu.setFeatures(qt.QDockWidget.DockWidgetMovable)
        self._dockWidgetMenu.setWidget(self._selectionTable)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockWidgetMenu)

        self.setCentralWidget(self._plot)

        self._selectionTable.sigImageAChanged.connect(self._updateImageA)
        self._selectionTable.sigImageBChanged.connect(self._updateImageB)
Exemplo n.º 13
0
    def setUp(self):
        super(TestScalarFieldView, self).setUp()
        self.widget = ScalarFieldView()
        self.widget.show()

        # Create a parameter tree for the scalar field view
        self.treeView = TreeView()
        self.treeView.setSfView(
            self.widget)  # Attach the parameter tree to the view
        self.treeView.show()

        # Add the parameter tree to the main window in a dock widget
        dock = qt.QDockWidget()
        dock.setWindowTitle('Parameters')
        dock.setWidget(self.treeView)
        self.widget.addDockWidget(qt.Qt.RightDockWidgetArea, dock)
    def testIsoSliderNormalization(self):
        """Test set TreeView with a different isoslider normalization"""
        data = self._buildData(size=32)

        self.widget.setData(data)
        self.widget.addIsosurface(0.5, (1., 0., 0., 0.5))
        self.widget.addIsosurface(0.7, qt.QColor('green'))
        self.qapp.processEvents()

        # Add a second TreeView
        paramTreeWidget = TreeView(self.widget)
        paramTreeWidget.setIsoLevelSliderNormalization('arcsinh')
        paramTreeWidget.setSfView(self.widget)

        dock = qt.QDockWidget()
        dock.setWidget(paramTreeWidget)
        self.widget.addDockWidget(qt.Qt.BottomDockWidgetArea, dock)
    def __init__(self, parent=None):
        """

        :param parent: Parent QWidget
        """
        super(ArrayImagePlot, self).__init__(parent)

        self.__signals = None
        self.__signals_names = None
        self.__x_axis = None
        self.__x_axis_name = None
        self.__y_axis = None
        self.__y_axis_name = None

        self._plot = Plot2D(self)
        self._plot.setDefaultColormap(
            Colormap(name="viridis",
                     vmin=None,
                     vmax=None,
                     normalization=Colormap.LINEAR))
        self._plot.getIntensityHistogramAction().setVisible(True)

        self.selectorDock = qt.QDockWidget("Data selector", self._plot)
        # not closable
        self.selectorDock.setFeatures(qt.QDockWidget.DockWidgetMovable
                                      | qt.QDockWidget.DockWidgetFloatable)
        self._selector = NumpyAxesSelector(self.selectorDock)
        self._selector.setNamedAxesSelectorVisibility(False)
        self._selector.selectionChanged.connect(self._updateImage)

        self._auxSigSlider = HorizontalSliderWithBrowser(parent=self)
        self._auxSigSlider.setMinimum(0)
        self._auxSigSlider.setValue(0)
        self._auxSigSlider.valueChanged[int].connect(self._sliderIdxChanged)
        self._auxSigSlider.setToolTip("Select auxiliary signals")

        layout = qt.QVBoxLayout()
        layout.addWidget(self._plot)
        layout.addWidget(self._auxSigSlider)
        self.selectorDock.setWidget(self._selector)
        self._plot.addTabbedDockWidget(self.selectorDock)

        self.setLayout(layout)
Exemplo n.º 16
0
    def __init__(self, parent=None):
        """

        :param parent: Parent QWidget
        """
        super(ArrayImagePlot, self).__init__(parent)

        self.__signal = None
        self.__signal_name = None
        self.__x_axis = None
        self.__x_axis_name = None
        self.__y_axis = None
        self.__y_axis_name = None

        self._plot = Plot2D(self)
        self._plot.setDefaultColormap({
            "name": "viridis",
            "vmin": 0.,
            "vmax": 1.,  # ignored (autoscale) but mandatory
            "normalization": "linear",
            "autoscale": True
        })

        self.selectorDock = qt.QDockWidget("Data selector", self._plot)
        # not closable
        self.selectorDock.setFeatures(qt.QDockWidget.DockWidgetMovable
                                      | qt.QDockWidget.DockWidgetFloatable)
        self._legend = qt.QLabel(self)
        self._selector = NumpyAxesSelector(self.selectorDock)
        self._selector.setNamedAxesSelectorVisibility(False)
        self.__selector_is_connected = False

        layout = qt.QVBoxLayout()
        layout.addWidget(self._plot)
        layout.addWidget(self._legend)
        self.selectorDock.setWidget(self._selector)
        self._plot.addTabbedDockWidget(self.selectorDock)

        self.setLayout(layout)
Exemplo n.º 17
0
    def __init__(self, parent=None):
        """

        :param parent: Parent QWidget
        """
        super(ArrayCurvePlot, self).__init__(parent)

        self.__signal = None
        self.__signal_name = None
        self.__signal_errors = None
        self.__axis = None
        self.__axis_name = None
        self.__axis_errors = None
        self.__values = None

        self.__first_curve_added = False

        self._plot = Plot1D(self)
        self._plot.setDefaultColormap(   # for scatters
                {"name": "viridis",
                 "vmin": 0., "vmax": 1.,   # ignored (autoscale) but mandatory
                 "normalization": "linear",
                 "autoscale": True})

        self.selectorDock = qt.QDockWidget("Data selector", self._plot)
        # not closable
        self.selectorDock.setFeatures(qt.QDockWidget.DockWidgetMovable
                                      | qt.QDockWidget.DockWidgetFloatable)
        self._selector = NumpyAxesSelector(self.selectorDock)
        self._selector.setNamedAxesSelectorVisibility(False)
        self.__selector_is_connected = False
        self.selectorDock.setWidget(self._selector)
        self._plot.addTabbedDockWidget(self.selectorDock)

        layout = qt.QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self._plot, 0, 0)

        self.setLayout(layout)
Exemplo n.º 18
0
    def __init__(self,
                 intensityGroup,
                 parent=None,
                 **kwargs):
        super(IntensityView, self).__init__(parent, **kwargs)

        self.setWindowTitle('[XSOCS] {0}:{1}'.format(intensityGroup.filename,
                                                     intensityGroup.path))

        self.__displayedNode = None
        self.__selectedPoint = None

        self.__plotWindow = plotWindow = XsocsPlot2D()
        plotWindow.setShowMousePosition(True)
        plotWindow.setShowSelectedCoordinates(True)
        plotWindow.sigPointSelected.connect(self.__slotPointSelected)

        selector = Qt.QWidget()
        layout = Qt.QVBoxLayout(selector)

        # TODO : check item type
        self.__iGroup = intensityGroup
        self.__tree = tree = IntensityTree(intensityGroup, parent=self)
        tree.model().dataChanged.connect(self.__slotModelDataChanged)
        tree.sigCurrentChanged.connect(self.__slotItemSelected)
        layout.addWidget(tree)

        bnLayout = Qt.QHBoxLayout()
        selAllBn = FixedSizePushButon('Select All')
        selNoneBn = FixedSizePushButon('Clear')
        selAllBn.clicked.connect(tree.model().selectAll)
        selNoneBn.clicked.connect(tree.model().unselectAll)
        bnLayout.addWidget(selAllBn)
        bnLayout.addWidget(selNoneBn)
        layout.addLayout(bnLayout)

        dock = Qt.QDockWidget(self)
        dock.setWidget(selector)
        features = dock.features() ^ Qt.QDockWidget.DockWidgetClosable
        dock.setFeatures(features)
        self.addDockWidget(Qt.Qt.LeftDockWidgetArea, dock)

        self.__roiManager = roiManager = ImageRoiManager(plotWindow)

        rectRoiWidget = RectRoiWidget(roiManager)
        rectRoiWidget.sigRoiApplied.connect(self.__slotRoiApplied)

        dock = Qt.QDockWidget(self)
        dock.setWidget(rectRoiWidget)
        features = dock.features() ^ Qt.QDockWidget.DockWidgetClosable
        dock.setFeatures(features)
        self.addDockWidget(Qt.Qt.RightDockWidgetArea, dock)

        profileWid = Qt.QWidget()
        profileLayout = Qt.QHBoxLayout(profileWid)

        self.__profilePlot = profilePlot = XsocsPlot2D()
        profilePlot.setKeepDataAspectRatio(False)
        profileLayout.addWidget(profilePlot, 10)

        plotTree = PlotTree(profilePlot)
        profileLayout.addWidget(plotTree)

        dock = Qt.QDockWidget(self)
        dock.setWidget(profileWid)
        features = dock.features() ^ Qt.QDockWidget.DockWidgetClosable
        dock.setFeatures(features)
        self.addDockWidget(Qt.Qt.BottomDockWidgetArea, dock)

        self.setCentralWidget(plotWindow)
Exemplo n.º 19
0
roiToolbarEdit.addAction(modeSelectorAction)

# Add the region of interest table and the buttons to a dock widget
widget = qt.QWidget()
layout = qt.QVBoxLayout()
widget.setLayout(layout)
layout.addWidget(roiToolbar)
layout.addWidget(roiToolbarEdit)
layout.addWidget(roiTable)


def roiDockVisibilityChanged(visible):
    """Handle change of visibility of the roi dock widget

    If dock becomes hidden, ROI interaction is stopped.
    """
    if not visible:
        roiManager.stop()


dock = qt.QDockWidget('Image ROI')
dock.setWidget(widget)
dock.visibilityChanged.connect(roiDockVisibilityChanged)
plot.addTabbedDockWidget(dock)

# Show the widget and start the application
plot.show()
result = app.exec()
app.deleteLater()
sys.exit(result)
Exemplo n.º 20
0
    def __init__(self, parent=None, with_ipykernel=True, logger=None):
        """Constructor"""

        self._logger = logger or getLogger('RixsAppWindow')

        super(RixsAppWindow, self).__init__(parent=parent)

        if parent is not None:
            #: behave as a widget
            self.setWindowFlags(qt.Qt.Widget)
        else:
            #: main window
            self.setWindowTitle('RIXS_VIEW')

            # TODO: Add icon to the application
            #ico = qt.QIcon(os.path.join(_resourcesPath, "logo",
            #                            "xraysloth_logo_04.svg"))
            #self.setWindowIcon(ico)

        #: IPython kernel status
        self._with_ipykernel = with_ipykernel

        #: Model/view
        self._model = RixsModel()
        self._view = RixsView(parent=self)
        self._view.setModel(self._model)

        # Add additional sections to the header.
        values = [
            HeaderSection(name='Plot',
                          roles={qt.Qt.DisplayRole: 'currentPlotWindowIndex',
                                 qt.Qt.EditRole: 'plotWindowsIndexes'
                                 },
                          delegate=ComboBoxDelegate),
            ]

        for value in values:
            section = len(self._model.header)
            orientation = qt.Qt.Horizontal
            self._model.setHeaderData(section, orientation, value)

        # Add (empty) menu bar -> contents added later
        self._menuBar = qt.QMenuBar()
        self.setMenuBar(self._menuBar)
        self._initAppMenu()

        #: Plot Area
        self._plotArea = RixsPlotArea(self)
        self.setCentralWidget(self._plotArea)

        #: TreeView dock widget
        self._dockDataWidget = qt.QDockWidget(parent=self)
        self._dockDataWidget.setObjectName('Data View')
        self._dockDataWidget.setWidget(self._view)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockDataWidget)

        #: Plots update
        self._model.dataChanged.connect(self.updatePlot)
        self._plotArea.changed.connect(self.updateModel)

        #: Console
        if self._with_ipykernel:
            # Initialize internal ipykernel
            self._ipykernel = InternalIPyKernel()
            self._ipykernel.init_kernel(backend='qt')
            self._ipykernel.add_to_namespace('view', self._view)
            self._ipykernel.add_to_namespace('model', self._model)
            self._ipykernel.add_to_namespace('plot', self._plotArea)

            # Add IPython console at menu
            self._initConsoleMenu()
        else:
            self._ipykernel = None
Exemplo n.º 21
0
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_()
Exemplo n.º 22
0
    def __init__(self, parent, model, node, **kwargs):
        super(FitView, self).__init__(parent)

        self.__firstShow = True

        self.setWindowTitle('[XSOCS] {0}'.format(node.h5Path))

        item = h5NodeToProjectItem(node)
        fitH5 = self.__fitH5 = item.fitH5

        # TODO : this parent().parent() thing is ugly...
        qspaceItem = h5NodeToProjectItem(node.parent().parent())

        self.__qspaceH5 = qspaceItem.qspaceH5
        self.__node = node

        with fitH5:
            # only one entry per file supposed right now
            self.__entry = fitH5.entries()[0]

        centralWid = Qt.QWidget()
        layout = Qt.QGridLayout(centralWid)

        self.__plots = []
        self.__fitPlots = []

        treeDock = Qt.QDockWidget()

        self.__model = FitModel()
        rootNode = FitH5Node(item.fitFile)
        self.__model.appendGroup(rootNode)

        tree = self.__tree = TreeView()
        tree.setModel(self.__model)
        # tree.setRootIndex(self.__model.index(0, 0, tree.rootIndex()))
        tree.setSelectionBehavior(Qt.QAbstractItemView.SelectItems)
        tree.header().setStretchLastSection(False)
        tree.setShowUniqueGroup(True)
        tree.setDragDropMode(Qt.QAbstractItemView.DragDrop)

        treeDock.setWidget(tree)
        self.addDockWidget(Qt.Qt.LeftDockWidgetArea, treeDock)

        grpBox = GroupBox('Maps')
        grpLayout = Qt.QVBoxLayout(grpBox)

        plot = DropPlotWidget(grid=False,
                              curveStyle=False,
                              colormap=False,
                              roi=False,
                              mask=False,
                              yInverted=False)
        grpLayout.addWidget(plot)
        self.__plots.append(plot)
        plot.sigPointSelected.connect(self.__slotPointSelected)

        plot = DropPlotWidget(grid=False,
                              curveStyle=False,
                              colormap=False,
                              roi=False,
                              mask=False,
                              yInverted=False)
        grpLayout.addWidget(plot)
        self.__plots.append(plot)
        plot.sigPointSelected.connect(self.__slotPointSelected)

        plot = DropPlotWidget(grid=False,
                              curveStyle=False,
                              colormap=False,
                              roi=False,
                              mask=False,
                              yInverted=False)
        grpLayout.addWidget(plot)
        self.__plots.append(plot)
        plot.sigPointSelected.connect(self.__slotPointSelected)

        layout.addWidget(grpBox, 0, 1)

        # =================================
        # =================================
        grpBox = GroupBox('Fit')
        grpLayout = Qt.QVBoxLayout(grpBox)

        plot = XsocsPlot2D()
        plot.setKeepDataAspectRatio(False)
        grpLayout.addWidget(plot)
        self.__fitPlots.append(plot)
        plot.setGraphTitle('Qx fit')
        plot.setShowMousePosition(True)

        plot = XsocsPlot2D()
        plot.setKeepDataAspectRatio(False)
        grpLayout.addWidget(plot)
        self.__fitPlots.append(plot)
        plot.setGraphTitle('Qy fit')
        plot.setShowMousePosition(True)

        plot = XsocsPlot2D()
        plot.setKeepDataAspectRatio(False)
        grpLayout.addWidget(plot)
        self.__fitPlots.append(plot)
        plot.setGraphTitle('Qz fit')
        plot.setShowMousePosition(True)

        layout.addWidget(grpBox, 0, 2)

        # =================================
        # =================================

        self.setCentralWidget(centralWid)
Exemplo n.º 23
0
    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
    _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)