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 (undeleted + fix added; astrowidgets + Ginga) #428

Closed
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
`Ginga <https://ginga.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,
GWCS, ASDF, 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
from jdaviz.configs.mosviz import MosViz
from jdaviz.configs.cubeviz import CubeViz
from jdaviz.configs.imviz import Imviz
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 *
from .default import *
from .mosviz import *
from .imviz import *
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
29 changes: 29 additions & 0 deletions jdaviz/configs/imviz/plugins/parsers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import base64
import pathlib
import uuid

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:
data_label = "imviz_data|" + str(
base64.b85encode(uuid.uuid4().bytes), "utf-8")

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)
73 changes: 73 additions & 0 deletions jdaviz/configs/imviz/plugins/viewers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from astrowidgets.core import ImageWidget
from ginga.misc.log import get_logger
from glue.core import Data
import ipywidgets as widgets

from jdaviz.core.registries import viewer_registry

__all__ = ['ImvizImageView']


class DummyModelID(widgets.Label):
pass


class DummyState:
def __init__(self):
self.layers = []


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

default_class = None
state = DummyState()

# session is a glue thing
def __init__(self, session, *args, **kwargs):
# logger needs special handling because using default logger of None
# will crash Ginga internals.
kwargs['logger'] = get_logger('imviz', log_stderr=True, log_file=None,
level=30)
super().__init__(*args, **kwargs)

# More glue things

def register_to_hub(self, *args, **kwargs):
pass

def add_data(self, data):
if type(data) == Data:
data = data.get_object()
self.load_nddata(data)

@property
def toolbar_selection_tools(self):
class Dummy(DummyModelID):
def __init__(self):
super().__init__()
self.borderless = False

return Dummy()

@property
def figure_widget(self):
return self

@property
def layer_options(self):
return DummyModelID()

@property
def viewer_options(self):
return DummyModelID()

def set_plot_axes(self, *args, **kwargs):
pass

def data(self, cls=None):
return [layer_state.layer
for layer_state in self.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
69 changes: 69 additions & 0 deletions notebooks/concepts/Imviz concept notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore')\n",
"\n",
" from jdaviz import Imviz\n",
" imviz = Imviz()\n",
"\n",
"imviz.app"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from astropy.utils.data import download_file\n",
"\n",
"filename = download_file('http://data.astropy.org/photometry/spitzer_example_image.fits', cache=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imviz.load_data(filename)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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": 4
}
Loading