astro.fits
Class FitsTools

java.lang.Object
  extended by astro.fits.FitsTools

public class FitsTools
extends Object

Some tools in dealing with FITS images.


Nested Class Summary
static class FitsTools.Binning
          Flip according to the second and third command line argument
static class FitsTools.Clip
          Reads the four extensions of an WiFSIP image, does clipping, flipping and tiling to produce a single output fits.
static class FitsTools.ClipOne
          Reads one extensions of an WiFSIP image, does clipping to produce a single output fits.
static class FitsTools.Dump
          Dumps the pixel values to stdout.
static class FitsTools.E2V
          Reads the two extensions of an WiFSIP/Robotel image, does clipping, flipping and tiling to produce a single output fits.
static class FitsTools.Flag
          Constructs a flag map from a weight map in a way that only values above a certain trashhold are set to 0, others to 1.
static class FitsTools.Flip
          Flip according to the second and third command line argument
static class FitsTools.Histogram
          Dumps the historgram to stdout.
static class FitsTools.Limit
          Limits an image to ADU borders.
static class FitsTools.Pixel
          Take the pixel at the given coordinates and print its value.
static class FitsTools.SiraitV
          Transformas small IRAIT V-data.
static class FitsTools.Size
           
static class FitsTools.Split
          Splits a fits file given on the command line into its image hdu's, each image found saved to a fits file with a number indication at the end of the fits file name (extensionless).
static class FitsTools.Stitcher
          Full use control on how to stitch quadrants together.
static class FitsTools.Test
           
static class FitsTools.TestFits
          Generates a test fits file, whose pixel value is adu=256*y+x.
static class FitsTools.Weight
          Constructs a weight map from a normalized flat in a way that all values above a certain trashhold are set to a lower threshold.
static class FitsTools.Wifsip
          Reads the four extensions of an WiFSIP image, does clipping, flipping and tiling to produce a single output fits.
static class FitsTools.WifsipTime
          We read the comment to the simple keyword, extract the creation date out of it, parse it, subtract 34 seconds from it and write this as DATE-OBS to the header again.
 
Field Summary
static String DATEKEY
          The FITS key denoting the yyyy-mm-tt of the observing date.
static List<String> DATEKEYS
          A list of fits keys that might also indicate a date.
static String DATEOBSKEY
          The FITS key denoting the yyyy-mm-tt of the observing date.
static String FITSBITPIX
          The mandatory FITS key denoting the end of the header section.
static DateFormat FITSDATE
          The default formatter used for FITS-header dates.
static DateFormat FITSDATEMS
           
static String FITSEND
          The mandatory FITS key denoting the end of the header section.
static String FITSEXTENSION
          The extension for fits files.
static String FITSNAXIS
          The mandatory FITS key denoting the end of the header section.
static String FITSSCALE
          The FITS key denoting the scale of image data.
static String FITSSCALEREM
          The FITS key denoting the scale of image data.
static String FITSSIMPLE
          The mandatory FITS key denoting the end of the header section.
static String FITSXTENSION
          The mandatory FITS key denoting the end of the header section.
static String FITSZERO
          The FITS key denoting the zero point of image data.
static String FITSZEROREM
          The FITS key denoting the zero point of image data.
static String FITZEXTENSION
          The extension for compressed fits files.
static String TIMEKEY
          The FITS key denoting the HH:MM:ss of the observing date.
static String TIMEOBSKEY
          The FITS key denoting the HH:MM:ss of the observing date.
static String XBIN
          Fits key for entering x-bin info to header.
static String XORIGIN
          Fits key for entering x-pregap info to header.
static String XTENSIONIMAGE
          The recognized extensions is an image
static String YBIN
          Fits key for entering y-bin info to header.
static String YORIGIN
          Fits key for entering y-pregap info to header.
 
Constructor Summary
FitsTools()
           
 
Method Summary
static nom.tam.fits.ImageHDU bin(nom.tam.fits.ImageHDU l, int xbin, int ybin)
          Bins ADUs in an imageHDU to the given values.
static nom.tam.fits.ImageHDU cap(nom.tam.fits.ImageHDU l, double cap, double low)
          Caps ADUs in an imageHDU whose values are above a certain threshold to a lower one.
static nom.tam.fits.ImageData flag(nom.tam.fits.ImageHDU in, double trig)
          Extracts ADU's from an Image HDU and converts them to an integer flag map.
static nom.tam.fits.ImageHDU flip(nom.tam.fits.ImageHDU in, boolean xflip, boolean yflip)
          We take a source HDU and flip it according to the flip indicators, where a positive value means leave unchanged, while negative values change the direction.
static
<T extends nom.tam.fits.BasicHDU>
T
getHduOfType(nom.tam.fits.Fits fits, Class<T> type, boolean ignorenull)
          Reads a fits file until a HDU is discovered that is of the provided type.
static
<T extends nom.tam.fits.BasicHDU>
T
getHduOfType(nom.tam.fits.Fits fits, Class<T> type, boolean ignorenull, int skip)
          Reads a fits file until a HDU is discovered that is of the provided type.
static Number getRawValue(nom.tam.fits.Fits image, int x, int y)
          Scans an image hdu and retrieves the data there.
static Number getRawValue(nom.tam.fits.ImageHDU image, int x, int y)
          Scans an image hdu and retrieves the data there.
static List<Number> getRawWindow(nom.tam.fits.Fits file, Rectangle window)
          Extracts a window from an image hdu and returns non-scaled, raw, ADUs as a list of Numbers.
static List<Number> getRawWindow(nom.tam.fits.ImageHDU image, Rectangle window)
          Extracts a window from an image hdu and returns ADUs as a list of Numbers.
static Dimension getSize(nom.tam.fits.ImageHDU raw)
          Reads the header for the axes and returns a dimension object out of it, if image is two-dimensional.
static List<Number> getTrueFrame(nom.tam.fits.ImageHDU hdu, Rectangle active, int thick)
          Extracts a frame at the inside of the active window.
static Number getTrueValue(nom.tam.fits.Fits image, int x, int y)
          Scans an image hdu and retrieves the data there.
static Number getTrueValue(nom.tam.fits.ImageHDU image, int x, int y)
          Scans an image hdu and retrieves the data there.
static List<Number> getTrueWindow(nom.tam.fits.Fits file, Rectangle window)
          Extracts a window from an image hdu and returns zero-shifted and scaled ADUs as a list of Numbers.
static List<Number> getTrueWindow(nom.tam.fits.ImageHDU image, Rectangle window)
          Extracts a window from an image hdu and returns ADUs as a list of Numbers.
static nom.tam.fits.ImageHDU hilo(nom.tam.fits.ImageHDU l, double cap, double low)
          Caps ADUs in an imageHDU whose values are above a certain threshold to a lower one.
static nom.tam.fits.Fits limit(nom.tam.fits.Fits raw, double min, double max)
          Limits ADUs in an image to the given values.
static nom.tam.fits.ImageData limit(nom.tam.fits.ImageHDU l, double low, double hi)
          Limits ADUs in an imageHDU to the given values.
static boolean saveAs(nom.tam.fits.Fits src, File as)
          To overcome the crude logic behind saving a fits file, we can do this here more easily.
static boolean saveAs(nom.tam.fits.Fits src, String as)
          To overcome the crude logic behind saving a fits file, we can do this here more easily.
static nom.tam.fits.ImageHDU scalarMultiply(nom.tam.fits.ImageHDU in, double scale)
          Multiplies the image with the given scalar.
static nom.tam.fits.ImageHDU scalarOffset(nom.tam.fits.ImageHDU in, double offset)
          Multiplies the image with the given scalar.
static nom.tam.fits.ImageHDU stitch(nom.tam.fits.ImageHDU left, nom.tam.fits.ImageHDU right, boolean rowpatch)
          Composes an image from two tiles and returns the union of both in a new ImageHDU.
static nom.tam.fits.Fits transform(nom.tam.fits.Fits image, Function eval)
          Extracts ADU's from an Image HDU, transforms them according to the given function f(ADU), and constructs an Image HDU of likewise type.
static nom.tam.fits.ImageHDU transform(nom.tam.fits.ImageHDU in, Function eval)
          Extracts ADU's from an Image HDU, transforms them according to the given function f(ADU), and constructs an Image HDU of likewise type.
static nom.tam.fits.ImageHDU trim(nom.tam.fits.ImageHDU in, Rectangle active)
          We take a source image hdu and trim it to the given active area.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FITSEXTENSION

public static final String FITSEXTENSION
The extension for fits files.

See Also:
Constant Field Values

FITZEXTENSION

public static final String FITZEXTENSION
The extension for compressed fits files.

See Also:
Constant Field Values

FITSDATE

public static final DateFormat FITSDATE
The default formatter used for FITS-header dates.


FITSDATEMS

public static final DateFormat FITSDATEMS

FITSSIMPLE

public static final String FITSSIMPLE
The mandatory FITS key denoting the end of the header section.

See Also:
Constant Field Values

FITSXTENSION

public static final String FITSXTENSION
The mandatory FITS key denoting the end of the header section.

See Also:
Constant Field Values

FITSBITPIX

public static final String FITSBITPIX
The mandatory FITS key denoting the end of the header section.

See Also:
Constant Field Values

FITSNAXIS

public static final String FITSNAXIS
The mandatory FITS key denoting the end of the header section.

See Also:
Constant Field Values

FITSZERO

public static final String FITSZERO
The FITS key denoting the zero point of image data.

See Also:
Constant Field Values

FITSSCALE

public static final String FITSSCALE
The FITS key denoting the scale of image data.

See Also:
Constant Field Values

FITSEND

public static final String FITSEND
The mandatory FITS key denoting the end of the header section.

See Also:
Constant Field Values

DATEKEY

public static final String DATEKEY
The FITS key denoting the yyyy-mm-tt of the observing date.

See Also:
Constant Field Values

DATEOBSKEY

public static final String DATEOBSKEY
The FITS key denoting the yyyy-mm-tt of the observing date.

See Also:
Constant Field Values

TIMEKEY

public static final String TIMEKEY
The FITS key denoting the HH:MM:ss of the observing date.

See Also:
Constant Field Values

TIMEOBSKEY

public static final String TIMEOBSKEY
The FITS key denoting the HH:MM:ss of the observing date.

See Also:
Constant Field Values

DATEKEYS

public static final List<String> DATEKEYS
A list of fits keys that might also indicate a date.


XTENSIONIMAGE

public static final String XTENSIONIMAGE
The recognized extensions is an image

See Also:
Constant Field Values

FITSZEROREM

public static final String FITSZEROREM
The FITS key denoting the zero point of image data.

See Also:
Constant Field Values

FITSSCALEREM

public static final String FITSSCALEREM
The FITS key denoting the scale of image data.

See Also:
Constant Field Values

XORIGIN

public static final String XORIGIN
Fits key for entering x-pregap info to header.

See Also:
Constant Field Values

XBIN

public static final String XBIN
Fits key for entering x-bin info to header.

See Also:
Constant Field Values

YORIGIN

public static final String YORIGIN
Fits key for entering y-pregap info to header.

See Also:
Constant Field Values

YBIN

public static final String YBIN
Fits key for entering y-bin info to header.

See Also:
Constant Field Values
Constructor Detail

FitsTools

public FitsTools()
Method Detail

getHduOfType

public static <T extends nom.tam.fits.BasicHDU> T getHduOfType(nom.tam.fits.Fits fits,
                                                               Class<T> type,
                                                               boolean ignorenull)
                                                    throws nom.tam.fits.FitsException,
                                                           IOException
Reads a fits file until a HDU is discovered that is of the provided type.

Parameters:
ignorenull - Ignore empty HDU's
Throws:
nom.tam.fits.FitsException
IOException

getHduOfType

public static <T extends nom.tam.fits.BasicHDU> T getHduOfType(nom.tam.fits.Fits fits,
                                                               Class<T> type,
                                                               boolean ignorenull,
                                                               int skip)
                                                    throws nom.tam.fits.FitsException,
                                                           IOException
Reads a fits file until a HDU is discovered that is of the provided type.

Parameters:
ignorenull - Ignore empty HDU's
Throws:
nom.tam.fits.FitsException
IOException

getTrueValue

public static Number getTrueValue(nom.tam.fits.Fits image,
                                  int x,
                                  int y)
                           throws nom.tam.fits.FitsException,
                                  IOException
Scans an image hdu and retrieves the data there. The instance returned is of the instance of the FITS data, except for (unsigned)byte, where it is returned as a Short

Throws:
nom.tam.fits.FitsException
IOException

getTrueValue

public static Number getTrueValue(nom.tam.fits.ImageHDU image,
                                  int x,
                                  int y)
                           throws nom.tam.fits.FitsException
Scans an image hdu and retrieves the data there. The instance returned is of the instance of the FITS data, except for (unsigned)byte, where it is returned as a Short. It simply shuffels primitives to objects, not correcting for scale or zero.

Throws:
nom.tam.fits.FitsException

getRawValue

public static Number getRawValue(nom.tam.fits.Fits image,
                                 int x,
                                 int y)
                          throws nom.tam.fits.FitsException,
                                 IOException
Scans an image hdu and retrieves the data there. The instance returned is of the instance of the FITS data, except for (unsigned)byte, where it is returned as a Short

Throws:
nom.tam.fits.FitsException
IOException

getRawValue

public static Number getRawValue(nom.tam.fits.ImageHDU image,
                                 int x,
                                 int y)
                          throws nom.tam.fits.FitsException
Scans an image hdu and retrieves the data there. The instance returned is of the instance of the FITS data, except for (unsigned)byte, where it is returned as a Short. It simply shuffels primitives to objects, not correcting for scale or zero.

Throws:
nom.tam.fits.FitsException

bin

public static nom.tam.fits.ImageHDU bin(nom.tam.fits.ImageHDU l,
                                        int xbin,
                                        int ybin)
                                 throws nom.tam.fits.FitsException
Bins ADUs in an imageHDU to the given values.

Throws:
nom.tam.fits.FitsException

limit

public static nom.tam.fits.Fits limit(nom.tam.fits.Fits raw,
                                      double min,
                                      double max)
                               throws nom.tam.fits.FitsException,
                                      IOException
Limits ADUs in an image to the given values. Works on all image HDUs found

Throws:
nom.tam.fits.FitsException
IOException

limit

public static nom.tam.fits.ImageData limit(nom.tam.fits.ImageHDU l,
                                           double low,
                                           double hi)
                                    throws nom.tam.fits.FitsException
Limits ADUs in an imageHDU to the given values.

Throws:
nom.tam.fits.FitsException

cap

public static nom.tam.fits.ImageHDU cap(nom.tam.fits.ImageHDU l,
                                        double cap,
                                        double low)
                                 throws nom.tam.fits.FitsException
Caps ADUs in an imageHDU whose values are above a certain threshold to a lower one.

Throws:
nom.tam.fits.FitsException

hilo

public static nom.tam.fits.ImageHDU hilo(nom.tam.fits.ImageHDU l,
                                         double cap,
                                         double low)
                                  throws nom.tam.fits.FitsException
Caps ADUs in an imageHDU whose values are above a certain threshold to a lower one.

Throws:
nom.tam.fits.FitsException

trim

public static nom.tam.fits.ImageHDU trim(nom.tam.fits.ImageHDU in,
                                         Rectangle active)
                                  throws nom.tam.fits.FitsException
We take a source image hdu and trim it to the given active area. The active area is matched to the image such that an upper left corner of 5,3 means that in the input image hdu the x-index starts at 5 and the y-index at 3. So, an upper left corner of 0,0 corresponds to the lower left corner 1,1 according to fits definition. The width and height define the stretch of the active order, respectively.
The header of the trimmed image is minimal in that sense that it only carries the information on image size, if you want to retain the old header info, you have to merge. This is an example of such a minimal header:
 SIMPLE  =                    T / Java FITS
        BITPIX  =                  -32 
        NAXIS   =                    2 / Dimensionality   
        NAXIS1  =                 4066  
        NAXIS2  =                 4064 
        EXTEND  =                    T / Extensions are permitted 
        END
 

Parameters:
active - If null or fill size, return the original image. O therwise a new image is allocated.
Throws:
IllegalArgumentException - If the active size does not fit in the source one.
nom.tam.fits.FitsException

flip

public static nom.tam.fits.ImageHDU flip(nom.tam.fits.ImageHDU in,
                                         boolean xflip,
                                         boolean yflip)
                                  throws nom.tam.fits.FitsException
We take a source HDU and flip it according to the flip indicators, where a positive value means leave unchanged, while negative values change the direction.

Throws:
nom.tam.fits.FitsException

stitch

public static nom.tam.fits.ImageHDU stitch(nom.tam.fits.ImageHDU left,
                                           nom.tam.fits.ImageHDU right,
                                           boolean rowpatch)
                                    throws nom.tam.fits.FitsException
Composes an image from two tiles and returns the union of both in a new ImageHDU. In particular, if the rowpatch parameter is true, the image returned is composed of the first image followed by the second in x (= to the right). If rowpatch is true, the image is composed such that the second image is index-wise after the first, i.e. in standard fits notation on top.

Throws:
IllegalArgumentException - if the stitched edges are different.
nom.tam.fits.FitsException

transform

public static nom.tam.fits.Fits transform(nom.tam.fits.Fits image,
                                          Function eval)
                                   throws nom.tam.fits.FitsException,
                                          IOException
Extracts ADU's from an Image HDU, transforms them according to the given function f(ADU), and constructs an Image HDU of likewise type. This transformed HDU is returned.

Throws:
nom.tam.fits.FitsException
IOException

flag

public static nom.tam.fits.ImageData flag(nom.tam.fits.ImageHDU in,
                                          double trig)
                                   throws nom.tam.fits.FitsException
Extracts ADU's from an Image HDU and converts them to an integer flag map. If ADU is above trig, set flag to zero, otherwise to 1 (bad oixel map). Works only on float images.

Throws:
nom.tam.fits.FitsException

scalarMultiply

public static nom.tam.fits.ImageHDU scalarMultiply(nom.tam.fits.ImageHDU in,
                                                   double scale)
                                            throws nom.tam.fits.FitsException
Multiplies the image with the given scalar.

Throws:
nom.tam.fits.FitsException

scalarOffset

public static nom.tam.fits.ImageHDU scalarOffset(nom.tam.fits.ImageHDU in,
                                                 double offset)
                                          throws nom.tam.fits.FitsException
Multiplies the image with the given scalar.

Throws:
nom.tam.fits.FitsException

transform

public static nom.tam.fits.ImageHDU transform(nom.tam.fits.ImageHDU in,
                                              Function eval)
                                       throws nom.tam.fits.FitsException
Extracts ADU's from an Image HDU, transforms them according to the given function f(ADU), and constructs an Image HDU of likewise type. This transformed HDU is returned.

Throws:
nom.tam.fits.FitsException

getSize

public static Dimension getSize(nom.tam.fits.ImageHDU raw)
                         throws nom.tam.fits.FitsException
Reads the header for the axes and returns a dimension object out of it, if image is two-dimensional.

Throws:
nom.tam.fits.FitsException

getRawWindow

public static List<Number> getRawWindow(nom.tam.fits.Fits file,
                                        Rectangle window)
                                 throws nom.tam.fits.FitsException,
                                        IOException
Extracts a window from an image hdu and returns non-scaled, raw, ADUs as a list of Numbers. Order is index=x*height+y. The number of elements in the list returned is always width*height of the window. If count extraction fails at any point, null is returned.

Parameters:
window - If null, entire HDU is read.
Returns:
A List of Numbers or null.
Throws:
nom.tam.fits.FitsException
IOException

getRawWindow

public static List<Number> getRawWindow(nom.tam.fits.ImageHDU image,
                                        Rectangle window)
                                 throws nom.tam.fits.FitsException
Extracts a window from an image hdu and returns ADUs as a list of Numbers. Order is index=x*height+y. The number of elements in the list returned is always width*height of the window. If count extraction fails at any point, null is returned.

Parameters:
window - If null, entire HDU is read.
Returns:
A List of Numbers or null.
Throws:
nom.tam.fits.FitsException

getTrueWindow

public static List<Number> getTrueWindow(nom.tam.fits.Fits file,
                                         Rectangle window)
                                  throws nom.tam.fits.FitsException,
                                         IOException
Extracts a window from an image hdu and returns zero-shifted and scaled ADUs as a list of Numbers. Order is index=x*height+y. The number of elements in the list returned is always width*height of the window. If count extraction fails at any point, null is returned.

Parameters:
window - If null, entire HDU is read.
Returns:
A List of Numbers or null.
Throws:
nom.tam.fits.FitsException
IOException

getTrueWindow

public static List<Number> getTrueWindow(nom.tam.fits.ImageHDU image,
                                         Rectangle window)
                                  throws nom.tam.fits.FitsException
Extracts a window from an image hdu and returns ADUs as a list of Numbers. Order is index=x*height+y. The number of elements in the list returned is always width*height of the window. If count extraction fails at any point, null is returned.

Parameters:
window - If null, entire HDU is read.
Returns:
A List of Numbers or null.
Throws:
nom.tam.fits.FitsException

getTrueFrame

public static List<Number> getTrueFrame(nom.tam.fits.ImageHDU hdu,
                                        Rectangle active,
                                        int thick)
                                 throws nom.tam.fits.FitsException
Extracts a frame at the inside of the active window. The thickness is the number of rectangular circumferences added to the ADU list.

Throws:
nom.tam.fits.FitsException

saveAs

public static boolean saveAs(nom.tam.fits.Fits src,
                             File as)
                      throws IOException
To overcome the crude logic behind saving a fits file, we can do this here more easily.

Throws:
IOException

saveAs

public static boolean saveAs(nom.tam.fits.Fits src,
                             String as)
                      throws IOException
To overcome the crude logic behind saving a fits file, we can do this here more easily.

Throws:
IOException