-
Notifications
You must be signed in to change notification settings - Fork 22
/
phdu.go
84 lines (71 loc) · 1.72 KB
/
phdu.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2015 The astrogo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fitsio
import "reflect"
type primaryHDU struct {
imageHDU
}
// Name returns the value of the 'EXTNAME' Card (or "PRIMARY" if none)
func (hdu *primaryHDU) Name() string {
card := hdu.hdr.Get("EXTNAME")
if card == nil {
return "PRIMARY"
}
return card.Value.(string)
}
// Version returns the value of the 'EXTVER' Card (or 1 if none)
func (hdu *primaryHDU) Version() int {
card := hdu.hdr.Get("EXTVER")
if card == nil {
return 1
}
rv := reflect.ValueOf(card.Value)
return int(rv.Int())
}
// NewPrimaryHDU creates a new PrimaryHDU with Header hdr.
// If hdr is nil, a default Header will be created.
func NewPrimaryHDU(hdr *Header) (Image, error) {
var err error
if hdr == nil {
hdr = NewDefaultHeader()
}
// add default cards (SIMPLE, BITPIX, NAXES, AXIS1, AXIS2)
keys := make(map[string]struct{}, len(hdr.cards))
for i := range hdr.cards {
card := &hdr.cards[i]
k := card.Name
keys[k] = struct{}{}
}
cards := make([]Card, 0, 3)
if _, ok := keys["SIMPLE"]; !ok {
cards = append(cards, Card{
Name: "SIMPLE",
Value: true,
Comment: "primary HDU",
})
}
if _, ok := keys["BITPIX"]; !ok {
cards = append(cards, Card{
Name: "BITPIX",
Value: hdr.Bitpix(),
Comment: "number of bits per data pixel",
})
}
if _, ok := keys["NAXIS"]; !ok {
cards = append(cards, Card{
Name: "NAXIS",
Value: len(hdr.Axes()),
Comment: "number of data axes",
})
}
phdr := *hdr
phdr.cards = append(cards, hdr.cards...)
hdu := &primaryHDU{
imageHDU{
hdr: phdr,
raw: make([]byte, 0),
},
}
return hdu, err
}