Package astLib :: Module astPlots :: 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 or astImages.resampleToTanProjection, WCS coordinate axes can be plotted, with tick marks set appropriately for the image size. 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="sexagesimal", axesFontFamily="serif", axesFontSize=12.0, RATickSteps="auto", decTickSteps="auto", colorBar=False, interpolation="bilinear")
Makes an ImagePlot from the given image array and astWCS.
source code
 
draw(self)
Redraws the ImagePlot.
source code
 
addContourOverlay(self, contourImageData, contourWCS, tag, levels=["linear","min","max",5], width=1, color="white", smooth=0, highAccuracy=False)
Adds image data to the ImagePlot as a contour overlay.
source code
 
removeContourOverlay(self, tag)
Removes the contourOverlay from the ImagePlot corresponding to the tag.
source code
 
addPlotObjects(self, objRAs, objDecs, tag, 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, tag)
Removes the plotObjects from the ImagePlot corresponding to the tag.
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
 
addScaleBar(self, location, sizeArcSec, color="white", fontSize=12, width=20.0)
Adds a scale bar to the ImagePlot at the given location ('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', or 'NW').
source code
 
calcWCSAxisLabels(self, axesLabels="decimal")
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
dictionary
getTickSteps(self)
Chooses the appropriate WCS coordinate tick steps for the plot based on its size.
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="sexagesimal", axesFontFamily="serif", axesFontSize=12.0, RATickSteps="auto", decTickSteps="auto", colorBar=False, interpolation="bilinear")
(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, or astImages.resampleToTanProjection).

If imageData is given as a list in the format [r, g, b], a 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. If RATickSteps or decTickSteps are set to "auto", the appropriate axis scales will be determined automatically from the size of the image array and associated WCS. The tick step sizes can be overidden. If the coordinate axes are in sexagesimal format a dictionary in the format {'deg', 'unit'} is needed (see RA_TICK_STEPS and DEC_TICK_STEPS for examples). If the coordinate axes are in decimal format, the tick step size is specified simply in RA, dec decimal degrees.

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)
  • 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.
  • interpolation (string) - interpolation to apply to the image plot (see the documentation for the matplotlib.pylab.imshow command)

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

source code 

Adds image data to the ImagePlot as a contour overlay. The contours can be removed using removeContourOverlay. If a contour overlay already exists with this tag, 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
  • tag (string) - identifying tag 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] - can use "min", "max" to automatically set min, max levels from image data
    • log spacing: contourLevels=['log', min level value, max level value, number of levels] - can use "min", "max" to automatically set min, max levels from image data
  • 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 arcsec) of Gaussian filter for pre-smoothing of contour image data (set to 0 for no smoothing)
  • highAccuracy (bool) - if True, sample every corresponding pixel in each image; otherwise, sample every nth pixel, where n = the ratio of the image scales.

removeContourOverlay(self, tag)

source code 

Removes the contourOverlay from the ImagePlot corresponding to the tag.

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

addPlotObjects(self, objRAs, objDecs, tag, 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. 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"
  • "diamond"

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 tag, 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
  • tag (string) - identifying tag for this set of objects
  • symbol (string) - either "circle", "box", "cross", or "diamond"
  • 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, tag)

source code 

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

Parameters:
  • tag (string) - tag 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

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

source code 

Adds a scale bar 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) - scale length to indicate 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 arrow used to mark scale

calcWCSAxisLabels(self, axesLabels="decimal")

source code 

This function calculates the positions of coordinate labels for the RA and Dec axes of the ImagePlot. The tick steps are calculated automatically unless self.RATickSteps, self.decTickSteps are set to values other than "auto" (see ImagePlot.__init__).

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

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

getTickSteps(self)

source code 

Chooses the appropriate WCS coordinate tick steps for the plot based on its size. Whether the ticks are decimal or sexagesimal is set by self.axesLabels.

Note: minor ticks not used at the moment.

Returns: dictionary
tick step sizes for major, minor plot ticks, in format {'major', 'minor'}