Skip to content

Commit

Permalink
add interfacing to Interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
kcarloni committed Dec 25, 2023
1 parent 7c7fee6 commit cf4aa17
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"
[deps]
BasicBSpline = "4c5d9882-2acf-4ea4-9e48-968fd4518195"
FITSIO = "525bcba6-941b-5504-bd06-fd0dc1a4d2eb"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

Expand Down
3 changes: 3 additions & 0 deletions src/PhotosplineReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ module PhotosplineReader

using FITSIO
using BasicBSpline
using Interpolations
using StaticArrays
using Printf

# structs
export SplineTable

export spline_interpolation

# evaluation functions:
export evaluate_simple

Expand Down
42 changes: 40 additions & 2 deletions src/_SplineTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end
"""
SplineTable( f::FITS )
read `FITS` file `f` into a `SplineTable` struct.
read a `FITS` file into a `SplineTable` struct.
"""
function SplineTable( f::FITS )

Expand Down Expand Up @@ -67,4 +67,42 @@ function Base.show( io::IO, spt::SplineTable )
@printf(io, "\n (%.2f, %.2f)", spt.extents[:, d]...)
end

end
end


# -----------------

"""
spline_interpolation( spt::SplineTable )
spline_interpolation( f::FITS )
make an Interpolation object from a given SplineTable.
note that this method assumes that spline padding knots are symmetric on both sides,
and that it Interpolations supports only up to cubic-order B-splines.
"""
function spline_interpolation( spt::SplineTable )

buffers = ( spt.nknots .- size(spt.coeffs) ) 2
knots = Tuple(
spt.knots[d][( 1+buffers[d] ):( end-buffers[d]) ]
for d in 1:spt.ndim
)
nknots = length.( knots )

orders = (
Constant(), Linear(), Quadratic(), Cubic() )

bsp = Tuple( BSpline(orders[o+1]) for o in spt.orders )

itp = Interpolations.BSplineInterpolation(
eltype(spt.coeffs),
spt.coeffs,
bsp,
range.(1, nknots)
)
sitp = scale(itp, knots... );
esitp = extrapolate(sitp, 0.)
end

spline_interpolation( f::FITS ) =
spline_interpolation( SplineTable(f) )

0 comments on commit cf4aa17

Please sign in to comment.