Skip to content

Added a new power-law ParametricModel#1048

Closed
keflavich wants to merge 3 commits into
astropy:masterfrom
keflavich:powerlaw-model
Closed

Added a new power-law ParametricModel#1048
keflavich wants to merge 3 commits into
astropy:masterfrom
keflavich:powerlaw-model

Conversation

@keflavich

Copy link
Copy Markdown
Contributor

Of course, not all models should be built-in, but I think a power-law is a simple and common enough one that it ought to be included.

I wrote this PR in part to get some practice working with models; any feedback on style would be helpful.

Comment thread astropy/models/functional_models.py Outdated

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.

Just a picky thing, but the general recommendation here is to use super(). It should be fine here to do super(PowerLawModel, self).__init__(self.param_names, ndim=1, outdim=1, param_dim=param_dim)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, that's a good idea - I think that should be added as a general recommendation in the models docs (which I have open as another PR, so I'll make that edit in both places)

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.

There is already a recommendation about that in the general developer guidelines. It's easy to miss though.

@nden

nden commented May 4, 2013

Copy link
Copy Markdown
Contributor

@keflavich Some Travis configurations don't have scipy installed and the test is failing in these with ImportError. Look at test_fitters.py for how to import scipy and mark tests which require it to be skipped when it is not available.

Comment thread astropy/models/functional_models.py Outdated

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.

Set self.deriv = noderiv here or just name the method deriv instead of noderiv. Otherwise the derivatives will be estimated.

You probably looked at how the Gaussian1DModel handles derivatives but it is misleading. There I wanted to show all possible ways of handling derivatives and also use it for testing/debugging. So Gaussian1D can be fitted without derivatives, with a function to calculate the derivatives supplied by a user or using the class method to do this. We probably don't want to be that "flexible" so it should be changed some time in the future to use the method in the class.

With this fixed and when the tests pass I think it's good.

@keflavich

Copy link
Copy Markdown
Contributor Author

@nden - Oops! I had that in there from some tests I was running where I wanted to check the numerical derivatives.

@iguananaut - thanks, fixed that

@keflavich

Copy link
Copy Markdown
Contributor Author

The last test failure is because the fit is actually bad.

@nden

nden commented May 7, 2013

Copy link
Copy Markdown
Contributor

@keflavich Could you please rebase this

Old commits:
* fix models reference in test and use super to init
* needed to add powerlaw to __all__
* need to use parameters.Parameter
* power law model only takes 2 pars
* tests still fail, but the error no longer makes any sense
* fixed the tests.  Sigh.
* skip test if no scipy
* use the derivative!
* corrected deriv function (was correct at some time earlier; must have
forgotten to pull...)
@eteq

eteq commented May 15, 2013

Copy link
Copy Markdown
Member

Note that in keflavich#2 I added a docstring for the model class itself.

Add a docstring to PowerLawModel
@nden

nden commented Jun 13, 2013

Copy link
Copy Markdown
Contributor

@keflavich I added a PR against your powerlaw-model branch but I am seeing a lot of changes in it probably due to the rebase. I'll make a PR against master to try to avoid this.

@nden

nden commented Jun 13, 2013

Copy link
Copy Markdown
Contributor

#1184

@keflavich keflavich closed this Jun 13, 2013
@keflavich keflavich mentioned this pull request Jun 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants