fits

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fits reads the images and binary tables in FITS files as the FITS Standard 4.0 describes them, and refuses the rest. It reads a header's cards, an image's pixels a row at a time, a table's cells a few thousand rows at a time, and where an image lies on the sky.

The image is the primary array or an `IMAGE` extension. Its pixels are any of the six types the standard allows. They are scaled by `BSCALE` and `BZERO`, and `BLANK` is read as no value.

The table is the first `BINTABLE` extension. A column is read when it holds one value a row: a logical, an integer of one to eight bytes, a single or double float, or text. `TSCAL` and `TZERO` scale the numbers.

An image or a table is also opened by the `EXTNAME` of its HDU.

A column of many numbers a row is read whole by Row.Floats, in the shape its `TDIM` gives. The one-value readers refuse it.

An integer equal to its column's `TNULL`, and a float that is not a number, are read as no value. A `TNULL` on a float column is ignored: archives write one on every column, and a float's null is not a number whatever the card says.

Where it lies on the sky is read from the world coordinate cards. The projections read are TAN and CAR, in equatorial or galactic coordinates. A TAN projection with `-SIP` in its `CTYPE` is read with its distortion polynomials, and an alternate system by its key letter.

Anything else is refused, and each refusal says why in words.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Refused

func Refused() error

Refused is wrapped by each error about a file this package does not read: a part of the standard it does not read, or a file that breaks the standard.

Types

type Column added in v0.0.7

type Column struct {
	// contains filtered or unexported fields
}

Column is one column of a binary table: its name and unit as the header gives them, the kind of value it holds, how many a row, and where it lies in a row.

func (Column) Count added in v0.0.7

func (column Column) Count() int

Count is how many values a row holds in the column: one, or more in a column of many, which Row.Floats reads. Text is one value however many characters it holds.

func (Column) Dims added in v0.0.10

func (column Column) Dims() []int

Dims is the shape of a cell's values, from the column's TDIM: the length of each axis, the first axis the one that runs fastest in the row, as Row.Floats gives the values. A column with no TDIM has one axis of all its values. A text column's axes are in characters.

func (Column) Kind added in v0.0.7

func (column Column) Kind() byte

Kind is the letter of the column's TFORM: what each value is and how many bytes it takes, L, B, I, J, K, E, D or A.

func (Column) Name added in v0.0.7

func (column Column) Name() string

Name is the column's name, its TTYPE.

func (Column) Unit added in v0.0.7

func (column Column) Unit() string

Unit is the column's unit as the header writes it, its TUNIT, or nothing when the header gives none.

type Frame

type Frame string

Frame is the coordinates an image's axes are in.

const (
	// Equatorial is right ascension and declination, ICRS. FK5 at the
	// J2000 equinox is read as ICRS: the two differ by tens of
	// milliarcseconds, far below any pixel here.
	Equatorial Frame = "equatorial"
	// Galactic is galactic longitude and latitude.
	Galactic Frame = "galactic"
)

The frames an image may be in.

type Header struct {
	// contains filtered or unexported fields
}

Header is a header's cards by keyword. Each value is kept as its card writes it, with its comment taken off.

func ReadHeader

func ReadHeader(from io.Reader) (*Header, error)

ReadHeader is the header at the front of a reader, read a block at a time to its END card. Headers that end before their END card are refused.

func (*Header) Has

func (read *Header) Has(key string) bool

Has is whether the header has a card for a keyword.

func (*Header) Integer added in v0.0.7

func (read *Header) Integer(key string) (int64, error)

Integer is a keyword's value as a whole number, read whole: one too large for a float to hold is read exactly. It refuses a value that is not a whole number.

func (*Header) Number

func (read *Header) Number(key string) (float64, error)

Number is a keyword's value as a number. Some writers put a D in the exponent, and it is read as E.

func (*Header) Text

func (read *Header) Text(key string) (string, error)

Text is a keyword's string value with its quotes taken off. Doubled quotes are read as one. The spaces after the value are dropped.

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image is a two-dimensional image in a FITS file. Its rows are read as they are asked for.

func Open

func Open(file io.ReaderAt) (*Image, error)

Open is the first two-dimensional image in a file: the primary array or an IMAGE extension. HDUs that hold no image are stepped over. Tables and empty primaries are such. Files with no image are refused.

func OpenNamed added in v0.0.10

func OpenNamed(file io.ReaderAt, name string) (*Image, error)

OpenNamed is the two-dimensional image in the HDU whose EXTNAME is a name: the primary array or an IMAGE extension. The first HDU of the name is the one taken. It refuses a name no HDU has, saying the names there are, and an HDU of that name that holds no image.

func (*Image) Header

func (image *Image) Header() *Header

Header is the image's header.

func (*Image) Height

func (image *Image) Height() int

Height is the image's rows.

func (*Image) Row

func (image *Image) Row(y int) ([]float64, error)

Row is the values of one row. The first row is the bottom one, as the standard counts them. Each is BZERO more than BSCALE times the stored value. Stored BLANKs are NaN, and so are floats that are not a number.

func (*Image) Sky

func (image *Image) Sky() (*Sky, error)

Sky is where the image's pixels lie on the sky.

func (*Image) SkyAlternate added in v0.0.10

func (image *Image) SkyAlternate(key string) (*Sky, error)

SkyAlternate is where the image's alternate world coordinate system of a key lies on the sky. See SkyOfAlternate.

func (*Image) Width

func (image *Image) Width() int

Width is the image's pixels a row.

type Row added in v0.0.7

type Row struct {
	// contains filtered or unexported fields
}

Row is one row of a table, counted from none. It is read from the file when a cell of it is asked for. It refuses a row the table does not have.

func (Row) Float added in v0.0.7

func (row Row) Float(column Column) (float64, error)

Float is a cell's value as a number, scaled by the column's TSCAL and TZERO. A float that is not a number, and an integer equal to the column's TNULL, read as not a number. It refuses a column of text or of logical values, and a column of many values a row.

func (Row) Floats added in v0.0.10

func (row Row) Floats(column Column) ([]float64, error)

Floats is the values of a cell as numbers, in the order the row stores them, each scaled as Float scales it and each not a number as Float reads it. A column of one value gives one. It refuses a column of text or of logical values. Dims is their shape.

func (Row) Int added in v0.0.7

func (row Row) Int(column Column) (int64, bool, error)

Int is a cell's value as a whole number, unscaled, and whether it is one: false for the column's TNULL. It refuses a column that holds no integers, and a column of many values a row.

func (Row) Logical added in v0.0.7

func (row Row) Logical(column Column) (bool, bool, error)

Logical is a cell's logical value, and whether it is one: a null logical is neither. It refuses a column that holds no logical values, and a column of many values a row.

func (Row) Text added in v0.0.7

func (row Row) Text(column Column) (string, error)

Text is a cell's text, with the spaces after it dropped. It refuses a column that holds no text.

type Sky

type Sky struct {
	// contains filtered or unexported fields
}

Sky is where an image's pixels lie on the sky: a projection about a reference point, and the matrix that turns pixels into degrees.

func SkyOf

func SkyOf(header *Header) (*Sky, error)

SkyOf is where a header says its image lies on the sky. It refuses a projection or a frame it does not read, and axes not in degrees.

It refuses a CAR grid not about the equator and a pole moved from where the projection puts it. It refuses an equinox other than J2000 and a pixel matrix with no inverse.

A TAN projection whose CTYPE ends in -SIP is read with its SIP distortion polynomials, A and B before the pixel matrix, as Shupe and others 2005 give them.

func SkyOfAlternate added in v0.0.10

func SkyOfAlternate(header *Header, key string) (*Sky, error)

SkyOfAlternate is where an alternate world coordinate system of a header lies on the sky. The key is one capital letter, A to Z, and each card of the system ends in it: CRPIX1A, CTYPE1A, CD1_1A and the rest. The primary system is SkyOf's, and is not touched.

It refuses what SkyOf refuses, a key that is not a capital letter, and a system with no cards under the key. It refuses -SIP under a key, since the paper does not address alternate keys.

func (*Sky) Frame

func (read *Sky) Frame() Frame

Frame is the coordinates the image's axes are in.

func (*Sky) Inverts added in v0.0.10

func (read *Sky) Inverts() bool

Inverts is whether Pixel can find a pixel. It is false for a SIP header with no AP and BP coefficients: the paper gives the sky to pixel direction only by those, and this package does not iterate the A and B polynomials to find it.

func (*Sky) Pixel

func (read *Sky) Pixel(lon, lat float64) (x, y float64, seen bool)

Pixel is the pixel at a longitude and latitude, in degrees in the image's frame. seen is false for a place a tangent projection cannot show: on the far half of the sky from its centre.

With SIP it is the pixel by the AP and BP polynomials, which the paper calls an approximation: a pixel taken to the sky and back lands near where it started, not on it. seen is false when the header has none.

func (*Sky) Place

func (read *Sky) Place(x, y float64) (lon, lat float64)

Place is the longitude and latitude at a pixel, in degrees in the image's frame. Pixels are counted as the standard counts them: the centre of the first is at one.

type Table added in v0.0.7

type Table struct {
	// contains filtered or unexported fields
}

Table is a binary table extension in a FITS file: columns of numbers and text in rows of one width, read as they are asked for, a few thousand rows at a time.

func OpenTable added in v0.0.7

func OpenTable(file io.ReaderAt) (*Table, error)

OpenTable is the first binary table in a file. HDUs that hold no table are stepped over: the primary array, images, and anything else the standard sizes. Files with no table are refused, and so is a table whose columns this package does not read.

func OpenTableNamed added in v0.0.10

func OpenTableNamed(file io.ReaderAt, name string) (*Table, error)

OpenTableNamed is the binary table in the HDU whose EXTNAME is a name. The first HDU of the name is the one taken. It refuses a name no HDU has, saying the names there are, and an HDU of that name that is no binary table.

func (*Table) Column added in v0.0.7

func (table *Table) Column(name string) (*Column, error)

Column is the column of a name. It refuses a name the table lacks.

func (*Table) Columns added in v0.0.7

func (table *Table) Columns() []Column

Columns is the table's columns, in the file's order.

func (*Table) Header added in v0.0.7

func (table *Table) Header() *Header

Header is the table's header.

func (*Table) Row added in v0.0.7

func (table *Table) Row(index int64) (*Row, error)

Row is a row, counted from none. It refuses a row past the end.

func (*Table) Rows added in v0.0.7

func (table *Table) Rows() int64

Rows is how many rows the table has.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL