Skip to main content

Feature extractor from noisy time series

Project description

light-curve processing toolbox for Python

The Python wrapper for Rust light-curve-feature and light-curve-dmdt packages which gives a collection of high-performant time-series feature extractors.

PyPI version testing publishing pre-commit.ci status

Installation

python3 -mpip install light-curve

We also provide light-curve-python package which is just an "alias" to the main light-curve package.

Minimum supported Python version is 3.6.

Support matrix

Arch \ OS Linux glibc Linux musl macOS Windows
x86-64 wheel (MKL) wheel (MKL) wheel not tested https://github.com/light-curve/light-curve-python/issues/12
i686 wheel not tested not tested
aarch64 wheel src src https://github.com/light-curve/light-curve-python/issues/5 not tested
ppc64le wheel not tested
  • "wheel": binary wheel is available on pypi.org, local building is not required for the platform, the only pre-requirement is a recent pip version. For Linux x86-64 we provide binary wheels built with Intel MKL for better periodogram perfromance, which is not a default build option.
  • "src": the package is confirmed to be built and pass unit tests locally, but testing and package building is not supported by CI yet. It is required to have the GNU scientific library (GSL) v2.1+ and the Rust toolchain v1.56+ to install it via pip install.
  • "not tested": building from the source code is not tested, please report us building status via issue/PR/email.

Feature evaluators

Most of the classes implement various feature evaluators useful for light-curve based astrophysical source classification and characterisation.

import light_curve as lc
import numpy as np

# Time values can be non-evenly separated but must be an ascending array
n = 101
t = np.linspace(0.0, 1.0, n)
perfect_m = 1e3 * t + 1e2
err = np.sqrt(perfect_m)
m = perfect_m + np.random.normal(0, err)

# Half-amplitude of magnitude
amplitude = lc.Amplitude()
# Fraction of points beyond standard deviations from mean
beyond_std = lc.BeyondNStd(nstd=1)
# Slope, its error and reduced chi^2 of linear fit
linear_fit = lc.LinearFit()
# Feature extractor, it will evaluate all features in more efficient way
extractor = lc.Extractor(amplitude, beyond_std, linear_fit)

# Array with all 5 extracted features
result = extractor(t, m, err, sorted=True, check=False)

print('\n'.join(f"{name} = {value:.2f}" for name, value in zip(extractor.names, result)))

# Run in parallel for multiple light curves:
results = amplitude.many(
    [(t[:i], m[:i], err[:i]) for i in range(n // 2, n)],
    n_jobs=-1,
    sorted=True,
    check=False,
)
print("Amplitude of amplitude is {:.2f}".format(np.ptp(results)))

If you confident in your inputs you could use sorted = True (t is in ascending order) and check = False (no NaNs in inputs, no infs in t or m) for better performance. Note that if your inputs are not valid and are not validated by sorted=None and check=True (default values) then all kind of bad things could happen.

Print feature classes list

import light_curve as lc

print([x for x in dir(lc) if hasattr(getattr(lc, x), "names")])

Read feature docs

import light_curve as lc

help(lc.BazinFit)

Experimental extractors

From the technical point of view the package consists of two parts: a wrapper for light-curve-feature Rust crate (light_curve_ext sub-package) and pure Python sub-package light_curve_py. We use the Python implementation of feature extractors to test Rust implementation and to implement new experimental extractors. Please note, that the Python implementation is much slower for the most of the extractors and doesn't provide the same functionality as the Rust implementation. However, the Python implementation provides some new feature extractors you can find useful.

You can manually use extractors from both implementations:

import numpy as np
from numpy.testing import assert_allclose
from light_curve.light_curve_ext import LinearTrend as RustLinearTrend
from light_curve.light_curve_py import LinearTrend as PythonLinearTrend

rust_fe = RustLinearTrend()
py_fe = PythonLinearTrend()

n = 100
t = np.sort(np.random.normal(size=n))
m = 3.14 * t - 2.16 + np.random.normal(size=n)

assert_allclose(rust_fe(t, m), py_fe(t, m),
                err_msg="Python and Rust implementations must provide the same result")

This should print a warning about experimental status of the Python class

dm-dt map

Class DmDt provides dm–dt mapper (based on Mahabal et al. 2011, Soraisam et al. 2020). It is a Python wrapper for light-curve-dmdt Rust crate.

import numpy as np
from light_curve import DmDt
from numpy.testing import assert_array_equal

dmdt = DmDt.from_borders(min_lgdt=0, max_lgdt=np.log10(3), max_abs_dm=3, lgdt_size=2, dm_size=4, norm=[])

t = np.array([0, 1, 2], dtype=np.float32)
m = np.array([0, 1, 2], dtype=np.float32)

desired = np.array(
    [
        [0, 0, 2, 0],
        [0, 0, 0, 1],
    ]
)
actual = dmdt.points(t, m)

assert_array_equal(actual, desired)

Citation

If you found this project useful for your research please cite Malanchev et al., 2021

@ARTICLE{2021MNRAS.502.5147M,
       author = {{Malanchev}, K.~L. and {Pruzhinskaya}, M.~V. and {Korolev}, V.~S. and {Aleo}, P.~D. and {Kornilov}, M.~V. and {Ishida}, E.~E.~O. and {Krushinsky}, V.~V. and {Mondon}, F. and {Sreejith}, S. and {Volnova}, A.~A. and {Belinski}, A.~A. and {Dodin}, A.~V. and {Tatarnikov}, A.~M. and {Zheltoukhov}, S.~G. and {(The SNAD Team)}},
        title = "{Anomaly detection in the Zwicky Transient Facility DR3}",
      journal = {\mnras},
     keywords = {methods: data analysis, astronomical data bases: miscellaneous, stars: variables: general, Astrophysics - Instrumentation and Methods for Astrophysics, Astrophysics - Solar and Stellar Astrophysics},
         year = 2021,
        month = apr,
       volume = {502},
       number = {4},
        pages = {5147-5175},
          doi = {10.1093/mnras/stab316},
archivePrefix = {arXiv},
       eprint = {2012.01419},
 primaryClass = {astro-ph.IM},
       adsurl = {https://ui.adsabs.harvard.edu/abs/2021MNRAS.502.5147M},
      adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

light_curve-0.5.8.tar.gz (58.9 kB view hashes)

Uploaded Source

Built Distributions

light_curve-0.5.8-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

light_curve-0.5.8-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

light_curve-0.5.8-cp310-cp310-musllinux_1_1_x86_64.whl (24.3 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

light_curve-0.5.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

light_curve-0.5.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

light_curve-0.5.8-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-cp310-cp310-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

light_curve-0.5.8-cp39-cp39-musllinux_1_1_x86_64.whl (24.3 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

light_curve-0.5.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

light_curve-0.5.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

light_curve-0.5.8-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-cp39-cp39-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

light_curve-0.5.8-cp38-cp38-musllinux_1_1_x86_64.whl (24.3 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

light_curve-0.5.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

light_curve-0.5.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

light_curve-0.5.8-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-cp38-cp38-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

light_curve-0.5.8-cp37-cp37m-musllinux_1_1_x86_64.whl (24.3 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

light_curve-0.5.8-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

light_curve-0.5.8-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

light_curve-0.5.8-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-cp37-cp37m-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

light_curve-0.5.8-cp36-cp36m-musllinux_1_1_x86_64.whl (24.3 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

light_curve-0.5.8-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

light_curve-0.5.8-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ppc64le

light_curve-0.5.8-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

light_curve-0.5.8-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

light_curve-0.5.8-cp36-cp36m-macosx_10_9_x86_64.whl (2.8 MB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page