Skip to content

Commit

Permalink
Merge pull request spacetelescope#2168 from bmorris3/viz-those-times
Browse files Browse the repository at this point in the history
adding support for temporal subsets

(cherry picked from commit d7f28ab)
  • Loading branch information
bmorris3 committed May 5, 2023
1 parent aec6ed1 commit 03af47d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from astropy.io import fits
from astropy import units as u
from astropy.coordinates import Angle
from astropy.time import Time
from regions import PixCoord, CirclePixelRegion, RectanglePixelRegion, EllipsePixelRegion

from echo import CallbackProperty, DictCallbackProperty, ListCallbackProperty
Expand Down Expand Up @@ -686,8 +687,13 @@ def get_data_from_viewer(self, viewer_reference, data_label=None,
if cls is not None:
handler, _ = data_translator.get_handler_for(cls)
try:
layer_data = handler.to_object(layer_data,
statistic=statistic)
if cls == Spectrum1D:
# if this is a spectrum, apply the `statistic`:
layer_data = handler.to_object(layer_data,
statistic=statistic)
else:
# otherwise simply translate to an object:
layer_data = handler.to_object(layer_data)
except IncompatibleAttribute:
continue

Expand Down Expand Up @@ -878,8 +884,9 @@ def get_subsets(self, subset_name=None, spectral_only=False,
all_subsets[label] = None
continue

# Is the subset spectral or spatial?
# Is the subset spectral, spatial, temporal?
is_spectral = self._is_subset_spectral(subset_region)
is_temporal = self._is_subset_temporal(subset_region)

# Remove duplicate spectral regions
if is_spectral and isinstance(subset_region, SpectralRegion):
Expand All @@ -903,6 +910,12 @@ def get_subsets(self, subset_name=None, spectral_only=False,
else:
all_subsets[label] = subset_region

if not (spectral_only or spatial_only) and is_temporal:
if object_only:
all_subsets[label] = [reg['region'] for reg in subset_region]
else:
all_subsets[label] = subset_region

all_subset_names = [subset.label for subset in dc.subset_groups]
if subset_name and subset_name in all_subset_names:
return all_subsets[subset_name]
Expand Down Expand Up @@ -935,6 +948,14 @@ def _is_subset_spectral(self, subset_region):
return True
return False

def _is_subset_temporal(self, subset_region):
if isinstance(subset_region, Time):
return True
elif isinstance(subset_region, list) and len(subset_region) > 0:
if isinstance(subset_region[0]['region'], Time):
return True
return False

def _remove_duplicate_bounds(self, spec_regions):
regions_no_dups = None

Expand Down

0 comments on commit 03af47d

Please sign in to comment.