Skip to content

Commit 6d16f41

Browse files
committed
Change markers → catalogs
1 parent 58d0350 commit 6d16f41

File tree

2 files changed

+68
-82
lines changed

2 files changed

+68
-82
lines changed

src/astro_image_display_api/interface_definition.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None:
9595
raise NotImplementedError
9696

9797
@abstractmethod
98-
def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
98+
def load_catalog(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
9999
skycoord_colname: str = 'coord', use_skycoord: bool = False,
100-
marker_name: str | None = None) -> None:
100+
catalog_label: str | None = None,
101+
catalog_style: str | None = None) -> None:
101102
"""
102103
Add markers to the image.
103104
@@ -118,9 +119,13 @@ def add_markers(self, table: Table, x_colname: str = 'x', y_colname: str = 'y',
118119
use_skycoord : bool, optional
119120
If `True`, the ``skycoord_colname`` column will be used to
120121
get the marker positions. Default is `False`.
121-
marker_name : str, optional
122+
catalog_label : str, optional
122123
The name of the marker set to use. If not given, a unique
123124
name will be generated.
125+
catalog_style: str, optional
126+
A dictionary that specifies the style of the markers used to
127+
rerpresent the catalog. See `ImageViewerInterface.set_catalog_style`
128+
for details.
124129
"""
125130
raise NotImplementedError
126131

@@ -177,29 +182,22 @@ def get_catalog_style(self, catalog_label: str | None = None) -> dict:
177182
raise NotImplementedError
178183

179184
@abstractmethod
180-
def reset_markers(self) -> None:
181-
"""
182-
Remove all markers from the image.
183-
"""
184-
raise NotImplementedError
185-
186-
@abstractmethod
187-
def remove_markers(self, marker_name: str | list[str] | None = None) -> None:
185+
def remove_catalog(self, catalog_label: str | list[str] | None = None) -> None:
188186
"""
189187
Remove markers from the image.
190188
191189
Parameters
192190
----------
193-
marker_name : str, optional
191+
catalog_label : str, optional
194192
The name of the marker set to remove. If the value is ``"all"``,
195193
then all markers will be removed.
196194
"""
197195
raise NotImplementedError
198196

199197
@abstractmethod
200-
def get_markers(self, x_colname: str = 'x', y_colname: str = 'y',
198+
def get_catalog(self, x_colname: str = 'x', y_colname: str = 'y',
201199
skycoord_colname: str = 'coord',
202-
marker_name: str | list[str] | None = None) -> Table:
200+
catalog_label: str | list[str] | None = None) -> Table:
203201
"""
204202
Get the marker positions.
205203
@@ -214,15 +212,27 @@ def get_markers(self, x_colname: str = 'x', y_colname: str = 'y',
214212
skycoord_colname : str, optional
215213
The name of the column containing the sky coordinates. Default
216214
is ``'coord'``.
217-
marker_name : str or list of str, optional
215+
catalog_label : str or list of str, optional
218216
The name of the marker set to use. If that value is ``"all"``,
219217
then all markers will be returned.
220218
221219
Returns
222220
-------
223221
table : `astropy.table.Table`
224222
The table containing the marker positions. If no markers match the
225-
``marker_name`` parameter, an empty table is returned.
223+
``catalog_label`` parameter, an empty table is returned.
224+
"""
225+
raise NotImplementedError
226+
227+
@abstractmethod
228+
def get_catalog_names(self) -> list[str]:
229+
"""
230+
Get the names of the loaded catalogs.
231+
232+
Returns
233+
-------
234+
list of str
235+
The names of the loaded catalogs.
226236
"""
227237
raise NotImplementedError
228238

src/astro_image_display_api/widget_api_test.py

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,14 @@ class variable does the trick.
4848
"""
4949
self.image = self.image_widget_class(image_width=250, image_height=100)
5050

51-
def _assert_empty_marker_table(self, table):
51+
def _assert_empty_catalog_table(self, table):
5252
assert isinstance(table, Table)
5353
assert len(table) == 0
5454
assert sorted(table.colnames) == sorted(['x', 'y', 'coord', 'marker name'])
5555

56-
def _get_marker_names_as_set(self):
57-
marks = self.image.get_markers(marker_name="all")["marker name"]
58-
if hasattr(marks, 'mask') and all(marks.mask):
59-
marker_names = set()
60-
else:
61-
marker_names = set(marks)
62-
return marker_names
56+
def _get_catalog_names_as_set(self):
57+
marks = self.image.get_catalog_names()
58+
return set(marks)
6359

6460
def test_width_height(self):
6561
assert self.image.image_width == 250
@@ -160,111 +156,91 @@ def test_get_catalog_style_with_multiple_labels_raises_error(self):
160156
with pytest.raises(ValueError, match='Multiple catalog styles'):
161157
self.image.get_catalog_style()
162158

163-
def test_add_markers(self):
159+
def test_load_catalog(self):
164160
data = np.arange(10).reshape(5, 2)
165161
orig_tab = Table(data=data, names=['x', 'y'], dtype=('float', 'float'))
166162
tab = Table(data=data, names=['x', 'y'], dtype=('float', 'float'))
167-
self.image.add_markers(tab, x_colname='x', y_colname='y',
168-
skycoord_colname='coord', marker_name='test1')
163+
self.image.load_catalog(tab, x_colname='x', y_colname='y',
164+
skycoord_colname='coord', catalog_label='test1')
169165

170166

171167
# Regression test for GitHub Issue 45:
172168
# Adding markers should not modify the input data table.
173169
assert (tab == orig_tab).all()
174170

175171
# Add more markers under different name.
176-
self.image.add_markers(tab, x_colname='x', y_colname='y',
177-
skycoord_colname='coord', marker_name='test2')
172+
self.image.load_catalog(tab, x_colname='x', y_colname='y',
173+
skycoord_colname='coord', catalog_label='test2')
178174

179-
marknames = self._get_marker_names_as_set()
175+
marknames = self._get_catalog_names_as_set()
180176
assert marknames == set(['test1', 'test2'])
181-
# assert self.image.get_marker_names() == ['test1', 'test2']
182177

183178
# No guarantee markers will come back in the same order, so sort them.
184-
t1 = self.image.get_markers(marker_name='test1')
179+
t1 = self.image.get_catalog(catalog_label='test1')
185180
# Sort before comparing
186181
t1.sort('x')
187182
tab.sort('x')
188183
assert np.all(t1['x'] == tab['x'])
189184
assert (t1['y'] == tab['y']).all()
190185

191-
# That should have given us two copies of the input table
192-
t2 = self.image.get_markers(marker_name="all")
193-
expected = vstack([tab, tab], join_type='exact')
186+
t2 = self.image.get_catalog(catalog_label="test2")
194187
# Sort before comparing
195188
t2.sort(['x', 'y'])
196-
expected.sort(['x', 'y'])
197-
assert (t2['x'] == expected['x']).all()
198-
assert (t2['y'] == expected['y']).all()
189+
tab.sort(['x', 'y'])
190+
assert (t2['x'] == tab['x']).all()
191+
assert (t2['y'] == tab['y']).all()
199192

200-
self.image.remove_markers(marker_name='test1')
201-
marknames = self._get_marker_names_as_set()
193+
self.image.remove_catalog(catalog_label='test1')
194+
marknames = self._get_catalog_names_as_set()
202195
assert marknames == set(['test2'])
203196

204197
# Add markers with no marker name and check we can retrieve them
205198
# using the default marker name
206-
self.image.add_markers(tab, x_colname='x', y_colname='y',
199+
self.image.load_catalog(tab, x_colname='x', y_colname='y',
207200
skycoord_colname='coord')
208201
# Don't care about the order of the marker names so use set instead of
209202
# list.
210-
marknames = self._get_marker_names_as_set()
203+
marknames = self._get_catalog_names_as_set()
211204
assert (set(marknames) == set(['test2']))
212205

213206
# Clear markers to not pollute other tests.
214-
self.image.reset_markers()
215-
marknames = self._get_marker_names_as_set()
207+
self.image.remove_catalog(catalog_label='*')
208+
marknames = self._get_catalog_names_as_set()
216209
assert len(marknames) == 0
217-
self._assert_empty_marker_table(self.image.get_markers(marker_name="all"))
210+
self._assert_empty_catalog_table(self.image.get_catalog())
218211
# Check that no markers remain after clearing
219-
tab = self.image.get_markers()
220-
self._assert_empty_marker_table(tab)
212+
tab = self.image.get_catalog()
213+
self._assert_empty_catalog_table(tab)
221214

222215
# Check that retrieving a marker set that doesn't exist returns
223216
# an empty table with the right columns
224-
tab = self.image.get_markers(marker_name='test1')
225-
self._assert_empty_marker_table(tab)
217+
tab = self.image.get_catalog(catalog_label='test1')
218+
self._assert_empty_catalog_table(tab)
226219

227-
def test_get_markers_accepts_list_of_names(self):
228-
# Check that the get_markers method accepts a list of marker names
229-
# and returns a table with all the markers from all the named sets.
230-
data = np.arange(10).reshape((5, 2))
231-
tab = Table(data=data, names=['x', 'y'])
232-
self.image.add_markers(tab, marker_name='test1')
233-
self.image.add_markers(tab, marker_name='test2')
234-
235-
# No guarantee markers will come back in the same order, so sort them.
236-
t1 = self.image.get_markers(marker_name=['test1', 'test2'])
237-
# Sort before comparing
238-
t1.sort('x')
239-
expected = vstack([tab, tab], join_type='exact')
240-
expected.sort('x')
241-
np.testing.assert_array_equal(t1['x'], expected['x'])
242-
np.testing.assert_array_equal(t1['y'], expected['y'])
243-
244-
def test_remove_markers(self):
220+
def test_remove_catalog(self):
245221
with pytest.raises(ValueError, match='arf'):
246-
self.image.remove_markers(marker_name='arf')
222+
self.image.remove_catalog(catalog_label='arf')
247223

248-
def test_remove_markers_name_all(self):
224+
def test_remove_catalogs_name_all(self):
249225
data = np.arange(10).reshape(5, 2)
250226
tab = Table(data=data, names=['x', 'y'])
251-
self.image.add_markers(tab, marker_name='test1')
252-
self.image.add_markers(tab, marker_name='test2')
227+
self.image.load_catalog(tab, catalog_label='test1')
228+
self.image.load_catalog(tab, catalog_label='test2')
253229

254-
self.image.remove_markers(marker_name='all')
255-
self._assert_empty_marker_table(self.image.get_markers(marker_name='all'))
230+
self.image.remove_catalog(catalog_label='*')
231+
self._assert_empty_catalog_table(self.image.get_catalog())
256232

257-
def test_remove_marker_accepts_list(self):
233+
def test_remove_catalog_accepts_list(self):
258234
data = np.arange(10).reshape(5, 2)
259235
tab = Table(data=data, names=['x', 'y'])
260-
self.image.add_markers(tab, marker_name='test1')
261-
self.image.add_markers(tab, marker_name='test2')
236+
self.image.load_catalog(tab, catalog_label='test1')
237+
self.image.load_catalog(tab, catalog_label='test2')
262238

263-
self.image.remove_markers(marker_name=['test1', 'test2'])
264-
marks = self.image.get_markers(marker_name='all')
265-
self._assert_empty_marker_table(marks)
239+
self.image.remove_catalog(catalog_label=['test1', 'test2'])
240+
marks = self.image.get_catalog()
241+
self._assert_empty_catalog_table(marks)
266242

267-
def test_adding_markers_as_world(self, data, wcs):
243+
def test_adding_catalog_as_world(self, data, wcs):
268244
ndd = NDData(data=data, wcs=wcs)
269245
self.image.load_nddata(ndd)
270246

@@ -273,8 +249,8 @@ def test_adding_markers_as_world(self, data, wcs):
273249
marks_pix = Table(data=pixels, names=['x', 'y'], dtype=('float', 'float'))
274250
marks_coords = wcs.pixel_to_world(marks_pix['x'], marks_pix['y'])
275251
mark_coord_table = Table(data=[marks_coords], names=['coord'])
276-
self.image.add_markers(mark_coord_table, use_skycoord=True)
277-
result = self.image.get_markers()
252+
self.image.load_catalog(mark_coord_table, use_skycoord=True)
253+
result = self.image.get_catalog()
278254
# Check the x, y positions as long as we are testing things...
279255
# The first test had one entry that was zero, so any check
280256
# based on rtol will not work. Added a small atol to make sure

0 commit comments

Comments
 (0)