Skip to content

Commit 207f7a3

Browse files
javerbukhpllim
andauthored
Autopopulate aperture photometry stats for JWST images (#1549)
* Autopopulate aperture photometry stats for JWST images * Address review comments * Add information to docs, update test * Update docs/imviz/plugins.rst Co-authored-by: P. L. Lim <[email protected]> * Update test * Fix Jy to ABmag conversion * Prettify mag formatting on GUI Co-authored-by: P. L. Lim <[email protected]>
1 parent aa86ecb commit 207f7a3

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Imviz
1616
- New "Catalog Search" plugin that uses a specified catalog (currently SDSS) to search for sources in an image
1717
and mark the sources found. [#1455]
1818

19+
- Auto-populate simple aperture photometry values if JWST data is loaded into viewer. [#1549]
20+
1921
Mosviz
2022
^^^^^^
2123
- NIRISS parser now sorts FITS files by header instead of file name. [#819]

docs/imviz/plugins.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ an interactively selected region. A typical workflow is as follows:
149149
If this field is not applicable for you, leave it at 0.
150150
**This field resets every time Data selection changes.**
151151
8. If you also want photometry result in magnitude unit, you can enter a flux
152-
scaling factor in the :guilabel:`Flux scaling` field. The value must be in the
152+
scaling factor in the :guilabel:`Flux scaling` field.
153+
:guilabel:`Flux scaling` is populated for JWST images
154+
if MJy/sr data unit is detected and pixel area is given to factor out the per-steradian unit.
155+
The value used, if this is the case, is the scaling to convert MJy to AB magnitude.
156+
Otherwise, the value must be in the
153157
same unit as display data unit. A magnitude is then calculated using
154158
``-2.5 * log(flux / flux_scaling)``. This calculation only makes sense if your
155159
display data unit is already in linear flux unit. Setting this to 1 is equivalent

jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def _dataset_selected_changed(self, event={}):
105105
if telescope == 'JWST':
106106
if 'photometry' in meta and 'pixelarea_arcsecsq' in meta['photometry']:
107107
self.pixel_area = meta['photometry']['pixelarea_arcsecsq']
108+
if 'bunit_data' in meta and meta['bunit_data'] == u.Unit("MJy/sr"):
109+
# Hardcode the flux conversion factor from MJy to ABmag
110+
self.flux_scaling = 0.003631
108111
elif telescope == 'HST':
109112
# TODO: Add more HST support, as needed.
110113
# HST pixel scales are from instrument handbooks.
@@ -310,8 +313,8 @@ def vue_do_aper_phot(self, *args, **kwargs):
310313
sum_ct_err = None
311314

312315
if include_flux_scale:
313-
flux_scale = flux_scale * rawsum.unit
314-
sum_mag = -2.5 * np.log10(rawsum / flux_scale) * u.mag
316+
flux_scale = flux_scale * phot_table['sum'][0].unit
317+
sum_mag = -2.5 * np.log10(phot_table['sum'][0] / flux_scale) * u.mag
315318
else:
316319
flux_scale = None
317320
sum_mag = None
@@ -425,7 +428,7 @@ def vue_do_aper_phot(self, *args, **kwargs):
425428
x = phot_table[key][0]
426429
if (isinstance(x, (int, float, u.Quantity)) and
427430
key not in ('xcentroid', 'ycentroid', 'sky_centroid', 'sum_aper_area',
428-
'aperture_sum_counts')):
431+
'aperture_sum_counts', 'aperture_sum_mag')):
429432
tmp.append({'function': key, 'result': f'{x:.4e}'})
430433
elif key == 'sky_centroid' and x is not None:
431434
tmp.append({'function': 'RA centroid', 'result': f'{x.ra.deg:.4f} deg'})
@@ -435,6 +438,8 @@ def vue_do_aper_phot(self, *args, **kwargs):
435438
elif key == 'aperture_sum_counts' and x is not None:
436439
tmp.append({'function': key, 'result':
437440
f'{x:.4e} ({phot_table["aperture_sum_counts_err"][0]:.4e})'})
441+
elif key == 'aperture_sum_mag' and x is not None:
442+
tmp.append({'function': key, 'result': f'{x:.3f}'})
438443
else:
439444
tmp.append({'function': key, 'result': str(x)})
440445

jdaviz/configs/imviz/tests/test_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def test_parse_jwst_nircam_level2(self, imviz_helper):
270270
phot_plugin.counts_factor = (data.meta['photometry']['conversion_megajanskys'] /
271271
data.meta['exposure']['exposure_time'])
272272
assert_allclose(phot_plugin.counts_factor, 0.0036385915646798953)
273-
phot_plugin.flux_scaling = 1 # Simple mag, no zeropoint
273+
assert_allclose(phot_plugin.flux_scaling, 0.003631)
274274
phot_plugin.vue_do_aper_phot()
275275
tbl = imviz_helper.get_aperture_photometry_results()
276276
assert_quantity_allclose(tbl[0]['xcentroid'], 970.935492 * u.pix)
@@ -286,8 +286,8 @@ def test_parse_jwst_nircam_level2(self, imviz_helper):
286286
assert_quantity_allclose(tbl[0]['aperture_sum_counts'], 132061.576643 * u.count, rtol=1e-6)
287287
assert_quantity_allclose(tbl[0]['aperture_sum_counts_err'], 363.402775 * u.count)
288288
assert_quantity_allclose(tbl[0]['counts_fac'], 0.0036385915646798953 * (data_unit / u.ct))
289-
assert_quantity_allclose(tbl[0]['aperture_sum_mag'], -6.704274 * u.mag)
290-
assert_quantity_allclose(tbl[0]['flux_scaling'], 1 * data_unit)
289+
assert_quantity_allclose(tbl[0]['aperture_sum_mag'], 19.770299 * u.mag)
290+
assert_quantity_allclose(tbl[0]['flux_scaling'], 3631 * u.Jy)
291291
assert_quantity_allclose(tbl[0]['min'], 0.041017 * data_unit, atol=1e-5 * data_unit)
292292
assert_quantity_allclose(tbl[0]['max'], 138.923752 * data_unit, rtol=1e-5)
293293
assert_quantity_allclose(tbl[0]['mean'], 4.391718 * data_unit)

0 commit comments

Comments
 (0)