Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/FITSWCSFITSFilesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function _set_fitsfiles_header_card!(dict::Dict{String, Any}, key::String, value
isnothing(parsed) && return dict

name, parsed_value = parsed
if name == "EXTVER" || name == "NAXES" || startswith(name, "AXIS.")
if name in ("EXTVER", "NAXES", "DOCORR") ||
any(prefix -> startswith(name, prefix), ("AXIS.", "OFFSET.", "SCALE.", "TPD.", "AUX."))
dict["$(key).$(name)"] = parsed_value
end
return dict
Expand Down
3 changes: 2 additions & 1 deletion ext/FITSWCSFITSIOExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function _set_fitsio_header_card!(dict::Dict{String, Any}, key::String, value)
isnothing(parsed) && return dict

name, parsed_value = parsed
if name == "EXTVER" || name == "NAXES" || startswith(name, "AXIS.")
if name in ("EXTVER", "NAXES", "DOCORR") ||
any(prefix -> startswith(name, prefix), ("AXIS.", "OFFSET.", "SCALE.", "TPD.", "AUX."))
dict["$(key).$(name)"] = parsed_value
end
return dict
Expand Down
4 changes: 1 addition & 3 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ matching the APE-14 convention. For `SlicedWCSTransform`: the parent's
matrix indexed by the kept axes.
"""
function axis_correlation_matrix(wcs::WCSTransform{N}) where {N}
# If any pre-linear distortion is present (SIP, D2IM, CPDIS), we must be
# conservative: distortions can introduce arbitrary cross-axis coupling
# that isn't captured by the CD matrix alone.
# Any distortion stage may introduce cross-axis coupling not captured by CD.
if has_distortion(wcs.pipeline)
return fill(true, SMatrix{N, N, Bool})
end
Expand Down
26 changes: 22 additions & 4 deletions src/auxiliary_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ function _paper_iv_lookup_spec(
)
dist_key = "$(dist_prefix)$(axis)$(alt_str)"
haskey(header, dist_key) || return nothing
uppercase(String(header[dist_key])) == "LOOKUP" ||
dtype = uppercase(strip(String(header[dist_key])))
dtype == "TPD" && return nothing
dtype == "LOOKUP" ||
throw(ArgumentError("unsupported Paper IV distortion type $(header[dist_key]) in $dist_key"))

# Skip tables whose declared error is below the requested threshold.
Expand Down Expand Up @@ -154,10 +156,26 @@ function _header_references_tabular_axis(header::AbstractDict, alt_str::Abstract
end

function _header_references_external_wcs_data(header::AbstractDict, alt_str::AbstractString)
# Paper IV distortion keywords and TAB axes are the current external-data signals.
for key in keys(header)
suffix = uppercase(String(alt_str))

# Only lookup distortions require external arrays; TPD is header-resident.
for (key, value) in header
key isa AbstractString || continue
is_lookup_distortion_keyword(key, alt_str) && return true
ukey = uppercase(String(key))
occursin(Regex("^D2IMDIS[1-9][0-9]*$(suffix)\$"), ukey) && return true
occursin(Regex("^D2IMERR[1-9][0-9]*$(suffix)\$"), ukey) && return true
ukey == "AXISCORR$(suffix)" && return true
if occursin(Regex("^CPDIS[1-9][0-9]*$(suffix)\$"), ukey)
uppercase(strip(String(value))) == "LOOKUP" && return true
end

# Undeclared DP/DQ records retain the legacy external-data guard, while
# records belonging to an explicit TPD function remain header-resident.
parameter = match(Regex("^D([PQ])([1-9][0-9]*)$(suffix)\\."), ukey)
isnothing(parameter) && continue
dist_prefix = parameter.captures[1] == "P" ? "CPDIS" : "CQDIS"
dist_key = "$(dist_prefix)$(parameter.captures[2])$(suffix)"
haskey(header, dist_key) && uppercase(strip(String(header[dist_key]))) == "TPD" || return true
end

return _header_references_tabular_axis(header, alt_str)
Expand Down
Loading