Skip to content

feat: use com-based PSF modeling - #29

Merged
icweaver merged 12 commits into
JuliaAstro:mainfrom
RainerHeintzmann:psf
May 20, 2026
Merged

feat: use com-based PSF modeling#29
icweaver merged 12 commits into
JuliaAstro:mainfrom
RainerHeintzmann:psf

Conversation

@RainerHeintzmann

@RainerHeintzmann RainerHeintzmann commented Apr 5, 2026

Copy link
Copy Markdown
Contributor
  • Removes PSFModels.jl dependency
  • Uses simpler/faster center-of-mass estimate for PSF

@icweaver icweaver mentioned this pull request Apr 23, 2026
@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.37%. Comparing base (8531176) to head (d64307f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #29      +/-   ##
==========================================
+ Coverage   99.35%   99.37%   +0.01%     
==========================================
  Files           3        4       +1     
  Lines         156      160       +4     
==========================================
+ Hits          155      159       +4     
  Misses          1        1              
Flag Coverage Δ
unittests 99.37% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@icweaver

Copy link
Copy Markdown
Member

Thanks Rainer, initial benchmarks are looking good! I plan to make this our new default fwhm estimator

┌────────────────────────┬─────────────┬────────────┬─────────┐
│ Benchmark              │ Median Time │     Memory │  Allocs │
├────────────────────────┼─────────────┼────────────┼─────────┤
│ photometry_fit         │  993.002 μs │ 540.14 KiB │   10259 │
| photometry_com         │   67.543 μs │ 106.50 KiB │    1583 |
└────────────────────────┴─────────────┴────────────┴─────────┘

@icweaver icweaver changed the title Psf feat: use com-based psf modeling May 20, 2026
@icweaver icweaver changed the title feat: use com-based psf modeling feat: use com-based PSF modeling May 20, 2026
@icweaver
icweaver merged commit 62c0b3b into JuliaAstro:main May 20, 2026
9 of 13 checks passed
icweaver referenced this pull request Jun 4, 2026
If you copy-paste the revised function definitions from this PR into
your REPL you can run the following comparison which will show the new
implementation is ~3x faster and allocation free **EDIT: If you have to
collect the input (as we do because of how Photometry.jl passes us the
cutout) then it will be 2 allocations and adds ~100 ns to the base case
speed**. I chose to do `com_psf(T::Type{<:AbstractFloat}, img_ap,
rel_thresh)` because Float64 is not really any slower on my testing so
this way it makes it easier for us to switch to Float64 in the future if
we every wanted to.

```julia
using PSFModels: gaussian
using BenchmarkTools
import Astroalign

const x = 1:20
const y = 1:20
const T = Float32
model(x, y, amp) = gaussian(T, 4, 4; x, y, fwhm=3) * amp
data = model.(x, y', 10) .+ T(0.1) * randn(T, length(x), length(y))
result_orig = Astroalign.com_psf(data; rel_thresh=0.1f0)
result_revised = com_psf(data; rel_thresh=0.1f0)
println("Original COM: ", (result_orig.psf_params.x, result_orig.psf_params.y))
println("Revised COM: ", (result_revised.psf_params.x, result_revised.psf_params.y))
println("Original FWHM: ", result_orig.psf_params.fwhm)
println("Revised FWHM: ", result_revised.psf_params.fwhm)
println("Original benchmark: ")
display(@benchmark Astroalign.com_psf($data; rel_thresh=$0.1f0))
println("Revised benchmark: ")
display(@benchmark com_psf($data; rel_thresh=$0.1f0))
```

My result:

**EDIT:** Because Photometry.jl will pass us an object from
Transducers.jl we have to call `collect`, giving us 2 allocations and
runtime +100 ns over not collecting (if we had a pure matrix input).

```julia
julia> println("Original COM: ", (result_orig.psf_params.x, result_orig.psf_params.y))
Original COM: (3.9974918f0, 3.9858212f0)

julia> println("Revised COM: ", (result_revised.psf_params.x, result_revised.psf_params.y))
Revised COM: (3.9974945f0, 3.9858336f0)

julia> println("Original FWHM: ", result_orig.psf_params.fwhm)
Original FWHM: (2.31581660320762, 2.3766457470426725)

julia> println("Revised FWHM: ", result_revised.psf_params.fwhm)
Revised FWHM: (2.3164616f0, 2.3772223f0)

julia> display(@benchmark Astroalign.com_psf($data; rel_thresh=$0.1f0))
BenchmarkTools.Trial: 10000 samples with 10 evaluations per sample.
 Range (min … max):  1.408 μs …  1.050 ms  ┊ GC (min … max):  0.00% … 99.19%
 Time  (median):     1.544 μs              ┊ GC (median):     0.00%
 Time  (mean ± σ):   2.372 μs ± 15.628 μs  ┊ GC (mean ± σ):  21.39% ±  4.62%

  ▆█▇▅▃▁▁▁                ▃▄▃▂                               ▂
  █████████▇▇▆▇▇▇▇▆▇▆▆▆▇▆██████▆▆▆▅▄▅▄▅▅▃▅▆███▇▅▄▄▄▁▁▄▁▆▅▇██ █
  1.41 μs      Histogram: log(frequency) by time     5.56 μs <

 Memory estimate: 10.41 KiB, allocs estimate: 20.

julia> println("Revised benchmark: ")
Revised benchmark:

julia> @benchmark com_psf($data; rel_thresh=$0.1f0)
BenchmarkTools.Trial: 10000 samples with 183 evaluations per sample.
 Range (min … max):  571.716 ns …   9.490 μs  ┊ GC (min … max): 0.00% … 88.05%
 Time  (median):     600.563 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   678.928 ns ± 532.693 ns  ┊ GC (mean ± σ):  8.48% ±  9.61%

  █▅▂▁▁                                                         ▁
  ██████▇▇▆▆▄▅▁▄▃▁▃▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▁▃▄▃▄▄▄▄▄▄▄▃▄▅ █
  572 ns        Histogram: log(frequency) by time        4.5 μs <

 Memory estimate: 1.64 KiB, allocs estimate: 2.
```

---------

Co-authored-by: Ian Weaver <weaveric@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants