Skip to content

perf: separable box dilation in blurring_mask_2d_from for large PSFs - #697

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/blurring-mask-separable
Nov 17, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/blurring-mask-separable

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #696. Community: PyAutoLabs/.github#45 (proposed and diagnosed by @GeorgeVassilakis, co-author on the commit).

Summary

blurring_mask_2d_from dilated the unmasked region with a dense np.ones((ky, kx)) structure. scipy builds an offsets table for it that grows as (ky·kx)², so large PSFs were slow and memory hungry: George measured 401 s and 462 GiB for a 499 × 499 kernel, which OOM-killed jobs on his cluster. A box is separable, so a (ky, 1) dilation followed by a (1, kx) dilation gives the identical mask.

API Changes

None. Same signature and identical output.

Numbers (laptop, after the change; masks byte-identical to before)

geometry PSF before after
HST 0.05"/px, 3" mask, 200² 21² 18 ms 3 ms
JWST 0.03"/px, 1.5" mask, 400² 37² 210 ms, +14 MiB peak 24 ms
JWST 0.03"/px, 3" mask, 400² 51² 412 ms, +52 MiB peak 31 ms
0.03"/px, 3" mask, 400² 101² 3.2 s, +794 MiB peak 76 ms
0.03"/px, 3" mask, 1200² 499² not run (George: 401 s, 462 GiB) 5.0 s

The blurring mask is built once or twice per apply_mask, never per likelihood call, so ordinary HST/JWST modelling saves milliseconds. Large PSFs (wide-field, oversampled, HWO/ELT-style simulations) go from minutes and tens of GB to seconds.

Tests

  • New test__blurring_mask_2d_from__matches_dense_box_dilation: compares against a dense 2-D box dilation for kernels (3,3), (5,3), (4,4), (6,2), (3,7), (8,5), (2,9).
  • test_autoarray/: 2418 passed.

🤖 Generated with Claude Code

The blurring mask dilated the unmasked region with a dense (ky, kx) box,
and scipy's offsets table for it grows as (ky*kx)**2: a 499x499 PSF took
401 s and 462 GiB. A box is separable, so a (ky, 1) dilation followed by a
(1, kx) dilation gives the identical mask. Adds a dense-reference test over
odd, even and rectangular kernels.

Proposed and diagnosed by George Vassilakis in
PyAutoLabs/.github#45. Closes #696.

Co-authored-by: George Vassilakis <90641828+GeorgeVassilakis@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 3f9424a into main Nov 17, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/blurring-mask-separable branch November 17, 2026 13:48
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 19, 2026
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 19, 2026
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.

perf: separable box dilation in blurring_mask_2d_from for large PSFs

1 participant