Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: astropy/astrowidgets
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6f14f0918f4370ef59978d90ce9f7cfd58a47df9
Choose a base ref
..
head repository: astropy/astrowidgets
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 82a7844cf4b7315bd303cb98646beb0dc70a1539
Choose a head ref
83 changes: 39 additions & 44 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
@@ -8,60 +8,55 @@ on:
# * is a special character in YAML so you have to quote this string
- cron: '0 5 * * 5'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
pep8:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Lint with flake8
run: |
python -m pip install --upgrade pip flake8
flake8 astrowidgets --count
tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
include:

- name: Code style checks
os: ubuntu-latest
python: 3.x
toxenv: codestyle

- name: Python 3.9 with abstract only
os: ubuntu-latest
python: 3.9
toxenv: py39-test

- name: Python 3.8 with Ginga backend (Linux)
os: ubuntu-latest
python: 3.8
toxenv: py38-test-alldeps

- name: Python 3.9 with Ginga backend (Windows)
os: windows-latest
python: 3.9
toxenv: py39-test-alldeps

- name: Python 3.7 with Ginga backend (OSX)
os: macos-latest
python: 3.7
toxenv: py37-test-alldeps

- name: Python 3.9 with Ginga backend (dev)
os: ubuntu-latest
python: 3.9
toxenv: py39-test-devdeps

- name: Python 3.6 with Ginga backend (old)
os: ubuntu-latest
python: 3.6
toxenv: py36-test-oldestdeps

os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
fetch-depth: 0
python-version: '3.9'
- name: Install and build
run: python -m pip install tox --upgrade
- name: Run tests
run: tox -e py39-test

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Python dependencies
run: python -m pip install --upgrade tox
python-version: '3.11'
- name: Install and build
run: python -m pip install tox --upgrade
- name: Run tests
run: tox -e ${{ matrix.toxenv }}
run: tox -e py311-test-devdeps
30 changes: 30 additions & 0 deletions .github/workflows/predeps_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: rc_testing

on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install and build
run: python -m pip install tox --upgrade
- name: Run tests
run: tox -e py310-test-predeps
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ jobs:
if: github.repository == 'astropy/astrowidgets'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: 3.8

2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ sphinx:
# Set the version of Python and requirements required to build your docs
python:
version: 3.8
system_packages: true
system_packages: false
install:
- method: pip
path: .
5 changes: 0 additions & 5 deletions astrowidgets/conftest.py
Original file line number Diff line number Diff line change
@@ -7,11 +7,6 @@
PYTEST_HEADER_MODULES = {}
TESTED_VERSIONS = {}

# Uncomment the following line to treat all DeprecationWarnings as
# exceptions.
# from astropy.tests.helper import enable_deprecations_as_exceptions
# enable_deprecations_as_exceptions()

# Uncomment and customize the following lines to add/remove entries from
# the list of packages for which version numbers are displayed when running
# the tests. Making it pass for KeyError is essential in some cases when
70 changes: 27 additions & 43 deletions astrowidgets/ginga.py
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
from ginga.AstroImage import AstroImage
from ginga.canvas.CanvasObject import drawCatalog
from ginga.web.jupyterw.ImageViewJpw import EnhancedCanvasView
from ginga.util.wcs import raDegToString, decDegToString
from ginga.util.wcs import ra_deg_to_str, dec_deg_to_str

__all__ = ['ImageWidget']

@@ -41,25 +41,26 @@ class ImageWidget(ipyw.VBox):
logger = get_logger('my_viewer', log_stderr=False,
log_file='ginga.log', level=40)
use_opencv : bool, optional
Let Ginga use ``opencv`` to speed up image transformation;
e.g., rotation and mosaic. If this is enabled and you
do not have ``opencv``, you will get a warning.
image_width, image_height : int
Dimension of Jupyter notebook's image widget.
image_height : int, optional
Height of Jupyter notebook's image widget.
image_width, pixel_coords_offset : int, optional
Width of Jupyter notebook's image widget.
Height is automatically determined.
image_widget : obj or None
Jupyter notebook's image widget. If None, a new widget will be created.
cursor_widget : obj or None
Jupyter notebook's cursor widget. If None, a new widget will be created.
"""

def __init__(self, logger=None, image_widget=None, cursor_widget=None,
image_width=500, image_height=500, pixel_coords_offset=0,
use_opencv=True):
def __init__(self, logger=None, image_width=500, image_height=500,
image_widget=None, cursor_widget=None,
**kwargs):
super().__init__()
if 'use_opencv' in kwargs:
warnings.warn("use_opencv kwarg has been deprecated--"
"opencv will be used if it is installed",
DeprecationWarning)

self._viewer = EnhancedCanvasView(logger=logger)
self.ALLOWED_CURSOR_LOCATIONS = ['top', 'bottom', None]
self.RESERVED_MARKER_SET_NAMES = ['all']

@@ -83,8 +84,6 @@ def __init__(self, logger=None, image_widget=None, cursor_widget=None,
self._jup_img.max_width = '100%'
self._jup_img.height = 'auto'

self._pixel_offset = pixel_coords_offset

# Set the width of the box containing the image to the desired width
# Note: We are NOT setting the height. That is because the height
# is automatically set by the image aspect ratio.
@@ -116,14 +115,6 @@ def __init__(self, logger=None, image_widget=None, cursor_widget=None,
self._cursor = 'bottom'
self.children = [self._jup_img, self._jup_coord]

# TODO: Is this the best place for this?
if use_opencv:
try:
from ginga import trcalc
trcalc.use('opencv')
except ImportError:
logger.warning('install opencv or set use_opencv=False')

# These need to also be set for now.
# Ginga uses them to figure out what size image to make.
self._jup_img.width = image_width
@@ -208,14 +199,14 @@ def _mouse_move_cb(self, viewer, button, data_x, data_y):
except Exception:
imval = 'N/A'

val = (f'X: {data_x + self._pixel_offset:.2f}, '
f'Y: {data_y + self._pixel_offset:.2f}')
val = (f'X: {data_x:.2f}, '
f'Y: {data_y:.2f}')

if image.wcs.wcs is not None:
try:
ra, dec = image.pixtoradec(data_x, data_y)
val += (f' (RA: {raDegToString(ra)},'
f' DEC: {decDegToString(dec)})')
val += (f' (RA: {ra_deg_to_str(ra)},'
f' DEC: {dec_deg_to_str(dec)})')
except Exception:
val += ' (RA, DEC: WCS error)'

@@ -237,7 +228,7 @@ def _mouse_click_cb(self, viewer, event, data_x, data_y):

# NOTE: By always using CompoundObject, marker handling logic
# is simplified.
obj = self._marker(x=data_x, y=data_y)
obj = self._marker(x=data_x, y=data_y, coord='data')
objs.append(obj)
viewer.canvas.add(self.dc.CompoundObject(*objs), tag=marker_name)
self._marktags.add(marker_name)
@@ -251,8 +242,8 @@ def _mouse_click_cb(self, viewer, event, data_x, data_y):

# For debugging.
with self.print_out:
print(f'Centered on X={data_x + self._pixel_offset} '
f'Y={data_y + self._pixel_offset}')
print(f'Centered on X={data_x} '
f'Y={data_y}')

def load_fits(self, filename, numhdu=None, memmap=None):
"""Load a FITS file or HDU into the viewer.
@@ -332,7 +323,7 @@ def center_on(self, point):
if isinstance(point, SkyCoord):
self._viewer.set_pan(point.ra.deg, point.dec.deg, coord='wcs')
else:
self._viewer.set_pan(*(np.asarray(point) - self._pixel_offset))
self._viewer.set_pan(*(np.asarray(point)))

@deprecated('0.3', alternative='offset_by')
def offset_to(self, dx, dy, skycoord_offset=False):
@@ -582,10 +573,6 @@ def get_markers_by_name(self, marker_name, x_colname='x', y_colname='y',

sky_col = SkyCoord(radec_col[:, 0], radec_col[:, 1], unit='deg')

# Convert X,Y from 0-indexed to 1-indexed
if self._pixel_offset != 0:
xy_col += self._pixel_offset

# Build table
if include_skycoord:
markers_table = Table(
@@ -679,12 +666,6 @@ def add_markers(self, table, x_colname='x', y_colname='y',
else: # Use X,Y
coord_x = table[x_colname].data
coord_y = table[y_colname].data
# Convert data coordinates from 1-indexed to 0-indexed
if self._pixel_offset != 0:
# Don't use the in-place operator -= here that modifies
# the input table.
coord_x = coord_x - self._pixel_offset
coord_y = coord_y - self._pixel_offset

# Prepare canvas and retain existing marks
try:
@@ -781,7 +762,10 @@ def stretch_options(self):

@property
def stretch(self):
return self._viewer.rgbmap.dist
"""
The image stretching algorithm in use.
"""
return self._viewer.rgbmap.get_dist()

# TODO: Possible to use astropy.visualization directly?
@stretch.setter
20 changes: 10 additions & 10 deletions astrowidgets/tests/test_api_ginga.py
Original file line number Diff line number Diff line change
@@ -94,15 +94,15 @@ def test_select_points():

def test_get_selection():
image = ImageWidget()
marks = image.get_markers()
marks = image.get_all_markers()
assert isinstance(marks, Table) or marks is None


def test_stop_marking():
image = ImageWidget()
# This is not much of a test...
image.stop_marking(clear_markers=True)
assert image.get_markers() is None
assert image.get_all_markers() is None
assert image.is_marking is False


@@ -168,27 +168,27 @@ def test_reset_markers():
image = ImageWidget()
# First test: this shouldn't raise any errors
# (it also doesn't *do* anything...)
image.reset_markers()
assert image.get_markers() is None
image.remove_all_markers()
assert image.get_all_markers() is None
table = Table(data=np.random.randint(0, 100, [5, 2]),
names=['x', 'y'], dtype=('int', 'int'))
image.add_markers(table, x_colname='x', y_colname='y',
skycoord_colname='coord', marker_name='test')
image.add_markers(table, x_colname='x', y_colname='y',
skycoord_colname='coord', marker_name='test2')
image.reset_markers()
image.remove_all_markers()
with pytest.raises(ValueError):
image.get_markers(marker_name='test')
image.get_markers_by_name('test')
with pytest.raises(ValueError):
image.get_markers(marker_name='test2')
image.get_markers_by_name('test2')


def test_remove_markers():
image = ImageWidget()
# Add a tag name...
image._marktags.add(image._default_mark_tag_name)
with pytest.raises(ValueError) as e:
image.remove_markers('arf')
image.remove_markers_by_name('arf')
assert 'arf' in str(e.value)


@@ -214,7 +214,7 @@ def test_cuts():
# should raise an error.
with pytest.raises(ValueError) as e:
image.cuts = (1, 10, 100)
assert 'length 2' in str(e.value)
assert 'Cut levels must be given as (low, high)' in str(e.value)

# These ought to succeed

@@ -283,7 +283,7 @@ def test_click_center():
# If marking is in progress then setting click center should fail
with pytest.raises(ValueError) as e:
image.click_center = True
assert 'Cannot set' in str(e.value)
assert 'Interactive marking is in progress' in str(e.value)

# setting to False is fine though so no error is expected here
image.click_center = False
Loading