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

**DO NOT MERGE** Make MultiImage a global plugin etc #96

Closed
wants to merge 1 commit 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
7 changes: 7 additions & 0 deletions docs/source/api/region.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _stginga-api-region:

region
======

.. automodule:: stginga.region
:members:
12 changes: 9 additions & 3 deletions docs/source/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ customizable via plugin configuration files, which are available in the
Local Plugins
-------------

These plugins work together to display the same object across multiple images:
This plugin works with :ref:`global-plugin-multiimage` to display the same
object across multiple images:

.. toctree::
:maxdepth: 2

plugins_manual/multiimage
plugins_manual/mipick

These plugins behave like a regular Ginga plugin:
Expand Down Expand Up @@ -48,4 +48,10 @@ one way is to use the ``--plugins`` option along with ``stginga`` command
Global Plugins
--------------

There is currently none to be distributed.
This plugin works with :ref:`local-plugin-mipick` to display the same
object across multiple images:

.. toctree::
:maxdepth: 2

plugins_manual/multiimage
11 changes: 4 additions & 7 deletions docs/source/plugins_manual/mipick.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ MIPick
:width: 800px
:alt: MIPick plugin

This local plugin is mainly a demonstration on how custom plugins can be
integrated with existing plugins. This plugin is based on the
`Pick plugin <https://ginga.readthedocs.org/en/latest/manual/plugins.html#pick>`_.
However, the pick region, instead of being fixed to image
pixel coordinates, uses the image sky coordinates. If run with
:ref:`local-plugin-multiimage`, the postage stamps will show the same region
in different images.
This local plugin is like :ref:`Pick plugin <ginga:sec-plugins-pick>` but it
also works with :ref:`global-plugin-multiimage` to show postage stamps of the
same region in different images. The pick region, instead of being fixed to
image pixel coordinates, uses the image sky coordinates.
Also, as images are cycled through the main viewer, the region
will automatically update, again always fixed on the same section of sky.
15 changes: 6 additions & 9 deletions docs/source/plugins_manual/multiimage.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _local-plugin-multiimage:
.. _global-plugin-multiimage:

MultiImage
==========
Expand All @@ -7,13 +7,10 @@ MultiImage
:width: 800px
:alt: MultiImage plugin

This local plugin is used to view a selectable region of sky in multiple
images. A box on the image in the main display defines the right
ascension/declination region of sky to view. Along the bottom, postage
stamps of that same region from other images loaded into Ginga are
displayed. If the box size and position change, all the postage stamps
update dynamically.
This global plugin is used to view a selected region of sky in multiple
images along the bottom of the main viewer.
Selection can be made using :ref:`local-plugin-mipick`.
If the box size and position change, all the postage stamps update dynamically.

Options include fixing the region either to sky coordinates, the
default, or to pixels (data). Standard editing controls over the box
are also available.
default, or to pixels (data).
1 change: 1 addition & 0 deletions docs/source/ref_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Reference/API
api/plugin_info
api/utils
api/local_plugin_mixin
api/region
2 changes: 1 addition & 1 deletion docs/source/run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Manually Load stginga Plugins

You can also run Ginga natively and just specify the plugins you want directly::

ginga --plugins=stginga.plugins.BackgroundSub,stginga.plugins.BadPixCorr,stginga.plugins.DQInspect,stginga.plugins.MIPick,stginga.plugins.MultiImage,stginga.plugins.SNRCalc [args]
ginga --plugins=stginga.plugins.BackgroundSub,stginga.plugins.BadPixCorr,stginga.plugins.DQInspect,stginga.plugins.MIPick,stginga.plugins.SNRCalc --modules=stginga.plugins.MultiImage [args]

If you do it this way, you need to manually start ``ChangeHistory`` global
plugin from Ginga viewer, as it is not started by default in Ginga.
6 changes: 4 additions & 2 deletions stginga/plugin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def _get_stginga_plugins():

gpfx = 'stginga.plugins' # To load custom plugins in Ginga namespace

global_plugins = []
global_plugins = [
Bunch(module='MultiImage', tab='MultiImage', ws='right', pfx=gpfx,
start=False)
]
local_plugins = [
Bunch(module='MultiImage', ws='dialogs', pfx=gpfx),
Bunch(module='MIPick', ws='dialogs', pfx=gpfx),
Bunch(module='BackgroundSub', ws='dialogs', pfx=gpfx),
Bunch(module='BadPixCorr', ws='dialogs', pfx=gpfx),
Expand Down
67 changes: 28 additions & 39 deletions stginga/plugins/MIPick.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#
# MIPick.py -- Multi-Image Pick plugin for Ginga reference viewer
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
"""Multi-Image Pick local plugin for Ginga."""
from __future__ import (absolute_import, division, print_function,
unicode_literals)

# GINGA
from ginga.misc.plugins.Pick import Pick

# LOCAL
from stginga.plugins.MultiImage import Region
from stginga.region import Region

__all__ = []

Expand All @@ -26,29 +23,14 @@ def __init__(self, fv, fitsimage):
self._textlabel = 'MIPick'

# Additional attributes
self.multiimage = None
self.multiimage_name = 'MultiImage'
self.region = None

def resume(self):
super(MIPick, self).resume()
self.region_default_width = 30
self.region_default_height = 30

# Setup the region
if self.region is None:
self.region = Region()
self.region.coord = 'wcs'
self.region.image = self.fitsimage.get_image()

# See if multiimage is active
opmon = self.chinfo.opmon
multiimage = None
if opmon.is_active(self.multiimage_name):
try:
multiimage = opmon.getPlugin(self.multiimage_name)
except:
multiimage = None
else:
multiimage.region = self.region
self.multiimage = multiimage
self.region = Region(logger=self.logger)
self.region.coord = 'wcs'

def redo(self):
if self.picktag is None:
Expand Down Expand Up @@ -118,13 +100,6 @@ def redo(self):
self.clear_fwhm()
self.clear_radial()

# If multiimage, redo there also.
try:
self.multiimage.redo()
except:
"""Doesn't matter"""
pass

# Delete previous peak marks
objs = self.canvas.getObjectsByTagpfx('peak')
self.canvas.delete_objects(objs)
Expand All @@ -139,8 +114,22 @@ def redo(self):
str(e)))
return True

# Try to find MultiImage plugin.
if self.multiimage is None:
try:
self.multiimage = self.fv.gpmon.getPlugin(self.multiimage_name)
except KeyError:
self.multiimage = None

# Force MultiImage to redo.
if self.multiimage is not None:
self.multiimage.set_region(self.region)
self.multiimage.redo(
self.fv.get_channelInfo(self.chname), self.region.image)

def draw_cb(self, canvas, tag):
obj = canvas.getObjectByTag(tag)
self.region.image = self.fitsimage.get_image()
self.draw_compound(obj, canvas)
return self.redo()

Expand All @@ -166,13 +155,13 @@ def edit_cb(self, canvas, obj):
text = c_obj.objects[2]
text.x, text.y = x1, y2 + 4

self.regions.set_bbox(x1, y1, x2, y2, coord='data')
self.region.set_bbox(x1, y1, x2, y2, coord='data')

return self.redo()

def reset_region(self):
self.dx = region_default_width
self.dy = region_default_height
self.dx = self.region_default_width
self.dy = self.region_default_height

obj = self.canvas.get_object_by_tag(self.picktag)
if obj.kind != 'compound':
Expand All @@ -190,8 +179,8 @@ def reset_region(self):
bbox.x1, bbox.y1, bbox.x2, bbox.y2 = (x - self.dx, y - self.dy,
x + self.dx, y + self.dy)

self.regions.set_bbox(bbox.x1, bbox.y1,
bbox.x2, bbox.y2, coord='data')
self.region.set_bbox(bbox.x1, bbox.y1,
bbox.x2, bbox.y2, coord='data')

self.redo()

Expand Down
Loading