Skip to content

Commit

Permalink
add a more convenient FITSHeader constructor (#199)
Browse files Browse the repository at this point in the history
* add a more convenient FITSHeader constructor

* fix typo
  • Loading branch information
aplavin authored Aug 16, 2024
1 parent d267f48 commit 6d4a051
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/header.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# Used here and in other files. Functions that operate on FITSFile
# start with `fits_`.

FITSIO.FITSHeader(cards::AbstractVector{<:NamedTuple}) = FITSHeader(
map(x -> x.key, cards),
map(x -> x.value, cards),
map(x -> x.comment, cards),
)

"""
try_parse_hdrval(T, s) -> x::Union{T,Nothing}
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,17 @@ end
"string value",
"this is a comment",
"this is a history"])
inhdr2 = FITSHeader(map(NamedTuple{(:key,:value,:comment)}, [
("FLTKEY", 1.0, "floating point keyword",),
("INTKEY", 1, "",),
("BOOLKEY", true, "boolean keyword",),
("STRKEY", "string value", "string value",),
("COMMENT", nothing, "this is a comment",),
("HISTORY", nothing, "this is a history",),
]))
@test inhdr.keys == inhdr2.keys
@test inhdr.values == inhdr2.values
@test inhdr.comments == inhdr2.comments

@test repr(inhdr) == """
FLTKEY = 1.0 / floating point keyword
Expand Down

0 comments on commit 6d4a051

Please sign in to comment.