Skip to content

Commit

Permalink
Autopopulate aperture photometry stats for JWST images (#1549)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
javerbukh and pllim committed Aug 10, 2022
1 parent aa86ecb commit 207f7a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Imviz
- New "Catalog Search" plugin that uses a specified catalog (currently SDSS) to search for sources in an image
and mark the sources found. [#1455]

- Auto-populate simple aperture photometry values if JWST data is loaded into viewer. [#1549]

Mosviz
^^^^^^
- NIRISS parser now sorts FITS files by header instead of file name. [#819]
Expand Down
6 changes: 5 additions & 1 deletion docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ an interactively selected region. A typical workflow is as follows:
If this field is not applicable for you, leave it at 0.
**This field resets every time Data selection changes.**
8. If you also want photometry result in magnitude unit, you can enter a flux
scaling factor in the :guilabel:`Flux scaling` field. The value must be in the
scaling factor in the :guilabel:`Flux scaling` field.
:guilabel:`Flux scaling` is populated for JWST images
if MJy/sr data unit is detected and pixel area is given to factor out the per-steradian unit.
The value used, if this is the case, is the scaling to convert MJy to AB magnitude.
Otherwise, the value must be in the
same unit as display data unit. A magnitude is then calculated using
``-2.5 * log(flux / flux_scaling)``. This calculation only makes sense if your
display data unit is already in linear flux unit. Setting this to 1 is equivalent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def _dataset_selected_changed(self, event={}):
if telescope == 'JWST':
if 'photometry' in meta and 'pixelarea_arcsecsq' in meta['photometry']:
self.pixel_area = meta['photometry']['pixelarea_arcsecsq']
if 'bunit_data' in meta and meta['bunit_data'] == u.Unit("MJy/sr"):
# Hardcode the flux conversion factor from MJy to ABmag
self.flux_scaling = 0.003631
elif telescope == 'HST':
# TODO: Add more HST support, as needed.
# HST pixel scales are from instrument handbooks.
Expand Down Expand Up @@ -310,8 +313,8 @@ def vue_do_aper_phot(self, *args, **kwargs):
sum_ct_err = None

if include_flux_scale:
flux_scale = flux_scale * rawsum.unit
sum_mag = -2.5 * np.log10(rawsum / flux_scale) * u.mag
flux_scale = flux_scale * phot_table['sum'][0].unit
sum_mag = -2.5 * np.log10(phot_table['sum'][0] / flux_scale) * u.mag
else:
flux_scale = None
sum_mag = None
Expand Down Expand Up @@ -425,7 +428,7 @@ def vue_do_aper_phot(self, *args, **kwargs):
x = phot_table[key][0]
if (isinstance(x, (int, float, u.Quantity)) and
key not in ('xcentroid', 'ycentroid', 'sky_centroid', 'sum_aper_area',
'aperture_sum_counts')):
'aperture_sum_counts', 'aperture_sum_mag')):
tmp.append({'function': key, 'result': f'{x:.4e}'})
elif key == 'sky_centroid' and x is not None:
tmp.append({'function': 'RA centroid', 'result': f'{x.ra.deg:.4f} deg'})
Expand All @@ -435,6 +438,8 @@ def vue_do_aper_phot(self, *args, **kwargs):
elif key == 'aperture_sum_counts' and x is not None:
tmp.append({'function': key, 'result':
f'{x:.4e} ({phot_table["aperture_sum_counts_err"][0]:.4e})'})
elif key == 'aperture_sum_mag' and x is not None:
tmp.append({'function': key, 'result': f'{x:.3f}'})
else:
tmp.append({'function': key, 'result': str(x)})

Expand Down
6 changes: 3 additions & 3 deletions jdaviz/configs/imviz/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def test_parse_jwst_nircam_level2(self, imviz_helper):
phot_plugin.counts_factor = (data.meta['photometry']['conversion_megajanskys'] /
data.meta['exposure']['exposure_time'])
assert_allclose(phot_plugin.counts_factor, 0.0036385915646798953)
phot_plugin.flux_scaling = 1 # Simple mag, no zeropoint
assert_allclose(phot_plugin.flux_scaling, 0.003631)
phot_plugin.vue_do_aper_phot()
tbl = imviz_helper.get_aperture_photometry_results()
assert_quantity_allclose(tbl[0]['xcentroid'], 970.935492 * u.pix)
Expand All @@ -286,8 +286,8 @@ def test_parse_jwst_nircam_level2(self, imviz_helper):
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))
assert_quantity_allclose(tbl[0]['aperture_sum_mag'], -6.704274 * u.mag)
assert_quantity_allclose(tbl[0]['flux_scaling'], 1 * data_unit)
assert_quantity_allclose(tbl[0]['aperture_sum_mag'], 19.770299 * u.mag)
assert_quantity_allclose(tbl[0]['flux_scaling'], 3631 * u.Jy)
assert_quantity_allclose(tbl[0]['min'], 0.041017 * data_unit, atol=1e-5 * data_unit)
assert_quantity_allclose(tbl[0]['max'], 138.923752 * data_unit, rtol=1e-5)
assert_quantity_allclose(tbl[0]['mean'], 4.391718 * data_unit)
Expand Down

0 comments on commit 207f7a3

Please sign in to comment.