astLib :: astPlots :: ImagePlot :: Class ImagePlot
[hide private]
[frames] | no frames]

Class ImagePlot

source code

This class describes a matplotlib image plot containing an astronomical image with an associated WCS.

Objects within the image boundaries can be marked by passing their WCS coordinates to ImagePlot.addPlotObjects.

Other images can be overlaid using ImagePlot.addContourOverlay.

For images rotated with North at the top, East at the left (as can be done using astImages.clipRotatedImageSectionWCS), WCS coordinate axes can be plotted, with tic marks set appropriately for the image size (note that this may not currently be 100% reliable for sexagesimal coordinates). Otherwise, a compass can be plotted showing the directions of North and East in the image.

RGB images are also supported.

The plot can of course be tweaked further after creation using matplotlib/pylab commands.

Instance Methods [hide private]
 
__init__(self, imageData, imageWCS, axes=[0.1,0.1,0.8,0.8], cutLevels=["smart",99.5], colorMapName="gray", title=None, axesLabels="decimal", minorLabels=False, axesFontFamily="serif", axesFontSize=12.0, colorBar=False)
Makes an ImagePlot from the given image array and astWCS.
source code
 
draw(self)
Redraws the ImagePlot - this should be called after adding plot objects, compass, contours etc.
source code
 
addContourOverlay(self, contourImageData, contourWCS, label, levels=['linear','min','max',5], width=1, color="white", smooth=0)
Adds image data to the ImagePlot as a contour overlay.
source code
 
removeContourOverlay(self, label)
Removes the contourOverlay from the ImagePlot corresponding to the label.
source code
 
addPlotObjects(self, objRAs, objDecs, label, symbol="circle", size=4.0, width=1.0, color="yellow", objLabels=None, objLabelSize=12.0)
Add objects with RA, dec coords objRAs, objDecs to the ImagePlot.
source code
 
removePlotObjects(self, label)
Removes the plotObjects from the ImagePlot corresponding to the label.
source code
 
addCompass(self, location, sizeArcSec, color="white", fontSize=12, width=20.0)
Adds a compass to the ImagePlot at the given location ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', or 'NW').
source code
 
calcWCSAxisLabels(self, axesLabels="decimal", minorLabels=False)
This function calculates the positions of coordinate labels for the RA and Dec axes of the ImagePlot.
source code
 
save(self, fileName)
Saves the ImagePlot in any format that matplotlib can understand, as determined from the fileName extension.
source code
Method Details [hide private]

__init__(self, imageData, imageWCS, axes=[0.1,0.1,0.8,0.8], cutLevels=["smart",99.5], colorMapName="gray", title=None, axesLabels="decimal", minorLabels=False, axesFontFamily="serif", axesFontSize=12.0, colorBar=False)
(Constructor)

source code 

Makes an ImagePlot from the given image array and astWCS. For coordinate axes to work, the image and WCS should have been rotated such that East is at the left, North is at the top (see e.g. astImages.clipRotatedImageSectionWCS).

If imageData is given as a list in the format [r, g, b], an color RGB plot will be made. However, in this case the cutLevels must be specified manually for each component as a list - i.e. cutLevels = [[r min, r max], [g min, g max], [b min, b max]]. In this case of course, the colorMap will be ignored. All r, g, b image arrays must have the same dimensions.

Set axesLabels = None to make a plot without coordinate axes plotted.

The axes can be marked in either sexagesimal or decimal celestial coordinates: the appropriate axis scales will be determined automatically from the size of the image array and associated WCS.

Parameters:
  • imageData (numpy array or list) - image data array or list of numpy arrays [r, g, b]
  • imageWCS (astWCS.WCS) - astWCS.WCS object
  • axes (list) - specifies where in the current figure to draw the finder chart (see pylab.axes)
  • cutLevels (list) - sets the image scaling - available options:
    • pixel values: cutLevels=[low value, high value].
    • histogram equalisation: cutLevels=["histEq", number of bins ( e.g. 1024)]
    • relative: cutLevels=["relative", cut per cent level (e.g. 99.5)]
    • smart: cutLevels=["smart", cut per cent level (e.g. 99.5)]

    ["smart", 99.5] seems to provide good scaling over a range of different images. Note that for RGB images, cut levels must be specified manually i.e. as a list: [[r min, rmax], [g min, g max], [b min, b max]]

  • colorMapName (string) - name of a standard matplotlib colormap, e.g. "hot", "cool", "gray" etc. (do "help(pylab.colormaps)" in the Python interpreter to see available options)
  • title (string) - optional title for the plot
  • axesLabels (string) - either "sexagesimal" (for H:M:S, D:M:S), "decimal" (for decimal degrees) or None (for no coordinate axes labels)
  • minorLabels (bool) - if set to True, add additional labels between coordinate labels
  • axesFontFamily (string) - matplotlib fontfamily, e.g. 'serif', 'sans-serif' etc.
  • axesFontSize (float) - font size of axes labels and titles (in points)
  • colorBar (bool) - if True, plot a vertical color bar at the side of the image indicating the intensity scale.

