diff --git a/CHANGES.rst b/CHANGES.rst index bddef99e37..49ccb7e70b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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] diff --git a/docs/imviz/plugins.rst b/docs/imviz/plugins.rst index cca6143dcb..9ba4667082 100644 --- a/docs/imviz/plugins.rst +++ b/docs/imviz/plugins.rst @@ -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 diff --git a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py index fdc7711430..c9bf7e5d75 100644 --- a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py +++ b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py @@ -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. @@ -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 @@ -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'}) @@ -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)}) diff --git a/jdaviz/configs/imviz/tests/test_parser.py b/jdaviz/configs/imviz/tests/test_parser.py index c500d996ef..539fdc6407 100644 --- a/jdaviz/configs/imviz/tests/test_parser.py +++ b/jdaviz/configs/imviz/tests/test_parser.py @@ -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) @@ -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)