jsky.image.fits.codec
Class FITSImage

java.lang.Object
  extended by jsky.image.SimpleRenderedImage
      extended by jsky.image.fits.codec.FITSImage
All Implemented Interfaces:
java.awt.image.RenderedImage

public class FITSImage
extends SimpleRenderedImage

This is the core class for JAI FITS support. It handles the conversion between the FITS image data and the display data.

This class defines a number of properties that can be accessed by applications via the getProperty method.

The value of the property "#fits_image" returns the FITSImage object managing the image data.

The value of the property "#num_pages" returns an Integer with the number of HDUs (FITS header/data units).

The "#preview_image" property returns a preshrunk preview image suitable for use in a pan window. The size of the preview image may be set by calling the static method FITSImage.setPreviewSize(int).

Version:
$Revision: 1.2 $
Author:
Allan Brighton

Field Summary
 
Fields inherited from class jsky.image.SimpleRenderedImage
colorModel, height, minX, minY, properties, sampleModel, sources, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, width
 
Constructor Summary
FITSImage(nom.tam.fits.Fits fits, FITSDecodeParam param, int page)
          Create a FITSImage from an already existing Fits object.
FITSImage(java.lang.Object ar)
          Create a FITSImage from a primitive array of data.
FITSImage(com.sun.media.jai.codec.SeekableStream input, FITSDecodeParam param, int page)
          Construct a FITSImage.
FITSImage(java.lang.String fileOrUrl)
          Construct a FITSImage from an image file or URL.
 
Method Summary
 void clearTileCache()
          Try to save memory by clearing out the tile cache
 void close()
          Close the FITS input stream.
 java.nio.MappedByteBuffer getByteBuffer()
          Return the memory mapped to the image data, if the FITS input is from a BufferedFile, otherwise null.
 int getCurrentHDUIndex()
          Return the index of the current image HDU
static int getDefaultTileHeight()
           
