Skip to content

perf: separable box dilation in blurring_mask_2d_from for large PSFs #696

Closed

Description

@Jammy2211

Overview

blurring_mask_2d_from dilates the unmasked region with a dense np.ones((ky, kx)) structure, and scipy's internal offsets table grows as (ky·kx)². That makes large PSFs very slow and memory hungry (George Vassilakis, hub discussion PyAutoLabs/.github#45: 499×499 took 401 s and 462 GiB). A box structuring element is separable, so a (ky, 1) dilation followed by a (1, kx) dilation gives the identical mask.

Plan

  • Replace the dense 2-D dilation with two 1-D dilations; the output mask is byte-identical.
  • Add tests comparing against a dense 2-D reference for odd, even and rectangular kernels.
  • Credit @GeorgeVassilakis as co-author.
  • Tier: judge — merge mode: human /prm
Detailed implementation plan

Affected Repositories

  • PyAutoArray (primary)

Suggested branch: feature/blurring-mask-separable

Implementation Steps

  1. autoarray/mask/mask_2d_util.py blurring_mask_2d_from: binary_dilation with np.ones((ky, 1)) then np.ones((1, kx)) instead of np.ones((ky, kx)).
  2. test_autoarray/mask/test_mask_2d_util.py: parametrized dense-reference test over (3,3), (5,3), (4,4), (6,2), (3,7), (8,5), (2,9).

Measured (laptop, masks byte-identical)

geometry PSF before after
HST 0.05", 3" mask 21² 18 ms 1.9 ms
JWST 0.03", 1.5" mask 37² 210 ms, +14 MiB 11 ms
JWST 0.03", 3" mask 51² 412 ms, +52 MiB 14 ms
0.03", 3" mask 101² 3.2 s, +794 MiB 33 ms

Activity

  1. GeorgeVassilakis commented on Nov 17, 2026

    @GeorgeVassilakis
    Contributor

    @Jammy2211, want me to commit the PR now, or is this issue marking it for yourself to fix? Happy with either!

  2. Jammy2211 commented on Nov 17, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped: #697 merged on 2026-11-17 (co-authored with @GeorgeVassilakis). Separable box dilation in blurring_mask_2d_from; byte-identical masks; full test_autoarray suite 2418 passed. Pending the next PyPI release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions