ImageFITSConverter.h
Classes
- ImageFITSConverter -- Interconvert between AIPS++ Images and FITS files. (full description)
- ImageFITSConverterImpl -- This class is an internal class for ImageFITSConverter. (full description)
Interface
- Public Members
- static Bool FITSToImage(ImageInterface<Float>*& newImage, String &error, const String &imageName, const String &fitsName, uInt whichHDU = 0, uInt memoryInMB = 64, Bool allowOverwrite=False, Bool zeroBlanks=False)
- static Bool ImageToFITS(String &error, ImageInterface<Float> &image, const String &fitsName, uInt memoryInMB = 64, Bool preferVelocity = True, Bool opticalVelocity = True, Int BITPIX=-32, Float minPix = 1.0, Float maxPix = -1.0, Bool allowOverwrite=False)
- static IPosition copyCursorShape(String &report, const IPosition &shape, uInt imagePixelSize, uInt fitsPixelSize, uInt memoryInMB)
- static CoordinateSystem getCoordinateSystem (Int& imageType, RecordInterface& header, LogIO& os, LogIO& shape, Bool dropStokes)
- static ImageInfo getImageInfo (RecordInterface& header)
- static Unit getBrightnessUnit (RecordInterface& header, LogIO& os)
- static void restoreHistory (LoggerHolder& logger, ConstFitsKeywordList& kw)
- Private Members
- static Bool removeFile (String& error, const File& outFile, const String& outName, Bool allowOverwrite)
Review Status
- Date Reviewed:
- yyyy/mm/dd
Prerequisite
Synopsis
This class is a helper class that is used to interconvert between AIPS++
images and FITS files. This adds no functionality over the general abilities
available in the underlying FITS classes, however it is a useful higher-level
packaging.
There are two fundamental member functions in this class.
FITSToImage which turns a FITS file into an AIPS++ image, and
ImageToFITS which does the opposite.
We can read images from any HDU inside the FITS file (although this isn't
well tested). However at the moment we always write to the first HDU, i.e.
to the primary array, not an image extension.
Pixels in the FITS file which are blanked are masked out (the mask
is set to False) in the output image. On conversion to FITS,
masked values are blanked. The mask which is read is the current
default mask.
Example
A FITS to image conversion may be accomplished as follows:
PagedImage<Float> *image = 0;
String fitsName = "exists.fits";
String imageName = "new.image";
String error;
Bool ok = ImageFITSConverter::FITSToImage(image, error, imageName, fitsName);
if (!image) ... error ...
A couple of things to note:
- If ok is False, the conversion failed and error
will be set.
- The pointer "image" is set if the conversion succeeds. If it is
zero the conversion failed and error will contain an
error message.
- The caller is responsible for deleting the pointer image
when the conversion is successful.
Similarly, an image to FITS conversion may be accomplished as follows:
String imageName = argv[1];
PagedImage<Float> image = ...; // An existing image from somewhere
String fitsName = "new.fits";
String error;
Bool ok = ImageFITSConverter::ImageToFITS(error, image, fitsName);
A couple of similar remarks can be made about this example:
- If ok is False, the conversion failed and error
will be set.
Motivation
FITS files are the fundamental transport format for images in Astronomy.
To Do
- It might be useful to have functions that convert between FITS
and general lattices.
- Add support for PagedImage
- Convert multiple images at once?
- Allow writing FITS files to an image extension in an existing
FITS file.
Member Description
static Bool FITSToImage(ImageInterface<Float>*& newImage, String &error, const String &imageName, const String &fitsName, uInt whichHDU = 0, uInt memoryInMB = 64, Bool allowOverwrite=False, Bool zeroBlanks=False)
Convert a FITS file to an AIPS++ image.
- newImage will be zero if the conversion fail. If the
conversion succeeds, the caller is responsible for deleting this
pointer.
- error will be set if the conversion fails.
- If imageName is empty, a TempImage will be created,
otherwise a PagedImage on disk.
- fitsName must already exist (and have an image at the
indicated HDU).
- whichHDU Zero-relative hdu. The default is correct for
a primary array, set it for an image extension. Only zero has been
tested.
- memoryInMB. Setting this to zero will result in
row-by-row copying, otherwise it will attempt to with as large
a chunk-size as possible, while fitting in the desired memory.
- allowOverwrite If True, allow imageName to be
overwritten if it already exists.
- zeroBlanks If True, allow any blanked pixels are set
to zero rather than NaN
static Bool ImageToFITS(String &error, ImageInterface<Float> &image, const String &fitsName, uInt memoryInMB = 64, Bool preferVelocity = True, Bool opticalVelocity = True, Int BITPIX=-32, Float minPix = 1.0, Float maxPix = -1.0, Bool allowOverwrite=False)
Convert an AIPS++ image to a FITS file.
- return True if the conversion succeeds, False
otherwise.
- error will be set if the conversion fails.
- image The image to convert.
- fitsName If the name is "-" (the minus character),
then write to stdout Always writes to the primary array.
- memoryInMB. Setting this to zero will result in
row-by-row copying, otherwise it will attempt to with as large
a chunk-size as possible, while fitting in the desired memory.
- preferVelocityWrite a velocity primary spectral axis
if possible.
- opticalVelocityIf writing a velocity, use the optical
definition (otherwise use radio).
- BITPIX, minPix, maxPix
BITPIX can presently be set to -32 or 16 only. When BITPIX is
16 it will write BSCALE and BZERO into the FITS file. If minPix
is greater than maxPix the minimum and maximum pixel values
will be determined from the array, otherwise the supplied
values will be used and pixels outside that range will be
truncated to the minimum and maximum pixel values (note that
this truncation does not occur for BITPIX=-32).
- allowOverwrite If True, allow fitsName to be
overwritten if it already exists.
static IPosition copyCursorShape(String &report, const IPosition &shape, uInt imagePixelSize, uInt fitsPixelSize, uInt memoryInMB)
Helper function - used to calculate a cursor appropriate for the desired
memory use. It's not intended that application programmers call this, but
you may if it's useful to you.
static CoordinateSystem getCoordinateSystem (Int& imageType, RecordInterface& header, LogIO& os, LogIO& shape, Bool dropStokes)
Recover CoordinateSystem from header. Used keywords are removed from header
Degenerate axes may be added to shape if needed
Recover ImageInfo from header. Used keywords are removed from header
static Unit getBrightnessUnit (RecordInterface& header, LogIO& os)
Recover brightness unit from header. Used keywords are removed from header
Recover history from FITS file keywrod list into logger
static Bool removeFile (String& error, const File& outFile, const String& outName, Bool allowOverwrite)
Interface
Public Members
- static void FITSToImage(ImageInterface<Float> *&newImage, String &error, const String &imageName, HDUType &fitsImage, uInt memoryInMB = 64, Bool zeroBlanks=False)
Synopsis
This class is an internal class used to implement
ImageFitsConverter::FITSToImage - in particular, it has the code which
is dependent on the various types (BITPIX values).
Member Description
static void FITSToImage(ImageInterface<Float> *&newImage, String &error, const String &imageName, HDUType &fitsImage, uInt memoryInMB = 64, Bool zeroBlanks=False)