Skip to content

Commit

Permalink
new feature peak-to-peak variation
Browse files Browse the repository at this point in the history
  • Loading branch information
GaluTi authored and hombit committed Mar 21, 2024
1 parent 8bb701d commit 8fedfc5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions light-curve/light_curve/light_curve_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .features.otsusplit import *
from .features.pdiffmperc import *
from .features.percampl import *
from .features.ptp_var import *
from .features.rainbow import *
from .features.redchi2 import *
from .features.roms import *
Expand Down
33 changes: 33 additions & 0 deletions light-curve/light_curve/light_curve_py/features/ptp_var.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import numpy as np

from ._base import BaseSingleBandFeature


class PeakToPeakVar(BaseSingleBandFeature):
r"""Peak-to-peak variation
$$
\frac{(m_i - \sigma_i)_\text{max} - (m_i + \sigma_i)_\text{min}}{(m_i - \sigma_i)_\text{max} + (m_i + \sigma_i)_\text{min}}
$$
For non-variable data, it should be close to zero.
If data is close to be variable, the index should be more or equal than 0.10-0.15.
It is sensitive to magnitude of error values and can be negative in overestimated errors case.
- Depends on: **flux density**, **errors**
- Minimum number of observations: **2**
- Number of features: **1**
Aller M.F., Aller H.D., Hughes P.A. 1992. [DOI:10.1086/171898](https://www.doi.org/10.1086/171898)
"""

def _eval_single_band(self, t, m, sigma=None):
a = np.max(m - sigma)
b = np.min(m + sigma)
return (a - b) / (a + b)

@property
def size_single_band(self):
return 1


__all__ = ("PeakToPeakVar",)
74 changes: 74 additions & 0 deletions light-curve/tests/light_curve_py/features/test_ptp_var.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import numpy as np
from numpy.testing import assert_allclose

from light_curve.light_curve_py import PeakToPeakVar


def test_ptpvar_const_data():
feature = PeakToPeakVar()
n = 100
t = np.arange(n)
m = np.ones_like(t)
sigma = 0.1 * np.ones_like(t)
actual = feature(t, m, sigma)
desired = -0.1
assert_allclose(actual, desired)


def test_ptpvar_periodic_data():
feature = PeakToPeakVar()
n = 100
t = np.linspace(0, np.pi, n)
m = np.sin(t)
sigma = 0.1 * np.ones_like(t)
actual = feature(t, m, sigma)
desired = 0.8
assert_allclose(actual, desired, rtol=3 / np.sqrt(n))


def test_ptpvar_norm_data_1():
rng = np.random.default_rng(0)
n = 100
t = np.linspace(0, 1, n)
m = np.abs(rng.normal(0, 1, n))
sigma = 0.2 * np.ones_like(t)
feature = PeakToPeakVar()
actual = feature(t, m, sigma)
desired = 1
assert_allclose(actual, desired, rtol=3 / np.sqrt(n))


def test_ptpvar_norm_data_2():
rng = np.random.default_rng(0)
n = 10000
t = np.linspace(0, 1, n)
m = np.abs(rng.normal(0, 1, n))
sigma = 0.2 * np.ones_like(t)
feature = PeakToPeakVar()
actual = feature(t, m, sigma)
desired = 1
assert_allclose(actual, desired, rtol=3 / np.sqrt(n))


def test_ptpvar_expon_data_1():
rng = np.random.default_rng(0)
n = 100
t = np.linspace(0, 1, n)
m = rng.exponential(2, n)
sigma = np.ones_like(t)
feature = PeakToPeakVar()
actual = feature(t, m, sigma)
desired = 1
assert_allclose(actual, desired, rtol=3 / np.sqrt(n))


def test_ptpvar_expon_data_2():
rng = np.random.default_rng(0)
n = 10000
t = np.linspace(0, 1, n)
m = rng.exponential(2, n)
sigma = np.ones_like(t)
feature = PeakToPeakVar()
actual = feature(t, m, sigma)
desired = 1
assert_allclose(actual, desired, rtol=3 / np.sqrt(n))

0 comments on commit 8fedfc5

Please sign in to comment.