Skip to content

Commit

Permalink
Merge pull request #3120 from bmorris3/cube-base-class
Browse files Browse the repository at this point in the history
Add Rampviz helper, generalize cube config helper and profile viewer
  • Loading branch information
bmorris3 authored Aug 22, 2024
2 parents 43f2bb0 + f796e77 commit 0c63463
Show file tree
Hide file tree
Showing 49 changed files with 2,479 additions and 496 deletions.
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

.. 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
===============



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:

.. 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 @@ def to_unit(self, data, cid, values, original_units, target_units):
# 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
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 @@ def _get_display_unit(self, axis):
if check_if_unit_is_per_solid_angle(sv_y_unit):
return sv_y_unit
return sv_y_unit / u.sr
elif axis == 'temporal':
# No unit for ramp's time (group/resultant) axis:
return None
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 @@ def _get_first_viewer_reference_name(
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 @@ def _get_first_viewer_reference_name(
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 @@ def _get_first_viewer_reference_name(
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']
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 @@ def slice_component_label(self):

@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 @@ def slice_component_label(self):

@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 @@ def slice_values(self):
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

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

0 comments on commit 0c63463

Please sign in to comment.