Documentation
¶
Overview ¶
fitsio provides read and write access to FITS files.
Example (CreateImage3x4F64) ¶
package main
import (
"log"
"os"
"codeberg.org/astrogo/fitsio"
)
func main() {
f, err := os.Create("testdata/ex-img-bitpix-64.fits")
if err != nil {
log.Fatalf("could not create file: %+v", err)
}
defer f.Close()
fits, err := fitsio.Create(f)
if err != nil {
log.Fatalf("could not create FITS file: %+v", err)
}
defer fits.Close()
// create primary HDU image
var (
bitpix = -64
axes = []int{3, 4}
data = []float64{
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
}
)
img := fitsio.NewImage(bitpix, axes)
defer img.Close()
err = img.Header().Append(
fitsio.Card{
"EXTNAME",
"primary hdu",
"the primary HDU",
},
fitsio.Card{
"EXTVER",
2,
"the primary hdu version",
},
)
if err != nil {
log.Fatalf("could append cards: %+v", err)
}
err = img.Write(data)
if err != nil {
log.Fatalf("could not write data to image: %+v", err)
}
err = fits.Write(img)
if err != nil {
log.Fatalf("could not write image to FITS file: %+v", err)
}
err = fits.Close()
if err != nil {
log.Fatalf("could not close FITS file: %+v", err)
}
err = f.Close()
if err != nil {
log.Fatalf("could not close file: %+v", err)
}
}
Example (CreateImage3x4I64) ¶
package main
import (
"log"
"os"
"codeberg.org/astrogo/fitsio"
)
func main() {
f, err := os.Create("testdata/ex-img-bitpix+64.fits")
if err != nil {
log.Fatalf("could not create file: %+v", err)
}
defer f.Close()
fits, err := fitsio.Create(f)
if err != nil {
log.Fatalf("could not create FITS file: %+v", err)
}
defer fits.Close()
// create primary HDU image
var (
bitpix = 64
axes = []int{3, 4}
data = []int64{
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
}
)
img := fitsio.NewImage(bitpix, axes)
defer img.Close()
err = img.Header().Append(
fitsio.Card{
"EXTNAME",
"primary hdu",
"the primary HDU",
},
fitsio.Card{
"EXTVER",
2,
"the primary hdu version",
},
)
if err != nil {
log.Fatalf("could append cards: %+v", err)
}
err = img.Write(data)
if err != nil {
log.Fatalf("could not write data to image: %+v", err)
}
err = fits.Write(img)
if err != nil {
log.Fatalf("could not write image to FITS file: %+v", err)
}
err = fits.Close()
if err != nil {
log.Fatalf("could not close FITS file: %+v", err)
}
err = f.Close()
if err != nil {
log.Fatalf("could not close file: %+v", err)
}
}
Example (CreateImage3x4I8) ¶
package main
import (
"log"
"os"
"codeberg.org/astrogo/fitsio"
)
func main() {
f, err := os.Create("testdata/ex-img-bitpix+8.fits")
if err != nil {
log.Fatalf("could not create file: %+v", err)
}
defer f.Close()
fits, err := fitsio.Create(f)
if err != nil {
log.Fatalf("could not create FITS file: %+v", err)
}
defer fits.Close()
// create primary HDU image
var (
bitpix = 8
axes = []int{3, 4}
data = []int8{
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 0, 1,
}
)
img := fitsio.NewImage(bitpix, axes)
defer img.Close()
err = img.Header().Append(
fitsio.Card{
"EXTNAME",
"primary hdu",
"the primary HDU",
},
fitsio.Card{
"EXTVER",
2,
"the primary hdu version",
},
)
if err != nil {
log.Fatalf("could append cards: %+v", err)
}
err = img.Write(data)
if err != nil {
log.Fatalf("could not write data to image: %+v", err)
}
err = fits.Write(img)
if err != nil {
log.Fatalf("could not write image to FITS file: %+v", err)
}
err = fits.Close()
if err != nil {
log.Fatalf("could not close FITS file: %+v", err)
}
err = f.Close()
if err != nil {
log.Fatalf("could not close file: %+v", err)
}
}
Example (Open) ¶
package main
import (
"fmt"
"log"
"os"
"codeberg.org/astrogo/fitsio"
)
func main() {
f, err := os.Open("testdata/file-img2-bitpix+08.fits")
if err != nil {
log.Fatalf("could not open file: %+v", err)
}
defer f.Close()
fits, err := fitsio.Open(f)
if err != nil {
log.Fatalf("could not open FITS file: %+v", err)
}
defer fits.Close()
for i, hdu := range fits.HDUs() {
fmt.Printf("Header listing for HDU #%d:\n", i)
hdr := hdu.Header()
for k := range hdr.Keys() {
card := hdr.Card(k)
fmt.Printf(
"%-8s= %-29s / %s\n",
card.Name,
fmt.Sprintf("%v", card.Value),
card.Comment)
}
fmt.Printf("END\n\n")
}
}
Output: Header listing for HDU #0: SIMPLE = true / primary HDU BITPIX = 8 / number of bits per data pixel NAXIS = 2 / number of data axes NAXIS1 = 50 / length of data axis 1 NAXIS2 = 50 / length of data axis 2 IMAGENBR= 0 / image number END Header listing for HDU #1: XTENSION= IMAGE / IMAGE extension BITPIX = 8 / number of bits per data pixel NAXIS = 2 / number of data axes NAXIS1 = 50 / length of data axis 1 NAXIS2 = 50 / length of data axis 2 IMAGENBR= 1 / image number END
Example (OpenImage3x4F64) ¶
package main
import (
"fmt"
"log"
"os"
"codeberg.org/astrogo/fitsio"
)
func main() {
f, err := os.Open("testdata/example.fits")
if err != nil {
log.Fatalf("could not open file: %+v", err)
}
defer f.Close()
fits, err := fitsio.Open(f)
if err != nil {
log.Fatalf("could not open FITS file: %+v", err)
}
defer fits.Close()
var (
hdu = fits.HDU(0)
hdr = hdu.Header()
img = hdu.(fitsio.Image)
bitpix = hdr.Bitpix()
axes = hdr.Axes()
)
fmt.Printf("bitpix: %d\n", bitpix)
fmt.Printf("axes: %v\n", axes)
data := make([]float64, axes[0]*axes[1])
err = img.Read(&data)
if err != nil {
log.Fatalf("could not read image: %+v", err)
}
fmt.Printf("data: %v\n", data)
}
Output: bitpix: -64 axes: [3 4] data: [0 1 2 3 4 5 6 7 8 9 0 1]
Index ¶
- Constants
- func CopyHDU(dst, src *File, i int) error
- func CopyTable(dst, src *Table) error
- func CopyTableRange(dst, src *Table, beg, end int64) error
- func NewImage(bitpix int, axes []int) *imageHDU
- type Card
- type Column
- type Decoder
- type Encoder
- type File
- type HDU
- type HDUType
- type Header
- func (hdr *Header) Append(cards ...Card) error
- func (hdr *Header) Axes() []int
- func (hdr *Header) Bitpix() int
- func (hdr *Header) Card(i int) *Card
- func (hdr *Header) Clear()
- func (hdr *Header) Comment() string
- func (hdr *Header) Get(n string) *Card
- func (hdr *Header) History() string
- func (hdr *Header) Index(n string) int
- func (hdr *Header) Keys() []string
- func (hdr *Header) Set(n string, v interface{}, comment string)
- func (hdr *Header) Text() string
- func (hdr *Header) Type() HDUType
- type Image
- type Mode
- type Reader
- type Rows
- type Table
- func (t *Table) Close() error
- func (t *Table) Col(i int) *Column
- func (t *Table) Cols() []Column
- func (t *Table) Data() (Value, error)
- func (t *Table) Header() *Header
- func (t *Table) Index(n string) int
- func (t *Table) Name() string
- func (t *Table) NumCols() int
- func (t *Table) NumRows() int64
- func (t *Table) Read(beg, end int64) (*Rows, error)
- func (t *Table) ReadRange(beg, end, inc int64) (*Rows, error)
- func (t *Table) Type() HDUType
- func (t *Table) Version() int
- func (t *Table) Write(args ...interface{}) error
- type Type
- type Value
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func CopyTableRange ¶
CopyTableRange copies the rows interval [beg,end) from src into dst
Types ¶
type Column ¶
type Column struct {
Name string // column name, corresponding to “TTYPE“ keyword
Format string // column format, corresponding to “TFORM“ keyword
Unit string // column unit, corresponding to “TUNIT“ keyword
Null string // null value, corresponding to “TNULL“ keyword
Bscale float64 // bscale value, corresponding to “TSCAL“ keyword
Bzero float64 // bzero value, corresponding to “TZERO“ keyword
Display string // display format, corresponding to “TDISP“ keyword
Dim []int64 // column dimension corresponding to “TDIM“ keyword
Start int64 // column starting position, corresponding to “TBCOL“ keyword
// contains filtered or unexported fields
}
Column represents a column in a FITS table
type Decoder ¶
func NewDecoder ¶
NewDecoder creates a new Decoder according to the capabilities of the underlying io.Reader
type Encoder ¶
func NewEncoder ¶
NewEncoder creates a new Encoder according to the capabilities of the underlying io.Writer
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a FITS file.
func (*File) Close ¶
Close releases resources held by a FITS file.
It does not close the underlying io.Reader or io.Writer.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header describes a Header-Data Unit of a FITS file
func NewDefaultHeader ¶
func NewDefaultHeader() *Header
NewDefaultHeader creates a Header with CFITSIO default Cards, of type IMAGE_HDU and bitpix=8, no axes.
func (*Header) Get ¶
Get returns the Card with name n or nil if it doesn't exist. If multiple cards with the same name exist, the first one is returned.
type Image ¶
type Image interface {
HDU
Read(ptr interface{}) error
Write(ptr interface{}) error
Raw() []byte
Image() image.Image
// contains filtered or unexported methods
}
Image represents a FITS image
func NewPrimaryHDU ¶
NewPrimaryHDU creates a new PrimaryHDU with Header hdr. If hdr is nil, a default Header will be created.
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows is the result of a query on a FITS Table. Its cursors starts before the first row of the result set. Use Next to advance through the rows:
rows, err := table.Read(0, -1)
...
for rows.Next() {
var id int
var x float64
err = rows.Scan(&id, &x)
...
}
err = rows.Err() // get any error encountered during iteration
...
func (*Rows) Close ¶
Close closes the Rows, preventing further enumeration. Close is idempotent and does not affect the result of Err.
func (*Rows) Err ¶
Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
func NewTableFrom ¶
NewTableFrom creates a new table in the given FITS file, using the struct v as schema
func (*Table) Read ¶
Read reads rows over the range [beg, end) and returns the corresponding iterator. if end > maxrows, the iteration will stop at maxrows ReadRange has the same semantics than a `for i=0; i < max; i++ {...}` loop
func (*Table) ReadRange ¶
ReadRange reads rows over the range [beg, end) and returns the corresponding iterator. if end > maxrows, the iteration will stop at maxrows ReadRange has the same semantics than a `for i=0; i < max; i+=inc {...}` loop
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
go-fitsio-fitscopy
command
|
|
|
go-fitsio-listhead
command
|
|
|
go-fitsio-mergefiles
command
|
|
|
go-fitsio-tablist
command
|
|
|
fltimg provides image.Image implementations for the float32- and float64-image encodings of FITS.
|
fltimg provides image.Image implementations for the float32- and float64-image encodings of FITS. |