Skip to content

Commit

Permalink
Aperture photometry: refactor, batch mode, enable user API (spacetele…
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry authored Oct 12, 2023
1 parent 14b61e5 commit ffde818
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 453 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Cubeviz
Imviz
^^^^^

- Aperture photometry (previously "Imviz Simple Aperture Photometry") now supports batch mode. [#2465]

Mosviz
^^^^^^

Expand Down
4 changes: 2 additions & 2 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ This plugin only considers pixel locations, not sky coordinates.

.. _aper-phot-simple:

Simple Aperture Photometry
==========================
Aperture Photometry
===================

.. warning::

Expand Down
65 changes: 47 additions & 18 deletions jdaviz/components/plugin_dataset_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,68 @@
:label="label ? label : 'Data'"
:hint="hint ? hint : 'Select data.'"
:rules="rules ? rules : []"
:multiple="multiselect"
:chips="multiselect"
item-text="label"
item-value="label"
persistent-hint
>
<template slot="selection" slot-scope="data">
<div class="single-line">
<span>
<j-layer-viewer-icon v-if="data.item.icon" span_style="margin-right: 4px" :icon="data.item.icon" :prevent_invert_if_dark="true"></j-layer-viewer-icon>
{{ data.item.label }}
</span>
</div>
</template>
<template slot="item" slot-scope="data">
<div class="single-line">
<span>
<j-layer-viewer-icon v-if="data.item.icon" span_style="margin-right: 4px" :icon="data.item.icon" :prevent_invert_if_dark="true"></j-layer-viewer-icon>
{{ data.item.label }}
</span>
</div>
</template>
<template slot="selection" slot-scope="data">
<div class="single-line" style="width: 100%">
<v-chip v-if="multiselect" style="width: calc(100% - 10px)">
<span>
<j-layer-viewer-icon v-if="data.item.icon" span_style="margin-right: 4px" :icon="data.item.icon" :prevent_invert_if_dark="true"></j-layer-viewer-icon>
{{ data.item.label }}
</span>
</v-chip>
<span v-else>
<j-layer-viewer-icon v-if="data.item.icon" span_style="margin-right: 4px" :icon="data.item.icon" :prevent_invert_if_dark="true"></j-layer-viewer-icon>
{{ data.item.label }}
</span>
</div>
</template>
<template v-slot:prepend-item v-if="multiselect">
<v-list-item
ripple
@mousedown.prevent
@click="() => {if (selected.length < items.length) { $emit('update:selected', items.map((item) => item.label))} else {$emit('update:selected', [])}}"
>
<v-list-item-action>
<v-icon>
{{ selected.length == items.length ? 'mdi-close-box' : selected.length ? 'mdi-minus-box' : 'mdi-checkbox-blank-outline' }}
</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>
{{ selected.length < items.length ? "Select All" : "Clear All" }}
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider class="mt-2"></v-divider>
</template>
<template slot="item" slot-scope="data">
<div class="single-line">
<span>
<j-layer-viewer-icon v-if="data.item.icon" span_style="margin-right: 4px" :icon="data.item.icon" :prevent_invert_if_dark="true"></j-layer-viewer-icon>
{{ data.item.label }}
</span>
</div>
</template>
</v-select>
</v-row>
</div>
</template>
<script>
module.exports = {
props: ['items', 'selected', 'label', 'hint', 'rules', 'show_if_single_entry']
props: ['items', 'selected', 'label', 'hint', 'rules', 'show_if_single_entry', 'multiselect']
};
</script>

<style>
<style scoped>
.v-select__selections {
flex-wrap: nowrap !important;
display: block !important;
margin-bottom: -32px;
}
.single-line {
white-space: nowrap;
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/components/plugin_layer_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
>
<template slot="selection" slot-scope="data">
<div class="single-line" style="width: 100%">
<v-chip v-if="multiselect" style="width: calc(100% - 20px)">
<v-chip v-if="multiselect" style="width: calc(100% - 10px)">
<span>
<j-layer-viewer-icon :icon="data.item.icon" :prevent_invert_if_dark="true"></j-layer-viewer-icon>
{{ data.item.label }}
Expand Down
14 changes: 8 additions & 6 deletions jdaviz/components/plugin_subset_select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
persistent-hint
>
<template slot="selection" slot-scope="data">
<div class="single-line">
<v-chip v-if="multiselect" style="width: calc(100% - 20px)">
<div class="single-line" style="width: 100%">
<v-chip v-if="multiselect" style="width: calc(100% - 10px)">
<span>
<v-icon v-if="data.item.color" left :color="data.item.color">
{{ data.item.type=='spectral' ? 'mdi-chart-bell-curve' : 'mdi-chart-scatter-plot' }}
Expand Down Expand Up @@ -79,10 +79,12 @@ module.exports = {
};
</script>

<style>
.v-select__selections {
flex-wrap: nowrap !important;
}
<style scoped>
.v-select__selections {
flex-wrap: nowrap !important;
display: block !important;
margin-bottom: -32px;
}
.single-line {
white-space: nowrap;
overflow: hidden;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def reset(self):

@observe("dataset_selected")
def show_metadata(self, event):
if not hasattr(self, 'dataset'): # pragma: no cover
# plugin not fully initialized
return

data = self.dataset.selected_dc_item
if (data is None or not hasattr(data, 'meta') or not isinstance(data.meta, dict)
or len(data.meta) < 1):
Expand Down
41 changes: 19 additions & 22 deletions jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SubsetPlugin(PluginTemplateMixin, DatasetSelectMixin):

subplugins_opened = Any().tag(sync=True)

multiselect = Bool(False).tag(sync=True)
multiselect = Bool(False).tag(sync=True) # multiselect only for subset
is_centerable = Bool(False).tag(sync=True)
can_simplify = Bool(False).tag(sync=True)
can_freeze = Bool(False).tag(sync=True)
Expand Down Expand Up @@ -453,21 +453,30 @@ def _do_recentering(subset, subset_state):
else:
self.set_center((x, y), subset_name=subset, update=True)

dict_subset_to_state = self.subset_select.selected_subset_state
if not self.multiselect:
_do_recentering(self.subset_selected, dict_subset_to_state)
_do_recentering(self.subset_selected, self.subset_select.selected_subset_state)
else:
for sub in self.subset_selected:
for sub, subset_state in zip(self.subset_selected,
self.subset_select.selected_subset_state):
if (sub != self.subset_select.default_text and
not isinstance(dict_subset_to_state[sub], CompositeSubsetState)):
not isinstance(subset_state, CompositeSubsetState)):
self.is_centerable = True
_do_recentering(sub, dict_subset_to_state[sub])
_do_recentering(sub, subset_state)
elif (sub != self.subset_select.default_text and
isinstance(dict_subset_to_state[sub], CompositeSubsetState)):
isinstance(subset_state, CompositeSubsetState)):
self.hub.broadcast(SnackbarMessage(f"Unable to recenter "
f"composite subset {sub}",
color='error', sender=self))

def _get_subset_state(self, subset_name=None):
if self.multiselect and not subset_name:
raise ValueError("Please include subset_name in when in multiselect mode")

if subset_name is not None:
return self.subset_select._get_subset_state(subset_name)
# guaranteed to only return a single entry because of check above
return self.subset_select.selected_subset_state

def get_center(self, subset_name=None):
"""Return the center of the Subset.
This may or may not be the centroid obtain from data.
Expand All @@ -489,14 +498,7 @@ def get_center(self, subset_name=None):
if not self.is_centerable: # no-op
return

if self.multiselect and not subset_name:
raise ValueError("Please include subset_name in"
" get_center call when in multiselect mode")
elif not self.multiselect:
subset_state = self.subset_select.selected_subset_state
elif self.multiselect and subset_name:
subset_state = self.subset_select.selected_subset_state[subset_name]

subset_state = self._get_subset_state(subset_name)
return subset_state.center()

def set_center(self, new_cen, subset_name=None, update=False):
Expand Down Expand Up @@ -525,13 +527,8 @@ def set_center(self, new_cen, subset_name=None, update=False):
if not self.is_centerable: # no-op
return

if self.multiselect and not subset_name:
raise ValueError("Please include subset_name in"
" set_center call when in multiselect mode")
elif not self.multiselect:
subset_state = self.subset_select.selected_subset_state
elif self.multiselect and subset_name:
subset_state = self.subset_select.selected_subset_state[subset_name]
subset_state = self._get_subset_state(subset_name)

if isinstance(subset_state, RoiSubsetState):
x, y = new_cen
# x and y are arrays so this converts them back to floats
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def get_aperture_photometry_results(self):
Photometry results if available or `None` otherwise.
"""
return self.plugins['Imviz Simple Aperture Photometry']._obj.export_table()
return self.plugins['Aperture Photometry']._obj.export_table()

def get_catalog_source_results(self):
"""Return table of sources given by querying from a catalog, if any.
Expand Down
Loading

0 comments on commit ffde818

Please sign in to comment.