Main Content

FITS Files

Flexible Image Transport System

Flexible Image Transport System (FITS) is an open standard defining a digital file format useful for storage, transmission, and processing of data, formatted as multidimensional arrays or tables. You can interact with FITS files in two ways:

  • The MATLAB® high-level FITS functions provide a simplified programmatic interface for reading data from FITS files and writing data from the MATLAB workspace to FITS files.

  • The MATLAB low-level FITS functions provide finer control over the reading and writing process of FITS files by providing access to more than 50 functions in the CFITSIO C library. To use these functions in MATLAB, prefix the function name with the matlab.io.fits namespace path, or use the import function to add the namespace to the current import list prior to calling the function. For example:

    import matlab.io.*;
    fptr = fits.openFile("tst0012.fits");
    

    To use the MATLAB low-level FITS functions, you must be familiar with CFITSIO C API programming concepts, described at https://fits.gsfc.nasa.gov/.

MATLAB uses FITS C library version 4.1.0.

Functions

expand all

fitsdispDisplay FITS metadata
fitsinfoInformation about FITS file
fitsreadRead data from FITS file
fitswriteWrite image to FITS file

File Access

closeFileClose FITS file
createFileCreate FITS file
deleteFileDelete FITS file
fileModeGet I/O mode of FITS file
fileNameGet name of FITS file
openDiskFileOpen FITS file
openFileOpen FITS file (extended-filename syntax)

Image Manipulation

createImgCreate FITS image
getImgSizeGet size of FITS image
getImgTypeGet data type of FITS image
insertImgInsert FITS image after current image
readImgRead FITS image data
setBscaleReset FITS image scaling
writeImgWrite to FITS image

Keywords

deleteKeyDelete key by name
deleteRecordDelete key by record number
getHdrSpaceGet number of keywords in header
readCardRead header record of keyword
readKeyRead keyword
readKeyCmplxRead keyword as complex scalar value
readKeyDblRead keyword as double precision value
readKeyLongLongRead keyword as 64-bit integer value
readKeyLongStrRead keyword as long string value
readKeyUnitRead physical units string from keyword
readRecordRead header record specified by number
writeCommentWrite or append COMMENT keyword to CHU
writeDateWrite DATE keyword to CHU
writeHistoryWrite or append HISTORY keyword to CHU
writeKeyUpdate or add new keyword into current HDU
writeKeyUnitWrite physical units string

Header Data Unit (HDU) Access

copyHDUCopy current HDU from one file to another
deleteHDUDelete current HDU in FITS file
getHDUnumGet number of current HDU in FITS file
getHDUtypeGet type of current HDU in FITS file
getNumHDUsGet total number of HDUs in FITS file
movAbsHDUMove to absolute HDU number
movNamHDUMove to first HDU having specific type and keyword values
movRelHDUMove relative number of HDUs from current HDU
writeChecksumCompute and write checksum for current HDU

Image Compression

imgCompressCompress HDU from one file into another
isCompressedImgDetermine if current image is compressed
setCompressionTypeSet image compression type
setHCompScaleSet scale parameter for HCOMPRESS algorithm
setHCompSmoothSet smoothing for images compressed with HCOMPRESS
setTileDimSet tile dimensions

ASCII and Binary Tables

createTblCreate new ASCII or binary table extension
insertColInsert column into table
insertRowsInsert rows into table
insertATblInsert ASCII table after current HDU
insertBTblInsert binary table after current HDU
deleteColDelete column from table
deleteRowsDelete rows from table
getAColParmsGet ASCII table information
getBColParmsGet binary table information
getColNameGet table column name
getColTypeGet scaled column data type, repeat value, width
getEqColTypeGet column data type, repeat value, width
getNumColsGet number of columns in table
getNumRowsGet number of rows in table
readATblHdrRead header information from current ASCII table
readBTblHdrRead header information from current binary table
readColRead rows of ASCII or binary table column
setTscaleReset image scaling
writeColWrite elements into ASCII or binary table column

Utilities

getConstantValueGet numeric value of named constant
getVersionGet revision number of the CFITSIO library
getOpenFilesGet list of open FITS files

Topics

Related Information