Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Imviz: Add a different radial profile approach #1097

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ an interactively selected region. A typical workflow is as follows:

1. Load image(s) in Imviz (see :ref:`imviz-import-data`).
2. Draw a region over the object of interest (see :ref:`imviz_defining_spatial_regions`).
3. Select the desired image using :guilabel:`Data` drop-down menu.
4. Select the desired region using :guilabel:`Subset` drop-down menu.
3. Select the desired image using the :guilabel:`Data` drop-down menu.
4. Select the desired region using the :guilabel:`Subset` drop-down menu.
5. If you want to subtract background before performing photometry, enter
the background value in the :guilabel:`Background value` field. This value
must be in the same unit as display data, if applicable.
Expand All @@ -82,8 +82,9 @@ an interactively selected region. A typical workflow is as follows:
display data unit is already in linear flux unit. Setting this to 1 is equivalent
to not applying any scaling. If this field is not applicable for you, leave it at 0.
**This field resets every time Data selection changes.**
9. Once all inputs are populated correctly, click on the :guilabel:`CALCULATE`
button to perform simple aperture photometry.
9. Select the desired plot type using the :guilabel:`Plot Type` drop-down menu.
10. Once all inputs are populated correctly, click on the :guilabel:`CALCULATE`
button to perform simple aperture photometry.

.. note::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from glue.core.message import SubsetCreateMessage, SubsetDeleteMessage, SubsetUpdateMessage
from ipywidgets import widget_serialization
from regions.shapes.rectangle import RectanglePixelRegion
from traitlets import Any, Bool, List
from traitlets import Any, Bool, List, Unicode

from jdaviz.configs.imviz.helper import layer_is_image_data
from jdaviz.core.events import AddDataMessage, RemoveDataMessage, SnackbarMessage
Expand All @@ -29,6 +29,8 @@ class SimpleAperturePhotometry(TemplateMixin):
flux_scaling = Any(0).tag(sync=True)
result_available = Bool(False).tag(sync=True)
results = List().tag(sync=True)
plot_types = List([]).tag(sync=True)
current_plot_type = Unicode().tag(sync=True)
plot_available = Bool(False).tag(sync=True)
radial_plot = Any('').tag(sync=True, **widget_serialization)

Expand All @@ -43,12 +45,15 @@ def __init__(self, *args, **kwargs):

self._selected_data = None
self._selected_subset = None
self.plot_types = ["Radial Profile", "Radial Profile (Raw)"]
self.current_plot_type = self.plot_types[0]

def reset_results(self):
self.result_available = False
self.results = []
self.plot_available = False
self.radial_plot = ''
bqplt.clear()

def _on_viewer_data_changed(self, msg=None):
# To support multiple viewers, we allow the entire data collection.
Expand Down Expand Up @@ -241,25 +246,38 @@ def vue_do_aper_phot(self, *args, **kwargs):
d['id'] = 1
self.app._aper_phot_results = _qtable_from_dict(d)

# Radial profile
# Radial profile (Raw)
reg_bb = reg.bounding_box
reg_ogrid = np.ogrid[reg_bb.iymin:reg_bb.iymax, reg_bb.ixmin:reg_bb.ixmax]
radial_dx = reg_ogrid[1] - reg.center.x
radial_dy = reg_ogrid[0] - reg.center.y
radial_r = np.hypot(radial_dx, radial_dy).ravel() # pix
radial_img = comp_no_bg_cutout.ravel()

if comp.units:
y_data = radial_img.value
y_label = radial_img.unit.to_string()
else:
y_data = radial_img
y_label = 'Value'

# Radial profile
if self.current_plot_type == "Radial Profile":
# This algorithm is from the imexam package,
# see licenses/IMEXAM_LICENSE.txt for more details
radial_r = list(radial_r)
y_data = np.bincount(radial_r, y_data) / np.bincount(radial_r)
radial_r = np.arange(len(y_data))
markerstyle = 'g--o'
else:
markerstyle = 'go'

bqplt.clear()
# NOTE: default margin in bqplot is 60 in all directions
fig = bqplt.figure(1, title='Radial profile from Subset center',
fig_margin={'top': 60, 'bottom': 60, 'left': 40, 'right': 10},
title_style={'font-size': '12px'}) # TODO: Jenn wants title at bottom. # noqa
bqplt.plot(radial_r, y_data, 'go', figure=fig, default_size=1)
bqplt.plot(radial_r, y_data, markerstyle, figure=fig, default_size=1)
bqplt.xlabel(label='pix', mark=fig.marks[-1], figure=fig)
bqplt.ylabel(label=y_label, mark=fig.marks[-1], figure=fig)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
</v-text-field>
</v-row>

<v-row>
<v-select
:items="plot_types"
v-model="current_plot_type"
label="Plot Type"
hint="Aperture photometry plot type"
persistent-hint
></v-select>
</v-row>

<v-row justify="end">
<v-btn color="primary" text @click="do_aper_phot">Calculate</v-btn>
</v-row>
Expand Down
3 changes: 3 additions & 0 deletions jdaviz/configs/imviz/tests/test_simple_aper_phot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def test_plugin_wcs_dithered(self):
assert self.imviz.get_aperture_photometry_results() is None
assert not phot_plugin.plot_available
assert phot_plugin.radial_plot == ''
assert phot_plugin.current_plot_type == 'Radial Profile' # Software default

# Perform photometry on both images using same Subset.
phot_plugin.vue_data_selected('has_wcs_1[SCI,1]')
phot_plugin.vue_subset_selected('Subset 1')
phot_plugin.vue_do_aper_phot()
phot_plugin.vue_data_selected('has_wcs_2[SCI,1]')
phot_plugin.current_plot_type = 'Radial Profile (Raw)'
phot_plugin.vue_do_aper_phot()
assert_allclose(phot_plugin.background_value, 0)
assert_allclose(phot_plugin.counts_factor, 0)
Expand Down Expand Up @@ -82,6 +84,7 @@ def test_plugin_wcs_dithered(self):
phot_plugin._on_viewer_data_changed()
phot_plugin.vue_data_selected('has_wcs_1[SCI,1]')
phot_plugin.vue_subset_selected('Subset 2')
phot_plugin.current_plot_type = 'Radial Profile'
phot_plugin.vue_do_aper_phot()
tbl = self.imviz.get_aperture_photometry_results()
assert len(tbl) == 3 # New result is appended
Expand Down
28 changes: 28 additions & 0 deletions licenses/IMEXAM_LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright (c) 2011-2021, Imexam developers

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.