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 Rampviz helper, generalize cube config helper and profile viewer #3120

Merged
merged 21 commits into from
Aug 22, 2024
Merged
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
5 changes: 5 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ specviz2d:
- changed-files:
- any-glob-to-any-file:
- jdaviz/configs/specviz2d/**/*

rampviz:
- changed-files:
- any-glob-to-any-file:
- jdaviz/configs/rampviz/**/*
2 changes: 1 addition & 1 deletion docs/cubeviz/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:alt: Introductory video tour of the Cubeviz configuration and its features

Cubeviz is a visualization and analysis toolbox for data cubes from
integral field units (IFUs). It is built as part of the
integral field units (IFUs). It is built on top of the
`glue visualization <https://glueviz.org>`_ tool. Cubeviz is designed to work
with data cubes from the NIRSpec and MIRI instruments on JWST, and will work
with IFU data cubes. It uses
Expand Down
10 changes: 10 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ Jdaviz

Jump to Mosviz

.. grid-item-card::
:img-top: logos/cube.svg
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we don't have a Rampviz logo yet, and won't until we have Jenn back. I'm leaving the cubeviz logo here in the mean time.


.. button-ref:: rampviz/index
:expand:
:color: primary
:click-parent:

Jump to Rampviz

``jdaviz`` is a package of astronomical data analysis visualization
tools based on the Jupyter platform. These GUI-based tools link data
visualization and interactive analysis. They are designed to work
Expand Down
1 change: 1 addition & 0 deletions docs/index_using_jdaviz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ User Guide
cubeviz/index
specviz2d/index
mosviz/index
rampviz/index
plugin_api
save_state
display
Expand Down
21 changes: 21 additions & 0 deletions docs/rampviz/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. |cubeviz_logo| image:: ../logos/cube.svg
:height: 42px

.. _rampviz:

######################
|cubeviz_logo| Rampviz
######################


Rampviz is a visualization and analysis toolbox for ramp cubes from
infrared detectors. It is built on top of the
`glue visualization <https://glueviz.org>`_ tool. Rampviz is designed to work
with ramp files from the Roman Space Telescope and JWST.

**Using Rampviz**

.. toctree::
:maxdepth: 2

plugins
66 changes: 66 additions & 0 deletions docs/rampviz/plugins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
*********************
Data Analysis Plugins
*********************



.. _rampviz-metadata-viewer:

Metadata Viewer
===============

.. seealso::

:ref:`Metadata Viewer <imviz_metadata-viewer>`
Documentation on using the metadata viewer.


.. _rampviz-plot-options:

Plot Options
============

This plugin gives access to per-viewer and per-layer plotting options.
To show axes on image viewers, toggle on the "Show axes" option at the bottom of the plugin.

.. seealso::

:ref:`Image Plot Options <imviz-display-settings>`
Documentation on Imviz display settings in the Jdaviz viewers.

.. _rampviz-subset-plugin:

Subset Tools
============

.. seealso::

:ref:`Subset Tools <imviz-subset-plugin>`
Imviz documentation describing the concept of subsets in Jdaviz.


Markers
=======

.. seealso::

:ref:`Markers <markers-plugin>`
Imviz documentation describing the markers plugin.

.. _rampviz-slice:

Slice
=====

.. seealso::

:ref:`Slice <slice>`
Documentation on using the Slice plugin.

.. _ramp-extraction:

Ramp Extraction
===============



Comment on lines +62 to +66
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be added once we converge on the way it works...

3 changes: 3 additions & 0 deletions docs/reference/api_configs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ Helpers API

.. automodapi:: jdaviz.configs.specviz2d.helper
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.rampviz.helper
:no-inheritance-diagram:
3 changes: 3 additions & 0 deletions docs/reference/api_parsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ Parsers API

.. automodapi:: jdaviz.configs.specviz2d.plugins.parsers
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.rampviz.plugins.parsers
:no-inheritance-diagram:
6 changes: 6 additions & 0 deletions docs/reference/api_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Plugins API
.. automodapi:: jdaviz.configs.cubeviz.plugins.slice.slice
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.cubeviz.plugins.spectral_extraction.spectral_extraction
:no-inheritance-diagram:

Comment on lines +51 to +53
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you believe this was missing!?

.. automodapi:: jdaviz.configs.imviz.plugins.aper_phot_simple.aper_phot_simple
:no-inheritance-diagram:

Expand Down Expand Up @@ -86,3 +89,6 @@ Plugins API

