Documentation Center

  • Trial Software
  • Product Updates

fitsread

Read data from FITS file

Syntax

data = fitsread(filename)
data = fitsread(filename,extname)
data = fitsread(filename,extname,index)
data = fitsread(filename,Name,Value)

Description

data = fitsread(filename) reads the primary data of the Flexible Image Transport System (FITS) file specified by the text string filename. The function replaces undefined data values with NaN and scales numeric data by the slope and intercept values, always returning double precision values.

data = fitsread(filename,extname) reads data from the FITS file extension specified by extname.

data = fitsread(filename,extname,index) reads data from the FITS file extension specified by extname . If there is more than one of the specified extensions in the file, index specifies the one to read.

data = fitsread(filename,Name,Value) reads data from the FITS file with additional options specified by one or more Name,Value pair arguments.

Input Arguments

filename

Text string specifying the name of a FITS file.

extname

One of the following text strings specifying the name of a data array or extension in the FITS file. To determine the contents of a FITS, view the Contents field of the structure returned by fitsinfo.

Data Arrays or Extensions

Extname

Description

'primary'

Read data from the primary data array.

'asciitable'

Read data from the ASCII Table extension. The return value, data, is a 1-D cell array.

'binarytable'

Read data from the Binary Table extension. The return value, data, is a 1-D cell array.

'image'

Read data from the Image extension.

'unknown'

Read data from the Unknown extension.

index

Numeric value specifying which extension to read, if more than one exists in the file.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'info'

info structure returned by fitsinfo specifying the location of data to read.

    Note:   Using the info structure returned by fitsinfo to specify the location of data in a FITS file can significantly improve performance, especially when reading multiple images from the file.

'PixelRegion'

Cell array {rows,cols,...} specifying the boundaries of a subimage region to read from the file. Each dimension (rows, cols) is a vector of 1-based indices given either as START, [START STOP], or [START INCREMENT STOP]. This parameter is valid only for primary or image extensions.

'raw'

Specifies that fitsread should not scale the data read from the file or replace undefined values with NaN. Data read from the file is the same class as it is stored in the file.

'TableColumns'

Vector of 1-based indices specifying the columns to read from the ASCII or Binary table extension. This vector should contain unique and valid indices into the table data specified in increasing order. This parameter is valid only for ASCII or Binary extensions.

'TableRows'

Vector of 1-based indices specifying the rows to read from the ASCII or Binary table extension. This vector should contain unique and valid indices into the table data specified in increasing order. This parameter is valid only for ASCII or Binary extensions.

Output Arguments

data

Data returned from the FITS file.

Examples

Read primary data from FITS file

data = fitsread('tst0012.fits');

Name        Size             Bytes  Class     Attributes

data      109x102            88944  double
 

Inspect available extensions, read 'image' extension using the extname option.

info = fitsinfo('tst0012.fits');
 % List of contents, includes any extensions if present.
 disp(info.Contents);
 imageData = fitsread('tst0012.fits','image');
 

Subsample the fifth plane of 'image' extension by 2.

info        = fitsinfo('tst0012.fits');
 rowend      = info.Image.Size(1);
 colend      = info.Image.Size(2);
 primaryData = fitsread('tst0012.fits','image',...
              'Info', info,...
              'PixelRegion',{[1 2 rowend], [1 2 colend], 5 });
 

Read every other row from an ASCII table.

info      = fitsinfo('tst0012.fits');
rowend    = info.AsciiTable.Rows; 
tableData = fitsread('tst0012.fits','asciitable',...
                    'Info',info,...
                    'TableRows',[1:2:rowend]);
 

Read all data for the first, second and fifth columns of the Binary table.

info      = fitsinfo('tst0012.fits');
rowend    = info.BinaryTable.Rows;       
tableData = fitsread('tst0012.fits','binarytable',...
                    'Info',info,...
                    'TableColumns',[1 2 5]);

More About

expand all

extension

A FITS file contains primary data and can optionally contain any number of optional components, called extensions in FITS terminology.

See Also

| |

Tutorials

Was this topic helpful?