Imviz

class jdaviz.configs.imviz.Imviz(*args, **kwargs)[source] [edit on github]

Bases: jdaviz.core.helpers.ConfigHelper

Imviz Helper class

Attributes Summary

autocut_options

List of all available options for automatic image cut levels.

colormap_options

List of colormap names.

cuts

Current image cut levels.

marker

Marker to use.

stretch

The image stretching algorithm in use.

stretch_options

List of all available options for image stretching.

zoom_level

Zoom level:

Methods Summary

add_markers(table[, x_colname, y_colname, …])

Creates markers w.r.t.

center_on(point)

Centers the view on a particular point.

get_interactive_regions()

Return regions interactively drawn in the viewer.

load_data(data[, parser_reference])

Load data into Imviz.

load_static_regions(regions, **kwargs)

Load given region(s) into the viewer.

offset_by(dx, dy)

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.

zoom(val)

Zoom in or out by the given factor.

Attributes Documentation

autocut_options

List of all available options for automatic image cut levels.

colormap_options

List of colormap names.

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.

marker

Marker to use.

Marker can be set as follows; e.g.:

{'color': 'red', 'alpha': 1.0, 'markersize': 3}
{'color': '#ff0000', 'alpha': 0.5, 'markersize': 10}
{'color': (1, 0, 0)}

The valid properties for markers in imviz are listed at https://docs.glueviz.org/en/stable/api/glue.core.visual.VisualAttributes.html

stretch

The image stretching algorithm in use.

stretch_options

List of all available options for image stretching.

Their astropy.visualization counterparts are also accepted, as follows:

  • 'arcsinh': astropy.visualization.AsinhStretch

  • 'linear': astropy.visualization.LinearStretch

  • 'log': astropy.visualization.LogStretch

  • 'sqrt': astropy.visualization.SqrtStretch

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.

  • ‘fit’ means zoomed to fit the whole image width into display.

Methods Documentation

add_markers(table, x_colname='x', y_colname='y', skycoord_colname='coord', use_skycoord=False, marker_name=None)[source] [edit on github]

Creates markers w.r.t. the reference image at given points in the table.

Note

Use marker to change marker appearance.

Parameters
tableTable

Table containing marker locations.

x_colname, y_colnamestr

Column names for X and Y. Coordinates must be 0-indexed.

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.

Raises
AttributeError

Sky coordinates are given but reference image does not have a valid WCS.

ValueError

Invalid marker name.

center_on(point)[source] [edit on github]

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 and 0-indexed.

Raises
AttributeError

Sky coordinates are given but image does not have a valid WCS.

get_interactive_regions()[source] [edit on github]

Return regions interactively drawn in the viewer. This does not return regions added via load_static_regions().

Returns
regionsdict

Dictionary mapping interactive region names to respective Astropy regions objects.

load_data(data, parser_reference=None, **kwargs)[source] [edit on github]

Load data into Imviz.

Parameters
dataobj or str

File name or object to be loaded. Supported formats include:

  • 'filename.fits' (or any extension that astropy.io.fits supports; first image extension found is loaded unless ext keyword is also given)

  • 'filename.fits[SCI]' (loads only first SCI extension)

  • 'filename.fits[SCI,2]' (loads the second SCI extension)

  • 'filename.jpg' (requires scikit-image; grayscale only)

  • 'filename.png' (requires scikit-image; grayscale only)

  • JWST ASDF-in-FITS file (requires asdf and gwcs; data or given ext + GWCS)

  • astropy.io.fits.HDUList object (first image extension found is loaded unless ext keyword is also given)

  • astropy.io.fits.ImageHDU object

  • astropy.nddata.NDData object (2D only but may have unit, mask, or uncertainty attached)

  • Numpy array (2D only)

parser_reference

This is used internally by the app.

kwargsdict

Extra keywords to be passed into app-level parser. The only one you might call directly here is ext (any FITS extension format supported by astropy.io.fits) and show_in_viewer (bool).

Notes

When loading image formats that support RGB color like JPG or PNG, the files are converted to greyscale. This is done following the algorithm of skimage.color.rgb2grey, which involves weighting the channels as 0.2125 R + 0.7154 G + 0.0721 B. If you prefer a different weighting, you can use skimage.io.imread to produce your own greyscale image as Numpy array and load the latter instead.

load_static_regions(regions, **kwargs)[source] [edit on github]

Load given region(s) into the viewer. Region(s) is relative to the reference image. Once loaded, the region(s) cannot be modified.

Parameters
regionsdict

Dictionary mapping desired region name to one of the following:

  • Astropy regions object

  • photutils apertures (limited support until photutils fully supports regions)

  • Numpy boolean array (shape must match data)

Region name that starts with “Subset” is forbidden and reserved for internal use only.

kwargsdict

Extra keywords to be passed into the region’s to_mask method. This is ignored if Numpy array is given.

offset_by(dx, dy)[source] [edit on github]

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.

Raises
AttributeError

Sky offset is given but image does not have a valid WCS.

ValueError

Offsets are of different types.

astropy.units.core.UnitTypeError

Sky offset has invalid unit.

remove_markers(marker_name=None)[source] [edit on github]

Remove some but not all of the markers by name used when adding the markers.

Parameters
marker_namestr

Name used when the markers were added. If not given, will delete markers added under default name.

reset_markers()[source] [edit on github]

Delete all markers.

save(filename)[source] [edit on github]

Save out the current image view to given PNG filename.

set_colormap(cmap)[source] [edit on github]

Set colormap to the given colormap name.

Parameters
cmapstr

Colormap name. Possible values can be obtained from colormap_options().

Raises
ValueError

Invalid colormap name.

zoom(val)[source] [edit on github]

Zoom in or out by the given factor.

Parameters
valint or float

The zoom level to zoom the image. See zoom_level.

Raises
ValueError

Invalid zoom factor.