.. automodapi:: jdaviz.configs.specviz2d.plugins.spectral_extraction.spectral_extraction
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.rampviz.plugins.ramp_extraction.ramp_extraction
:no-inheritance-diagram:
3 changes: 3 additions & 0 deletions docs/reference/api_viewers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ Viewers API

.. automodapi:: jdaviz.configs.specviz.plugins.viewers
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.rampviz.plugins.viewers
:no-inheritance-diagram:
9 changes: 6 additions & 3 deletions jdaviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

# Top-level API as exposed to users.
from jdaviz.app import * # noqa: F401, F403
from jdaviz.configs.specviz import Specviz # noqa: F401
from jdaviz.configs.specviz2d import Specviz2d # noqa: F401
from jdaviz.configs.mosviz import Mosviz # noqa: F401

from jdaviz.configs.cubeviz import Cubeviz # noqa: F401
from jdaviz.configs.imviz import Imviz # noqa: F401
from jdaviz.configs.mosviz import Mosviz # noqa: F401
from jdaviz.configs.rampviz import Rampviz # noqa: F401
from jdaviz.configs.specviz import Specviz # noqa: F401
from jdaviz.configs.specviz2d import Specviz2d # noqa: F401

from jdaviz.utils import enable_hot_reloading # noqa: F401
from jdaviz.core.launcher import open # noqa: F401

Expand Down
25 changes: 20 additions & 5 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@
# should return the converted values. Note that original_units
# gives the units of the values array, which might not be the same
# as the original native units of the component in the data.
if cid.label == "flux":

if cid.label == 'Pixel Axis 0 [z]' and target_units == '':
# handle ramps loaded into Rampviz by avoiding conversion
# of the groups axis:
return values

Check warning on line 106 in jdaviz/app.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/app.py#L106

Added line #L106 was not covered by tests
elif cid.label == "flux":
try:
spec = data.get_object(cls=Spectrum1D)

except RuntimeError:
data = data.get_object(cls=NDDataArray)
spec = Spectrum1D(flux=data.data * u.Unit(original_units))
Expand Down Expand Up @@ -1290,6 +1294,9 @@
if check_if_unit_is_per_solid_angle(sv_y_unit):
return sv_y_unit
return sv_y_unit / u.sr
elif axis == 'temporal':

Check warning on line 1297 in jdaviz/app.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/app.py#L1297

Added line #L1297 was not covered by tests
# No unit for ramp's time (group/resultant) axis:
return None

Check warning on line 1299 in jdaviz/app.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/app.py#L1299

