ImageWidget¶
-
class
astrowidgets.
ImageWidget
(logger=None, image_width=500, image_height=500, use_opencv=True, pixel_coords_offset=0)[source]¶ Bases:
ipywidgets.widgets.widget_box.VBox
Image widget for Jupyter notebook using Ginga viewer.
Parameters: - logger : obj or
None
Ginga logger. For example:
from ginga.misc.log import get_logger logger = get_logger('my_viewer', log_stderr=False, log_file='ginga.log', level=40)
- image_width, image_height : int
Dimension of Jupyter notebook’s image widget.
- use_opencv : bool
Let Ginga use
opencv
to speed up image transformation; e.g., rotation and mosaic. If this is enabled and you do not haveopencv
, you will get a warning.- pixel_coords_offset : int, optional
An offset, typically either 0 or 1, to add/subtract to all pixel values when going to/from the displayed image. In almost all situations the default value, ``0``, is the correct value to use.
Attributes Summary
autocut_options
List all available options for image auto-cut. click_center
Settable. click_drag
Settable. colormap_options
List of colormap names. cursor
Show or hide cursor information (X, Y, WCS). cuts
Current image cut levels. image_height
image_width
is_marking
True
if in marking mode,False
otherwise.logger
Logger for this widget. marker
Marker to use. pixel_offset
An offset, typically either 0 or 1, to add/subtract to all pixel values when going to/from the displayed image. scroll_pan
Settable. stretch
The image stretching algorithm in use. stretch_options
List all available options for image stretching. zoom_level
Zoom level: Methods Summary
add_markers
(table[, x_colname, y_colname, …])Creates markers in the image at given points. center_on
(point)Centers the view on a particular point. get_markers
([x_colname, y_colname, …])Return the locations of existing markers. load_array
(arr)Load a 2D array into the viewer. load_fits
(fitsorfn[, numhdu, memmap])Load a FITS file into the viewer. load_nddata
(nddata)Load an NDData
object into the viewer.offset_to
(dx, dy[, skycoord_offset])Move the center to a point that is given offset away from the current center. remove_markers
([marker_name])Remove some but not all of the markers by name used when adding the markers reset_markers
()Delete all markers. save
(filename)Save out the current image view to given PNG filename. set_colormap
(cmap)Set colormap to the given colormap name. start_marking
([marker_name, marker])Start marking, with option to name this set of markers or to specify the marker style. stop_marking
([clear_markers])Stop marking mode, with option to clear markers, if desired. zoom
(val)Zoom in or out by the given factor. Attributes Documentation
-
autocut_options
¶ List all available options for image auto-cut.
-
click_center
¶ Settable. If True, middle-clicking can be used to center. If False, that interaction is disabled.
In the future this might go from True/False to being a selectable button. But not for the first round.
-
click_drag
¶ Settable. If True, the “click-and-drag” mode is an available interaction for panning. If False, it is not.
Note that this should be automatically made
False
when selection mode is activated.
-
colormap_options
¶ List of colormap names.
-
cursor
¶ Show or hide cursor information (X, Y, WCS). Acceptable values are ‘top’, ‘bottom’, or
None
.
-
cuts
¶ Current image cut levels. To set new cut levels, either provide a tuple of
(low, high)
values or one of the options fromautocut_options
.
-
image_height
¶
-
image_width
¶
-
is_marking
¶ True
if in marking mode,False
otherwise. Marking mode means a mouse click adds a new marker. This does not affectadd_markers()
.
-
logger
¶ Logger for this widget.
-
marker
¶ Marker to use.
Marker can be set as follows:
{'type': 'circle', 'color': 'cyan', 'radius': 20} {'type': 'cross', 'color': 'green', 'radius': 20} {'type': 'plus', 'color': 'red', 'radius': 20}
-
pixel_offset
¶ An offset, typically either 0 or 1, to add/subtract to all pixel values when going to/from the displayed image. In almost all situations the default value, ``0``, is the correct value to use.
This value cannot be modified after initialization.
-
scroll_pan
¶ Settable. If True, scrolling moves around in the image. If False, scrolling (up/down) zooms the image in and out.
-
stretch
¶ The image stretching algorithm in use.
-
stretch_options
¶ List all available options for image stretching.
-
zoom_level
¶ Zoom level:
- 1 means real-pixel-size.
- 2 means zoomed in by a factor of 2.
- 0.5 means zoomed out by a factor of 2.
Methods Documentation
-
add_markers
(table, x_colname='x', y_colname='y', skycoord_colname='coord', use_skycoord=False, marker_name=None)[source]¶ Creates markers in the image at given points.
Parameters: - table :
Table
Table containing marker locations.
- x_colname, y_colname : str
Column names for X and Y. Coordinates can be 0- or 1-indexed, as given by
self.pixel_offset
.- skycoord_colname : str
Column name with
SkyCoord
objects.- use_skycoord : bool
If
True
, useskycoord_colname
to mark. Otherwise, usex_colname
andy_colname
.- marker_name : str, optional
Name to assign the markers in the table. Providing a name allows markers to be removed by name at a later time.
- table :
-
center_on
(point)[source]¶ Centers the view on a particular point.
Parameters: - point : tuple or
SkyCoord
If tuple of
(X, Y)
is given, it is assumed to be in data coordinates.
- point : tuple or
-
get_markers
(x_colname='x', y_colname='y', skycoord_colname='coord', marker_name=None)[source]¶ Return the locations of existing markers.
Parameters: - x_colname, y_colname : str
Column names for X and Y data coordinates. Coordinates returned are 0- or 1-indexed, depending on
self.pixel_offset
.- skycoord_colname : str
Column name for
SkyCoord
, which contains sky coordinates associated with the active image. This is ignored if image has no WCS.
Returns: - markers_table :
Table
orNone
Table of markers, if any, or
None
.
-
load_array
(arr)[source]¶ Load a 2D array into the viewer.
Note
Use
load_nddata()
for WCS support.Parameters: - arr : array-like
2D array.
-
load_fits
(fitsorfn, numhdu=None, memmap=None)[source]¶ Load a FITS file into the viewer.
Parameters: - fitsorfn : str or HDU
Either a file name or an HDU (not an HDUList). If file name is given, WCS in primary header is automatically inherited. If a single HDU is given, WCS must be in the HDU header.
- numhdu : int or
None
Extension number of the desired HDU. If
None
, it is determined automatically.- memmap : bool or
None
Memory mapping. If
None
, it is determined automatically.
-
load_nddata
(nddata)[source]¶ Load an
NDData
object into the viewer.Parameters: - nddata :
NDData
NDData
with image data and WCS.
- nddata :
-
offset_to
(dx, dy, skycoord_offset=False)[source]¶ Move the center to a point that is given offset away from the current center.
Parameters: - dx, dy : float
Offset value. Unit is assumed based on
skycoord_offset
.- skycoord_offset : bool
If
True
, offset must be given in degrees. Otherwise, they are in pixel values.
-
remove_markers
(marker_name=None)[source]¶ Remove some but not all of the markers by name used when adding the markers
Parameters: - marker_name : str, optional
Name used when the markers were added.
-
set_colormap
(cmap)[source]¶ Set colormap to the given colormap name.
Parameters: - cmap : str
Colormap name. Possible values can be obtained from
colormap_options()
.
-
start_marking
(marker_name=None, marker=None)[source]¶ Start marking, with option to name this set of markers or to specify the marker style.
-
stop_marking
(clear_markers=False)[source]¶ Stop marking mode, with option to clear markers, if desired.
Parameters: - clear_markers : bool, optional
If
clear_markers
isFalse
, existing markers are retained untilreset_markers()
is called. Otherwise, they are erased.
-
zoom
(val)[source]¶ Zoom in or out by the given factor.
Parameters: - val : int
The zoom level to zoom the image. See
zoom_level
.
- logger : obj or