Skip to content

Commit 5032cae

Browse files
committed
Make polarized model testing better
1 parent fb28a85 commit 5032cae

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

src/models/polarized.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ function Base.show(io::IO, model::PolarizedModel)
3939
print(io, "\tV: $(model.V)")
4040
end
4141

42-
ChainRulesCore.@non_differentiable visanalytic(::Type)
43-
ChainRulesCore.@non_differentiable imanalytic(::Type)
4442
Base.@assume_effects :foldable @inline visanalytic(::Type{PolarizedModel{I,Q,U,V}}) where {I,Q,U,V} = visanalytic(I)*visanalytic(Q)*visanalytic(U)*visanalytic(V)
4543
Base.@assume_effects :foldable @inline imanalytic(::Type{PolarizedModel{I,Q,U,V}}) where {I,Q,U,V} = imanalytic(I)*imanalytic(Q)*imanalytic(U)*imanalytic(V)
4644

test/polarized.jl

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
function testpol(m)
1+
function testpol(m, uv)
22
g = imagepixels(5.0, 5.0, 128, 128)
33
img = intensitymap(m, g)
44
img2 = zero(img)
55
intensitymap!(img2, m)
66

77
@test all(==(1), img .≈ img2)
88

9-
u = fftshift(fftfreq(length(g.X), 1/step(g.X)))
10-
uv = (U=u, V=u)
11-
v = visibilities(m, uv)
12-
13-
9+
@inferred visibilities(m, uv)
1410

11+
v = visibilities(m, uv)
1512

1613
plot(m)
1714
plot(img)
@@ -23,16 +20,26 @@ end
2320

2421
@testset "Polarized Analytic" begin
2522
m = PolarizedModel(Gaussian(), 0.1*Gaussian(), 0.1*Gaussian(), 0.1*Gaussian())
26-
testpol(m)
23+
g = imagepixels(10.0, 10.0, 512, 512)
24+
s = map(length, dims(g))
25+
26+
u = fftshift(fftfreq(length(g.X), 1/step(g.X)))
27+
uv = (U=u, V=-u)
28+
29+
testpol(m, uv)
2730
end
2831

2932
@testset "Polarized Semi Analytic" begin
3033
m = PolarizedModel(ExtendedRing(8.0), 0.1*Gaussian(), 0.1*Gaussian(), 0.1*Gaussian())
3134
g = imagepixels(10.0, 10.0, 512, 512)
3235
s = map(length, dims(g))
33-
vff = testpol(modelimage(m, g, FFTAlg()))
34-
vnf = testpol(modelimage(m, g, NFFTAlg()))
35-
vdf = testpol(modelimage(m, g, DFTAlg()))
36+
37+
u = fftshift(fftfreq(length(g.X), 1/step(g.X)))
38+
uv = (U=u, V=-u)
39+
40+
vff = testpol(modelimage(m, g, FFTAlg()), uv)
41+
vnf = testpol(modelimage(m, g, NFFTAlg(uv.U, uv.V)), uv)
42+
vdf = testpol(modelimage(m, g, DFTAlg(uv.U, uv.V)), uv)
3643

3744
@test isapprox(vff, vnf, atol=1e-6)
3845
@test isapprox(vff, vdf, atol=1e-6)
@@ -41,29 +48,36 @@ end
4148

4249
@testset "Polarized Modified" begin
4350
g = imagepixels(5.0, 5.0, 128, 128)
51+
u = fftshift(fftfreq(length(g.X), 1/step(g.X)))
52+
uv = (U=u, V=-u)
53+
4454
s = map(length, dims(g))
4555
m0 = PolarizedModel(ExtendedRing(2.0), 0.1*Gaussian(), 0.1*Gaussian(), 0.1*Gaussian())
4656
m = shifted(m0, 0.1 ,0.1)
47-
testpol(modelimage(m, g))
57+
testpol(modelimage(m, g, NFFTAlg(uv.U, uv.V)), uv)
4858

4959
m = rotated(m0, 0.1)
50-
testpol(modelimage(m, g))
60+
testpol(modelimage(m, g, NFFTAlg(uv.U, uv.V)), uv)
5161

5262
m = renormed(m0, 0.1)
53-
testpol(modelimage(m, g))
63+
testpol(modelimage(m, g, NFFTAlg(uv.U, uv.V)), uv)
5464

5565
m = stretched(m0, 0.1, 0.4)
56-
testpol(modelimage(m, g))
66+
testpol(modelimage(m, g, NFFTAlg(uv.U, uv.V)), uv)
5767

5868
end
5969

6070
@testset "Polarized Combinators" begin
6171
m1 = PolarizedModel(Gaussian(), 0.1*Gaussian(), 0.1*Gaussian(), 0.1*Gaussian())
6272
m2 = PolarizedModel(Disk(), shifted(Disk(), 0.1, 1.0), ZeroModel(), ZeroModel())
63-
testpol(convolved(m1,m2))
73+
g = imagepixels(5.0, 5.0, 128, 128)
74+
u = fftshift(fftfreq(length(g.X), 1/step(g.X)))
75+
uv = (U=u, V=-u)
76+
77+
testpol(convolved(m1,m2), uv)
6478

65-
testpol(convolved(m1,Gaussian()))
66-
testpol(convolved(stretched(m1, 0.5, 0.5),Gaussian()))
79+
testpol(convolved(m1,Gaussian()), uv)
80+
testpol(convolved(stretched(m1, 0.5, 0.5),Gaussian()), uv)
6781
end
6882

6983
@testset "Polarized All Mod" begin
@@ -72,7 +86,10 @@ end
7286
m = convolved(m1,m2)+m1
7387
g = imagepixels(5.0, 5.0, 128, 128)
7488
s = map(length, dims(g))
75-
testpol(modelimage(m, g))
89+
u = fftshift(fftfreq(length(g.X), 1/step(g.X)))
90+
uv = (U=u, V=-u)
91+
92+
testpol(modelimage(m, g), uv)
7693
end
7794

7895
@testset "Rotation" begin

0 commit comments

Comments
 (0)