-
Notifications
You must be signed in to change notification settings - Fork 26
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
Allow LogParabola to be defined using natural log #295
base: main
Are you sure you want to change the base?
Conversation
e146a41
to
34b9085
Compare
34b9085
to
bffea3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
@@ -195,25 +195,32 @@ class LogParabola: | |||
:math:`\beta` | |||
e_ref: astropy.units.Quantity[energy] | |||
:math:`E_\text{ref}` | |||
from_log10: bool | |||
If True, compute the energy ration in the exponent factor | |||
using base 10, else use natural logarithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here say that the default is base 10 log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't particularly like the keyword name here, why not call this "log_base" or just pass the log function?
E.g. log=np.log10
vs. log=np.log
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think you took the name from https://docs.gammapy.org/0.19/api/gammapy.modeling.models.LogParabolaSpectralModel.html#gammapy.modeling.models.LogParabolaSpectralModel.from_log10
But this is not a keyword, it's an alternative constructor, that's why it starts with from_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the idea was to keep a nomenclature analog to gammapy
which is what people tends to use more lately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it doesn't make sense to use the name of a class method for the name of a keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could implement the same (or rather the inverse) logic as gammapy, e.g. offer a from_ln
method that converts the parameters to base 10.
Or you change the name to log
, maybe with an enum like this:
class LogType(Enum):
LOG10 = auto()
LN = auto()
class LogParabola:
def __init__(self, ..., log=LogType.LOG10)
In some experiments or software the definition of a LogParabola spectral model might brequire to use the natural logarithm instead of the one in base 10.
This PR allows to instantiate such a model with the addition of a new class attribute analog to the one used by gammapy.modeling.models.LogParabolaSpectralModel