Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

HealthyPear
Copy link
Member

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

@HealthyPear HealthyPear added enhancement New feature or request spectral labels Jan 20, 2025
@HealthyPear HealthyPear requested a review from maxnoe as a code owner January 20, 2025 14:41
HealthyPear added a commit that referenced this pull request Jan 20, 2025
HealthyPear added a commit that referenced this pull request Jan 20, 2025
@HealthyPear HealthyPear force-pushed the feature-log_parabola_from_natural_log branch from e146a41 to 34b9085 Compare January 20, 2025 15:10
@HealthyPear HealthyPear requested review from maxnoe and removed request for maxnoe January 20, 2025 15:13
@HealthyPear HealthyPear force-pushed the feature-log_parabola_from_natural_log branch from 34b9085 to bffea3d Compare January 20, 2025 15:15
Copy link
Member

@morcuended morcuended left a 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.
Copy link
Member

@morcuended morcuended Jan 20, 2025

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

Copy link
Member

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.

Copy link
Member

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_.

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member

@maxnoe maxnoe Jan 20, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request spectral
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants