Skip to content

Fix Polynomial2D fitting when used in compound model - #17618

Merged
astrofrog merged 9 commits into
astropy:mainfrom
astrofrog:fix-polynomial-2d-fitting
Jan 28, 2025
Merged

astrofrog merged 9 commits into
astropy:mainfrom
astrofrog:fix-polynomial-2d-fitting

Conversation

@astrofrog

@astrofrog astrofrog commented Jan 9, 2025 •

Copy link
Copy Markdown
Member

This fixes #17509

The issue was that Polynomial2D 'forgets' about the dimensionality of the input and so always returns a 2D array, whereas other models don't. I really think we should at some point tighten up the fit_deriv methods to be more consistent, but since that usage has been allowed for now, I am fixing our implementation of CompoundModel.fit_deriv to be more robust.

I have expanded the tests compared to the numerical derivatives and while Polynomial2D works, in fact some other models are failing when passing 2D inputs so I am going to try and see how to fix that.

  • 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

github-actions Bot commented Jan 9, 2025

Copy link
Copy Markdown
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.

@github-actions

github-actions Bot commented Jan 9, 2025

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@pllim pllim added this to the v7.0.1 milestone Jan 9, 2025
@astrofrog

Copy link
Copy Markdown
Member Author

Ah I found the remaining issue, however I will need to wait until later today or tomorrow to fix. Please hold...

@astrofrog

Copy link
Copy Markdown
Member Author

I think this should now be fixed

@astrofrog
astrofrog requested a review from Cadair January 10, 2025 10:08
@astrofrog
astrofrog force-pushed the fix-polynomial-2d-fitting branch from a5bcfc9 to 42a46e4 Compare January 10, 2025 10:08
@astrofrog
astrofrog marked this pull request as ready for review January 10, 2025 10:09
@astrofrog
astrofrog requested a review from a team as a code owner January 10, 2025 10:09

@perrygreenfield perrygreenfield left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM except for a comment on the last test.

Comment thread astropy/modeling/tests/test_compound.py Outdated
p_init = Polynomial2D(degree=2) + Gaussian2D(amplitude=50000, x_mean=60, y_mean=60)
fit_p = DogBoxLSQFitter()

p = fit_p(p_init, x, y, z)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm puzzled at the intent of this test. Is it to ensure no exception happens for the fit? Nothing seems to be done with the fit results.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes it's just a regression test for this bug where the fitting raised an exception

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A comment to that effect would clarify that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done!

@astrofrog

Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

Comment thread astropy/modeling/tests/test_compound.py Outdated

@pytest.mark.skipif(not HAS_SCIPY, reason="requires scipy")
def test_fit_compound_polynomial2d():
# Regression test for a bug that caused compound models with Polynomial2D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you just make this a docstring?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@perrygreenfield perrygreenfield left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@astrofrog
astrofrog merged commit f6bce05 into astropy:main Jan 28, 2025
meeseeksmachine pushed a commit to meeseeksmachine/astropy that referenced this pull request Jan 28, 2025
pllim added a commit that referenced this pull request Jan 28, 2025
…618-on-v7.0.x

Backport PR #17618 on branch v7.0.x (Fix Polynomial2D fitting when used in compound model)
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.

Fitting compound Polynominal2D models no longer works

4 participants