static int getDefaultTileWidth()
           
 nom.tam.fits.Fits getFits()
          Return the internal Fits object used to manage the image
 nom.tam.fits.BasicHDU getHDU(int num)
          Return the given HDU or null if it can not be accessed.
 nom.tam.fits.Header getHeader()
          Return the FITS header object
 nom.tam.image.ImageTiler getImageTiler()
          Return the object used to access FITS data tiles (used only if MappedByteBuffer can't be used)
 java.lang.String getKeywordComment(java.lang.String name)
          Return the comment for the given FITS keyword from the FITS header, or null if not found.
 java.lang.String[] getKeywords()
          Returns a list of FITS keywords for this image.
 java.lang.Object getKeywordValue(java.lang.String name)
          Return the value of the given FITS keyword from the FITS header, or null if not found.
 double getKeywordValue(java.lang.String name, double defaultValue)
          Return the value of the given FITS keyword as a double, or the given default value, if not found.
 float getKeywordValue(java.lang.String name, float defaultValue)
          Return the value of the given FITS keyword as a float, or the given default value, if not found.
 int getKeywordValue(java.lang.String name, int defaultValue)
          Return the value of the given FITS keyword as an integer, or the given default value, if not found.
 java.lang.String getKeywordValue(java.lang.String name, java.lang.String defaultValue)
          Return the value of the given FITS keyword as a string, or the given default value, if not found.
 int getNAXIS()
          Return the number of axes
 int getNumHDUs()
          Return the number of FITS HDUs in the current image.
static int getPreviewSize()
          Return the requested size for the preview image
 java.lang.Object getProperty(java.lang.String name)
          Gets a property from the property set of this image.
 java.lang.String[] getPropertyNames()
          Returns a list of property names that are recognized by this image.
 int getRealHeight()
          Returns the real height of the image.
 int getRealWidth()
          Returns the real width of the image.
 float getScale()
          Return the current scale factor (zooming out is handled here for performance reasons).
 int getSubsample()
          Return the increment to use when accessing the image data if _scale is less than 1.
 java.awt.image.Raster getTile(int tileX, int tileY)
          Generate and return the given tile (required by the RenderedImage interface).
 boolean isEmpty()
          Return true if the image is empty (such as the primary extension)
 boolean isYFlipped()
          Return true if the Y axis of the image data tiles returned by this class is flipped (for performance reasons, so it doesn't have to be done afterwards).
static void setDefaultTileHeight(int h)
           
static void setDefaultTileWidth(int w)
           
 void setHDU(int num)
          Move to the given HDU.
static void setPreviewSize(int i)
          Set the requested size for the preview image
 boolean setScale(float scale)
          Set the scale (zoom factor) for the image and return true if a new image was generated.
 void update()
          This method should be called after adding a new HDU.
 
Methods inherited from class jsky.image.SimpleRenderedImage
copyData, getBounds, getColorModel, getData, getData, getHeight, getMaxTileX, getMaxTileY, getMaxX, getMaxY, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getPropertyNames, getSampleModel, getSources, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, tileXToX, tileXToX, tileYToY, tileYToY, XToTileX, XToTileX, YToTileY, YToTileY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FITSImage

public FITSImage(com.sun.media.jai.codec.SeekableStream input,
                 FITSDecodeParam param,
                 int page)
          throws java.io.IOException,
                 nom.tam.fits.FitsException
Construct a FITSImage.

Parameters:
input - the SeekableStream for the FITS file.
param - the parameter passed to the JAI create method
page - specifies the desired image extension (default: 0, for the primary extension)
Throws:
java.io.IOException
nom.tam.fits.FitsException

FITSImage

public FITSImage(java.lang.String fileOrUrl)
          throws java.io.IOException,
                 nom.tam.fits.FitsException
Construct a FITSImage from an image file or URL.

Parameters:
fileOrUrl - the file name or URL
Throws:
java.io.IOException
nom.tam.fits.FitsException

FITSImage

public FITSImage(nom.tam.fits.Fits fits,
                 FITSDecodeParam param,
                 int page)
          throws java.io.IOException,
                 nom.tam.fits.FitsException
Create a FITSImage from an already existing Fits object.

Parameters:
fits - object managing the FITS file
param - the parameter passed to the JAI create method
page - specifies the desired image extension (default: 0, for the primary extension)
Throws:
java.io.IOException
nom.tam.fits.FitsException

FITSImage

public FITSImage(java.lang.Object ar)
          throws java.io.IOException,
                 nom.tam.fits.FitsException
Create a FITSImage from a primitive array of data.

Parameters:
ar - a 2D array of a primitive numeric type (doubles not supported yet)
Throws:
java.io.IOException
nom.tam.fits.FitsException
Method Detail

getCurrentHDUIndex

public int getCurrentHDUIndex()
Return the index of the current image HDU


close

public void close()
Close the FITS input stream. After calling this method, this object should no longer be used.


getNumHDUs

public int getNumHDUs()
Return the number of FITS HDUs in the current image.


getFits

public nom.tam.fits.Fits getFits()
Return the internal Fits object used to manage the image


getHDU

public nom.tam.fits.BasicHDU getHDU(int num)
Return the given HDU or null if it can not be accessed.


update

public void update()
This method should be called after adding a new HDU.


setHDU

public void setHDU(int num)
            throws java.io.IOException,
                   nom.tam.fits.FitsException
Move to the given HDU.

Parameters:
num - The HDU number (0 is the primary HDU).
Throws:
java.io.IOException
nom.tam.fits.FitsException

getRealWidth

public int getRealWidth()
Returns the real width of the image. This may be different than the value returned by getWidth() if the image is zoomed out.


getRealHeight

public int getRealHeight()
Returns the real height of the image. This may be different than the value returned by getHeight() if the image is zoomed out.


getNAXIS

public int getNAXIS()
Return the number of axes


getImageTiler

public nom.tam.image.ImageTiler getImageTiler()
Return the object used to access FITS data tiles (used only if MappedByteBuffer can't be used)


isEmpty

public boolean isEmpty()
Return true if the image is empty (such as the primary extension)


getScale

public float getScale()
Return the current scale factor (zooming out is handled here for performance reasons). Zooming in still needs to be done by the image widget.


getSubsample

public int getSubsample()
Return the increment to use when accessing the image data if _scale is less than 1. A value of 1 means no scaling is done.


getByteBuffer

public java.nio.MappedByteBuffer getByteBuffer()
Return the memory mapped to the image data, if the FITS input is from a BufferedFile, otherwise null. The FITSData classes then view this buffer as a FloatBuffer, ShortBuffer, etc.


setDefaultTileWidth

public static void setDefaultTileWidth(int w)

getDefaultTileWidth

public static int getDefaultTileWidth()

setDefaultTileHeight

public static void setDefaultTileHeight(int h)

getDefaultTileHeight

public static int getDefaultTileHeight()

clearTileCache

public void clearTileCache()
Try to save memory by clearing out the tile cache


getHeader

public nom.tam.fits.Header getHeader()
Return the FITS header object


getProperty

public java.lang.Object getProperty(java.lang.String name)
Gets a property from the property set of this image.

Specified by:
getProperty in interface java.awt.image.RenderedImage
Overrides:
getProperty in class SimpleRenderedImage
Parameters:
name - the name of the property to get, as a String.
Returns:
a reference to the property value or null if not found.

getPropertyNames

public java.lang.String[] getPropertyNames()
Returns a list of property names that are recognized by this image.

Specified by:
getPropertyNames in interface java.awt.image.RenderedImage
Overrides:
getPropertyNames in class SimpleRenderedImage
Returns:
an array of Strings containing valid property names.

getKeywordValue

public java.lang.Object getKeywordValue(java.lang.String name)
Return the value of the given FITS keyword from the FITS header, or null if not found.

Parameters:
name - a FITS keyword
Returns:
the value for the given keyword, or null if not found.

getKeywordComment

public java.lang.String getKeywordComment(java.lang.String name)
Return the comment for the given FITS keyword from the FITS header, or null if not found.

Parameters:
name - a FITS keyword
Returns:
the comment string, or an empty string if not found.

getKeywordValue

public java.lang.String getKeywordValue(java.lang.String name,
                                        java.lang.String defaultValue)
Return the value of the given FITS keyword as a string, or the given default value, if not found.

Parameters:
name - a FITS keyword
defaultValue - the value to return if the keyword is not found
Returns:
the string value for the given keyword

getKeywordValue

public int getKeywordValue(java.lang.String name,
                           int defaultValue)
Return the value of the given FITS keyword as an integer, or the given default value, if not found.

Parameters:
name - a FITS keyword
defaultValue - the value to return if the keyword is not found
Returns:
the integer value for the given keyword

getKeywordValue

public double getKeywordValue(java.lang.String name,
                              double defaultValue)
Return the value of the given FITS keyword as a double, or the given default value, if not found.

Parameters:
name - a FITS keyword
defaultValue - the value to return if the keyword is not found
Returns:
the double value for the given keyword

getKeywordValue

public float getKeywordValue(java.lang.String name,
                             float defaultValue)
Return the value of the given FITS keyword as a float, or the given default value, if not found.

Parameters:
name - a FITS keyword
defaultValue - the value to return if the keyword is not found
Returns:
the float value for the given keyword

getKeywords

public java.lang.String[] getKeywords()
Returns a list of FITS keywords for this image.

Returns:
an array of Strings containing FITS keywords.

setScale

public boolean setScale(float scale)
                 throws java.io.IOException
Set the scale (zoom factor) for the image and return true if a new image was generated.

Note that zooming out is handled here for performance reasons, to avoid having to read in whole tiles, only to discard most of the data later. Zooming in should be handled in the image viewer widget at the end of the image processing chain.

Parameters:
scale - the scale factor (a value of less than 1.0 means the image is zoomed out and is handled specially here)
Returns:
true if the new scale value caused a new image to be generated, requiring an image update in the viewer widget
Throws:
java.io.IOException

isYFlipped

public boolean isYFlipped()
Return true if the Y axis of the image data tiles returned by this class is flipped (for performance reasons, so it doesn't have to be done afterwards). If this method returns false, the image will normally be flipped before displaying.


getTile

public java.awt.image.Raster getTile(int tileX,
                                     int tileY)
Generate and return the given tile (required by the RenderedImage interface). Note that tileX and tileY are indices into the tile array, not pixel locations.

Parameters:
tileX - the X index of the requested tile in the tile array.
tileY - the Y index of the requested tile in the tile array.
Returns:
the tile given by (tileX, tileY).

setPreviewSize

public static void setPreviewSize(int i)
Set the requested size for the preview image


getPreviewSize

public static int getPreviewSize()
Return the requested size for the preview image