Skip to content

Commit

Permalink
Add tests for sky bg
Browse files Browse the repository at this point in the history
and remove debug comment
  • Loading branch information
pllim committed Aug 10, 2023
1 parent 901375b commit 7e1dc50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,6 @@ def vue_do_aper_phot(self, *args, **kwargs):
sky_center = None

aperture = regions2aperture(reg)

# UNTIL HERE - pass in pixel region explicitly and see if answers are correct
# print("HERE 1", reg)
# print("HERE 2", aperture)
# if hasattr(reg, "to_pixel"):
# print("HERE 3", reg.to_pixel(data.coords))

include_pixarea_fac = False
include_counts_fac = False
include_flux_scale = False
Expand Down
24 changes: 22 additions & 2 deletions jdaviz/configs/imviz/tests/test_simple_aper_phot.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def setup_class(self, imviz_helper):
self.imviz = imviz_helper
self.viewer = imviz_helper.default_viewer
self.phot_plugin = imviz_helper.plugins["Imviz Simple Aperture Photometry"]._obj
self.phot_plugin.bg_subset_selected = 'Manual'

@pytest.mark.parametrize(('data_label', 'local_bkg'), [
('gauss100_fits_wcs[PRIMARY,1]', 5.0),
Expand All @@ -234,14 +233,35 @@ def setup_class(self, imviz_helper):
def test_aperphot(self, data_label, local_bkg, subset_label, expected_sum):
"""All data should give similar result for the same Subset."""
self.phot_plugin.dataset_selected = data_label
self.phot_plugin.background_value = local_bkg
self.phot_plugin.subset_selected = subset_label
self.phot_plugin.bg_subset_selected = 'Manual'
self.phot_plugin.background_value = local_bkg
self.phot_plugin.vue_do_aper_phot()
tbl = self.imviz.get_aperture_photometry_results()

# Imperfect down-sampling and imperfect apertures, so 10% is good enough.
assert_allclose(tbl['sum'][-1], expected_sum, rtol=0.1)

@pytest.mark.parametrize(('data_label', 'fac'), [
('gauss100_fits_wcs[PRIMARY,1]', 1),
('gauss100_fits_wcs_block_reduced[PRIMARY,1]', 4),
('gauss100_fits_wcs_block_reduced_rotated[PRIMARY,1]', 4),
('no_wcs', 1)])
@pytest.mark.parametrize(('bg_label', 'expected_bg'), [
('Subset 2', 12.269274711608887),
('Subset 3', 7.935906410217285),
('Subset 4', 11.120951652526855)])
def test_sky_background(self, data_label, fac, bg_label, expected_bg):
"""All background (median) should give similar result for the same Subset.
Down-sampled data has higher factor due to flux conservation.
"""
self.phot_plugin.dataset_selected = data_label
self.phot_plugin.subset_selected = "Subset 1" # Does not matter
self.phot_plugin.bg_subset_selected = bg_label

# Imperfect down-sampling and abusing apertures, so 10% is good enough.
assert_allclose(float(self.phot_plugin.background_value), expected_bg * fac, rtol=0.1)


def test_annulus_background(imviz_helper):
from photutils.datasets import make_4gaussians_image
Expand Down

0 comments on commit 7e1dc50

Please sign in to comment.