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

Introduction of a new specialized class for lightcurves #5174

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

cgalelli
Copy link
Contributor

In this draft PR I introduce the basic structure for a specialized LightCurve class which inherits from FluxPoints.
I tried to keep the code duplication as minimal as possible.

The first implementation introduces read/write and from/to_table method adaptations from FluxPoints, and simple methods for variability tools. It also includes the translator for stingray (as an optional inclusion) previously presented in #5170 .

The class could also use utilities proposed in #5145 and #5156 once they are added, and any future specific utilities.

Signed-off-by: cgalelli <claudio.galelli@obspm.fr>
Signed-off-by: cgalelli <claudio.galelli@obspm.fr>
Signed-off-by: cgalelli <claudio.galelli@obspm.fr>
Signed-off-by: cgalelli <claudio.galelli@obspm.fr>
@cgalelli cgalelli self-assigned this Mar 19, 2024
@cgalelli cgalelli added this to the 1.3 milestone Mar 19, 2024
Copy link
Member

@AtreyeeS AtreyeeS left a comment

Choose a reason for hiding this comment

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

Thank you @cgalelli ! I think this can go in and then we work on the improvements
I would add a customised .plot

gammapy/estimators/points/core.py Outdated Show resolved Hide resolved
)

if format == "lightcurve":
return LightCurve.from_maps(
Copy link
Member

Choose a reason for hiding this comment

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

Is this the responsibility of the parent class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here was not only to give "responsability" to the parent, but to create a Lightcurve "by force" when using FluxPoints with a time axis (e.g. to keep compatibility with old code but still access the new functionalities and checks)

gammapy/estimators/points/core.py Show resolved Hide resolved
gammapy/estimators/points/core.py Show resolved Hide resolved
…plot function for lightcurve.

Signed-off-by: cgalelli <claudio.galelli@obspm.fr>
Signed-off-by: cgalelli <claudio.galelli@obspm.fr>

return super().from_table(table, **kwargs)

def to_stingray_lightcurve(self):
Copy link
Member

Choose a reason for hiding this comment

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

It seems you can create a stingray light curve with flux units https://docs.stingray.science/en/stable/notebooks/Lightcurve/Lightcurve%20tutorial.html#Error-Distributions-in-stingray.Lightcurve

maybe you can add a .from_stingray as well, then stingray functionalities can be fully used by gammapy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add a translator function on that direction as well. I would still be wary of actually using the stingray functions with flux (and they say so in the paragraph), but if they themselves show an example it means that it's not unheard of, just not exactly the standard approach. I can put a disclaimer in the docstring for both to and from-stingray

Copy link
Member

@bkhelifi bkhelifi left a comment

Choose a reason for hiding this comment

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

Thanks @cgalelli ... I have put some comments in order to make a step forward



class LightCurve(FluxPoints):
"""Specialized 'FluxPoints' heir class for lightcurves"""
Copy link
Member

Choose a reason for hiding this comment

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

To be developed: description, exemple, parameters and attributes, ....


@classmethod
def read(cls, filename, **kwargs):
kwargs.setdefault("format", "lightcurve")
Copy link
Member

Choose a reason for hiding this comment

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

One would need to add a metadata class, as for the flux class, or re-used this metadata class

kwargs.setdefault("axis_name", "time")
return super().plot(**kwargs)

def fvar(self, flux_quantity="flux"):
Copy link
Member

Choose a reason for hiding this comment

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

docstring to add

def fvar(self, flux_quantity="flux"):
return compute_lightcurve_fvar(self, flux_quantity)

def fpp(self, flux_quantity="flux"):
Copy link
Member

Choose a reason for hiding this comment

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

docstring to add

return compute_lightcurve_fpp(self, flux_quantity)

def doubling_time(self, flux_quantity="flux"):
return compute_lightcurve_doublingtime(self, flux_quantity)
Copy link
Member

Choose a reason for hiding this comment

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

docstring to add

def doubling_time(self, flux_quantity="flux"):
return compute_lightcurve_doublingtime(self, flux_quantity)

def structure_function(self, flux_quantity="flux", tdelta_precision=5):
Copy link
Member

Choose a reason for hiding this comment

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

docstring to add

@@ -849,3 +865,98 @@ def resample_axis(self, axis_new):
fluxpoints.append(fp_new)

return self.__class__.from_stack(fluxpoints, axis=axis_new)


class LightCurve(FluxPoints):
Copy link
Member

Choose a reason for hiding this comment

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

Add all the test functions

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.

None yet

3 participants