Skip to content

Commit 5b06f8e

Browse files
committed
fix bounds checking and add plotting tests
1 parent 36fc9d7 commit 5b06f8e

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/core.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ abstract type PSFModel{T} <: AbstractMatrix{T} end
2929
# getindex just calls model with reversed indices
3030
Base.getindex(model::PSFModel, idx::Vararg{<:Integer,2}) = model(reverse(idx))
3131
# always inbounds
32-
Base.checkbounds(::Type{Bool}, ::PSFModel, idx) = true
33-
Base.checkbounds(::Type{Bool}, ::PSFModel, idx...) = true
32+
Base.checkbounds(::Type{Bool}, ::PSFModel, inds...) = true
33+
Base.checkbounds(::Type{Bool}, ::PSFModel, inds::CartesianIndex) = true
3434

3535
# broadcasting hack to slurp other axes (doesn't work for numbers)
3636
Broadcast.combine_axes(psf::PSFModel, other::AbstractMatrix) = axes(other)
@@ -56,8 +56,8 @@ _position(nt::NamedTuple{()}) = SA[0, 0]
5656
]
5757

5858
function indices_from_extent(pos, extent)
59-
halfextent = @. 0.5 * extent
60-
lower = @. round(Int, pos - halfextent)
61-
upper = @. round(Int, pos + halfextent)
59+
half_extent = @. 0.5 * extent
60+
lower = @. floor(Int, pos - half_extent)
61+
upper = @. ceil(Int, pos + half_extent)
6262
return last(lower):last(upper), first(lower):first(upper)
6363
end

src/plotting.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ using RecipesBase
33
@recipe function f(model::PSFModel, inds...)
44
seriestype := :heatmap
55
aspect_ratio --> 1
6-
xlim --> extrema(inds[2])
7-
ylim --> extrema(inds[1])
6+
xlims --> extrema(first(inds))
7+
ylims --> extrema(last(inds))
88

9-
arr = model[inds...]
9+
arr = model[reverse(inds)...]
1010

1111
return inds..., arr
1212
end
1313

14-
@recipe f(model::PSFModel, inds=axes(model)) = model, inds...
14+
@recipe f(model::PSFModel, inds=reverse(axes(model))) = model, inds...

test/plotting.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
using RecipesBase: apply_recipe
22

33
@testset "plotting - $K" for K in (Gaussian, AiryDisk, Moffat)
4-
psf = K(y=1, fwhm=5)
4+
psf = K(x=0, y=1, fwhm=5)
55
recipes = apply_recipe(Dict{Symbol,Any}(), psf)
66
for rec in recipes
7-
@test getfield(rec, 1) == Dict{Symbol,Any}(
7+
@test rec.args[1] === psf
8+
ys, xs = axes(psf)
9+
@test rec.args[2] == xs
10+
@test rec.args[3] == ys
11+
end
12+
13+
recipes_full = apply_recipe(Dict{Symbol,Any}(), psf, reverse(axes(psf))...)
14+
for rec in recipes_full
15+
@test rec.plotattributes == Dict{Symbol,Any}(
816
:seriestype => :heatmap,
9-
:xlim => (-15, 15),
10-
:ylim => (-14, 16),
17+
:xlims => (-8, 8),
18+
:ylims => (-7, 9),
1119
:aspect_ratio => 1
20+
)
1221

1322
xs = rec.args[1]
1423
ys = rec.args[2]
1524
_psf = rec.args[3]
1625

17-
@test xs == -15:15
18-
@test ys == -14:16
26+
@test xs == -8:8
27+
@test ys == -7:9
1928
@test _psf == collect(psf)
2029
end
2130
end

0 commit comments

Comments
 (0)