Package astLib :: Module astImages
[hide private]
[frames] | no frames]

Module astImages

source code

module for simple .fits image tasks (rotation, clipping out sections, making .pngs etc.)

(c) 2007, 2008 Matt Hilton

http://astlib.sourceforge.net

Some routines in this module will fail if, e.g., asked to clip a section from a .fits image at a position not found within the image (as determined using the WCS). Where this occurs, the function will return None. An error message will be printed to the console when this happens if astImages.REPORT_ERRORS=True (the default). Testing if an astImages function returns None can be used to handle errors in scripts.

Functions [hide private]
dictionary
clipImageSectionWCS(imageData, imageWCS, RADeg, decDeg, clipSizeDeg, returnWCS=True)
Clips a square section from an image array at the given celestial coordinates.
source code
numpy array
clipImageSectionPix(imageData, XCoord, YCoord, clipSizePix)
Clips a square section from an image array at the given pixel coordinates.
source code
numpy array
clipRotatedImageSectionWCS(imageData, imageWCS, RADeg, decDeg, clipSizeDeg, returnWCS=True)
Clips a square section from an image array at the given celestial coordinates.
source code
dictionary
intensityCutImage(imageData, cutLevels)
Creates a matplotlib.pylab plot of an image array with the specified cuts in intensity applied.
source code
 
generateContourOverlay(backgroundImageData, contourImageData, contourLevels, contourSmoothFactor=0)
Rescales an image array to be used as a contour overlay to have the same dimensions as the background image, and generates a set of contour levels suitable for plotting by e.g.
source code
 
saveBitmap(outputFileName, imageData, cutLevels, size, colorMapName)
Makes a bitmap image from an image array; the image format is specified by the filename extension.
source code
 
saveContourOverlayBitmap(outputFileName, backgroundImageData, cutLevels, size, colorMapName, contourImageData, contourSmoothFactor, contourLevels, contourColor, contourWidth)
Makes a bitmap image from an image array, with a set of contours generated from a second image array overlaid.
source code
 
saveFITS(outputFileName, imageData, imageWCS=None)
Writes an image array to a new .fits file.
source code
numpy array
histEq(inputArray, numBins)
Performs histogram equalisation of the input numpy array.
source code
Variables [hide private]
  REPORT_ERRORS = True
Function Details [hide private]

clipImageSectionWCS(imageData, imageWCS, RADeg, decDeg, clipSizeDeg, returnWCS=True)

source code 
Clips a square section from an image array at the given celestial coordinates. An updated WCS for the clipped section is optionally returned.
Parameters:
  • imageData (numpy array) - image data array
  • imageWCS (astWCS.WCS) - astWCS.WCS object
  • RADeg (float) - coordinate in decimal degrees
  • decDeg (float) - coordinate in decimal degrees
  • clipSizeDeg (float) - size of square clipped section in decimal degrees
  • returnWCS (bool) - if True, return an updated WCS for the clipped section
Returns: dictionary
clipped image section (numpy array), updated astWCS WCS object for clipped image section, in format {'clippedData', 'clippedWCS'}.

clipImageSectionPix(imageData, XCoord, YCoord, clipSizePix)

source code 
Clips a square section from an image array at the given pixel coordinates.
Parameters:
  • imageData (numpy array) - image data array
  • XCoord (float) - coordinate in pixel degrees
  • YCoord (float) - coordinate in pixel degrees
  • clipSizePix (float) - size of square clipped section in pixels
Returns: numpy array
clipped image section

clipRotatedImageSectionWCS(imageData, imageWCS, RADeg, decDeg, clipSizeDeg, returnWCS=True)

source code 
Clips a square section from an image array at the given celestial coordinates. The resulting clip is rotated and/or flipped such that North is at the top, and East appears at the left. An updated WCS for the clipped section is also returned.
Parameters:
  • imageData (numpy array) - image data array
  • imageWCS (astWCS.WCS) - astWCS.WCS object
  • RADeg (float) - coordinate in decimal degrees
  • decDeg (float) - coordinate in decimal degrees
  • clipSizeDeg (float) - size of square clipped section in decimal degrees
Returns: numpy array
clipped image section (numpy array), updated astWCS WCS object for clipped image section, in format {'clippedData', 'clippedWCS'}.

Note: Returns 'None' if the requested position is not found within the image. If the image WCS does not have keywords of the form CD1_1 etc., the output WCS not be rotated.

intensityCutImage(imageData, cutLevels)

