Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP: RequiresWCSLinking component #3277

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def to_unit(self, data, cid, values, original_units, target_units):
'plugin-slider': 'components/plugin_slider.vue',
'plugin-color-picker': 'components/plugin_color_picker.vue',
'plugin-input-header': 'components/plugin_input_header.vue',
'plugin-requires-wcs-linking': 'components/plugin_requires_wcs_linking.vue',
'glue-state-sync-wrapper': 'components/glue_state_sync_wrapper.vue',
'data-menu-add-data': 'components/data_menu_add_data.vue',
'data-menu-remove': 'components/data_menu_remove.vue',
Expand Down
78 changes: 78 additions & 0 deletions jdaviz/components/plugin_requires_wcs_linking.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<template>
<div>
<v-alert
v-if="!wcs_linking_available"
type='warning'
class="ignore-api-hints"
style="margin-left: -12px; margin-right: -12px"
>
Please add at least one data with valid WCS to align by sky (WCS).
</v-alert>

<v-alert
v-if="wcs_linking_available && !need_clear_astrowidget_markers &&!need_clear_subsets"
type='warning'
class="ignore-api-hints"
style="margin-left: -12px; margin-right: -12px"
>
Switching alignment will reset zoom.
</v-alert>

<v-alert
v-if="plugin_markers_exist && !need_clear_astrowidget_markers &&!need_clear_subsets"
type='warning'
style="margin-left: -12px; margin-right: -12px"
>
Marker positions may not be pixel-perfect when changing alignment/linking options.
</v-alert>

<v-alert v-if="need_clear_astrowidget_markers" type='warning' style="margin-left: -12px; margin-right: -12px">
Astrowidget markers must be cleared before changing alignment/linking options.
<v-row justify="end" style="margin-right: 2px; margin-top: 16px">
<v-btn @click="$emit('reset-astrowidget-markers')">Clear Markers</v-btn>
</v-row>
</v-alert>


<v-alert v-if="need_clear_subsets" type='warning' style="margin-left: -12px; margin-right: -12px">
Existing subsets must be deleted before changing alignment/linking options.
<v-row justify="end" style="margin-right: 2px; margin-top: 16px">
<v-btn @click="$emit('delete-subsets')">
{{ api_hints_enabled ?
'plg.delete_subsets()'
:
'Clear Subsets'
}}
</v-btn>
</v-row>
</v-alert>

<v-alert
v-if="show_link_by_wcs_button"
type='warning'
style="margin-left: -12px; margin-right: -12px"
>
cannot plot footprint when aligned by pixels (see Orientation plugin).
<v-row justify="end" style="margin-right: 2px; margin-top: 16px">
<v-btn @click="link_by_wcs">
link by WCS
</v-btn>
</v-row>
</v-alert>
<v-alert v-if="viewer_items.length===0" type='warning' style="margin-left: -12px; margin-right: -12px">
no valid viewers (with necessary WCS information) to show footprint overlay.
</v-alert>

</div>
</template>

<script>
module.exports = {
props: ['api_hints_enabled',
'wcs_linking_available',
'need_clear_astrowidget_markers',
'need_clear_subsets',
'plugin_markers_exist',
'show_link_by_wcs_button'],
};
</script>
4 changes: 3 additions & 1 deletion jdaviz/configs/imviz/plugins/footprints/footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from jdaviz.core.region_translators import regions2roi
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin, ViewerSelectMixin,
RequiresWCSLinkingMixin,
EditableSelectPluginComponent,
FileImportSelectPluginComponent, HasFileImportSelect)
from jdaviz.core.user_api import PluginUserApi
Expand All @@ -21,7 +22,8 @@


@tray_registry('imviz-footprints', label="Footprints")
class Footprints(PluginTemplateMixin, ViewerSelectMixin, HasFileImportSelect):
class Footprints(PluginTemplateMixin, ViewerSelectMixin,
RequiresWCSLinkingMixin, HasFileImportSelect):
"""
See the :ref:`Footprints Plugin Documentation <imviz-footprints>` for more details.

Expand Down
25 changes: 10 additions & 15 deletions jdaviz/configs/imviz/plugins/footprints/footprints.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@
>
</plugin-editable-select>

<v-alert
<plugin-requires-wcs-linking
v-if="is_pixel_linked"
type='warning'
style="margin-left: -12px; margin-right: -12px"
>
cannot plot footprint when aligned by pixels (see Orientation plugin).
<v-row justify="end" style="margin-right: 2px; margin-top: 16px">
<v-btn @click="link_by_wcs">
link by WCS
</v-btn>
</v-row>
</v-alert>
<v-alert v-if="viewer_items.length===0" type='warning' style="margin-left: -12px; margin-right: -12px">
no valid viewers (with necessary WCS information) to show footprint overlay.
</v-alert>

:wcs_linking_available="wcs_linking_available"
:need_clear_astrowidget_markers="need_clear_astrowidget_markers"
:need_clear_subsets="need_clear_subsets"
:api_hints_enabled="false"
:show_link_by_wcs_button="true"
@delete-subsets="delete_subsets"
@reset-astrowidget-markers="reset_astrowidget_markers"
/>

<div v-if="!is_pixel_linked && viewer_items.length > 0 && overlay_selected.length > 0">
<j-plugin-section-header>Display Options</j-plugin-section-header>

Expand Down
73 changes: 5 additions & 68 deletions jdaviz/configs/imviz/plugins/orientation/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from astropy.utils import deprecated
from astropy.wcs.wcsapi import BaseHighLevelWCS
from glue.core.link_helpers import LinkSame
from glue.core.message import (
DataCollectionAddMessage, SubsetCreateMessage, SubsetDeleteMessage
)
from glue.core.subset import Subset
from glue.core.subset_group import GroupedSubset
from glue.plugins.wcs_autolinking.wcs_autolinking import WCSLink, NoAffineApproximation
Expand All @@ -15,14 +12,14 @@
)
from jdaviz.core.custom_traitlets import FloatHandleEmpty
from jdaviz.core.events import (
ExitBatchLoadMessage, ChangeRefDataMessage,
AstrowidgetMarkersChangedMessage, MarkersPluginUpdate,
ChangeRefDataMessage,
SnackbarMessage, ViewerAddedMessage, AddDataMessage, LinkUpdatedMessage
)

from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (
PluginTemplateMixin, SelectPluginComponent, LayerSelect, ViewerSelectMixin, AutoTextField
PluginTemplateMixin,
RequiresWCSLinkingMixin, SelectPluginComponent, LayerSelect, ViewerSelectMixin, AutoTextField
)
from jdaviz.core.user_api import PluginUserApi
from jdaviz.utils import get_reference_image_data, layer_is_2d, _wcs_only_label
Expand All @@ -34,7 +31,7 @@


@tray_registry('imviz-orientation', label="Orientation", viewer_requirements="image")
class Orientation(PluginTemplateMixin, ViewerSelectMixin):
class Orientation(PluginTemplateMixin, RequiresWCSLinkingMixin, ViewerSelectMixin):
"""
See the :ref:`Orientation Plugin Documentation <imviz-orientation>` for more details.

Expand Down Expand Up @@ -66,12 +63,8 @@ class Orientation(PluginTemplateMixin, ViewerSelectMixin):
align_by_selected = Unicode().tag(sync=True)
wcs_use_fallback = Bool(True).tag(sync=True)
wcs_fast_approximation = Bool(True).tag(sync=True)
wcs_linking_available = Bool(False).tag(sync=True)

need_clear_astrowidget_markers = Bool(False).tag(sync=True)
plugin_markers_exist = Bool(False).tag(sync=True)
linking_in_progress = Bool(False).tag(sync=True)
need_clear_subsets = Bool(False).tag(sync=True)

# rotation angle, counterclockwise [degrees]
rotation_angle = FloatHandleEmpty(0).tag(sync=True)
Expand Down Expand Up @@ -108,27 +101,9 @@ def __init__(self, *args, **kwargs):
self, 'new_layer_label', 'new_layer_label_default', 'new_layer_label_auto', None
)

self.hub.subscribe(self, DataCollectionAddMessage,
handler=self._on_new_app_data)

self.hub.subscribe(self, ExitBatchLoadMessage,
handler=self._on_new_app_data)

self.hub.subscribe(self, AstrowidgetMarkersChangedMessage,
handler=self._on_astrowidget_markers_changed)

self.hub.subscribe(self, MarkersPluginUpdate,
handler=self._on_markers_plugin_update)

self.hub.subscribe(self, ChangeRefDataMessage,
handler=self._on_refdata_change)

self.hub.subscribe(self, SubsetCreateMessage,
handler=self._on_subset_change)

self.hub.subscribe(self, SubsetDeleteMessage,
handler=self._on_subset_change)

self.hub.subscribe(self, ViewerAddedMessage,
handler=self._on_viewer_added)

Expand Down Expand Up @@ -187,32 +162,9 @@ def _link_image_data(self):
finally:
self.linking_in_progress = False

def _check_if_data_with_wcs_exists(self):
for data in self.app.data_collection:
if hasattr(data.coords, 'pixel_to_world'):
self.wcs_linking_available = True
return
self.wcs_linking_available = False

def _on_new_app_data(self, msg):
if self.app._jdaviz_helper._in_batch_load > 0:
return
if isinstance(msg, DataCollectionAddMessage):
components = [str(comp) for comp in msg.data.main_components]
if "ra" in components or "Lon" in components:
# linking currently removes any markers, so we want to skip
# linking immediately after new markers are added.
# Eventually we'll probably want to support linking WITH markers,
# at which point this if-statement should be removed.
return
super()._on_new_app_data(msg)
self._link_image_data()
self._check_if_data_with_wcs_exists()

def _on_astrowidget_markers_changed(self, msg):
self.need_clear_astrowidget_markers = msg.has_markers

def _on_markers_plugin_update(self, msg):
self.plugin_markers_exist = msg.table_length > 0

@observe('align_by_selected', 'wcs_use_fallback', 'wcs_fast_approximation')
def _update_link(self, msg={}):
Expand Down Expand Up @@ -277,21 +229,6 @@ def _update_link(self, msg={}):
for v in self.app._viewer_store.values():
v._prev_limits = None

def _on_subset_change(self, msg):
self.need_clear_subsets = len(self.app.data_collection.subset_groups) > 0

def delete_subsets(self):
# subsets will be deleted on changing link type:
for subset_group in self.app.data_collection.subset_groups:
self.app.data_collection.remove_subset_group(subset_group)

def vue_delete_subsets(self, *args):
self.delete_subsets()

def vue_reset_astrowidget_markers(self, *args):
for viewer in self.app._viewer_store.values():
viewer.reset_markers()

def _get_wcs_angles(self, first_loaded_image=None):
if first_loaded_image is None:
first_loaded_image = self.viewer.selected_obj.first_loaded_data
Expand Down
54 changes: 8 additions & 46 deletions jdaviz/configs/imviz/plugins/orientation/orientation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,14 @@
<div style="grid-area: 1/1; margin-top: -36px">
<j-plugin-section-header>Align Layers</j-plugin-section-header>

<v-alert
v-if="!wcs_linking_available"
type='warning'
class="ignore-api-hints"
style="margin-left: -12px; margin-right: -12px"
>
Please add at least one data with valid WCS to align by sky (WCS).
</v-alert>

<v-alert
v-if="wcs_linking_available && !need_clear_astrowidget_markers && !need_clear_subsets"
type='warning'
class="ignore-api-hints"
style="margin-left: -12px; margin-right: -12px"
>
Switching alignment will reset zoom.
</v-alert>

<v-alert
v-if="plugin_markers_exist && !need_clear_astrowidget_markers && !need_clear_subsets"
type='warning'
style="margin-left: -12px; margin-right: -12px"
>
Marker positions may not be pixel-perfect when changing alignment/linking options.
</v-alert>

<v-alert v-if="need_clear_astrowidget_markers" type='warning' style="margin-left: -12px; margin-right: -12px">
Astrowidget markers must be cleared before changing alignment/linking options.
<v-row justify="end" style="margin-right: 2px; margin-top: 16px">
<v-btn @click="reset_astrowidget_markers">Clear Markers</v-btn>
</v-row>
</v-alert>


<v-alert v-if="need_clear_subsets" type='warning' style="margin-left: -12px; margin-right: -12px">
Existing subsets must be deleted before changing alignment/linking options.
<v-row justify="end" style="margin-right: 2px; margin-top: 16px">
<v-btn @click="delete_subsets">
{{ api_hints_enabled ?
'plg.delete_subsets()'
:
'Clear Subsets'
}}
</v-btn>
</v-row>
</v-alert>
<plugin-requires-wcs-linking
:wcs_linking_available="wcs_linking_available"
:need_clear_astrowidget_markers="need_clear_astrowidget_markers"
:need_clear_subsets="need_clear_subsets"
:api_hints_enabled="false"
@delete-subsets="delete_subsets"
@reset-astrowidget-markers="reset_astrowidget_markers"
/>

<v-row class="row-min-bottom-padding">
<v-radio-group
Expand Down
Loading
Loading