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

Add option to get_data to apply spectral subset to collapse spatial #2199

Merged
merged 21 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 2 deletions jdaviz/configs/cubeviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def specviz(self):
self._specviz = Specviz(app=self.app)
return self._specviz

def get_data(self, data_label=None, cls=None, subset_to_apply=None, function=None):
def get_data(self, data_label=None, cls=None, subset_to_apply=None, function=None,
spectral_to_spatial=None):
"""
Returns data with name equal to data_label of type cls with subsets applied from
subset_to_apply.
Expand All @@ -138,6 +139,9 @@ def get_data(self, data_label=None, cls=None, subset_to_apply=None, function=Non
If True, will collapse according to the current collapse function defined in the
spectrum viewer. If provided as a string, the cube will be collapsed with the provided
function. If False, None, or not passed, the entire cube will be returned.
spectral_to_spatial : str, optional
Spectral subset to be applied to spatial subset. Only possible if function is
set to True.

Returns
-------
Expand All @@ -147,7 +151,8 @@ def get_data(self, data_label=None, cls=None, subset_to_apply=None, function=Non
"""
if function is True:
return self.specviz.get_data(data_label=data_label, cls=cls,
subset_to_apply=subset_to_apply)
subset_to_apply=subset_to_apply,
spectral_to_spatial=spectral_to_spatial)
javerbukh marked this conversation as resolved.
Show resolved Hide resolved
elif function is False:
function = None
return self._get_data(data_label=data_label, cls=cls, subset_to_apply=subset_to_apply,
Expand Down
7 changes: 5 additions & 2 deletions jdaviz/configs/specviz/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def set_spectrum_tick_format(self, fmt, axis=None):
self._default_spectrum_viewer_reference_name
).figure.axes[axis].tick_format = fmt

def get_data(self, data_label=None, cls=None, subset_to_apply=None):
def get_data(self, data_label=None, cls=None, subset_to_apply=None, spectral_to_spatial=None):
"""
Returns data with name equal to data_label of type cls with subsets applied from
subset_to_apply.
Expand All @@ -284,6 +284,9 @@ def get_data(self, data_label=None, cls=None, subset_to_apply=None):
The type that data will be returned as.
subset_to_apply : str, optional
Subset that is to be applied to data before it is returned.
spectral_to_spatial : str, optional
Spectral subset to be applied to spatial subset. Only possible if this is
a specviz instance inside cubeviz.

Returns
-------
Expand All @@ -302,4 +305,4 @@ def get_data(self, data_label=None, cls=None, subset_to_apply=None):
function = None

return self._get_data(data_label=data_label, cls=cls, subset_to_apply=subset_to_apply,
function=function)
function=function, spectral_to_spatial=spectral_to_spatial)
17 changes: 14 additions & 3 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from glue.config import data_translator
from ipywidgets.widgets import widget_serialization
from specutils import Spectrum1D
from specutils.manipulation import extract_region


from jdaviz.app import Application
Expand Down Expand Up @@ -410,7 +411,8 @@ def show_in_new_tab(self, title=None): # pragma: no cover
DeprecationWarning)
return self.show(loc="sidecar:tab-after", title=title)

def _get_data(self, data_label=None, cls=None, subset_to_apply=None, function=None):
def _get_data(self, data_label=None, cls=None, subset_to_apply=None, function=None,
spectral_to_spatial=None):
list_of_valid_function_values = ('minimum', 'maximum', 'mean',
'median', 'sum')
if function and function not in list_of_valid_function_values:
Expand Down Expand Up @@ -480,9 +482,15 @@ def _get_data(self, data_label=None, cls=None, subset_to_apply=None, function=No
warnings.warn(f"Not able to get {data_label} returned with"
f" subset {subsets.label} applied of type {cls}."
f" Exception: {e}")
# Apply spectral subset to spatial subset if applicable
if spectral_to_spatial:
sr = self.app.get_subsets(spectral_to_spatial)
if sr:
data = extract_region(data, sr, return_single_spectrum=True)

return data

def get_data(self, data_label=None, cls=None, subset_to_apply=None):
def get_data(self, data_label=None, cls=None, subset_to_apply=None, spectral_to_spatial=None):
"""
Returns data with name equal to data_label of type cls with subsets applied from
subset_to_apply.
Expand All @@ -495,14 +503,17 @@ def get_data(self, data_label=None, cls=None, subset_to_apply=None):
The type that data will be returned as.
subset_to_apply : str, optional
Subset that is to be applied to data before it is returned.
spectral_to_spatial : str, optional
Spectral subset to be applied to spatial subset.

Returns
-------
data : cls
Data is returned as type cls with subsets applied.

"""
return self._get_data(data_label=data_label, cls=cls, subset_to_apply=subset_to_apply)
return self._get_data(data_label=data_label, cls=cls, subset_to_apply=subset_to_apply,
spectral_to_spatial=spectral_to_spatial)


class ImageConfigHelper(ConfigHelper):
Expand Down