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"] = nothingERROR: MethodError: no method matching FITSFiles.Card(::String, ::Nothing) The type `FITSFiles.Card` exists, but no method is defined for this combination of argument types when trying to construct it. Closest candidates are: FITSFiles.Card(::Any, ::Any, ::Any, ::Any, ::Any) @ FITSFiles ~/.julia/packages/FITSFiles/0MEHx/src/card.jl:232 FITSFiles.Card(::S; ...) where S<:AbstractString @ FITSFiles ~/.julia/packages/FITSFiles/0MEHx/src/card.jl:237 FITSFiles.Card(::S, ::V; ...) where {S<:AbstractString, V<:Union{Missing, AbstractString, Number}} @ FITSFiles ~/.julia/packages/FITSFiles/0MEHx/src/card.jl:237 ...

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.
       """)ERROR: Value string contains invalid characters.

Add HISTORY entry:

julia> push!(img, History, """
       We now describe how to add a long form history to the end of a header.
       """)ERROR: Value string contains invalid characters.

Retrieve long form comments/ history:

julia> comment_strings = img[Comment]Any[]
julia> history_strings = img[History]Any[]

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 vector of FITSFiles.jl Cards. If necessary, you can recover it using header(img); however, in most cases you can access header keywords directly from the image.

API docs: