Skip to content

Updates to bounding box interface and cleanup - #4264

Merged
astrofrog merged 4 commits into
astropy:masterfrom
embray:modeling/bbox2
Nov 9, 2015
Merged

astrofrog merged 4 commits into
astropy:masterfrom
embray:modeling/bbox2

Conversation

@embray

@embray embray commented Oct 22, 2015

Copy link
Copy Markdown
Member

This is the update to #4040--it includes all the fixes from #4040, but also includes my updates to the bounding box interface.

The purpose of these updates, as explained in the commit message of 779ef3e, is to make the interface for bounding_box fairly consistent with the interface for Model.inverse. To that end the bounding_box_default method is eliminated, and model classes that define a bounding box can do so as a class-level attribute, method, or property simply called bounding_box, which is then wrapped by the Model metaclass to incorporate the default getter/setter behavior for the Model.bounding_box property. This is similar to how Model.inverse works.

One downside to this that I just noticed while testing the documentation is that if a Model subclass has a bounding_box with its own docstring, that docstring usually gets thrown away. We definitely don't want that, so I am going to open a separate issue to fix that later.

patti and others added 4 commits October 22, 2015 14:05
a bounding box on a model.  The format of the bounding box itself
(as a tuple of tuples) is not changed.  This is motivated in large
part by wanting the API to more closely resemble the API for inverses
which is somewhat simiar--model.inverse is a property of a model that
returns something based on a model instance *if* the inverse is defined
on that model's class.  Otherwise it raises NotImplementedError.  Regardless
of whether a default inverse is defined on the class, the user can assign
their own inverse to any model instance.  The user-defined inverse can
unset (as of PR astropy#4236) by calling del model.inverse, which will reset it
back to the inverse defined at the class level.

This PR makes bounding_box work entirely analogously to the above.
The bounding_box_default() method is removed--instead, in order to
define a bounding box for a specific model class, simply define a
property called bounding_box on the class (the metaclass will then handle)
wrapping that property in the standard getter/setter for Model.bounding_box
defined in the Model base class).

The one extra complexity for bounding_box is that we want *some* cases
of bounding_box to be *callable* with adjustable parameters (such as
how Gaussian1D.bounding_box_default() takes an optional "factor" argument).
To this end, the object returned by model.bounding_box is actually a
subclass of tuple that looks like a normal bounding box tuple.  But on
a model whose bounding_box takes arguments (and is a method instead of
a property) one can *call* model.bounding_box like
``model.bounding_box(factor=1.2)`` to adjust the bounding box.
…interface, and some minor code style cleanup to go with it.
@embray embray added modeling Affects-dev PRs and issues that do not impact an existing Astropy release labels Oct 22, 2015
@embray embray added this to the v1.1.0 milestone Oct 22, 2015
@embray

embray commented Oct 22, 2015

Copy link
Copy Markdown
Member Author

cc: @patti @adonath

@patti

patti commented Oct 22, 2015

Copy link
Copy Markdown
Contributor

👍

Comment thread astropy/modeling/core.py

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.

At some point something needs to be done with these assertions--really there's no reason to use assert and then catch AssertionErrors and reraise them. This should just raise a ValueError something after checking the condtion, and not use assert at all. I don't think I have time to fix it now though.

@embray

embray commented Oct 22, 2015

Copy link
Copy Markdown
Member Author

FWIW the Sphinx build for this failed due to a failure to fetch the matplotlib object.inv. Didn't appear to have any failures actually related to PR, but I've restarted it anyways.

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.

"Note:" is not necessary in a warning (and perhaps confusing, because .. note:: means something different)

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.

Fixed in 96f531b

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.

👍

astrofrog added a commit that referenced this pull request Nov 9, 2015
Updates to bounding box interface and cleanup
@astrofrog
astrofrog merged commit e67e47e into astropy:master Nov 9, 2015
astrofrog added a commit that referenced this pull request Nov 9, 2015
Updates to bounding box interface and cleanup
@embray
embray deleted the modeling/bbox2 branch November 12, 2015 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release modeling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants