Skip to content

Commit

Permalink
WIP: Attempt to add tests for zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Jul 27, 2021
1 parent a39b66a commit fa852b0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def zoom_level(self):
"""
viewer = self.app.get_viewer("viewer-1")
if viewer.shape is None:
if viewer.shape is None: # pragma: no cover
raise ValueError('Viewer is still loading, try again later')

screenx = viewer.shape[1]
Expand Down
14 changes: 14 additions & 0 deletions jdaviz/configs/imviz/tests/test_astrowidgets_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ def test_center_offset_sky(self):
self.imviz.offset_by(dsky, dsky)


class TestZoom(BaseImviz_WCS_NoWCS):

def test_invalid_zoom(self):
pass

def test_zoom(self):
self.imviz.zoom_level = 'fit'
assert_allclose(self.imviz.zoom_level, 10)

# TODO: Does not update properly in CI setting. I swear it works in notebook!
self.imviz.zoom_level = 1
assert_allclose(self.imviz.zoom_level, 1)


class TestMarkers(BaseImviz_WCS_NoWCS):

def test_invalid_markers(self):
Expand Down
80 changes: 42 additions & 38 deletions jdaviz/configs/imviz/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
import numpy as np
import pytest
from astropy.io import fits
from astropy.wcs import WCS

__all__ = ['BaseImviz_WCS_NoWCS']


class BaseImviz_WCS_NoWCS:
@pytest.fixture(autouse=True)
def setup_class(self, imviz_app):
hdu = fits.ImageHDU(np.zeros((10, 10)), name='SCI')

# Apply some celestial WCS from
# https://learn.astropy.org/rst-tutorials/celestial_coords1.html
hdu.header.update({'CTYPE1': 'RA---TAN',
'CUNIT1': 'deg',
'CDELT1': -0.0002777777778,
'CRPIX1': 1,
'CRVAL1': 337.5202808,
'NAXIS1': 10,
'CTYPE2': 'DEC--TAN',
'CUNIT2': 'deg',
'CDELT2': 0.0002777777778,
'CRPIX2': 1,
'CRVAL2': -20.833333059999998,
'NAXIS2': 10})

# Data with WCS
imviz_app.load_data(hdu, data_label='has_wcs')

# Data without WCS
imviz_app.load_data(hdu, data_label='no_wcs')
imviz_app.app.data_collection[1].coords = None

self.wcs = WCS(hdu.header)
self.imviz = imviz_app
self.viewer = imviz_app.app.get_viewer('viewer-1')
import numpy as np
import pytest
from astropy.io import fits
from astropy.wcs import WCS

__all__ = ['BaseImviz_WCS_NoWCS']


class BaseImviz_WCS_NoWCS:
@pytest.fixture(autouse=True)
def setup_class(self, imviz_app):
hdu = fits.ImageHDU(np.zeros((10, 10)), name='SCI')

# Apply some celestial WCS from
# https://learn.astropy.org/rst-tutorials/celestial_coords1.html
hdu.header.update({'CTYPE1': 'RA---TAN',
'CUNIT1': 'deg',
'CDELT1': -0.0002777777778,
'CRPIX1': 1,
'CRVAL1': 337.5202808,
'NAXIS1': 10,
'CTYPE2': 'DEC--TAN',
'CUNIT2': 'deg',
'CDELT2': 0.0002777777778,
'CRPIX2': 1,
'CRVAL2': -20.833333059999998,
'NAXIS2': 10})

# Data with WCS
imviz_app.load_data(hdu, data_label='has_wcs')

# Data without WCS
imviz_app.load_data(hdu, data_label='no_wcs')
imviz_app.app.data_collection[1].coords = None

self.wcs = WCS(hdu.header)
self.imviz = imviz_app
self.viewer = imviz_app.app.get_viewer('viewer-1')

# TODO: Does not really work. How to fix?
# Since we are not really displaying, need this to test zoom.
self.viewer.shape = (100, 100)

0 comments on commit fa852b0

Please sign in to comment.