예제 #1
0
    def __init__(self,
                 graph,
                 yvalues,
                 xvalues=None,
                 axes=None,
                 name=None,
                 **kwargs):
        LogSource.__init__(self)
        if axes is None:
            self.axes = graph.axes
        if xvalues is None:
            xvalues = range(len(yvalues))

        self.name = name
        self.graph = graph
        self.axes = axes

        self.graph.options.sig_options_changed.connect(self._options_changed)

        self.yvalues = np.copy(np.array(yvalues, dtype=np.double))
        self.xvalues = np.copy(np.array(xvalues, dtype=np.double))
        self.line_col = kwargs.get("line_col", (255, 255, 255))
        self.line_width = kwargs.get("line_width", 1.0)
        self.line_style = kwargs.get("line_style", QtCore.Qt.SolidLine)
        self.point_col = kwargs.get("point_col", "k")
        self.point_size = kwargs.get("point_size", 5.0)
        self.point_brush = kwargs.get("point_brush", (200, 200, 200))

        self.legend_item = None
        self.graphics_items = ()
        self.show()
예제 #2
0
    def __init__(self, ivm, qpdata, viewbox, plane, vol, view_metadata=None):
        """
        :param qpdata: QpData instance
        :param viewbox: pyqtgraph ViewBox instance
        :param view_metadata: View parameters
        """
        LogSource.__init__(self)
        self._ivm = ivm
        self._qpdata = qpdata
        self._viewbox = viewbox
        self._plane = plane
        self._vol = vol
        self._view = self._qpdata.view
        if view_metadata is not None:
            self._view = view_metadata

        self._redraw_options = [
            "visible",
            "roi",
            "z_order",
            "interp_order",
            "contour",
        ]
        self._img = MaskableImage()
        self._contours = []
        self._viewbox.addItem(self._img)
        self._lut = get_lut(self._view.cmap, self._view.alpha)
        self.update()
        self.redraw()
        self._view.sig_changed.connect(self._view_metadata_changed)
예제 #3
0
 def __init__(self, name, tooltip=""):
     """
     :param name: Name of tool
     :param tooltip: Descriptive text
     """
     LogSource.__init__(self)
     self.name = name
     self.tooltip = tooltip
예제 #4
0
 def __init__(self, name, ivm, display_name=None):
     LogSource.__init__(self)
     self.name = name
     self.ivm = ivm
     if display_name is not None:
         self.display_name = display_name
     else:
         self.display_name = name
예제 #5
0
    def __init__(self, ivm, parent=None, **kwargs):
        LogSource.__init__(self)
        QtGui.QWidget.__init__(self, parent)
        self.ivm = ivm
        self.data = None
        self.default_md = kwargs.get("default_metadata", DEFAULT_METADATA)
        self.md = dict(self.default_md)
        self.aslimage = None
        self.valid = True

        vbox = QtGui.QVBoxLayout()
        self.setLayout(vbox)

        grid = QtGui.QGridLayout()

        grid.addWidget(QtGui.QLabel("ASL data"), 0, 0)
        self.data_combo = OverlayCombo(self.ivm)
        self.data_combo.currentIndexChanged.connect(self._data_changed)
        grid.addWidget(self.data_combo, 0, 1)

        view_classes = [
            LabelType, RepeatsChoice, NumPhases, NumEncodings, BlockFormat,
            DataStructure, SignalView, Labelling, Readout, SliceTime,
            Multiband, Times, BolusDurations, VariableRepeats
        ]

        self.views = []
        for idx, view_class in enumerate(view_classes):
            if view_class in kwargs.get("ignore_views", ()):
                continue
            view = view_class(grid, ypos=idx + 2)
            view.ivm = self.ivm
            view.sig_md_changed.connect(self._metadata_changed)
            self.views.append(view)

        #grid.addWidget(QtGui.QLabel("Data order preview"), 5, 0)

        # Code below is for specific multiple phases
        #self.phases_lbl = QtGui.QLabel("Phases (\N{DEGREE SIGN})")
        #grid.addWidget(self.phases_lbl, 3, 0)
        #self.phases_lbl.setVisible(False)
        #self.phases = NumberList([float(x)*360/8 for x in range(8)])
        #grid.addWidget(self.phases, 3, 1)
        #self.phases.setVisible(False)

        grid.setColumnStretch(0, 0)
        grid.setColumnStretch(1, 1)
        grid.setColumnStretch(2, 0)
        grid.setRowStretch(len(view_classes) + 2, 1)

        self.grid = grid
        vbox.addLayout(grid)

        self.warn_label = WarningBox()
        vbox.addWidget(self.warn_label)

        self._update_ui()
        self._data_changed()
