Table of Contents

Class FitsFile

Namespace
Egami.Formats.Extended.Fits
Assembly
Egami.Formats.Extended.dll

A whole FITS file, for the numbers rather than a picture: every HDU's header cards, and an image's physical values, BZERO + BSCALE × stored, unstretched, with missing pixels (BLANK, NaN, damaged tiles, data past the file's end) as NaN. Tile-compressed images decode as plain ones. World coordinate (WCS) keywords are in the header; Egami does no sky coordinate math.

public sealed class FitsFile
Inheritance
FitsFile
Inherited Members

Examples

// FitsFile lists every HDU with its header, tables included, and reads an image's values in file order.
FitsFile file = FitsFile.Load("m51.fits");
foreach (FitsHdu hdu in file.Hdus)
{
    Console.WriteLine($"HDU {hdu.Index}: {hdu.Kind}, {string.Join(" × ", hdu.Axes)}");
}

FitsHdu image = file.FirstImage!;
double exposure = image.Header.GetReal("EXPTIME") ?? 0;
double[] counts = file.ReadValues(image);
using Raster<GrayF32> plane = file.ReadPlane(image);

Properties

FirstImage

Gets the first HDU that holds an image, or null.

public FitsHdu? FirstImage { get; }

Property Value

FitsHdu

Hdus

Gets every HDU, the primary one first.

public IReadOnlyList<FitsHdu> Hdus { get; }

Property Value

IReadOnlyList<FitsHdu>

Methods

Load(Stream, EgamiContext?)

Reads a FITS file from a stream, to its end.

public static FitsFile Load(Stream stream, EgamiContext? context = null)

Parameters

stream Stream

The stream.

context EgamiContext

The context whose safety limits apply, or null for the default.

Returns

FitsFile

The file, its headers read.

Exceptions

ArgumentNullException

stream is null.

CorruptDataException

The primary header is not FITS or is damaged.

Load(string, EgamiContext?)

Reads a FITS file from a path.

public static FitsFile Load(string path, EgamiContext? context = null)

Parameters

path string

The file.

context EgamiContext

The context whose safety limits apply, or null for the default.

Returns

FitsFile

The file, its headers read.

Exceptions

ArgumentNullException

path is null.

CorruptDataException

The primary header is not FITS or is damaged.

ReadPlane(FitsHdu, int)

Returns one plane of an image HDU as physical values in GrayF32, the file's first row at the bottom as Load gives it.

public Raster<GrayF32> ReadPlane(FitsHdu hdu, int plane = 0)

Parameters

hdu FitsHdu

An image HDU of this file.

plane int

The plane of a cube, from 0.

Returns

Raster<GrayF32>

The plane.

Exceptions

ArgumentException

hdu is not an image of this file.

ArgumentOutOfRangeException

plane is outside the cube.

UnsupportedFormatException

The image uses a tile compression Egami does not read.

ReadValues(FitsHdu)

Returns an image HDU's physical values, every plane, in the file's order: along a row first, then up the rows from the file's first, then plane by plane.

public double[] ReadValues(FitsHdu hdu)

Parameters

hdu FitsHdu

An image HDU of this file.

Returns

double[]

The values.

Exceptions

ArgumentException

hdu is not an image of this file.

UnsupportedFormatException

The image uses a tile compression Egami does not read.