Skip to content

Commit

Permalink
Merge pull request #99 from mwcraig/fix-add-single-marker
Browse files Browse the repository at this point in the history
Add test and fix for case of adding single SkyCoord marker
  • Loading branch information
mwcraig committed Oct 14, 2019
2 parents d82c71e + 5e239bb commit 14bd771
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions astrowidgets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,11 @@ def add_markers(self, table, x_colname='x', y_colname='y',
coord_x, coord_y = image.wcs.wcs.all_world2pix(coord_val.ra.deg,
coord_val.dec.deg,
0)
# In the event a *single* marker has been added, coord_x and coord_y
# will be scalars. Make them arrays always.
if np.ndim(coord_x) == 0:
coord_x = np.array([coord_x])
coord_y = np.array([coord_y])
else: # Use X,Y
coord_x = table[x_colname].data
coord_y = table[y_colname].data
Expand Down
19 changes: 19 additions & 0 deletions astrowidgets/tests/test_image_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,22 @@ def test_empty_marker_name_works_with_all():
marks = iw.get_markers(marker_name='all')
assert len(marks) == len(x)
assert 'empty' not in marks['marker name']


def test_add_single_marker():
"""
Test a few things related to naming marker sets
"""
fake_ccd = _make_fake_ccd(with_wcs=True)
npix_side = fake_ccd.shape[0]
wcs = fake_ccd.wcs
iw = ImageWidget(pixel_coords_offset=0)
iw.load_nddata(fake_ccd)
# Get me 100 positions please, not right at the edge
marker_locs = np.random.randint(10,
high=npix_side - 10,
size=(100, 2))
marks_world = wcs.all_pix2world(marker_locs, 0)
marks_coords = SkyCoord(marks_world, unit='degree')
mark_coord_table = Table(data=[marks_coords], names=['coord'])
iw.add_markers(mark_coord_table[0], use_skycoord=True)

0 comments on commit 14bd771

Please sign in to comment.