ImageWidget

class astrowidgets.ImageWidget(**kwargs: Any)[source]

Bases: VBox

Image widget for Jupyter notebook using Ginga viewer.

Parameters:
loggerobj 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_heightint

Dimension of Jupyter notebook’s image widget.

use_opencvbool

Let Ginga use opencv to speed up image transformation; e.g., rotation and mosaic. If this is enabled and you do not have opencv, you will get a warning.

pixel_coords_offsetint, 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.

Public constructor

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_by(dx, dy)

Move the center to a point that is given offset away from the current center.

offset_to(dx, dy[, skycoord_offset])

Deprecated since version 0.3.

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 from autocut_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 affect add_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:
tableTable

Table containing marker locations.

x_colname, y_colnamestr

Column names for X and Y. Coordinates can be 0- or 1-indexed, as given by self.pixel_offset.

skycoord_colnamestr

Column name with SkyCoord objects.

use_skycoordbool

If True, use skycoord_colname to mark. Otherwise, use x_colname and y_colname.

marker_namestr, optional

Name to assign the markers in the table. Providing a name allows markers to be removed by name at a later time.

center_on(point)[source]

Centers the view on a particular point.

Parameters:
pointtuple or SkyCoord

If tuple of (X, Y) is given, it is assumed to be in data coordinates.

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_colnamestr

Column names for X and Y data coordinates. Coordinates returned are 0- or 1-indexed, depending on self.pixel_offset.

skycoord_colnamestr

Column name for SkyCoord, which contains sky coordinates associated with the active image. This is ignored if image has no WCS.

Returns:
markers_tableTable or None

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:
arrarray-like

2D array.

load_fits(fitsorfn, numhdu=None, memmap=None)[source]

Load a FITS file into the viewer.

Parameters:
fitsorfnstr 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.

numhduint or None

Extension number of the desired HDU. If None, it is determined automatically.

memmapbool or None

Memory mapping. If None, it is determined automatically.

load_nddata(nddata)[source]

Load an NDData object into the viewer.

Parameters:
nddataNDData

NDData with image data and WCS.

offset_by(dx, dy)[source]

Move the center to a point that is given offset away from the current center.

Parameters:
dx, dyfloat or Quantity

Offset value. Without a unit, assumed to be pixel offsets. If a unit is attached, offset by pixel or sky is assumed from the unit.

offset_to(dx, dy, skycoord_offset=False)[source]

Deprecated since version 0.3: The offset_to function is deprecated and may be removed in a future version. Use offset_by instead.

Move the center to a point that is given offset away from the current center.

Note

This is deprecated. Use offset_by().

Parameters:
dx, dyfloat

Offset value. Unit is assumed based on skycoord_offset.

skycoord_offsetbool

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_namestr, optional

Name used when the markers were added.

reset_markers()[source]

Delete all markers.

save(filename)[source]

Save out the current image view to given PNG filename.

set_colormap(cmap)[source]

Set colormap to the given colormap name.

Parameters:
cmapstr

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_markersbool, optional

If clear_markers is False, existing markers are retained until reset_markers() is called. Otherwise, they are erased.

zoom(val)[source]

Zoom in or out by the given factor.

Parameters:
valint

The zoom level to zoom the image. See zoom_level.