Skip to content

Commit

Permalink
Manual backport of spacetelescope#2905 to v3.10.x
Browse files Browse the repository at this point in the history
but only for photutils changes
  • Loading branch information
pllim committed Jun 4, 2024
1 parent 225804f commit a31ad36
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
24 changes: 18 additions & 6 deletions jdaviz/configs/imviz/tests/test_simple_aper_phot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from jdaviz.configs.imviz.plugins.aper_phot_simple.aper_phot_simple import (
_curve_of_growth, _radial_profile)
from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_WCS, BaseImviz_WCS_NoWCS
from jdaviz.tests.test_utils import PHOTUTILS_LT_1_12_1


class TestSimpleAperPhot(BaseImviz_WCS_WCS):
Expand Down Expand Up @@ -333,6 +334,17 @@ def test_annulus_background(imviz_helper):
gauss4 = make_4gaussians_image() # The background has a mean of 5 with noise
ones = np.ones(gauss4.shape)

if PHOTUTILS_LT_1_12_1:
bg_4gauss_1 = 5.745596129482831
bg_4gauss_2 = 5.13918435824334
bg_4gauss_3 = 44.72559981461203
bg_4gauss_4 = 4.89189
else:
bg_4gauss_1 = 5.802287
bg_4gauss_2 = 5.052332
bg_4gauss_3 = 45.416834
bg_4gauss_4 = 4.939397

imviz_helper.load_data(gauss4, data_label='four_gaussians')
imviz_helper.load_data(ones, data_label='ones')

Expand All @@ -354,7 +366,7 @@ def test_annulus_background(imviz_helper):

# Switch data
phot_plugin.dataset_selected = 'four_gaussians'
assert_allclose(phot_plugin.background_value, 5.745596129482831) # Changed
assert_allclose(phot_plugin.background_value, bg_4gauss_1) # Changed

# Draw ellipse on another object
ellipse_1 = EllipsePixelRegion(center=PixCoord(x=20.5, y=37.5), width=41, height=15)
Expand All @@ -378,19 +390,19 @@ def test_annulus_background(imviz_helper):
phot_plugin.background_selected = 'Subset 4'

# Check new annulus for four_gaussians
assert_allclose(phot_plugin.background_value, 5.13918435824334) # Changed
assert_allclose(phot_plugin.background_value, bg_4gauss_2) # Changed

# Switch to manual, should not change
phot_plugin.background_selected = 'Manual'
assert_allclose(phot_plugin.background_value, 5.13918435824334)
assert_allclose(phot_plugin.background_value, bg_4gauss_2)

# Switch to Subset, should change a lot because this is not background area
phot_plugin.background_selected = 'Subset 1'
assert_allclose(phot_plugin.background_value, 44.72559981461203)
assert_allclose(phot_plugin.background_value, bg_4gauss_3)

# Switch back to annulus, should be same as before in same mode
phot_plugin.background_selected = 'Subset 4'
assert_allclose(phot_plugin.background_value, 5.13918435824334)
assert_allclose(phot_plugin.background_value, bg_4gauss_2)

# Edit the annulus and make sure background updates
subset_plugin = imviz_helper.plugins["Subset Tools"]._obj
Expand All @@ -400,7 +412,7 @@ def test_annulus_background(imviz_helper):
subset_plugin._set_value_in_subset_definition(0, "Inner Radius (pixels)", "value", 40)
subset_plugin._set_value_in_subset_definition(0, "Outer Radius (pixels)", "value", 45)
subset_plugin.vue_update_subset()
assert_allclose(phot_plugin.background_value, 4.89189)
assert_allclose(phot_plugin.background_value, bg_4gauss_4)


# NOTE: Extracting the cutout for radial profile is aperture
Expand Down
20 changes: 14 additions & 6 deletions jdaviz/core/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import time

import numpy as np
from astropy import units as u
from astropy.nddata import NDData
from photutils.datasets import make_4gaussians_image
import numpy as np
from numpy.testing import assert_allclose
from photutils.datasets import make_4gaussians_image

from jdaviz.tests.test_utils import PHOTUTILS_LT_1_12_1


def test_boxzoom(cubeviz_helper, image_cube_hdu_obj_microns):
Expand Down Expand Up @@ -91,10 +94,15 @@ def test_stretch_bounds_and_spline(imviz_helper):
"domain": {"x": 11.639166666374734, "y": 970.9392968750001},
}

knots_after_drag_move = (
[0.0, 0.1, 0.21712585033417825, 0.7, 1.0],
[0.0, 0.05, 0.2900993441358025, 0.9, 1.0],
)
if PHOTUTILS_LT_1_12_1:
knots_after_drag_move = (
[0.0, 0.1, 0.21712585033417825, 0.7, 1.0],
[0.0, 0.05, 0.2852214046563617, 0.9, 1.0],
)
else:
knots_after_drag_move = (
[0.0, 0.1, 0.21712585033417825, 0.7, 1.0],
[0.0, 0.05, 0.2956323141982414, 0.9, 1.0])

stretch_tool.on_mouse_event(knot_move_msg)

Expand Down
4 changes: 4 additions & 0 deletions jdaviz/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import photutils
import pytest
from astropy.utils import minversion

from jdaviz import utils

PHOTUTILS_LT_1_12_1 = not minversion(photutils, "1.12.1.dev")


@pytest.mark.parametrize("test_input,expected", [(0, 'a'), (1, 'b'), (25, 'z'), (26, 'aa'),
(701, 'zz'), (702, '{a')])
Expand Down

0 comments on commit a31ad36

Please sign in to comment.