-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
light-curve/light_curve/light_curve_py/features/ptp_var.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |