image_io.h

Overview

These are utility functions for inspecting and reading in FITS files; they are wrappers around calls to CFITSIO functions.

Note that ReadImageAsVector allocates the memory for the image it reads (via the FFTW3 utility routine fftw_alloc_real); the caller is responsible for freeing the memory (via fftw_free) when it is no longer needed.

API

Files: core/image_io.h, core/image_io.cpp

Public interfaces for the FITS image I/O routines.

Functions

bool CheckHDUForImage(fitsfile *imageFile_ptr, int hduNum, int *status_ptr)

Checks to see if current HDU in FITS file has proper 2D image.

int CheckForImage(const std::string filename, const bool verbose = false)

Checks to see if FITS file has proper 2D image in first HDU (or second, if first is empty)

Given the filename of a FITS image, this function opens the file and checks the first header-data unit to see if it is a 2D image. If it is not and a second HDU exists, then that is also checked.

Returns -1 if something goes wrong opening the file or if primary HDU is not a proper 2D image; otherwise, returns 1 if the specified FITS file (including implicitly specified extension number, if that was part of filename) is a proper2D image.

Currently uses int as return value for possible case of finding and returning a different HDU. FIXME: probably good idea to make this bool return value.

std::tuple<int, int, int> GetImageSize(const std::string filename, const bool verbose = false)

Gets dimensions (nColumns, nRows) of specified FITS image.

Given the filename of a FITS image, this function opens the file, reads the size of the image and returns the dimensions in nRows and nColumns.

Returns 0 for successful operation, -1 if a CFITSIO-related error occurred.

double *ReadImageAsVector(const std::string filename, int *nColumns, int *nRows, const bool verbose = false)

Reads image data from specified FITS image, returning it as 1D array (with image dimensions stored in nColumns, nRows)

Given a filename, it opens the file, reads the size of the image and stores that size in nRows and nColumns, then allocates memory for a 1-D array to hold the image and reads the image from the file into the array. Finally, it returns the image array &#8212; or, more precisely, it returns a pointer to the array; it also stores the image dimensions in the pointer-parameters nRows and nColumns.

Returns NULL (and prints error message) if a CFITSIO-related error occurred.

int SaveVectorAsImage(double *pixelVector, const std::string filename, int nColumns, int nRows, std::vector<std::string> comments)

Saves image data (1D array, logical dimensions nColumns x nRows) as FITS file, with comments added to header.

Saves specified 1D array (representing an image with size nColumns x nRows) in specified filename as a FITS image, with strings stored in comments vector written as comments to the FITS header.

Returns 0 for successful operation, -1 if a CFITSIO-related error occurred.

int CountHeaderDataUnits(fitsfile *imfile_ptr)