addContourOverlay(self, contourImageData, contourWCS, label, levels=['linear','min','max',5], width=1, color="white", smooth=0)

source code 

Adds image data to the ImagePlot as a contour overlay. The contours will be plotted when ImagePlot.draw() is next called. The contours can be removed using removeContourOverlay If a contour overlay already exists with this label, it will be replaced.

Parameters:
  • contourImageData (numpy array) - image data array from which contours are to be generated
  • contourWCS (astWCS.WCS) - astWCS.WCS object for the image to be contoured
  • label (string) - identifying label for this set of contours
  • levels (list) - sets the contour levels - available options:
    • values: contourLevels=[list of values specifying each level]
    • linear spacing: contourLevels=['linear', min level value, max level value, number of levels]
    • log spacing: contourLevels=['log', min level value, max level value, number of levels]
  • width (int) - width of the overlaid contours
  • color (string) - color of the overlaid contours, specified by the name of a standard matplotlib color, e.g., "black", "white", "cyan" etc. (do "help(pylab.colors)" in the Python interpreter to see available options)
  • smooth (float) - standard deviation (in pixels) of Gaussian filter for pre-smoothing of contour image data (set to 0 for no smoothing)

removeContourOverlay(self, label)

source code 

Removes the contourOverlay from the ImagePlot corresponding to the label. The plot must be redrawn for the change to take effect.

Parameters:
  • label (string) - label for contour overlay in ImagePlot.contourOverlays to be removed

addPlotObjects(self, objRAs, objDecs, label, symbol="circle", size=4.0, width=1.0, color="yellow", objLabels=None, objLabelSize=12.0)

source code 

Add objects with RA, dec coords objRAs, objDecs to the ImagePlot. The objects will be plotted when ImagePlot.draw() is next called; only objects that fall within the image boundaries will be plotted.

symbol specifies the type of symbol with which to mark the object in the image. The following values are allowed:

  • "circle"
  • "box"
  • "cross"

size specifies the diameter in arcsec of the symbol (if plotSymbol == "circle"), or the width of the box in arcsec (if plotSymbol == "box")

width specifies the thickness of the symbol lines in pixels

color can be any valid matplotlib color (e.g. "red", "green", etc.)

The objects can be removed from the plot by using removePlotObjects(), and then calling draw(). If the ImagePlot already has a set of plotObjects with the same label, they will be replaced.

Parameters:
  • objRAs (numpy array or list) - object RA coords in decimal degrees
  • objDecs (numpy array or list) - corresponding object Dec. coords in decimal degrees
  • label (string) - identifying label for this set of objects
  • symbol (string) - either "circle" or "box"
  • size (float) - size of symbols to plot (radius in arcsec, or width of box)
  • width (float) - width of symbols in pixels
  • color (string) - any valid matplotlib color string, e.g. "red", "green" etc.
  • objLabels (list) - text labels to plot next to objects in figure
  • objLabelSize (float) - size of font used for object labels (in points)

removePlotObjects(self, label)

source code 

Removes the plotObjects from the ImagePlot corresponding to the label. The plot must be redrawn for the change to take effect.

Parameters:
  • label (string) - label for set of objects in ImagePlot.plotObjects to be removed

addCompass(self, location, sizeArcSec, color="white", fontSize=12, width=20.0)

source code 

Adds a compass to the ImagePlot at the given location ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', or 'NW'). Note these aren't directions on the WCS coordinate grid, they are relative positions on the plot - so N is top centre, NE is top right, SW is bottom right etc.. Alternatively, pixel coordinates (x, y) in the image can be given.

Parameters:
  • location (string or tuple) - location in the plot where the compass is drawn:
    • string: N, NE, E, SE, S, SW, W or NW
    • tuple: (x, y)
  • sizeArcSec (float) - length of the compass arrows on the plot in arc seconds
  • color (string) - any valid matplotlib color string
  • fontSize (float) - size of font used to label N and E, in points
  • width (float) - width of arrows used to mark compass

calcWCSAxisLabels(self, axesLabels="decimal", minorLabels=False)

source code 

This function calculates the positions of coordinate labels for the RA and Dec axes of the ImagePlot. The ImagePlot must be redrawn for changes to be applied.

Parameters:
  • axesLabels (string) - either "sexagesimal" (for H:M:S, D:M:S), "decimal" (for decimal degrees), or None for no coordinate axes labels
  • minorLabels (bool) - if set to True, add additional labels between coordinate labels

save(self, fileName)

source code 

Saves the ImagePlot in any format that matplotlib can understand, as determined from the fileName extension.

Parameters:
  • fileName (string) - path where plot will be written