Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the contour extraction for 3D data #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Sphinx & coverage
build
doc/_build
doc/api
glue/tests/htmlcov
*.coverage
*htmlcov*

# Packages/installer info
doc/.eggs
Glue.egg-info
glueviz.egg-info
dist

# Compiled files
*.pyc

# Other generated files
glue/_githash.py

# Other
.pylintrc
*.ropeproject
glue/qt/glue_qt_resources.py
*.__junk*
*.orig
*~
.cache

# Mac OSX
.DS_Store

# PyCharm
.idea

# Eclipse editor project files
.project
.pydevproject
.settings
2 changes: 1 addition & 1 deletion glue_exp/importers/vizier/qt_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from glue.external.qt import QtGui
from glue.external.qt.QtCore import Qt
from glue.qt.qtutil import load_ui
from glue.utils.qt.helpers import load_ui

from .vizier_helpers import query_vizier, fetch_vizier_catalog

Expand Down
2 changes: 1 addition & 1 deletion glue_exp/importers/webcam/qt_widget.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from glue.external.qt import QtGui, QtCore
from glue.qt.qtutil import load_ui
from glue.utils.qt.helpers import load_ui

from .webcam_helpers import Webcam, frame_to_data

Expand Down
2 changes: 1 addition & 1 deletion glue_exp/tools/contour_selection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def setup():

from glue.logger import logger
from glue.config import tool_registry
from glue.qt.widgets.image_widget import ImageWidget
from glue.viewers.image.qt import ImageWidget

from .contour_selection import ContourSelectionTool

Expand Down
27 changes: 24 additions & 3 deletions glue_exp/tools/contour_selection/contour_selection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import numpy as np

from glue.qt.mouse_mode import MouseMode
from glue.viewers.common.qt.mouse_mode import MouseMode
from glue.core import roi
from glue.external.qt import QtGui

Expand Down Expand Up @@ -33,13 +34,31 @@ def _contour_roi(self, mode):

if im is None or att is None:
return
if im.size > WARN_THRESH and not self._confirm_large_image(im):
if im.size > WARN_THRESH and not self.widget._confirm_large_image(im):
return
slc = self.widget.client.slice

roi = mode.roi(im[att])
# attribute is Primary,
data = np.take(im[att], slc[self.profile_axis], axis=self.profile_axis)

# when mouse pos of xy and axis status shown on left selection panel doesn't match
# TODO: this would be solved when switch axis labels and its value
if slc.index('x') < slc.index('y'):
data = data.transpose()

roi = mode.roi(data)
if roi:
self.widget.apply_roi(roi)

@property
def profile_axis(self):
# XXX make this settable
# defaults to the non-xy axis with the most channels
slc = self.widget.client.slice
candidates = [i for i, s in enumerate(slc) if s not in ['x', 'y']]

return max(candidates, key=lambda i: self.widget.client.display_data.shape[i])

def _display_data_hook(self, data):
pass

Expand Down Expand Up @@ -76,6 +95,8 @@ def roi(self, data):
A new ROI made by the (single) contour that passes through the
mouse location (and `None` if this could not be calculated)
"""
# here the xy refers to the x and y related to the order of left panel

x, y = self._event_xdata, self._event_ydata
return contour_to_roi(x, y, data)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from mock import MagicMock, patch

from glue.qt.tests.test_mouse_mode import TestMouseMode, Event
from glue.viewers.common.qt.tests.test_mouse_mode import TestMouseMode, Event

from ..contour_selection import ContourMode, contour_to_roi

Expand Down