Skip to content

Commit

Permalink
Merge pull request #1332 from pllim/apersum-mjysr-conv
Browse files Browse the repository at this point in the history
BUG: aperture sum counted npix twice
  • Loading branch information
pllim authored May 24, 2022
2 parents 067c2ae + 2e58202 commit dcebb9a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Imviz
- Radial profile plot in Simple Aperture Photometry plugin
no longer shows masked aperture data. [#1224]

- Aperture sum in Simple Aperture Photometry plugin no longer reports
the wrong value in MJy when input data is in MJy/sr. Previously,
it applied number of pixels twice in the calculations, so sum in MJy
with 10-pixel aperture would be off by a factor of 10. This bug did not
affect data in any other units. [#1332]

- Markers API now handles GWCS with ICRS Lon/Lat defined instead of
Right Ascension and Declination. [#1314]

Expand Down
4 changes: 2 additions & 2 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ The columns are as follow:
* :attr:`~photutils.aperture.ApertureStats.sum_aper_area`: The pixel area
covered by the region. Partial coverage is reported as fraction.
* ``pixarea_tot``: If per steradian is in input data unit and pixel area is
provided, this contains the total pixel area covered by the aperture in
steradian. Otherwise, it is `None`.
provided, this contains the conversion factor for the *sum* to take out
the steradian unit. Otherwise, it is `None`.
* ``aperture_sum_counts``: This is the aperture sum converted to counts,
if :guilabel:`Counts conversion factor` was set. Otherwise, it is `None`.
This calculation is done without taking account of ``pixarea_tot``, even
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ def vue_do_aper_phot(self, *args, **kwargs):
phot_table['xcentroid'].unit = u.pix # photutils only assumes, we make it real
phot_table['ycentroid'].unit = u.pix
rawsum = phot_table['sum'][0]
npix = phot_table['sum_aper_area'][0]

if include_pixarea_fac:
pixarea = pixarea * (u.arcsec * u.arcsec / (u.pix * u.pix))
pixarea_fac = npix * pixarea.to(u.sr / (u.pix * u.pix))
# NOTE: Sum already has npix value encoded, so we simply apply the npix unit here.
pixarea_fac = (u.pix * u.pix) * pixarea.to(u.sr / (u.pix * u.pix))
phot_table['sum'] = [rawsum * pixarea_fac]
else:
pixarea_fac = None
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/imviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def test_parse_jwst_nircam_level2(self, imviz_helper):
assert_allclose(sky.dec.deg, -69.494592)
data_unit = u.MJy / u.sr
assert_quantity_allclose(tbl[0]['background'], 0.1741226315498352 * data_unit)
assert_quantity_allclose(tbl[0]['sum'], 4.989882e-09 * u.MJy)
assert_quantity_allclose(tbl[0]['sum'], 4.486487e-11 * u.MJy, rtol=1e-6)
assert_quantity_allclose(tbl[0]['sum_aper_area'], 111.220234 * (u.pix * u.pix))
assert_quantity_allclose(tbl[0]['pixarea_tot'], 1.038438e-11 * u.sr, atol=1e-15 * u.sr)
assert_quantity_allclose(tbl[0]['pixarea_tot'], 9.33677e-14 * u.sr, rtol=1e-6)
assert_quantity_allclose(tbl[0]['aperture_sum_counts'], 132061.576643 * u.count, rtol=1e-6)
assert_quantity_allclose(tbl[0]['aperture_sum_counts_err'], 363.402775 * u.count)
assert_quantity_allclose(tbl[0]['counts_fac'], 0.0036385915646798953 * (data_unit / u.ct))
Expand Down

0 comments on commit dcebb9a

Please sign in to comment.