Headers

FITS files consist of one or more HDUs (header data units), and each HDU can contain an N-dimensional image or table. Before the data is a header. Headers contain (key, value, comment) groups as well as dedicated long-form COMMENT and HISTORY sections used to document, for example, the series of post-processing steps applied to an image.

Accessing Headers

Here are some examples of how to set and read keys, comments, and history.

We'll start by making a blank image:

julia> img = AstroImage(zeros(10, 10))10×10 AstroImage{Float64, 2}
├──────────────────────────────┴────────────────────────────── dims ┐
  ↓ X Sampled{Int64} Base.OneTo(10) ForwardOrdered Regular Points,
  → Y Sampled{Int64} Base.OneTo(10) ForwardOrdered Regular Points
└───────────────────────────────────────────────────────────────────┘
     1    2    3    4    5    6    7    8    9    10
  1    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
  2    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
  3    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
  4    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
  ⋮                        ⋮                         ⋮
  7    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
  8    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
  9    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0
 10    0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.0

Set keys to values with different data types:

julia> img["KEY1"] = 2   # Integer2
julia> img["KEY2"] = 2.0 # Float2.0
julia> img["KEY3"] = "STRING""STRING"
julia> img["KEY4"] = truetrue
julia> img["KEY5"] = falsefalse
julia> img["KEY6"] = nothing

Set comments:

julia> img["KEY1", Comment] = "A key with an integer value""A key with an integer value"

Read keys:

julia> a = img["KEY3"]"STRING"

Read comment:

julia> com = img["KEY1", Comment]"A key with an integer value"

Add long-form COMMENT:

julia> push!(img, Comment, """
       We now describe how to add a long form comment to the end of a header.
       """)7-element Vector{String}:
 "A key with an integer value"
 ""
 ""
 ""
 ""
 ""
 "We now describe how to add a long form comment to the end of a header.\n"

Add HISTORY entry:

julia> push!(img, History, """
       We now describe how to add a long form history to the end of a header.
       """)8-element Vector{String}:
 "A key with an integer value"
 ""
 ""
 ""
 ""
 ""
 "We now describe how to add a long form comment to the end of a header.\n"
 "We now describe how to add a long form history to the end of a header.\n"

Retrieve long form comments/ history:

julia> comment_strings = img[Comment]1-element view(::Vector{String}, [7]) with eltype String:
 "We now describe how to add a long form comment to the end of a header.\n"
julia> history_strings = img[History]1-element view(::Vector{String}, [8]) with eltype String: "We now describe how to add a long form history to the end of a header.\n"

Note that floating point values are formatted as ASCII strings when written to the FITS files, so the precision may be limited.

AstroImage objects wrap a FITSIO.jl FITSHeader. If necessary, you can recover it using header(img); however, in most cases you can access header keywords directly from the image.

API docs: