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

imviz-round-1.5 (astrowidgets + Glupyter) #445

Closed
wants to merge 6 commits into from
Closed
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
19 changes: 10 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ repository.

``jdaviz`` provides data viewers and analysis plugins that can be flexibly
combined as desired to create interactive applications that fit your workflow.
Three named preset configurations for common use cases are provided. **Specviz**
is a tool for visualization and quick-look analysis of 1D astronomical spectra.
**MOSviz** is a visualization tool for many astronomical spectra,
typically the output of a multi-object spectrograph (e.g., JWST
NIRSpec), and includes viewers for 1D and 2D spectra as well as
contextual information like on-sky views of the spectrograph slit.
**Cubeviz** provides a view of spectroscopic data cubes (like those to be
produced by JWST MIRI), along with 1D spectra extracted from the cube.
Several named preset configurations for common use cases are provided:

* **Specviz**: Visualization and quick-look analysis of 1D astronomical spectra.
* **MOSviz**: Visualization tool for many astronomical spectra,
typically the output of a multi-object spectrograph (e.g., JWST
NIRSpec), and includes viewers for 1D and 2D spectra as well as
contextual information like on-sky views of the spectrograph slit.
* **Cubeviz**: View of spectroscopic data cubes (like those to be
produced by JWST MIRI), along with 1D spectra extracted from the cube.
* **Imviz**: Visualization and quick-look analysis of 2D astronomical images.


Installing
Expand All @@ -41,7 +43,6 @@ For details on installing and using JDAViz, see the
`Jdaviz documentation <https://jdaviz.readthedocs.io/en/latest/>`_.



License
-------

Expand Down
30 changes: 30 additions & 0 deletions docs/imviz/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(TODO: Nice logo here.)

.. _imviz:

#####
Imviz
#####

Imviz is a tool for visualization and quick-look analysis of 2D astronomical
images. Like the rest of `jdaviz`, it is written in the Python programming
language, and therefore can be run anywhere Python is supported
(see :doc:`../installation`). Imviz is built on top of the
`astrowidgets <https://astrowidgets.readthedocs.io>`_ using
`Glupyter <https://glue-jupyter.readthedocs.io>`_ backend, providing a visual,
interactive interface to the analysis capabilities in that library.

Imviz allows images to be easily displayed and examined. It supports WCS
and so on. (TODO: Add content.)


Using Imviz
-----------

To run Imviz in a notebook::

from jdaviz import Imviz
imviz = Imviz()
imviz.app

(TODO: Add content.)
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Using Jdaviz
specviz/index.rst
cubeviz/index.rst
mosviz/index.rst
imviz/index.rst

Reference/API
=============
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ or simply start a new Jupyter notebook and run the following in a cell::
app

To learn more about the various ``jdaviz`` application configurations and loading data, see the :ref:`cubeviz`,
:ref:`specviz`, or :ref:`mosviz` tools.
:ref:`specviz`, :ref:`mosviz`, or :ref:`imviz` tools.
1 change: 1 addition & 0 deletions jdaviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from jdaviz.configs.specviz2d import Specviz2d # noqa
from jdaviz.configs.mosviz import MosViz # noqa
from jdaviz.configs.cubeviz import CubeViz # noqa
from jdaviz.configs.imviz import Imviz # noqa
4 changes: 2 additions & 2 deletions jdaviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
default='default',
nargs=1,
show_default=True,
type=click.Choice(['default', 'cubeviz', 'specviz', 'mosviz'],
case_sensitive=False),
type=click.Choice(['default', 'cubeviz', 'specviz', 'mosviz',
'imviz'], case_sensitive=False),
help="Configuration to use on application startup")
def main(filename, layout='default'):
"""
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .specviz import * # noqa
from .default import * # noqa
from .mosviz import * # noqa
from .imviz import * # noqa
2 changes: 2 additions & 0 deletions jdaviz/configs/imviz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .plugins import * # noqa
from .helper import Imviz # noqa
12 changes: 12 additions & 0 deletions jdaviz/configs/imviz/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from jdaviz.core.helpers import ConfigHelper

__all__ = ['Imviz']


class Imviz(ConfigHelper):
"""Imviz helper class."""

_default_configuration = "imviz"

def show(self):
self.app
38 changes: 38 additions & 0 deletions jdaviz/configs/imviz/imviz.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from jdaviz import Imviz\n",
"\n",
"imviz = Imviz()\n",
"imviz.load_data('DATA_FILENAME')\n",
"imviz.app"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
20 changes: 20 additions & 0 deletions jdaviz/configs/imviz/imviz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
settings:
configuration: imviz
data:
parser: imviz-image-parser
visible:
menu_bar: false
toolbar: false
tray: false
tab_headers: false
context:
notebook:
max_height: 600px
viewer_area:
- container: col
children:
- container: row
viewers:
- name: Image
plot: imviz-image-viewer
reference: imviz-image-viewer
2 changes: 2 additions & 0 deletions jdaviz/configs/imviz/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .viewers import * # noqa
from .parsers import * # noqa
27 changes: 27 additions & 0 deletions jdaviz/configs/imviz/plugins/parsers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pathlib

from astropy.nddata import CCDData

from jdaviz.core.registries import data_parser_registry

__all__ = ["imviz_image_parser"]


@data_parser_registry("imviz-image-parser")
def imviz_image_parser(app, data, data_label=None, show_in_viewer=True):
"""Loads an image into Imviz"""
# If no data label is assigned, give it a unique identifier
if not data_label:
from astrowidgets.glupyter import _gen_random_label
data_label = _gen_random_label(prefix="imviz_data|")

path = pathlib.Path(data)
if path.is_file():
# TODO: Support other image formats
data = CCDData.read(path)
else:
raise FileNotFoundError(f"No such file: {path}")

app.add_data(data, data_label)
if show_in_viewer:
app.add_data_to_viewer("imviz-image-viewer", data_label, clear_other_data=True)
68 changes: 68 additions & 0 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from astrowidgets.glupyter import ImageWidget
from glue.core import BaseData

from jdaviz.core.registries import viewer_registry

__all__ = ['ImvizImageView']


@viewer_registry("imviz-image-viewer", label="Image 2D (Imviz)")
class ImvizImageView(ImageWidget):
"""Image widget for Imviz."""

default_class = None

# session is a glue thing
def __init__(self, session, *args, **kwargs):

super().__init__(*args, **kwargs)
self._viewer._session = session

# More glue things

def register_to_hub(self, *args, **kwargs):
self._viewer.register_to_hub(*args, **kwargs)

def add_data(self, data):
self._viewer.add_data(data)
self._link_image_to_cb()

def remove_data(self, data):
self._viewer.remove_data(data)
self.viewer.interaction = None

@property
def toolbar_selection_tools(self):
return self._viewer.toolbar_selection_tools

@property
def figure_widget(self):
return self

@property
def layer_options(self):
return self._viewer.layer_options

@property
def viewer_options(self):
return self._viewer.viewer_options

@property
def state(self):
return self._viewer.state

def set_plot_axes(self):
self.viewer.axes[1].tick_format = None
self.viewer.axes[0].tick_format = None

self.viewer.axes[1].label = "y: pixels"
self.viewer.axes[0].label = "x: pixels"

# Make it so y axis label is not covering tick numbers.
self.viewer.axes[1].label_offset = "-50"

def data(self, cls=None):
return [layer_state.layer
for layer_state in self._viewer.state.layers
if hasattr(layer_state, 'layer') and
isinstance(layer_state.layer, BaseData)]
1 change: 1 addition & 0 deletions jdaviz/configs/imviz/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for Imviz image viewer."""
2 changes: 2 additions & 0 deletions jdaviz/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def read_configuration(path=None):
path = default_path / "mosviz" / "mosviz.yaml"
elif path == 'specviz2d':
path = default_path / "specviz2d" / "specviz2d.yaml"
elif path == 'imviz':
path = default_path / "imviz" / "imviz.yaml"
elif not os.path.isfile(path):
raise ValueError("Configuration must be path to a .yaml file.")

Expand Down
Loading