Skip to content

Commit

Permalink
add unit tests for calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
mileslucas committed Dec 25, 2024
1 parent 847718c commit 2c7edc6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 51 deletions.
32 changes: 16 additions & 16 deletions src/QuadPol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ function extract_quadrants(

## Step 3
# integrate apertures for Q
mask = @. (disk_angles <= 45) | (disk_angles > 315)
mask = @. (disk_angles < 45) | (disk_angles >= 315)
Q000 = mask .* Qrot

mask = @. 45 < disk_angles <= 135
mask = @. 45 <= disk_angles < 135
Q090 = mask .* Qrot

mask = @. 135 < disk_angles <= 225
mask = @. 135 <= disk_angles < 225
Q180 = mask .* Qrot

mask = @. 225 < disk_angles <= 315
mask = @. 225 <= disk_angles < 315
Q270 = mask .* Qrot

# integrate apertures for U
mask = @. 0 < disk_angles <= 90
mask = @. 0 <= disk_angles < 90
U045 = mask .* Urot

mask = @. 90 < disk_angles <= 180
mask = @. 90 <= disk_angles < 180
U135 = mask .* Urot

mask = @. 180 < disk_angles <= 270
mask = @. 180 <= disk_angles < 270
U225 = mask .* Urot

mask = @. 270 < disk_angles <= 360
mask = @. 270 <= disk_angles < 360
U315 = mask .* Urot

return Quadrants(
Expand Down Expand Up @@ -132,36 +132,36 @@ function extract_quadrants(

## Step 3
# integrate apertures for Q
mask = @. (disk_angles <= 45) | (disk_angles > 315)
mask = @. (disk_angles < 45) | (315 <= disk_angles)
Q000 = mask .* Qrot
Q000_err = mask .* Qrot_err

mask = @. 45 < disk_angles <= 135
mask = @. 45 <= disk_angles < 135
Q090 = mask .* Qrot
Q090_err = mask .* Qrot_err

mask = @. 135 < disk_angles <= 225
mask = @. 135 <= disk_angles < 225
Q180 = mask .* Qrot
Q180_err = mask .* Qrot_err

mask = @. 225 < disk_angles <= 315
mask = @. 225 <= disk_angles < 315
Q270 = mask .* Qrot
Q270_err = mask .* Qrot_err

# integrate apertures for U
mask = @. 0 < disk_angles <= 90
mask = @. 0 <= disk_angles < 90
U045 = mask .* Urot
U045_err = mask .* Urot_err

mask = @. 90 < disk_angles <= 180
mask = @. 90 <= disk_angles < 180
U135 = mask .* Urot
U135_err = mask .* Urot_err

mask = @. 180 < disk_angles <= 270
mask = @. 180 <= disk_angles < 270
U225 = mask .* Urot
U225_err = mask .* Urot_err

mask = @. 270 < disk_angles <= 360
mask = @. 270 <= disk_angles < 360
U315 = mask .* Urot
U315_err = mask .* Urot_err

Expand Down
70 changes: 35 additions & 35 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.11.1"
julia_version = "1.11.2"
manifest_format = "2.0"
project_hash = "be112346cee6dbb227eb052069e5b5f7ba295254"

Expand Down Expand Up @@ -61,9 +61,9 @@ version = "1.1.2"

[[deps.ArrayInterface]]
deps = ["Adapt", "LinearAlgebra"]
git-tree-sha1 = "d5140b60b87473df18cf4fe66382b7c3596df047"
git-tree-sha1 = "017fcb757f8e921fb44ee063a7aafe5f89b86dd1"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "7.17.1"
version = "7.18.0"

[deps.ArrayInterface.extensions]
ArrayInterfaceBandedMatricesExt = "BandedMatrices"
Expand Down Expand Up @@ -157,9 +157,9 @@ version = "1.5.0"

[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "8873e196c2eb87962a2048b3b8e08946535864a1"
git-tree-sha1 = "35abeca13bc0425cff9e59e229d971f5231323bf"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+2"
version = "1.0.8+3"

[[deps.CEnum]]
git-tree-sha1 = "389ad5c84de1ae7cf0e28e381131c98ea87d54fc"
Expand Down Expand Up @@ -208,9 +208,9 @@ weakdeps = ["SparseArrays"]

[[deps.CodecBzip2]]
deps = ["Bzip2_jll", "TranscodingStreams"]
git-tree-sha1 = "e7c529cc31bb85b97631b922fa2e6baf246f5905"
git-tree-sha1 = "84990fa864b7f2b4901901ca12736e45ee79068c"
uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
version = "0.8.4"
version = "0.8.5"

[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
Expand Down Expand Up @@ -431,9 +431,9 @@ version = "1.8.0"

[[deps.FFTW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "4d81ed14783ec49ce9f2e168208a12ce1815aa25"
git-tree-sha1 = "5cf2433259aa3985046792e2afc01fcec076b549"
uuid = "f5851436-0d7a-5f13-b9de-f02708fd171a"
version = "3.3.10+1"
version = "3.3.10+2"

[[deps.FITSIO]]
deps = ["CFITSIO", "Printf", "Reexport", "Tables"]
Expand Down Expand Up @@ -503,9 +503,9 @@ version = "6.3.0+0"

[[deps.Giflib_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "0224cce99284d997f6880a42ef715a37c99338d1"
git-tree-sha1 = "7141135f9073f135e68c5ee8df44fb0fb80689b8"
uuid = "59f7168a-df46-5410-90c8-f2779963d0ec"
version = "5.2.2+0"
version = "5.2.2+1"

[[deps.IfElse]]
git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1"
Expand Down Expand Up @@ -642,9 +642,9 @@ weakdeps = ["Dates", "Test"]
InverseFunctionsTestExt = "Test"

[[deps.InvertedIndices]]
git-tree-sha1 = "0dc7b50b8d436461be01300fd8cd45aa0274b038"
git-tree-sha1 = "6da3c4316095de0f5ee2ebd875df8721e7e0bdbe"
uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
version = "1.3.0"
version = "1.3.1"

[[deps.IrrationalConstants]]
git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2"
Expand All @@ -663,9 +663,9 @@ version = "1.0.0"

[[deps.JLLWrappers]]
deps = ["Artifacts", "Preferences"]
git-tree-sha1 = "be3dc50a92e5a386872a493a10050136d4703f9b"
git-tree-sha1 = "a007feb38b422fbdab534406aeca1b86823cb4d6"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.6.1"
version = "1.7.0"

[[deps.JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
Expand All @@ -681,9 +681,9 @@ version = "0.1.5"

[[deps.JpegTurbo_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "25ee0be4d43d0269027024d75a24c24d6c6e590c"
git-tree-sha1 = "3447a92280ecaad1bd93d3fce3d408b6cfff8913"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "3.0.4+0"
version = "3.1.0+1"

[[deps.JuMP]]
deps = ["LinearAlgebra", "MacroTools", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays"]
Expand All @@ -697,9 +697,9 @@ weakdeps = ["DimensionalData"]

[[deps.LERC_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "36bdbc52f13a7d1dcb0f3cd694e01677a515655b"
git-tree-sha1 = "78e0f4b5270c4ae09c7c5f78e77b904199038945"
uuid = "88015f11-f218-50d7-93a8-a6af411a945d"
version = "4.0.0+0"
version = "4.0.0+2"

[[deps.LazyArtifacts]]
deps = ["Artifacts", "Pkg"]
Expand Down Expand Up @@ -760,9 +760,9 @@ version = "1.7.0+0"

[[deps.Libgpg_error_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "c6ce1e19f3aec9b59186bdf06cdf3c4fc5f5f3e6"
git-tree-sha1 = "a7f43994b47130e4f491c3b2dbe78fe9e2aed2b3"
uuid = "7add5ba3-2f88-524e-9cd5-f83b8a55f7b8"
version = "1.50.0+0"
version = "1.51.0+0"

[[deps.Libiconv_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand All @@ -783,9 +783,9 @@ version = "1.11.0"

[[deps.LogExpFunctions]]
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "a2d09619db4e765091ee5c6ffe8872849de0feea"
git-tree-sha1 = "13ca9e2586b89836fd20cccf56e57e2b9ae7f38f"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.28"
version = "0.3.29"

[deps.LogExpFunctions.extensions]
LogExpFunctionsChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -889,9 +889,9 @@ uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"

[[deps.OffsetArrays]]
git-tree-sha1 = "1a27764e945a152f7ca7efa04de513d473e9542e"
git-tree-sha1 = "5e1897147d1ff8d98883cda2be2187dcf57d8f0c"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.14.1"
version = "1.15.0"
weakdeps = ["Adapt"]

[deps.OffsetArrays.extensions]
Expand Down Expand Up @@ -1148,9 +1148,9 @@ version = "1.11.0"

[[deps.SpecialFunctions]]
deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
git-tree-sha1 = "2f5d4697f21388cbe1ff299430dd169ef97d7e14"
git-tree-sha1 = "64cca0c26b4f31ba18f13f6c12af7c85f478cfde"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "2.4.0"
version = "2.5.0"
weakdeps = ["ChainRulesCore"]

[deps.SpecialFunctions.extensions]
Expand Down Expand Up @@ -1199,9 +1199,9 @@ weakdeps = ["OffsetArrays", "StaticArrays"]

[[deps.StaticArrays]]
deps = ["LinearAlgebra", "PrecompileTools", "Random", "StaticArraysCore"]
git-tree-sha1 = "777657803913ffc7e8cc20f0fd04b634f871af8f"
git-tree-sha1 = "7c01731da8ab6d3094c4d44c9057b00932459255"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.9.8"
version = "1.9.9"
weakdeps = ["ChainRulesCore", "Statistics"]

[deps.StaticArrays.extensions]
Expand Down Expand Up @@ -1279,9 +1279,9 @@ version = "1.11.0"

[[deps.TiffImages]]
deps = ["ColorTypes", "DataStructures", "DocStringExtensions", "FileIO", "FixedPointNumbers", "IndirectArrays", "Inflate", "Mmap", "OffsetArrays", "PkgVersion", "ProgressMeter", "SIMD", "UUIDs"]
git-tree-sha1 = "0248b1b2210285652fbc67fd6ced9bf0394bcfec"
git-tree-sha1 = "3c0faa42f2bd3c6d994b06286bba2328eae34027"
uuid = "731e570b-9d59-4bfa-96dc-6df516fadf69"
version = "0.11.1"
version = "0.11.2"

[[deps.TiledIteration]]
deps = ["OffsetArrays", "StaticArrayInterface"]
Expand Down Expand Up @@ -1438,15 +1438,15 @@ version = "5.11.0+0"

[[deps.libpng_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Zlib_jll"]
git-tree-sha1 = "b70c870239dc3d7bc094eb2d6be9b73d27bef280"
git-tree-sha1 = "9c42636e3205e555e5785e902387be0061e7efc1"
uuid = "b53b4c65-9356-5827-b1ea-8c7a1a84506f"
version = "1.6.44+0"
version = "1.6.44+1"

[[deps.libsixel_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Pkg", "libpng_jll"]
git-tree-sha1 = "7dfa0fd9c783d3d0cc43ea1af53d69ba45c447df"
git-tree-sha1 = "80c5ae2c7b5163441018f4666b179f1ffca194c1"
uuid = "075b6546-f08a-558a-be8f-8157d0f608a5"
version = "1.10.3+1"
version = "1.10.3+2"

[[deps.libwebp_jll]]
deps = ["Artifacts", "Giflib_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libglvnd_jll", "Libtiff_jll", "libpng_jll"]
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ using QuadPol
using Test

@testset "QuadPol.jl" begin
include("test_calculations.jl")
include("test_HR4796.jl")
end
64 changes: 64 additions & 0 deletions test/test_calculations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

@testset "Trivial Quadrants" begin
Q_img = Matrix{Float64}(undef, 50, 50)
U_img = Matrix{Float64}(undef, 50, 50)

nx, ny = size(Q_img)
xs = range(-nx/2 + 0.5, nx/2 - 0.5)
ys = range(-ny/2 + 0.5, ny/2 - 0.5)
sky_angles = mod.(atand.(-xs, ys'), 360)

quad_values = [1, 2, 3, 4]

@. Q_img[(sky_angles < 45) | (315 <= sky_angles)] = quad_values[1]
@. Q_img[(45 <= sky_angles < 135)] = quad_values[2]
@. Q_img[(135 <= sky_angles < 225)] = quad_values[3]
@. Q_img[(225 <= sky_angles < 315)] = quad_values[4]

@. U_img[(0 <= sky_angles < 90)] = quad_values[1]
@. U_img[(90 <= sky_angles < 180)] = quad_values[2]
@. U_img[(180 <= sky_angles < 270)] = quad_values[3]
@. U_img[(270 <= sky_angles < 360)] = quad_values[4]

pa = 0
quad = QuadPol.extract_quadrants(Q_img, U_img; pa=pa)

@test maximum(quad.Q000) quad_values[1]
@test maximum(quad.Q090) quad_values[2]
@test maximum(quad.Q180) quad_values[3]
@test maximum(quad.Q270) quad_values[4]

@test maximum(quad.U045) quad_values[1]
@test maximum(quad.U135) quad_values[2]
@test maximum(quad.U225) quad_values[3]
@test maximum(quad.U315) quad_values[4]

stats = QuadPol.calculate_statistics(quad)
quad_area = prod(size(Q_img)) / 4
@test stats.Q000 quad_area * quad_values[1]
@test stats.Q090 quad_area * quad_values[2]
@test stats.Q180 quad_area * quad_values[3]
@test stats.Q270 quad_area * quad_values[4]

@test stats.U045 quad_area * quad_values[1]
@test stats.U135 quad_area * quad_values[2]
@test stats.U225 quad_area * quad_values[3]
@test stats.U315 quad_area * quad_values[4]

@test stats.Qd sum(quad_area .* quad_values)
@test stats.Ud sum(quad_area .* quad_values)

@test stats.Qd_abs sum(quad_area .* quad_values)
@test stats.Ud_abs sum(quad_area .* quad_values)

@test stats.delta_090_270 (quad_values[2] - quad_values[4]) / (quad_values[2] + quad_values[4])
@test stats.delta_045_315 (quad_values[1] - quad_values[4]) / (quad_values[1] + quad_values[4])
@test stats.delta_135_225 (quad_values[2] - quad_values[3]) / (quad_values[2] + quad_values[3])

@test stats.lambda_000_180 quad_values[1]/quad_values[3]
@test stats.lambda_045_135 quad_values[1]/quad_values[2]
@test stats.lambda_315_225 quad_values[4]/quad_values[3]

@test stats.lambda_a (quad_values[2] + quad_values[4]) / (2 * quad_values[3])
@test stats.lambda_b (quad_values[2] + quad_values[4]) / (quad_values[2] + quad_values[3])
end

0 comments on commit 2c7edc6

Please sign in to comment.