Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: POC on glue and glue-jupyter POC
Browse files Browse the repository at this point in the history
[ci skip]
pllim committed Aug 8, 2022
1 parent c523cf6 commit 5d423da
Showing 9 changed files with 94 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ Imviz
- New "Catalog Search" plugin that uses a specified catalog (currently SDSS) to search for sources in an image
and mark the sources found. [#1455]

- New Simple Image Rotation plugin to rotate the axes of images. [#1551]

Mosviz
^^^^^^
- NIRISS parser now sorts FITS files by header instead of file name. [#819]
19 changes: 19 additions & 0 deletions docs/imviz/plugins.rst
Original file line number Diff line number Diff line change
@@ -91,6 +91,25 @@ data label, the X and Y directions, and the zoom box.
When you have multiple viewers created in Imviz, use the Viewer dropdown menu
to change the active viewer that it tracks.

.. _rotate-image-simple:

Simple Image Rotation
=====================

.. warning::

Distortion is ignored, so using this plugin on distorted data is
not recommended.

.. note::

Zoom box in :ref:`imviz-compass` will not show when rotation mode is on.

This plugins rotates image(s) by the given angle.
You can select viewer but that option only shows when applicable.
You can enter the desired rotation angle in degrees clockwise.
Click on the :guilabel:`ROTATE` button to finalize.

.. _line-profile-xy:

Line Profiles
3 changes: 3 additions & 0 deletions docs/reference/api.rst
Original file line number Diff line number Diff line change
@@ -126,6 +126,9 @@ Plugins
.. automodapi:: jdaviz.configs.imviz.plugins.links_control.links_control
:no-inheritance-diagram:

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

.. automodapi:: jdaviz.configs.mosviz.plugins.row_lock.row_lock
:no-inheritance-diagram:

2 changes: 1 addition & 1 deletion jdaviz/app.py
Original file line number Diff line number Diff line change
@@ -1104,7 +1104,7 @@ def _viewer_by_reference(self, reference):
Returns
-------
`~glue_jupyter.bqplot.common.BqplotBaseView`
viewer : `~glue_jupyter.bqplot.common.BqplotBaseView`
The viewer class instance.
"""
viewer_item = self._viewer_item_by_reference(reference)
1 change: 1 addition & 0 deletions jdaviz/configs/imviz/imviz.yaml
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ tray:
- g-subset-plugin
- imviz-links-control
- imviz-compass
- imviz-rotate-image
- imviz-line-profile-xy
- imviz-aper-phot-simple
- imviz-catalogs
3 changes: 2 additions & 1 deletion jdaviz/configs/imviz/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from .coords_info import * # noqa
from .links_control import * # noqa
from .compass import * # noqa
from .rotate_image import * # noqa
from .aper_phot_simple import * # noqa
from .line_profile_xy import * # noqa
from .catalogs import * # noqa
from .catalogs import * # noqa
1 change: 1 addition & 0 deletions jdaviz/configs/imviz/plugins/rotate_image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .rotate_image import * # noqa
35 changes: 35 additions & 0 deletions jdaviz/configs/imviz/plugins/rotate_image/rotate_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from matplotlib.transforms import Affine2D
from traitlets import Any

from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import TemplateMixin, ViewerSelectMixin


@tray_registry('imviz-rotate-image', label="Simple Image Rotation")
class RotateImageSimple(TemplateMixin, ViewerSelectMixin):
template_file = __file__, "rotate_image.vue"

angle = Any(0).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._theta = 0 # degrees, clockwise

def vue_rotate_image(self, *args, **kwargs):
# We only grab the value here to avoid constantly updating as
# user is still entering or updating the value.
try:
self._theta = float(self.angle)
except Exception:
return

viewer = self.app._viewer_by_id(self.viewer_selected)

# TODO: Is this really clockwise? Does it take negative angle?
# Rotate selected viewer canvas. This changes zoom too.
affine_transform = Affine2D().rotate_deg(self._theta)
viewer.state.affine_matrix = affine_transform

# TODO: Does the zoom box behave? If not, we need to disable it.
# Update Compass plugin.
viewer.on_limits_change()
30 changes: 30 additions & 0 deletions jdaviz/configs/imviz/plugins/rotate_image/rotate_image.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<template>
<j-tray-plugin>
<v-row>
<j-docs-link :link="'https://jdaviz.readthedocs.io/en/'+vdocs+'/'+config+'/plugins.html#simple-image-rotation'">Rotate image.</j-docs-link>
</v-row>

<plugin-viewer-select
:items="viewer_items"
:selected.sync="viewer_selected"
label="Viewer"
hint="Select viewer."
/>

<v-row>
<v-col>
<v-text-field
v-model="angle"
type="number"
label="Angle"
hint="Rotation angle in degrees clockwise"
></v-text-field>
</v-col>
</v-row>

<v-row justify="end">
<v-btn color="primary" text @click="rotate_image">Rotate</v-btn>
</v-row>

</j-tray-plugin>
</template>

0 comments on commit 5d423da

Please sign in to comment.