Skip to content

Commit

Permalink
consolidate has_wcs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry authored and bmorris3 committed Nov 6, 2023
1 parent b07e51d commit 57f03ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
12 changes: 4 additions & 8 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from astropy.io import fits
from astropy.time import Time
from astropy.utils.decorators import deprecated
from astropy.wcs.wcsapi import BaseHighLevelWCS
from echo import CallbackProperty, DictCallbackProperty, ListCallbackProperty
from ipygoldenlayout import GoldenLayout
from ipysplitpanes import SplitPanes
Expand Down Expand Up @@ -58,7 +57,7 @@
from jdaviz.core.registries import (tool_registry, tray_registry, viewer_registry,
data_parser_registry)
from jdaviz.core.tools import ICON_DIR
from jdaviz.utils import SnackbarQueue, alpha_index, MultiMaskSubsetState
from jdaviz.utils import SnackbarQueue, alpha_index, data_has_valid_wcs, MultiMaskSubsetState
from ipypopout import PopoutButton

__all__ = ['Application', 'ALL_JDAVIZ_CONFIGS']
Expand Down Expand Up @@ -554,11 +553,8 @@ def _change_reference_data(self, new_refdata_label, viewer_id=None):
)

# only re-center the viewer if all data layers have WCS:
data_has_wcs = [
hasattr(d, 'coords') and isinstance(d.coords, BaseHighLevelWCS)
for d in viewer.data()
]
if all(data_has_wcs):
has_wcs_per_data = [data_has_valid_wcs(d) for d in viewer.data()]
if all(has_wcs_per_data):
# re-center the viewer on previous location.
viewer.center_on(sky_cen)

Expand Down Expand Up @@ -2391,7 +2387,7 @@ def _expose_meta(key):
'locked': False,
'ndims': data.ndim,
'type': typ,
'has_wcs': wcsaxes is not None,
'has_wcs': data_has_valid_wcs(data),
'meta': {k: v for k, v in data.meta.items() if _expose_meta(k)},
'children': []}

Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from jdaviz.configs.imviz.wcs_utils import (
_get_rotated_nddata_from_label, get_compass_info
)
from jdaviz.utils import data_has_valid_wcs

__all__ = ['Imviz', 'link_image_data']

Expand Down Expand Up @@ -198,7 +199,7 @@ def load_data(self, data, data_label=None, do_link=True, show_in_viewer=True, **
applied_labels.append(label)
applied_visible.append(True)
layer_is_wcs_only.append(data.meta.get(self.app._wcs_only_label, False))
layer_has_wcs.append(hasattr(data.coords, 'pixel_to_world'))
layer_has_wcs.append(data_has_valid_wcs(data))

if show_in_viewer is True:
show_in_viewer = f"{self.app.config}-0"
Expand Down
10 changes: 1 addition & 9 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import numpy as np
import astropy.units as u
from astropy.wcs.wcsapi import BaseHighLevelWCS
from astropy.nddata import CCDData, StdDevUncertainty
from regions.core.core import Region
from glue.core import HubListener
Expand All @@ -28,6 +27,7 @@
from jdaviz.app import Application
from jdaviz.core.events import SnackbarMessage, ExitBatchLoadMessage
from jdaviz.core.template_mixin import show_widget
from jdaviz.utils import data_has_valid_wcs

__all__ = ['ConfigHelper', 'ImageConfigHelper']

Expand Down Expand Up @@ -900,14 +900,6 @@ def _delete_all_regions(self):
self.app.data_collection.remove_subset_group(subset_grp)


def data_has_valid_wcs(data, ndim=None):
"""Check if given glue Data has WCS that is compatible with APE 14."""
status = hasattr(data, 'coords') and isinstance(data.coords, BaseHighLevelWCS)
if ndim is not None:
status = status and data.coords.world_n_dim == ndim
return status


def _next_subset_num(label_prefix, subset_groups):
"""Assumes ``prefix i`` format.
Does not go back and fill in lower but available numbers. This is consistent with Glue.
Expand Down
9 changes: 9 additions & 0 deletions jdaviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from astropy.io import fits
from astropy.utils import minversion
from astropy.wcs.wcsapi import BaseHighLevelWCS
from ipyvue import watch
from glue.core.exceptions import IncompatibleAttribute
from glue.config import settings
Expand Down Expand Up @@ -216,6 +217,14 @@ def alpha_index(index):
return chr(97 + index//26 - 1) + chr(97 + index % 26)


def data_has_valid_wcs(data, ndim=None):
"""Check if given glue Data has WCS that is compatible with APE 14."""
status = hasattr(data, 'coords') and isinstance(data.coords, BaseHighLevelWCS)
if ndim is not None:
status = status and data.coords.world_n_dim == ndim
return status


def standardize_metadata(metadata):
"""Standardize given metadata so it can be viewed in
Metadata Viewer plugin. The input can be plain
Expand Down

0 comments on commit 57f03ff

Please sign in to comment.