source code 
Creates a matplotlib.pylab plot of an image array with the specified cuts in intensity applied. This routine is used by saveBitmap and saveContourOverlayBitmap, which both produce output as .png, .jpg, etc. images.
Parameters:
  • imageData (numpy array) - image data array
  • 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.
Returns: dictionary
image section (numpy.array), matplotlib image normalisation (matplotlib.colors.Normalize), in the format {'image', 'norm'}.

Note: If cutLevels[0] == "histEq", then only {'image'} is returned.

generateContourOverlay(backgroundImageData, contourImageData, contourLevels, contourSmoothFactor=0)

source code 
Rescales an image array to be used as a contour overlay to have the same dimensions as the background image, and generates a set of contour levels suitable for plotting by e.g. saveContourOverlayBitmap. The image array from which the contours are to be generated can optionally be pre-smoothed using a Gaussian filter.
Parameters:
  • backgroundImageData (numpy array) - background image data array
  • contourImageData (numpy array) - image data array from which contours are to be generated
  • contourLevels (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]
    For linear and log spacing, the minimum contour level can either be set explicitly or have one of the following special values:
    • 'min': sets the minimum level automatically to the minimum value in contourImageData
    • ['mean', x]: sets the minimum level to x*the mean value of contourImageData
    • ['median', x]: sets the minimum level to x*the median value of contourImageData
    • ['mode', x]: sets the minimum level x*the mode value of the contourImageData (note that the mode is estimated using mode=3*median-2*mode: if mode<0 and log scaling is set, defaults to using x*median as the minimum contour level.)
    Likewise, the maximum contour level can either be set explicitly or have the following special value:
    • 'max': sets the maximum level automatically to the maximum value of contourImageData
  • contourSmoothFactor (float) - standard deviation (in pixels) of Gaussian filter for pre-smoothing of contour image data (set to 0 for no smoothing)

saveBitmap(outputFileName, imageData, cutLevels, size, colorMapName)

source code 
Makes a bitmap image from an image array; the image format is specified by the filename extension. (e.g. ".jpg" =JPEG, ".png"=PNG).
Parameters:
  • outputFileName (string) - filename of output bitmap image
  • imageData (numpy array) - image data array
  • 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.
  • size (int) - size of output image in pixels
  • 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)

saveContourOverlayBitmap(outputFileName, backgroundImageData, cutLevels, size, colorMapName, contourImageData, contourSmoothFactor, contourLevels, contourColor, contourWidth)

source code 
Makes a bitmap image from an image array, with a set of contours generated from a second image array overlaid. The image format is specified by the file extension (e.g. ".jpg"=JPEG, ".png"=PNG). The image array from which the contours are to be generated can optionally be pre-smoothed using a Gaussian filter.
Parameters:
  • outputFileName (string) - filename of output bitmap image
  • backgroundImageData (numpy array) - background image data array
  • 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.
  • size (int) - size of output image in pixels
  • 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)
  • contourImageData (numpy array) - image data array from which contours are to be generated
  • contourSmoothFactor (float) - standard deviation (in pixels) of Gaussian filter for pre-smoothing of contour image data (set to 0 for no smoothing)
  • contourLevels (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]
    For linear and log spacing, the minimum contour level can either be set explicitly or have one of the following special values:
    • 'min': sets the minimum level automatically to the minimum value in contourImageData
    • ['mean', x]: sets the minimum level to x*the mean value of contourImageData
    • ['median', x]: sets the minimum level to x*the median value of contourImageData
    • ['mode', x]: sets the minimum level x*the mode value of the contourImageData (note that the mode is estimated using mode=3*median-2*mode: if mode<0 and log scaling is set, defaults to using x*median as the minimum contour level.)
    Likewise, the maximum contour level can either be set explicitly or have the following special value:
    • 'max': sets the maximum level automatically to the maximum value of contourImageData
  • contourColor (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)
  • contourWidth (int) - width of the overlaid contours

saveFITS(outputFileName, imageData, imageWCS=None)

source code 
Writes an image array to a new .fits file.
Parameters:
  • outputFileName (string) - filename of output FITS image
  • imageData (numpy array) - image data array
  • imageWCS (astWCS.WCS object) - image WCS object

Note: If imageWCS=None, the FITS image will be written with a rudimentary header containing no meta data.

histEq(inputArray, numBins)

source code 
Performs histogram equalisation of the input numpy array.
Parameters:
  • inputArray (numpy array) - image data array
  • numBins (int) - number of bins in which to perform the operation (e.g. 1024)
Returns: numpy array
image data array