예제 #6
0
    def __init__(self, n_components, norm_modes=True, norm_input=False, norm_type='perc'):
        """
        :param data: 4D image to be processed
        :param roi: Optional sub region to extract
        """
        LogSource.__init__(self)

        # Variables
        self.pca = PCA(n_components=n_components)
        self.norm_modes = norm_modes
        self.norm_input = norm_input
        self.norm_type = norm_type
예제 #7
0
    def __init__(self, ivl, label, axis, layout_grid, layout_ypos):
        LogSource.__init__(self)
        self.ivl = ivl
        self.axis = axis
        self.data_axis = axis
        self.data_grid = None
        self._pos = -1

        layout_grid.addWidget(QtGui.QLabel(label), layout_ypos, 0)
        self.slider = QtGui.QSlider(QtCore.Qt.Horizontal)
        self.slider.setFocusPolicy(QtCore.Qt.NoFocus)
        self.slider.setMinimumWidth(100)
        self.slider.valueChanged.connect(self._changed)
        layout_grid.addWidget(self.slider, layout_ypos, 1)

        self.spin = QtGui.QSpinBox()
        self.spin.valueChanged.connect(self._changed)
        layout_grid.addWidget(self.spin, layout_ypos, 2)

        self.ivl.ivm.sig_main_data.connect(self._main_data_changed)
        self.ivl.sig_focus_changed.connect(self._focus_changed)
예제 #8
0
    def __init__(self, img, vox_sizes, mask=None):
        """
        :param img1: 4D image to load
        :param vox_size: voxel size of loaded image
        :return:
        """
        LogSource.__init__(self)

        self.img1 = img
        # cython is sensitive to the double definition
        self.vox_size = np.asarray(vox_sizes/vox_sizes[0], dtype=np.double)
        self.mask = mask

        self.segments = None
        self.adj_mat = None
        self.border_mat = None
        self.feat1_image = None
        self.img_slice = None
        self.zoom_factor = None
        self.n_components = None
        self.fe = None
예제 #9
0
    def __init__(self, ivm, **kwargs):
        """
        :param ivm: ImageVolumeManagement object
        
        Keyword arguments:

        :param proc_id: ID string for this process
        :param indir: Input data folder
        :param outdir: Output data folder
        :param worker_fn: For background processes a worker function
                          to call which will do the processing. This 
                          function should take parameters:
                          ``id``, ``queue``,  and a sequence of arguments.
                          It should return ``id``, True/False ``success`` and
                          an output object. If ``success=False`` the output
                          object should be an exception. Otherwise it can
                          be any pickleable object (e.g. Numpy array)
        """
        QtCore.QObject.__init__(self)
        LogSource.__init__(self)
        self.ivm = ivm
        self.proc_id = kwargs.pop("proc_id", None)
        self.indir = kwargs.pop("indir", "")
        self.outdir = kwargs.pop("outdir", "")
            
        self._log = ""
        self.status = Process.NOTSTARTED
        self._completed = False
        # We seem to get a segfault when emitting a signal with a None object
        self.exception = object()

        # Multiprocessing initialization
        self._multiproc = MULTIPROC and kwargs.get("multiproc", True)
        self._worker_fn = kwargs.get("worker_fn", None)
        self._sync = kwargs.get("sync", False)
        self._timer = None
        self._workers = []
        self._pool = None
        self._worker_output = []
        self._queue = None
예제 #10
0
    def __init__(self, ivl, ivm, ax_map, ax_labels):
        """
        :param ivl: Viewer
        :param ivm: ImageVolumeManagement
        :param ax_map: Sequence defining the x, y, z axis of the slice viewer
                       in terms of RAS axis sequence indexes
        :param ax_labels: Sequence of labels for the RAS axes
        """
        LogSource.__init__(self)
        pg.GraphicsView.__init__(self)
        self._ivl = ivl
        self.ivm = ivm
        self.xaxis, self.yaxis, self.zaxis = ax_map
        self._slicez = 0
        self._vol = 0
        self._plane = OrthoSlice(self._ivl.grid, self.zaxis, self._slicez)
        self._main_view = None
        self._dragging = False
        self._arrow_items = []
        self._data_views = {}
        self.debug("axes=%i, %i, %i", self.xaxis, self.yaxis, self.zaxis)

        # View box to display graphics items
        self._viewbox = pg.ViewBox(name="view%i" % self.zaxis,
                                   border=pg.mkPen((0x6c, 0x6c, 0x6c),
                                                   width=2.0))
        self._viewbox.setAspectLocked(True)
        self._viewbox.setBackgroundColor([0, 0, 0])
        self._viewbox.enableAutoRange()
        self.setCentralItem(self._viewbox)

        # Crosshairs
        self._vline = pg.InfiniteLine(angle=90, movable=False)
        self._vline.setZValue(2 * MAX_NUM_DATA_SETS)
        self._vline.setPen(
            pg.mkPen((0, 255, 0), width=1.0, style=QtCore.Qt.DashLine))

        self._hline = pg.InfiniteLine(angle=0, movable=False)
        self._hline.setZValue(2 * MAX_NUM_DATA_SETS)
        self._hline.setPen(
            pg.mkPen((0, 255, 0), width=1.0, style=QtCore.Qt.DashLine))

        self._viewbox.addItem(self._vline, ignoreBounds=True)
        self._viewbox.addItem(self._hline, ignoreBounds=True)

        # Dummy image item which enables us to translate click co-ordinates
        # into image space co-ordinates even when there is no data in the view
        self._dummy = pg.ImageItem()
        self._dummy.setVisible(False)
        self._viewbox.addItem(self._dummy, ignoreBounds=True)

        # Static labels for the view directions
        self._labels = []
        for axis in [self.xaxis, self.yaxis]:
            self._labels.append(QtGui.QLabel(ax_labels[axis][0], parent=self))
            self._labels.append(QtGui.QLabel(ax_labels[axis][1], parent=self))
        for label in self._labels:
            label.setAttribute(QtCore.Qt.WA_TranslucentBackground)

        self._grid_changed(self._ivl.grid)
        self._focus_changed(self._ivl.focus())
        self._update_crosshairs()
        self._update_orientation()

        # Connect to signals from the parent viewer
        self._ivl.sig_grid_changed.connect(self._grid_changed)
        self._ivl.sig_focus_changed.connect(self._focus_changed)
        self._ivl.sig_arrows_changed.connect(self._arrows_changed)
        self._ivl.opts.sig_changed.connect(self._view_opts_changed)

        # Connect to data change signals
        self.ivm.sig_all_data.connect(self._data_changed)
        self.ivm.sig_main_data.connect(self._main_data_changed)

        # Need to intercept the default resize event
        # FIXME why can't call superclass method normally?
        self.resizeEventOrig = self.resizeEvent
        self.resizeEvent = self._window_resized
예제 #11
0
 def __init__(self, iv):
     LogSource.__init__(self)
     self.ivl = iv
     self.use_drag = False
     self.view = None
     self.win = None
예제 #12
0
 def __init__(self, ivm, parent):
     LogSource.__init__(self)
     QtWidgets.QWidget.__init__(self, parent)
     self.ivm = ivm
예제 #13
0
    def __init__(self, ivm, opts):
        LogSource.__init__(self)
        QtGui.QSplitter.__init__(self, QtCore.Qt.Vertical)

        self.grid = DataGrid([1, 1, 1], np.identity(4))
        self._pos = [0, 0, 0, 0]

        self.ivm = ivm
        self.opts = opts
        self.picker = PointPicker(self)
        self.arrows = []

        # Visualisation information for data and ROIs
        self.main_data_view = MainDataView(self.ivm)
        self.current_data_view = OverlayView(self.ivm)
        self.current_roi_view = RoiView(self.ivm)

        # Navigation controls layout
        control_box = QtGui.QWidget()
        vbox = QtGui.QVBoxLayout()
        vbox.setSpacing(5)
        control_box.setLayout(vbox)

        # Create the navigation sliders and the ROI/Overlay view controls
        vbox.addWidget(DataSummary(self))
        hbox = QtGui.QHBoxLayout()
        nav_box = NavigationBox(self)
        hbox.addWidget(nav_box)
        roi_box = RoiViewWidget(self, self.current_roi_view)
        hbox.addWidget(roi_box)
        ovl_box = OverlayViewWidget(self, self.current_data_view)
        hbox.addWidget(ovl_box)
        vbox.addLayout(hbox)

        # Histogram which controls colour map and levels for main volume
        self.main_data_view.histogram = MultiImageHistogramWidget(
            self, self.main_data_view, percentile=99)

        # Histogram which controls colour map and levels for data
        self.current_data_view.histogram = MultiImageHistogramWidget(
            self, self.current_data_view)

        # For each view window, this is the volume indices of the x, y and z axes for the view
        self.ax_map = [[0, 1, 2], [0, 2, 1], [1, 2, 0]]
        self.ax_labels = [("L", "R"), ("P", "A"), ("I", "S")]

        # Create three orthogonal views
        self.ortho_views = {}
        for i in range(3):
            win = OrthoView(self, self.ivm, self.ax_map[i], self.ax_labels)
            win.sig_pick.connect(self._pick)
            win.sig_drag.connect(self._drag)
            win.sig_doubleclick.connect(self._toggle_maximise)
            win.add_data_view(self.main_data_view)
            win.add_data_view(self.current_data_view)
            win.add_data_view(self.current_roi_view)
            self.ortho_views[win.zaxis] = win

        # Main graphics layout
        #gview = pg.GraphicsView(background='k')
        gview = QtGui.QWidget()
        self.layout_grid = QtGui.QGridLayout()
        self.layout_grid.setHorizontalSpacing(2)
        self.layout_grid.setVerticalSpacing(2)
        self.layout_grid.setContentsMargins(0, 0, 0, 0)
        self.layout_grid.addWidget(
            self.ortho_views[1],
            0,
            0,
        )
        self.layout_grid.addWidget(self.ortho_views[0], 0, 1)
        self.layout_grid.addWidget(self.main_data_view.histogram, 0, 2)
        self.layout_grid.addWidget(self.ortho_views[2], 1, 0)
        self.layout_grid.addWidget(self.current_data_view.histogram, 1, 2)
        self.layout_grid.setColumnStretch(0, 3)
        self.layout_grid.setColumnStretch(1, 3)
        self.layout_grid.setColumnStretch(2, 1)
        self.layout_grid.setRowStretch(0, 1)
        self.layout_grid.setRowStretch(1, 1)
        gview.setLayout(self.layout_grid)
        self.addWidget(gview)
        self.addWidget(control_box)
        self.setStretchFactor(0, 5)
        self.setStretchFactor(1, 1)

        self.ivm.sig_main_data.connect(self._main_data_changed)
        self.opts.sig_options_changed.connect(self._opts_changed)