8000 Add SigmaClippedStats class by larrybradley · Pull Request #17221 · astropy/astropy · GitHub
[go: up one dir, main page]

Skip to content

Add SigmaClipped 8000 Stats class#17221

Merged
larrybradley merged 10 commits intoastropy:mainfrom
larrybradley:sigmaclippedstats
Oct 23, 2024
Merged

Add SigmaClippedStats class#17221
larrybradley merged 10 commits intoastropy:mainfrom
larrybradley:sigmaclippedstats

Conversation

@larrybradley
Copy link
Member
@larrybradley larrybradley commented Oct 21, 2024

Description

This PR adds a SigmaClippedStats class that extends the sigma_clipped_stats function. The function currently calculates only mean, median, and std. But if you want only one of those, it still calculates all 3. The new class calculates only the statistics that you request. It also adds the following stats: var, mode, biweight_location, biweight_scale, and mad_std.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions
Copy link
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim pllim added the Extra CI Run cron CI as part of PR label Oct 21, 2024
Copy link
Contributor
@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I focused on function signatures and type annotations. Since it's starting to pile up I'm going to keep it as that for this first round, but in short: I believe some confusion around the meaning of | None as an annotation may have slipped in from #16562, and I'd like to address that in a separate PR1, but I made a lot of comments here that boil down to "let's not propagate this mistake further".

Footnotes

  1. update: this is #17226

@larrybradley
Copy link
Member Author

@neutrinoceros Thanks for the review! The type annotations are due to me blindly copying the function signatures. I'm fixing them now. I'll also make the new class keyword-only.

@pllim
Copy link
Member
pllim commented Oct 22, 2024

Do we need What's New?

@larrybradley
Copy link
Member Author

@pllim I added a what's new entry.

@neutrinoceros
Copy link
Contributor

I'll review again in the morning. In the mean time, if you have a minute, it could be useful to rebase now that #17226 is merged, so I can checkout this branch and not stumble upon errors that I already fixed. Not a big deal if you can't though. Thanks !

@larrybradley
Copy link
Member Author

@neutrinoceros Rebased.

@larrybradley
Copy link
Member Author

I just pushed an update to ensure that the correct units are returned when using nanvar with Quantity arrays. Is there a better way to do that (i.e., using __array_wrap__)?

@neutrinoceros
Copy link
Contributor

let's ask @mhvk

Copy link
Contributor
@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't help but notice that sigma=3 is the only value exercised in tests and docs. Also, it's always passed explicitly, which seems to indicate that you don't actually want a default value for it, but of course the same argument holds for SigmaClip, and it's a bit late to change that, so I would recommend having a test exercising not passing sigma explicitly.

if isinstance(array, Quantity):
return array.__array_wrap__(result)
if function == bottleneck.nanvar:
result <<= array.unit**2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know here that array is a Quantity, so can use the private method array._result_as_quantity(result, unit**2) - that would keep any subclass in place but ensure that, e.g., an Angle will drop down to a Quantity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @mhvk! I've updated this to use _result_as_quantity and added a test for Angle input.

Copy link
Contributor
@mhvk mhvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall, just a small suggestion for the tests - though not important enough not to approve

@larrybradley
Copy link
Member Author

The linktest failure is unrelated.

@larrybradley larrybradley merged commit bf85293 into astropy:main Oct 23, 2024
@larrybradley larrybradley deleted the sigmaclippedstats branch October 23, 2024 18:19
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.

4 participants

0