Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor background classes #1232

Merged
merged 36 commits into from Sep 3, 2021
Merged

Conversation

larrybradley
Copy link
Member

@larrybradley larrybradley commented Sep 3, 2021

This PR is a refactor of the background classes, including Background2D, motivated to improve their performance. The original implementation used numpy MaskedArray, which can be slow. This implementation uses plain ndarray, using np.nan values to represent masked pixels. This is possible due to a change where all non-finite values (i.e, NaN, inf) are automatically masked. This is consistent with the behavior of astropy SigmaClip, which the background classes use heavily.

Additional performance gains also now come when the optional bottleneck package is installed.

Overall, the performance gains can be up to 10-50%, depending on the array size and input parameters.

The background_mesh_ma and background_rms_mesh_ma attributes have been renamed to background_mesh_masked and background_rms_mesh_masked and are now deprecated.

This PR introduces a backwards-incompatible API change in that the background statistics classes (e.g., MeanBackground) now return a ndarray with np.nan values at masked pixels instead of a MaskedArray. Any user-defined bkg_estimator or bkgrms_estimator functions/classes input to Background2D must also have the same behavior.

This PR also adds a masked keyword to the background statistic classes to return a MaskedArray.

@larrybradley larrybradley merged commit 8bbe2c1 into astropy:main Sep 3, 2021
@larrybradley larrybradley deleted the bkg2d-refactor branch September 3, 2021 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant