From feaa43c34b1b8dffa74e17a467c7655718ff231c Mon Sep 17 00:00:00 2001 From: William Thompson Date: Fri, 26 Aug 2022 13:13:33 -0700 Subject: [PATCH 1/5] Towards unified JuliaAstro docs --- docs/Project.toml | 6 +++--- docs/make.jl | 9 ++------- docs/pages.jl | 8 ++++++++ 3 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 docs/pages.jl diff --git a/docs/Project.toml b/docs/Project.toml index 7f4c52e..08717be 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -9,7 +9,7 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" [compat] -Documenter = "0.25" -HCIDatasets = "0.3" -Optim = "1" +Documenter = "0.25, 0.26, 0.27" Plots = "1" +Optim = "1" +HCIDatasets = "0.3" diff --git a/docs/make.jl b/docs/make.jl index f88fb83..647839c 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,7 +7,7 @@ setup = quote end DocMeta.setdocmeta!(PSFModels, :DocTestSetup, setup; recursive = true) - +include("pages.jl") makedocs(; modules=[PSFModels], authors="Miles Lucas and contributors", @@ -18,12 +18,7 @@ makedocs(; canonical="https://juliaastro.github.io/PSFModels.jl", assets=String[], ), - pages=[ - "Home" => "index.md", - "Examples" => "examples.md", - "Benchmarks" => "bench.md", - "API/Reference" => "api.md", - ], + pages=pages ) deploydocs(; diff --git a/docs/pages.jl b/docs/pages.jl new file mode 100644 index 0000000..a24980e --- /dev/null +++ b/docs/pages.jl @@ -0,0 +1,8 @@ + +pages=[ + "Home" => "index.md", + "Examples" => "examples.md", + "Benchmarks" => "bench.md", + "API/Reference" => "api.md", +] +requiredmods = Symbol[] From bf0f8f2b8c15365e762ef1ab8d0abc71bd42600d Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Wed, 13 Mar 2024 21:20:07 -1000 Subject: [PATCH 2/5] fix airy amplitude scaling --- Project.toml | 2 +- src/airy.jl | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index ed294b1..394255b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PSFModels" uuid = "9ba017d1-7760-46cd-84a3-1e79e9ae9ddc" authors = ["Miles Lucas and contributors"] -version = "0.7.1" +version = "0.8.0" [deps] CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" diff --git a/src/airy.jl b/src/airy.jl index f0b2162..5754c43 100644 --- a/src/airy.jl +++ b/src/airy.jl @@ -43,14 +43,12 @@ function _airydisk(px, py, x, y, fwhm, ratio, amp, theta, background) # unnormalized airydisk r = sqrt(dx^2 + dy^2) # short-circuit - iszero(r) && return amp / (1 - ratio^2)^2 + background + iszero(r) && return amp + background q = AIRY_PRE * r / fwhm I1 = 2 * besselj1(q) / q - if iszero(ratio) - return amp * I1^2 + background - end - I2 = 2 * ratio * besselj1(q * ratio) / q - return amp * ((I1 - I2) / (1 - ratio^2))^2 + background + iszero(ratio) && return amp * I1^2 + background + I2 = 2 * ratio^2 * besselj1(q * ratio) / q + return amp * (I1 - I2)^2 + background end # bivariate @@ -66,11 +64,9 @@ function _airydisk(px, py, x, y, fwhm::BivariateLike, ratio, amp, theta, backgro fwhmx, fwhmy = fwhm q = AIRY_PRE * sqrt((dx / fwhmx)^2 + (dy / fwhmy)^2) # short-circuit - iszero(q) && return amp / (1 - ratio^2)^2 + background + iszero(q) && return amp + background I1 = 2 * besselj1(q) / q - if iszero(ratio) - return amp * I1^2 + background - end - I2 = 2 * ratio * besselj1(q * ratio) / q - return amp * ((I1 - I2) / (1 - ratio^2))^2 + background + iszero(ratio) && return amp * I1^2 + background + I2 = 2 * ratio^2 * besselj1(q * ratio) / q + return amp * (I1 - I2)^2+ background end From 346d67e72105c0b7bc6d3c2bf638ff43ef4e068b Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Wed, 13 Mar 2024 21:20:14 -1000 Subject: [PATCH 3/5] fix moffat FWHM conversion --- src/moffat.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/moffat.jl b/src/moffat.jl index 53b032f..62540df 100644 --- a/src/moffat.jl +++ b/src/moffat.jl @@ -23,11 +23,15 @@ function _moffat(px, py, x, y, fwhm, alpha, amp, theta, background) # rotate !iszero(theta) && @warn "isotropic moffat is not affected by non-zero rotation angle $theta" # unnormalized moffat - dist = dx^2 + dy^2 - dist /= (fwhm / 2)^2 + gamma = _moffat_fwhm_to_gamma(fwhm, alpha) + dist = (dx / gamma)^2 + (dy / gamma)^2 return amp / (1 + dist)^alpha + background end +# http://openafox.com/science/peak-function-derivations.html#moffat +_moffat_gamma_to_fwhm(gamma, alpha) = 2 * gamma * sqrt(2^(1/alpha) - 1) +_moffat_fwhm_to_gamma(fwhm, alpha) = fwhm / (2 * sqrt(2^(1/alpha) - 1)) + # bivariate function _moffat(px, py, x, y, fwhm::BivariateLike, alpha, amp, theta, background) # find offset from center @@ -38,8 +42,8 @@ function _moffat(px, py, x, y, fwhm::BivariateLike, alpha, amp, theta, backgroun dx, dy = rotate_point(dx, dy, theta) end # unnormalized moffat - fwhmx, fwhmy = fwhm + gammax, gammay = _moffat_fwhm_to_gamma.(fwhm, alpha) # unnormalized moffat - dist = (dx / (fwhmx/2))^2 + (dy / (fwhmy/2))^2 + dist = (dx / gammax)^2 + (dy / gammay)^2 return amp / (1 + dist)^alpha + background end From ed63fd07c90c83a64b8f0ffec78a88babd8e273b Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Wed, 13 Mar 2024 21:20:18 -1000 Subject: [PATCH 4/5] add tests --- test/runtests.jl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 851f4be..0c8d922 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,12 @@ function test_model_interface(K) val_dir = @inferred K(12, 13; x=12, y=13, fwhm=10) @test m(12, 13) ≈ val_dir ≈ 1 + # test position off pixel grid + m = K(x=12.5, y=13.5, fwhm=10) + val_dir = @inferred K(12.5, 13.5; x=12.5, y=13.5, fwhm=10) + @test m(12.5, 13.5) ≈ val_dir ≈ 1 + + # test diagonal fwhm m = K(x=0, y=0, fwhm=(10, 9)) @test m(3, 5) ≈ K(3, 5; x=0, y=0, fwhm=(10, 9)) ≈ K(3, 5; x=0, y=0, fwhm=SA[10, 9]) @@ -103,16 +109,16 @@ end @test m(0, -r2) ≈ 0 atol=1e-5 # test with ratio - mratio = airydisk(x=0, y=0, fwhm=10, ratio=sqrt(0.5)) + mratio = airydisk(x=0, y=0, fwhm=10, amp=1, ratio=sqrt(0.5)) # test attenuation - @test mratio(0, 0) ≈ 4 + @test mratio(0, 0) ≈ 1 @test mratio(radius, 0) > m(radius, 0) @test mratio(-radius, 0) > m(-radius, 0) @test mratio(0, radius) > m(0, radius) @test mratio(0, -radius) > m(0, -radius) - mratio = airydisk(x=0, y=0, fwhm=(10, 6), ratio=sqrt(0.5)) + mratio = airydisk(x=0, y=0, fwhm=(10, 6), ratio=sqrt(0.5), amp=4) r1 = fwhm[1] * 1.18677 r2 = fwhm[2] * 1.18677 # test attenuation @@ -121,6 +127,10 @@ end @test mratio(-r1, 0) > m(-r1, 0) @test mratio(0, r2) > m(0, r2) @test mratio(0, -r2) > m(0, -r2) + + # https://github.com/JuliaAstro/PSFModels.jl/issues/14 + mratio = airydisk(x = 40.5, y=40.5, fwhm=10, ratio=0.2,amp=1) + @test mratio(40.5, 40.5) ≈ 1 end @testset "moffat" begin @@ -135,8 +145,15 @@ end # different alpha m = moffat(x=0, y=0, fwhm=10, alpha=2) - expected = inv(1 + sum(abs2, SA[1, 2]) / 25)^2 + expected = inv(1 + sum(abs2, SA[1, 2] ./ PSFModels._moffat_fwhm_to_gamma(10, 2)))^2 @test m(1, 2) ≈ expected + + fwhms = randn(rng, 100) .+ 10 + for alpha in [0.5, 1.0, 1.5] + gammas = PSFModels._moffat_fwhm_to_gamma.(fwhms, alpha) + fwhm_calc = PSFModels._moffat_gamma_to_fwhm.(gammas, alpha) + @test fwhms ≈ fwhm_calc + end end include("plotting.jl") From 9abf81301ba98418539bac9353c3c818784c6cca Mon Sep 17 00:00:00 2001 From: Miles Lucas Date: Thu, 28 Mar 2024 22:58:32 -1000 Subject: [PATCH 5/5] confirm correct ratio for obscured airy pattern --- src/airy.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/airy.jl b/src/airy.jl index 5754c43..a54b6c7 100644 --- a/src/airy.jl +++ b/src/airy.jl @@ -47,7 +47,7 @@ function _airydisk(px, py, x, y, fwhm, ratio, amp, theta, background) q = AIRY_PRE * r / fwhm I1 = 2 * besselj1(q) / q iszero(ratio) && return amp * I1^2 + background - I2 = 2 * ratio^2 * besselj1(q * ratio) / q + I2 = 2 * ratio * besselj1(q * ratio) / q return amp * (I1 - I2)^2 + background end @@ -67,6 +67,6 @@ function _airydisk(px, py, x, y, fwhm::BivariateLike, ratio, amp, theta, backgro iszero(q) && return amp + background I1 = 2 * besselj1(q) / q iszero(ratio) && return amp * I1^2 + background - I2 = 2 * ratio^2 * besselj1(q * ratio) / q + I2 = 2 * ratio * besselj1(q * ratio) / q return amp * (I1 - I2)^2+ background end