-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cubeviz spectral extraction through plugin #2827
Changes from all commits
49d499a
ec00996
a7bcc2c
d693cd0
dcca4c6
f3d8c31
1d5f470
eb48a9a
0aa82cd
8d2c6e5
09525b2
de94ef2
1753636
5ccb995
64909ff
69249f9
1d5b1ed
08861b2
5e1d353
e7f4e10
e7fb1db
e1c8a32
8d18167
b55ef9e
3ef4aaf
410f5ca
78a5615
816ce47
eccd413
a7f5400
3f39c8a
bf6864e
862d74e
c488a99
7f62fb5
fc74ccc
9c515f3
04b6779
b49f083
1fb2015
a39bb5a
43c0631
d9fd5a9
497810e
abc433e
1336f16
13b896a
386b6e7
1931f86
2d96aeb
21b7630
e6f38ad
027cc13
e4cdb35
72cc2e9
ff48983
b97a327
ae2e81e
a2fa931
ad8dbf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from specutils import Spectrum1D | ||
from specutils.io.registers import _astropy_has_priorities | ||
|
||
from jdaviz.core.events import SnackbarMessage | ||
from jdaviz.core.helpers import ImageConfigHelper | ||
from jdaviz.configs.default.plugins.line_lists.line_list_mixin import LineListMixin | ||
from jdaviz.configs.specviz import Specviz | ||
|
@@ -79,6 +80,27 @@ | |
|
||
super().load_data(data, parser_reference="cubeviz-data-parser", **kwargs) | ||
|
||
if 'Spectral Extraction' not in self.plugins: # pragma: no cover | ||
msg = SnackbarMessage( | ||
"Automatic spectral extraction requires the Spectral Extraction plugin to be enabled", # noqa | ||
color='error', sender=self, timeout=10000) | ||
self.app.hub.broadcast(msg) | ||
else: | ||
try: | ||
self.plugins['Spectral Extraction']._obj._extract_in_new_instance(auto_update=False, add_data=True) # noqa | ||
except Exception: | ||
msg = SnackbarMessage( | ||
"Automatic spectrum extraction for the entire cube failed." | ||
" See the spectral extraction plugin to perform a custom extraction", | ||
color='error', sender=self, timeout=10000) | ||
else: | ||
msg = SnackbarMessage( | ||
"The extracted 1D spectrum was generated automatically for the entire cube." | ||
" See the spectral extraction plugin for details or to" | ||
" perform a custom extraction.", | ||
color='warning', sender=self, timeout=10000) | ||
self.app.hub.broadcast(msg) | ||
|
||
@deprecated(since="3.9", alternative="select_wavelength") | ||
def select_slice(self, slice): | ||
""" | ||
|
@@ -120,26 +142,21 @@ | |
self._specviz = Specviz(app=self.app) | ||
return self._specviz | ||
|
||
def get_data(self, data_label=None, spatial_subset=None, spectral_subset=None, function=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have to deprecate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a large reason why we're bumping to 4.0 once we merge this PR (this also makes a few breaking changes to plugins). If there is a way to decorate and note the removal without having to temporarily support the old kwargs, I have no objections, but keeping the old code around with a warning proved to be messy and inconsistent with the "new way". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to remove it without deprecation, that is fine but should at least mention in change log under API? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, for sure, this PR will require a major change log entry (probably many of the entries in the PR description will need to be included somehow). |
||
def get_data(self, data_label=None, spatial_subset=None, spectral_subset=None, | ||
cls=None, use_display_units=False): | ||
""" | ||
Returns data with name equal to ``data_label`` of type ``cls`` with subsets applied from | ||
``spatial_subset`` and/or ``spectral_subset`` using ``function`` if applicable. | ||
``spectral_subset``, if applicable. | ||
|
||
Parameters | ||
---------- | ||
data_label : str, optional | ||
Provide a label to retrieve a specific data set from data_collection. | ||
spatial_subset : str, optional | ||
Spatial subset applied to data. | ||
Spatial subset applied to data. Only applicable if ``data_label`` points to a cube or | ||
image. To extract a spectrum from a cube, use the spectral extraction plugin instead. | ||
spectral_subset : str, optional | ||
Spectral subset applied to data. | ||
function : {True, False, 'minimum', 'maximum', 'mean', 'median', 'sum'}, optional | ||
Ignored if ``data_label`` does not point to cube-like data. | ||
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 (unless there | ||
are values for ``spatial_subset`` and ``spectral_subset``). | ||
cls : `~specutils.Spectrum1D`, `~astropy.nddata.CCDData`, optional | ||
The type that data will be returned as. | ||
|
||
|
@@ -149,20 +166,8 @@ | |
Data is returned as type cls with subsets applied. | ||
|
||
""" | ||
# If function is a value ('sum' or 'minimum') or True and spatial and spectral | ||
# are set, then we collapse the cube along the spatial subset using the function, then | ||
# we apply the mask from the spectral subset. | ||
# If function is any value other than False, we use specviz | ||
if (function is not False and spectral_subset and spatial_subset) or function: | ||
return self.specviz.get_data(data_label=data_label, spectral_subset=spectral_subset, | ||
cls=cls, spatial_subset=spatial_subset, function=function) | ||
elif function is False and spectral_subset: | ||
raise ValueError("function cannot be False if spectral_subset" | ||
" is set") | ||
elif function is False: | ||
function = None | ||
return self._get_data(data_label=data_label, spatial_subset=spatial_subset, | ||
spectral_subset=spectral_subset, function=function, | ||
spectral_subset=spectral_subset, | ||
cls=cls, use_display_units=use_display_units) | ||
|
||
# Need this method for Imviz Aperture Photometry plugin. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Is there any follow-up needed for all the JDAT notebooks out there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, I did go through and update the example notebooks. I'll create a general ticket for updating JDAT for any/all breaking changes in 4.0 - that's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.