Skip to content

Commit 6cca536

Browse files
committed
add printing and tests for all models
1 parent 1a2546c commit 6cca536

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
88
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
99
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
1010
KeywordCalls = "4d827475-d3e4-43d6-abe3-9688362ede9f"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1112
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1213
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1314
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

src/airy.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ end
4343
Base.size(a::AiryDisk) = map(length, a.indices)
4444
Base.axes(a::AiryDisk) = a.indices
4545

46+
# short printing
47+
Base.show(io::IO, a::AiryDisk{T}) where {T} = print(io, "AiryDisk{$T}(pos=$(a.pos), fwhm=$(a.fwhm), amp=$(a.amp))")
48+
4649
const rz = 3.8317059702075125 / π
4750

4851
function (a::AiryDisk{T})(point::AbstractVector) where T

src/moffat.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ end
3939
Base.size(m::Moffat) = map(length, m.indices)
4040
Base.axes(m::Moffat) = m.indices
4141

42+
# short printing
43+
Base.show(io::IO, m::Moffat{T}) where {T} = print(io, "Moffat{$T}(pos=$(m.pos), fwhm=$(m.fwhm), amp=$(m.amp), alpha=$(m.alpha))")
44+
45+
4246
# scalar case
4347
function (m::Moffat{T})(point::AbstractVector) where T
4448
hwhm = m.fwhm / 2

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,13 @@ end
8282
m = Gaussian(fwhm=10)
8383
expected = exp(-4 * log(2) * sum(abs2, SA[1, 2]) / 100)
8484
@test m[2, 1] m(1, 2) expected
85-
85+
@test repr(m) == "Gaussian{Float64}(pos=[0, 0], fwhm=10, amp=1.0)"
86+
8687
m = Gaussian(fwhm=(10, 9))
8788
wdist = (1/10)^2 + (2/9)^2
8889
expected = exp(-4 * log(2) * wdist)
8990
@test m[2, 1] m(1, 2) expected
91+
@test repr(m) == "Gaussian{Float64}(pos=[0, 0], fwhm=(10, 9), amp=1.0)"
9092

9193
# test Normal alias
9294
@test Normal(fwhm=10) === Gaussian(fwhm=10)
@@ -101,6 +103,7 @@ end
101103
@test m(-radius, 0) 0 atol=eps(Float64)
102104
@test m(0, radius) 0 atol=eps(Float64)
103105
@test m(0, -radius) 0 atol=eps(Float64)
106+
@test repr(m) == "AiryDisk{Float64}(pos=[0, 0], fwhm=10, amp=1.0)"
104107

105108
m = AiryDisk(fwhm=(10, 9))
106109
r1 = m.fwhm[1] * 1.18677
@@ -110,22 +113,26 @@ end
110113
@test m(-r1, 0) 0 atol=eps(Float64)
111114
@test m(0, r2) 0 atol=eps(Float64)
112115
@test m(0, -r2) 0 atol=eps(Float64)
116+
@test repr(m) == "AiryDisk{Float64}(pos=[0, 0], fwhm=(10, 9), amp=1.0)"
113117
end
114118

115119
@testset "Moffat" begin
116120
m = Moffat(fwhm=10)
117121
expected = inv(1 + sum(abs2, SA[1, 2]) / 25)
118122
@test m[2, 1] m(1, 2) expected
123+
@test repr(m) == "Moffat{Float64}(pos=[0, 0], fwhm=10, amp=1.0, alpha=1)"
119124

120125
m = Moffat(fwhm=(10, 9))
121126
wdist = (1/5)^2 + (2/4.5)^2
122127
expected = inv(1 + wdist)
123128
@test m[2, 1] m(1, 2) expected
129+
@test repr(m) == "Moffat{Float64}(pos=[0, 0], fwhm=(10, 9), amp=1.0, alpha=1)"
124130

125131
# different alpha
126132
m = Moffat(fwhm=10, alpha=2)
127133
expected = inv(1 + sum(abs2, SA[1, 2]) / 25)^2
128134
@test m[2, 1] m(1, 2) expected
135+
@test repr(m) == "Moffat{Float64}(pos=[0, 0], fwhm=10, amp=1.0, alpha=2)"
129136
end
130137

131138
include("plotting.jl")

0 commit comments

Comments
 (0)