Skip to content

Commit

Permalink
check if padding is between 0 and 1
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Dec 20, 2024
1 parent 961d60b commit a6c6af9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 3 additions & 0 deletions jdaviz/configs/imviz/plugins/catalogs/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def zoom_to_selected(self, padding=0.02, return_bounding_box=False):
if not len(selected_rows):
return

if padding <= 0 or padding > 1:
raise ValueError("`padding` must be between 0 and 1.")

x = [float(coord['x_coord']) for coord in selected_rows]
y = [float(coord['y_coord']) for coord in selected_rows]

Expand Down
18 changes: 7 additions & 11 deletions jdaviz/configs/imviz/tests/test_catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,8 @@ def test_offline_ecsv_catalog(imviz_helper, image_2d_wcs, tmp_path):
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == -0.5
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 9.5

# set 'padding' to reproduce original hard-coded 50 pixel window
# so test results don't change
catalogs_plugin.zoom_to_selected(padding=50 / 10)

assert imviz_helper.viewers['imviz-0']._obj.state.x_min == -49.99966
assert imviz_helper.viewers['imviz-0']._obj.state.x_max == 50.00034
assert imviz_helper.viewers['imviz-0']._obj.state.y_min == -48.99999
assert imviz_helper.viewers['imviz-0']._obj.state.y_max == 51.00001

# also test the more reasonable window using the new default which is 2%
# of the viewer size around the selected points
# test the zooming using the default 'padding' of 2% of the viewer size
# around selected points
catalogs_plugin.zoom_to_selected()
assert imviz_helper.viewers['imviz-0']._obj.state.x_min == -0.19966
assert imviz_helper.viewers['imviz-0']._obj.state.x_max == 0.20034000000000002
Expand Down Expand Up @@ -339,3 +330,8 @@ def test_zoom_to_selected(imviz_helper, image_2d_wcs, tmp_path):
assert_allclose(xmax, 100 + 25, atol=0.1) # max x of selected source plus pad
assert_allclose(ymin, 100 - 25, atol=0.1) # min y of selected source minus pad
assert_allclose(ymax, 100 + 25, atol=0.1) # max y of selected source plus pad

# test that appropriate error is raised when padding is not a valud percentage
with pytest.raises(ValueError, match="`padding` must be between 0 and 1."):
catalogs_plugin.zoom_to_selected(padding=5)

0 comments on commit a6c6af9

Please sign in to comment.