Added line #L1299 was not covered by tests
else:
raise ValueError(f"could not find units for axis='{axis}'")
uc = self._jdaviz_helper.plugins.get('Unit Conversion')._obj
Expand Down Expand Up @@ -1747,7 +1754,8 @@
require_spectrum_2d_viewer=False,
require_table_viewer=False,
require_flux_viewer=False,
require_image_viewer=False
require_image_viewer=False,
require_profile_viewer=False,
):
"""
Return the viewer reference name of the first available viewer.
Expand All @@ -1761,12 +1769,16 @@
from jdaviz.configs.mosviz.plugins.viewers import (
MosvizTableViewer, MosvizProfile2DView
)
from jdaviz.configs.rampviz.plugins.viewers import (
RampvizImageView, RampvizProfileView
)

spectral_viewers = (SpecvizProfileView, CubevizProfileView)
spectral_2d_viewers = (MosvizProfile2DView, )
table_viewers = (MosvizTableViewer, )
image_viewers = (ImvizImageView, CubevizImageView)
flux_viewers = (CubevizImageView, )
image_viewers = (ImvizImageView, CubevizImageView, RampvizImageView)
flux_viewers = (CubevizImageView, RampvizImageView)
ramp_viewers = (RampvizProfileView, )

for vid in self._viewer_store:
viewer_item = self._viewer_item_by_id(vid)
Expand All @@ -1789,6 +1801,9 @@
elif require_flux_viewer:
if isinstance(self._viewer_store[vid], flux_viewers) and is_returnable:
return viewer_item['reference']
elif require_profile_viewer:
if isinstance(self._viewer_store[vid], ramp_viewers) and is_returnable:
return viewer_item['reference']

Check warning on line 1806 in jdaviz/app.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/app.py#L1804-L1806

Added lines #L1804 - L1806 were not covered by tests
else:
if is_returnable:
return viewer_item['reference']
Expand Down
7 changes: 4 additions & 3 deletions jdaviz/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .cubeviz import * # noqa
from .specviz import * # noqa
from .specviz2d import * # noqa
from .default import * # noqa
from .mosviz import * # noqa
from .imviz import * # noqa
from .mosviz import * # noqa
from .rampviz import * # noqa
from .specviz import * # noqa
from .specviz2d import * # noqa
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/cubeviz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tray:
- g-data-quality
- g-subset-plugin
- g-markers
- cubeviz-slice
- cube-slice
- g-unit-conversion
- cubeviz-spectral-extraction
- g-gaussian-smooth
Expand Down
15 changes: 8 additions & 7 deletions jdaviz/configs/cubeviz/helper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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
from jdaviz.core.events import (AddDataMessage,
SliceSelectSliceMessage)
from jdaviz.core.events import AddDataMessage, SnackbarMessage
from jdaviz.core.helpers import CubeConfigHelper
from jdaviz.configs.cubeviz.plugins.viewers import CubevizImageView

__all__ = ['Cubeviz']

Expand All @@ -12,19 +11,22 @@
"Wavenumber", "Velocity", "Energy"]


class Cubeviz(ImageConfigHelper, LineListMixin):
class Cubeviz(CubeConfigHelper, LineListMixin):
"""Cubeviz Helper class"""
_default_configuration = 'cubeviz'
_default_spectrum_viewer_reference_name = "spectrum-viewer"
_default_uncert_viewer_reference_name = "uncert-viewer"
_default_flux_viewer_reference_name = "flux-viewer"
_default_image_viewer_reference_name = "image-viewer"
_cube_viewer_default_label = _default_flux_viewer_reference_name

_loaded_flux_cube = None
_loaded_uncert_cube = None
_cube_viewer_cls = CubevizImageView

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.app.hub.subscribe(self, AddDataMessage,
handler=self._set_spectrum_x_axis)

Expand Down Expand Up @@ -106,8 +108,7 @@ def select_wavelength(self, wavelength):
"""
if not isinstance(wavelength, (int, float)):
raise TypeError("wavelength must be a float or int")
msg = SliceSelectSliceMessage(value=wavelength, sender=self)
self.app.hub.broadcast(msg)
self.select_slice(wavelength)

@property
def specviz(self):
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/configs/cubeviz/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .tools import * # noqa
from .mixins import * # noqa
from .viewers import * # noqa
from .parsers import * # noqa
from .moment_maps.moment_maps import * # noqa
from .slice.slice import * # noqa
from .spectral_extraction.spectral_extraction import * # noqa
from .tools import * # noqa
9 changes: 7 additions & 2 deletions jdaviz/configs/cubeviz/plugins/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@property
def slice_display_unit_name(self):
return 'spectral'
return 'spectral' if self.jdaviz_app.config == 'cubeviz' else 'temporal'

@cached_property
def slice_indicator(self):
Expand Down Expand Up @@ -77,7 +77,7 @@

@property
def slice_display_unit_name(self):
return 'spectral'
return 'spectral' if self.jdaviz_app.config == 'cubeviz' else 'temporal'

@property
def slice_values(self):
Expand All @@ -91,6 +91,11 @@
converted_axis = np.array([])
for layer in self.layers:
world_comp_ids = layer.layer.data.world_component_ids

if not len(world_comp_ids):
# rampviz uses coordinate components:
world_comp_ids = layer.layer.data.coordinate_components

Check warning on line 97 in jdaviz/configs/cubeviz/plugins/mixins.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/cubeviz/plugins/mixins.py#L97

Added line #L97 was not covered by tests

if self.slice_index >= len(world_comp_ids):
# Case where 2D image is loaded in image viewer
continue
Expand Down
5 changes: 4 additions & 1 deletion jdaviz/configs/cubeviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from astropy.wcs import WCS
from specutils import Spectrum1D

from jdaviz.configs.imviz.plugins.parsers import prep_data_layer_as_dq
from jdaviz.core.registries import data_parser_registry
from jdaviz.utils import standardize_metadata, PRIHDR_KEY, download_uri_to_path

Expand Down Expand Up @@ -342,7 +341,11 @@ def _parse_jwst_s3d(app, hdulist, data_label, ext='SCI',
app.add_data(data, data_label, parent=parent)

# get glue data and update if DQ:

if ext == 'DQ':
# prevent circular import:
from jdaviz.configs.imviz.plugins.parsers import prep_data_layer_as_dq

data = app.data_collection[-1]
prep_data_layer_as_dq(data)

Expand Down
Loading