MicroLIA.features
Created on Thu Jan 12 14:30:12 2017
@author: danielgodinez
Module Contents
Functions
|
Shannon entropy (Shannon et al. 1949) is used as a metric to quantify the amount of |
|
Con is defined as the number of clusters containing three or more |
|
This function returns the calculated kurtosis of the lightcurve. |
|
Skewness measures the asymmetry of a lightcurve, with a positive skewness |
|
The von Neumann ratio η was defined in 1941 by John von Neumann and serves as the |
|
The variability index J was first suggested by Peter B. Stetson and serves as a |
|
The variability index K was first suggested by Peter B. Stetson and serves as a |
|
The variability index L was first suggested by Peter B. Stetson and serves as a |
|
This function returns the ratio of points that are between plus or minus 10% of the |
|
A measure of the ratio of standard deviation and mean. |
|
This amplitude metric is defined as the difference between the maximum magnitude |
|
This function calculates the median Euclidean distance between each photometric |
|
This function measures the ratio of data points that are above 1 standard deviation |
|
This function measures the ratio of data points that are above 3 standard deviations |
|
This function measures the ratio of data points that are above 5 standard deviations |
|
This function measures the ratio of data points that are below 1 standard deviation |
|
This function measures the ratio of data points that are below 3 standard deviations |
|
This function measures the ratio of data points that are below 5 standard deviations |
|
A measure of the mean average distance between each magnitude value |
|
A measure of the root mean square deviation that takes into account the photometric errors. |
|
Calculates mean magnitude, weighted by the errors. |
|
Integrate magnitude using the trapezoidal rule. |
|
Similarity between observations as a function of a time lag between them. |
|
Function to detect number of peaks. |
|
Examining successive (time-sorted) magnitudes, the maximal first difference |
|
Slope of a weighted linear fit to the light-curve. |
|
This is the percentage of all pairs of consecutive flux measurements that have positive slope, |
|
In order to characterize the sorted magnitudes distribution we use percentiles. |
|
In order to characterize the sorted magnitudes distribution we use percentiles. |
|
In order to characterize the sorted magnitudes distribution we use percentiles. |
|
In order to characterize the sorted magnitudes distribution we use percentiles. |
|
In order to characterize the sorted magnitudes distribution we use percentiles. |
|
The largest absolute departure from the median flux, divided by the median flux |
|
Calculates the ratio of the flux difference between the 5th and 95th percentiles of |
|
The ratio of the squared sum of residuals of magnitudes that are either brighter |
|
Range of cumulative sum. |
|
The Shapiro-Wilk test tests the null hypothesis that the data was drawn from a normal distribution. |
|
The Anderson-Darling test is a statistical test of whether a given |
|
Gskew is a measure of the skewness of a distribution of magnitudes. It is defined as the |
|
Calculates the absolute energy of the time series, defined to be the sum over the squared |
|
Calculates the sum over the abs value of consecutive changes in mag, weighted by the errors. |
|
Useful for anomaly detection applications. Calculates the |
|
The C3 measure is a way to estimate the non-linearity of a time series by measuring the third-order |
|
This function calculator is an estimate for a time series complexity. |
|
Number of values higher than the weighted median. |
|
Number of values below the median. |
|
Calculates the location of maximum mag relative to the length of mag array, |
|
Calculates the location of minimum mag relative to the |
|
Checks if any value in mag repeats, taking into account photometric errors if apply_weights |
|
Checks if the maximum value in mag repeats, taking into account photometric errors if apply_weights |
|
Checks if the minimum value in mag repeats, taking into account photometric errors if apply_weights |
|
Calculates the position of last maximum mag relative to |
|
Calculates the position of last minimum mag relative to |
|
Calculates the length of the longest consecutive subsequence in |
|
Calculates the length of the longest consecutive subsequence in mag |
|
Calculates mean over the differences between subsequent observations, |
|
Calculates the mean absolute change in the magnitude per unit of error. |
|
Calculates the weighted arithmetic mean of the n absolute maximum values of the time series, n=10 by design. |
|
Calculates the weighted mean value of a central approximation of the second derivative, |
|
Calculates the number of crossings of x on the median, m. A crossing is defined as two |
|
Calculates the number of peaks of at least support n in the time series x. |
|
Calculates the ratio of unique values, that are present in the time |
|
Calculates sample entropy: http://en.wikipedia.org/wiki/Sample_Entropy |
|
Sums over all mag values. |
|
Derives the time reversal asymmetric statistic introduced by Fulcher. |
|
Calculates the variance, or the weighted variance of the light curve if apply_weights=True. |
|
This feature denotes if the variance of x is greater than its standard deviation. |
|
Calculates the variation coefficient (standard error / mean, gives the relative value of variation around mean) of x. |
|
Does time series have "large" standard deviation? |
|
Check to see if the distribution of the mag "looks symmetric". This is the case if: |
|
Calculates the relative index i of time series x where r% of the mass of x lies left of i. |
|
Number of different peaks in the magnitude array. |
|
Calculate the permutation entropy. |
|
Calculates the r quantile of the mag. This is the value of mag greater than r% of the ordered values. |
- MicroLIA.features.shannon_entropy(time, mag, magerr, apply_weights=True)[source]
Shannon entropy (Shannon et al. 1949) is used as a metric to quantify the amount of information carried by a signal. The procedure employed here follows that outlined by (D. Mislis et al. 2015). The probability of each point is given by a Cumulative Distribution Function (CDF). Following the same procedure as (D. Mislis et al. 2015), this function employs both the normal and inversed gaussian CDF, with the total shannon entropy given by a combination of the two. See: (SIDRA: a blind algorithm for signal detection in photometric surveys, D. Mislis et al., 2015)
Does not incorporate errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The Shannon Entropy of the lightcurve.
- MicroLIA.features.con(time, mag, magerr, apply_weights=True)[source]
Con is defined as the number of clusters containing three or more consecutive observations with magnitudes brighter than the reference magnitude plus 3 standard deviations. For a microlensing event Con = 1, assuming a flat lightcurve prior to the event. The magnitude measurements are split into bins such that the reference magnitude is defined as the mean of the measurements in the largest bin.
In this updated version of the con function, the upper and lower bounds for each measurement are defined as mag[i] + 3*magerr[i] and mag[i] - 3*magerr[i], respectively. These bounds are then used to check if a measurement is within a cluster. If a measurement is outside the bounds and we’re in a cluster, the cluster is ended.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of clusters satisfying the conditions to the total number of measurements.
- MicroLIA.features.kurtosis(time, mag, magerr, apply_weights=True)[source]
This function returns the calculated kurtosis of the lightcurve. It’s a measure of the peakedness (or flatness) of the lightcurve relative to a normal distribution. See: www.xycoon.com/peakedness_small_sample_test_1.htm
This updated implementation calculates the weighted mean x_mean and the weighted standard deviation sigma using numpy.average() with the weights parameter set to 1/magerr**2. Then it calculates the weighted kurtosis using the above formula and returns the result.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated kurtosis of the lightcurve.
- MicroLIA.features.skewness(time, mag, magerr, apply_weights=True)[source]
Skewness measures the asymmetry of a lightcurve, with a positive skewness indicating a skew to the right, and a negative skewness indicating a skew to the left.
This function calculates the weighted mean and standard deviation using the photometric errors as weights, and then uses these values to compute the weighted skewness.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated skewness of the lightcurve.
- MicroLIA.features.vonNeumannRatio(time, mag, magerr, apply_weights=True)[source]
The von Neumann ratio η was defined in 1941 by John von Neumann and serves as the mean square successive difference divided by the sample variance. When this ratio is small, it is an indication of a strong positive correlation between the successive photometric data points. See: (J. Von Neumann, The Annals of Mathematical Statistics 12, 367 (1941))
In this updated version, np.average() is used to calculate the weighted average of the measurement errors squared as the sample variance. The weights argument in np.average() is used to specify the weights for each element in the input array, with larger weights given to elements with smaller errors. We also modify the calculation of delta to take into account the measurement errors by dividing the differences between successive magnitudes by the corresponding errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated von Neumann Ratio of the lightcurve.
- MicroLIA.features.stetsonJ(time, mag, magerr, apply_weights=True)[source]
The variability index J was first suggested by Peter B. Stetson and serves as a measure of the correlation between the data points, tending to 0 for variable stars and getting large as the difference between the successive data points increases. See: (P. B. Stetson, Publications of the Astronomical Society of the Pacific 108, 851 (1996)).
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated stetsonJ variability index of the lightcurve.
- MicroLIA.features.stetsonK(time, mag, magerr, apply_weights=True)[source]
The variability index K was first suggested by Peter B. Stetson and serves as a measure of the kurtosis of the magnitude distribution. See: (P. B. Stetson, Publications of the Astronomical Society of the Pacific 108, 851 (1996)).
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated stetsonK variability index of the lightcurve.
- MicroLIA.features.stetsonL(time, mag, magerr, apply_weights=True)[source]
The variability index L was first suggested by Peter B. Stetson and serves as a means of distinguishing between different types of variation. When individual random errors dominate over the actual variation of the signal, K approaches 0.798 (Gaussian limit). Thus, when the nature of the errors is Gaussian, stetsonL = stetsonJ, except it will be amplified by a small factor for smoothly varying signals, or suppressed by a large factor when data is infrequent or corrupt. See: (P. B. Stetson, Publications of the Astronomical Society of the Pacific 108, 851 (1996)).
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated stetsonL variability index of the lightcurve.
- MicroLIA.features.median_buffer_range(time, mag, magerr, apply_weights=True)[source]
This function returns the ratio of points that are between plus or minus 10% of the amplitude value over the mean.
In this updated version, we compute the weighted mean of the mag array using the corresponding magerr values as weights. Then we use the weighted mean to compute a and b values for the range around the mean that we want to consider. Finally, we compute the ratio of points within this range to the total number of points.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of points that are between plus or minus 10% of the lightcurve’s amplitude value over the mean.
- MicroLIA.features.std_over_mean(time, mag, magerr, apply_weights=True)[source]
A measure of the ratio of standard deviation and mean.
In this version, weights is calculated as the inverse square of magerr. The weighted_mean is calculated as the weighted average of mag, where the weights are given by weights. weighted_var is the weighted variance, and weighted_std is the square root of weighted_var. The final line returns the ratio of weighted_std and weighted_mean.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of standard deviation to the lightcurve’s mean.
- MicroLIA.features.amplitude(time, mag, magerr, apply_weights=True)[source]
This amplitude metric is defined as the difference between the maximum magnitude measurement and the lowest magnitude measurement, divided by 2. We account for outliers by removing the upper and lower 2% of magnitudes.
In this updated implementation we first sort the magnitude and error arrays based on the magnitude values. We then compute the median magnitude value after excluding the upper and lower 2% of magnitudes to account for outliers. We compute both the standard amplitude and the weighted amplitude, where each magnitude measurement is weighed by its corresponding error. The weighted amplitude is then returned by the function.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated amplitude of the lightcurve.
- MicroLIA.features.median_distance(time, mag, magerr, apply_weights=True)[source]
This function calculates the median Euclidean distance between each photometric measurement, a helpful metric for detecting overlapped lightcurves.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The calculated median Euclidean distance between each lightcurve measurement.
- MicroLIA.features.above1(time, mag, magerr, apply_weights=True)[source]
This function measures the ratio of data points that are above 1 standard deviation from the median magnitude, weighted by their errors.
In this updated function, each data point is weighed according to its error. The weighted ratio of points that are above 1 standard deviation from the median magnitude is returned. By weighting each data point according to its error, we are taking into account the fact that more weight should be given to data points that have lower measurement uncertainties.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the light curve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of points above 1 standard deviation from the light curve’s median measurement.
- MicroLIA.features.above3(time, mag, magerr, apply_weights=True)[source]
This function measures the ratio of data points that are above 3 standard deviations from the median magnitude, weighted by their errors.
In this updated function, each data point is weighed according to its error. The weighted ratio of points that are above 3 standard deviations from the median magnitude is returned.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the light curve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of points above 3 standard deviations from the light curve’s median measurement.
- MicroLIA.features.above5(time, mag, magerr, apply_weights=True)[source]
This function measures the ratio of data points that are above 5 standard deviations from the median magnitude, weighted by their errors.
In this updated function, each data point is weighed according to its error. The weighted ratio of points that are above 5 standard deviations from the median magnitude is returned.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the light curve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of points above 5 standard deviations from the light curve’s median measurement.
- MicroLIA.features.below1(time, mag, magerr, apply_weights=True)[source]
This function measures the ratio of data points that are below 1 standard deviation from the median magnitude, weighted by their errors.
In this updated function, each data point is weighed according to its error. The weighted ratio of points that are below 1 standard deviation from the median magnitude is returned.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the light curve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of points below 1 standard deviation from the light curve’s median measurement.
- MicroLIA.features.below3(time, mag, magerr, apply_weights=True)[source]
This function measures the ratio of data points that are below 3 standard deviations from the median magnitude, weighted by their errors.
In this updated function, each data point is weighed according to its error. The weighted ratio of points that are below 3 standard deviations from the median magnitude is returned.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the light curve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of points below 3 standard deviations from the light curve’s median measurement.
- MicroLIA.features.below5(time, mag, magerr, apply_weights=True)[source]
This function measures the ratio of data points that are below 5 standard deviations from the median magnitude, weighted by their errors.
In this updated function, each data point is weighed according to its error. The weighted ratio of points that are below 5 standard deviations from the median magnitude is returned.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the light curve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of points below 5 standard deviations from the light curve’s median measurement.
- MicroLIA.features.medianAbsDev(time, mag, magerr, apply_weights=True)[source]
A measure of the mean average distance between each magnitude value and the mean magnitude. https://en.wikipedia.org/wiki/Median_absolute_deviation
This updated function first calculates the median of the magnitude array, then calculates the absolute deviation from the median, divided by the corresponding error value. The median of these absolute deviations is returned as the MAD value.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The median absolute deviation of the lightcurve.
- MicroLIA.features.root_mean_squared(time, mag, magerr, apply_weights=True)[source]
A measure of the root mean square deviation that takes into account the photometric errors.
In this new version, the magnitudes are weighted by their corresponding errors, which takes into account the uncertainty in the measurements. The weighted mean of the magnitudes is subtracted from each magnitude to calculate the weighted deviations, which are then squared and averaged to get the weighted mean of the squared deviations. Finally, the square root of this quantity gives the root mean square deviation that takes into account the photometric errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The root-mean-square of the lightcurve.
- MicroLIA.features.meanMag(time, mag, magerr, apply_weights=True)[source]
Calculates mean magnitude, weighted by the errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The weighted mean measurement of the lightcurve.
- MicroLIA.features.integrate(time, mag, magerr, apply_weights=True)[source]
Integrate magnitude using the trapezoidal rule. See: http://en.wikipedia.org/wiki/Trapezoidal_rule
In the case of integrating the magnitude using the trapezoidal rule, it is not necessary to incorporate the error since the error in magnitude will affect each individual data point, but not the overall integration. The trapezoidal rule uses the values of the magnitudes and their timestamps to compute the area under the curve, without considering the individual errors at each point.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The integral value of the lightcurve.
- MicroLIA.features.auto_corr(time, mag, magerr, apply_weights=True)[source]
Similarity between observations as a function of a time lag between them.
This version of the function first calculates the mean and standard deviation of the magnitudes, and then uses these values to normalize the data before computing the autocovariance function. The weights for each data point are also calculated based on their measurement uncertainties, and are used to compute the weighted autocovariance. Finally, the autocovariance function is normalized by its value at zero lag to obtain the autocorrelation function.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The auto-correlation measurement of the lightcurve.
- MicroLIA.features.peak_detection(time, mag, magerr, apply_weights=True)[source]
Function to detect number of peaks.
Does not need to incorporate error since it is simply detecting the number of peaks in the lightcurve, which is based on the magnitude values alone.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of peaks detected in the lightcurve.
- MicroLIA.features.MaxSlope(time, mag, magerr, apply_weights=True)[source]
Examining successive (time-sorted) magnitudes, the maximal first difference (value of delta magnitude over delta time)
In this updated version of the function, the slope between successive magnitudes is calculated using the errors as weights, and the weighted slope is returned as a single value, not the max slopes as is the case when apply_weights=False.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The maximum-slope detected within the lightcurve.
- MicroLIA.features.LinearTrend(time, mag, magerr, apply_weights=True)[source]
Slope of a weighted linear fit to the light-curve.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The slope of a weighted linear fit to the lightcurve.
- MicroLIA.features.PairSlopeTrend(time, mag, magerr, apply_weights=True)[source]
This is the percentage of all pairs of consecutive flux measurements that have positive slope, considering only the last 30 (time-sorted) magnitude measurements.
This updated function incorporates error by calculating the weighted first differences and then taking the weighted mean of the positive differences and negative differences separately.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The percentage of all pairs of consecutive lightcurve measurements that have positive a slope.
- MicroLIA.features.FluxPercentileRatioMid20(time, mag, magerr, apply_weights=True)[source]
In order to characterize the sorted magnitudes distribution we use percentiles. If F5,95 is the difference between 95% and 5% magnitude values, we calculate the following: Ratio of flux percentiles (60th - 40th) over (95th - 5th)
In this updated version of the function, we first sort the magnitude data and associated uncertainties. We then calculate the weighted percentiles of the magnitude data using the cumulative sum of the weights. We calculate the percentiles using np.interp with the cumulative sum of the weights, and then calculate the flux percentile ratios using the weighted percentiles.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of the (60th - 40th) flux percentile over the (95th - 5th) percentile.
- MicroLIA.features.FluxPercentileRatioMid35(time, mag, magerr, apply_weights=True)[source]
In order to characterize the sorted magnitudes distribution we use percentiles. If F5,95 is the difference between 95% and 5% magnitude values, we calculate the following: Ratio of flux percentiles (67.5th - 32.5th) over (95th - 5th)
In this updated version of the function, we first sort the magnitude data and associated uncertainties. We then calculate the weighted percentiles of the magnitude data using np.interp with the cumulative sum of the weights, and then calculate the flux percentile ratios using the weighted percentiles.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of the (67.5th - 32.5th) flux percentile over the (95th - 5th) percentile.
- MicroLIA.features.FluxPercentileRatioMid50(time, mag, magerr, apply_weights=True)[source]
In order to characterize the sorted magnitudes distribution we use percentiles. If F5,95 is the difference between 95% and 5% magnitude values, we calculate the following: Ratio of flux percentiles (75th - 25th) over (95th - 5th)
In this updated version of the function, we first sort the magnitude data and associated uncertainties. We then calculate the weighted percentiles of the magnitude data using np.interp with the cumulative sum of the weights, and then calculate the flux percentile ratios using the weighted percentiles.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of the (75th - 25th) flux percentile over the (95th - 5th) percentile.
- MicroLIA.features.FluxPercentileRatioMid65(time, mag, magerr, apply_weights=True)[source]
In order to characterize the sorted magnitudes distribution we use percentiles. If F5,95 is the difference between 95% and 5% magnitude values, we calculate the following: Ratio of flux percentiles (82.5th - 17.5th) over (95th - 5th)
In this updated version of the function, we first sort the magnitude data and associated uncertainties. We then calculate the weighted percentiles of the magnitude data using np.interp with the cumulative sum of the weights, and then calculate the flux percentile ratios using the weighted percentiles.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of the (82.5th - 17.5th) flux percentile over the (95th - 5th) percentile.
- MicroLIA.features.FluxPercentileRatioMid80(time, mag, magerr, apply_weights=True)[source]
In order to characterize the sorted magnitudes distribution we use percentiles. If F5,95 is the difference between 95% and 5% magnitude values, we calculate the following: Ratio of flux percentiles (90th - 10th) over (95th - 5th)
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of the (90th - 10th) flux percentile over the (95th - 5th) percentile.
- MicroLIA.features.PercentAmplitude(time, mag, magerr, apply_weights=True)[source]
The largest absolute departure from the median flux, divided by the median flux Largest percentage difference between either the max or min magnitude and the median.
This function calculates both the regular median and a weighted median that takes into account the photometric errors. It then calculates the largest absolute departure from each of these medians and returns the largest percentage difference between either the max or min magnitude and the weighted median.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The largest percentage difference present in the lightcurve with respect to the median.
- MicroLIA.features.PercentDifferenceFluxPercentile(time, mag, magerr, apply_weights=True)[source]
Calculates the ratio of the flux difference between the 5th and 95th percentiles of the data (F5,95) to the median flux.
If apply_weights is set to True, the function first sorts the mag array and the corresponding magerr based on the magnitude values. It then calculates the weighted percentiles by interpolating the values at the desired percentiles (2%, 5%, 95%, and 98%) using cumulative weights. The difference between the 95th and 5th percentiles (F5,95) is calculated based on the interpolated values.
If apply_weights is set to False, the function directly operates on the mag array. It sorts the array and calculates the indices corresponding to the 5th and 95th percentiles. The flux difference between these percentiles (F5,95) is then calculated.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of the flux difference between the 5th and 95th percentiles to the median lightcurve measurement.
- MicroLIA.features.half_mag_amplitude_ratio(time, mag, magerr, apply_weights=True)[source]
The ratio of the squared sum of residuals of magnitudes that are either brighter than or fainter than the mean magnitude. For EB-like variability, having sharp flux gradients around its eclipses, this value is larger than 1.
In this modified version, the weighted standard deviation of each set of magnitudes (i.e., those above and those below the median) is used if apply_weights is set to True.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The ratio of squared residuals for measurements above and below the median.
- MicroLIA.features.cusum(time, mag, magerr, apply_weights=True)[source]
Range of cumulative sum.
In this updated version, we first calculate the weighted standard deviation of the magnitude using the formula wstd = np.sqrt(np.sum((mag - np.median(mag))**2 / magerr**2) / np.sum(1. / magerr**2)). Then we use this value instead of np.std(mag) to normalize the cumulative sum. This takes into account the error in the measurements of the magnitude.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The range of the cumulative sums of the lightcurve measurements.
- MicroLIA.features.shapiro_wilk(time, mag, magerr, apply_weights=True)[source]
The Shapiro-Wilk test tests the null hypothesis that the data was drawn from a normal distribution.
If this statistic is close to 1, then it suggests that the null hypothesis cannot be rejected, which means the data is likely to follow a normal distribution. Note that there is no error incorporation, as the Shapiro-Wilk test implemented in scipy.stats does not provide an option to incorporate measurement error.
Note that the Shapiro-Wilk test implemented in scipy.stats does not provide the option to incorporate measurement errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The Shapiro-Wilk statistic.
- MicroLIA.features.AndersonDarling(time, mag, magerr, apply_weights=True)[source]
The Anderson-Darling test is a statistical test of whether a given sample of data is drawn from a given probability distribution. When applied to testing if a normal distribution adequately describes a set of data, it is one of the most powerful statistical tools for detecting most departures from normality.
It is a measure of how well the data fits a normal distribution. The AndersonDarling_Weighted() function applies the same test, but with weights based on the input errors magerr. Both functions return a value between 0 and 1, with values closer to 1 indicating a better fit to a normal distribution. In short, values closer to 1 indicate a higher confidence that the data follow a normal distribution.
The weighted Anderson-Darling test is a statistical test of whether a given sample of data is drawn from a given probability distribution. When applied to testing if a normal distribution adequately describes a set of data, it is one of the most powerful statistical tools for detecting most departures from normality.
From Kim et al. 2009: “To test normality, we use the Anderson–Darling test (Anderson & Darling 1952; Stephens 1974) which tests the null hypothesis that a data set comes from the normal distribution.” (Doi:10.1111/j.1365-2966.2009.14967.x.)
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The Anderson-Darling test statistic.
- MicroLIA.features.Gskew(time, mag, magerr, apply_weights=True)[source]
Gskew is a measure of the skewness of a distribution of magnitudes. It is defined as the sum of the medians of the magnitudes below and above the 3rd and 97th percentiles, respectively, minus twice the median magnitude. In other words, Gskew is a measure of the asymmetry of the distribution of magnitudes. A positive Gskew value indicates a distribution that is skewed to the right (has a long tail on the right side), while a negative Gskew value indicates a distribution that is skewed to the left (has a long tail on the left side).
It is essentially a median-based measure of the skewness. See: Lopez et al. 2016: “A machine learned classifier for RR Lyrae in the VVV survey”
Gskew = mq3 + mq97 − 2m mq3 is the median of magnitudes lesser or equal than the quantile 3. mq97 is the median of magnitudes greater or equal than the quantile 97. 2m is 2 times the median magnitude.
If apply_weights=True a modified version will be used that incorporates the photometric errors of the data points. It calculates a weighted median for the magnitudes that fall below the 3rd percentile and above the 97th percentile, using the inverse square of the photometric errors as weights. The resulting weighted medians and the median magnitude are then used to calculate the Gskew value.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The median-based skewness of the lightcurve.
- MicroLIA.features.abs_energy(time, mag, magerr, apply_weights=True)[source]
Calculates the absolute energy of the time series, defined to be the sum over the squared values of the time-series.
If apply_weights is set to True, we calculate the inverse square of the photometric errors and use them as weights to calculate the weighted sum of squares of the magnitudes. In the case where weights are applied, the magnitudes are multiplied by their corresponding weights (inverse square of photometric errors) before squaring and summing them. This results in a larger contribution from data points with smaller errors, as they receive higher weights. As a result, the absolute energy value increases. On the other hand, when weights are not applied (apply_weights=False), all magnitudes are squared and summed without considering their errors. This leads to a smaller absolute energy value as the contributions from individual data points are not scaled by their respective errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The sum over the squared values of the lightcurve measurements.
- MicroLIA.features.abs_sum_changes(time, mag, magerr, apply_weights=True)[source]
Calculates the sum over the abs value of consecutive changes in mag, weighted by the errors.
In this updated version we incorporate photometric errors by dividing the absolute value of the difference between consecutive magnitudes by the square root of the sum of their squared errors. Therefore larger errors will result in smaller weight for the corresponding changes in magnitude.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The sum over the absolute value of consecutive changes in the lightcurve measurements.
- MicroLIA.features.benford_correlation(time, mag, magerr, apply_weights=True)[source]
Useful for anomaly detection applications. Calculates the correlation from first digit distribution when compared to the Newcomb-Benford’s Law distribution, weighted by the inverse variance of the magnitudes.
In this updated version, we calculate the weights as the inverse variance of the magnitudes (i.e., the inverse of the squared photometric errors), and use these weights to calculate the weighted distribution of the data. We then normalize this weighted distribution and compute the weighted correlation between the Benford distribution and the weighted data distribution.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The Benford Correlation statistic.
- MicroLIA.features.c3(time, mag, magerr, lag=1, apply_weights=True)[source]
The C3 measure is a way to estimate the non-linearity of a time series by measuring the third-order correlation between the values of the time series. It is based on the idea that a truly linear time series will have a third-order correlation of zero, while a non-linear time series will have a non-zero third-order correlation. The lag parameter controls the distance between the three values of the time series that are used to calculate the third-order correlation. A larger lag value will capture longer-term correlations in the data, while a smaller lag value will capture shorter-term correlations.
In this updated version, we first calculate the terms that make up the third-order correlation using the mag array and its two rolled versions. We then use the error propagation formula to calculate the errors associated with these terms. Finally, we calculate the third-order correlation as the weighted average of the terms, where the weights are given by the inverse squared errors. Note that this version of the function assumes Gaussian errors in the magerr array.
See: Measure of non-linearity in time series: [1] Schreiber, T. and Schmitz, A. (1997). Discrimination power of measures for nonlinearity in a time series PHYSICAL REVIEW E, VOLUME 55, NUMBER 5
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- lag: int
The lag to use. Defaults to 1.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The C3 non-linearity statistic.
- MicroLIA.features.complexity(time, mag, magerr, apply_weights=True)[source]
This function calculator is an estimate for a time series complexity. A higher value represents more complexity (more peaks,valleys,etc.) See: Batista, Gustavo EAPA, et al (2014). CID: an efficient complexity-invariant distance for time series. Data Mining and Knowledge Difscovery 28.3 (2014): 634-669.
To incorporate errors into the complexity function, we apply the weighted standard deviation formula. We exclude the last element of magerr since np.diff reduces the size of the mag array by one. Also, if the sum of the weights is zero, we return 0 to avoid division by zero errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The complexity measurement of the lightcurve.
- MicroLIA.features.count_above(time, mag, magerr, apply_weights=True)[source]
Number of values higher than the weighted median.
This function calculates the weighted median of the mag array using the photometric errors in magerr, and then counts the number of values in mag that are above the weighted median. The fraction of values above the weighted median is then calculated using the weights from magerr. If magerr is zero for all values, the function returns zero.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of lightcurve measurements above the median value.
- MicroLIA.features.count_below(time, mag, magerr, apply_weights=True)[source]
Number of values below the median.
To incorporate errors, we use the weighted median instead of the regular median. The weighted median takes into account the uncertainties associated with each data point.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of lightcurve measurements below the median value.
- MicroLIA.features.first_loc_max(time, mag, magerr, apply_weights=True)[source]
Calculates the location of maximum mag relative to the length of mag array, weighted by inverse square of magerr if apply_weights is True.
In this modified version, we first calculate the inverse square of magerr and set it to 0 where magerr2 is 0 to avoid division by zero. Then we multiply each value of mag by the corresponding inverse square of magerr, giving more weight to values with smaller magerr. Finally, we find the index of the maximum value in the weighted mag array using np.argmax, and return the location of the maximum relative to the length of mag.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The relative position of the maximum detected lightcurve measurement.
- MicroLIA.features.first_loc_min(time, mag, magerr, apply_weights=True)[source]
Calculates the location of minimum mag relative to the length of mag array.
This updated implementation first computes the weights for each measurement using the provided photometric errors in magerr. It then replaces all zero weights with 1 to avoid division by zero. Finally, it computes the location of the minimum mag by taking the weighted minimum of mag using the computed weights.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The relative position of the minimum detected lightcurve measurement.
- MicroLIA.features.check_for_duplicate(time, mag, magerr, apply_weights=True)[source]
Checks if any value in mag repeats, taking into account photometric errors if apply_weights is enabled so as to identify measurements that are within the error bars.
To incorporate error, we use np.isclose to check if two values of mag are close to each other, taking into account their respective errors. The tolerance is set using the atol argument, which is set to the sum of the errors in quadrature, to account for the fact that two measurements with similar values but different errors may still be considered duplicates. If a duplicate is found, the function returns 1, otherwise it returns 0.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- int
Whether or not a duplicate lightcurve measurement is found, 1 for True, 0 for False.
- MicroLIA.features.check_for_max_duplicate(time, mag, magerr, apply_weights=True)[source]
Checks if the maximum value in mag repeats, taking into account photometric errors if apply_weights is enabled so as to identify measurements that are within the error bars.
To incorporate error, we use np.isclose to check if the maximum value in mag is close to any other value in mag, taking into account their respective errors. The tolerance is set using the atol argument, which is calculated as the maximum of the maximum error and the error of the closest value to the maximum, to account for the fact that two measurements with similar values but different errors may still be considered duplicates. If a duplicate is found, the function returns 1, otherwise it returns 0.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- int
Whether or not the maximum lightcurve measurement is found more than once, 1 for True, 0 for False.
- MicroLIA.features.check_for_min_duplicate(time, mag, magerr, apply_weights=True)[source]
Checks if the minimum value in mag repeats, taking into account photometric errors if apply_weights is enabled so as to identify measurements that are within the error bars.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- int
Whether or not the minimum lightcurve measurement is found more than once, 1 for True, 0 for False.
- MicroLIA.features.check_max_last_loc(time, mag, magerr, apply_weights=True)[source]
Calculates the position of last maximum mag relative to the length of mag array, taking into account photometric errors.
In this implementation, we first find the maximum value in mag and calculate the tolerance value atol as the maximum photometric error in magerr. We then use np.isclose() with atol as the atol argument to find the indices of all values in mag that are within tolerance of max_mag. We select the last index in the resulting array (which corresponds to the last maximum value in mag) and calculate its position relative to the length of mag. If there are no values within tolerance (3sigma), we return np.NaN.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The relative position where the maximum lightcurve measurement was last found.
- MicroLIA.features.check_min_last_loc(time, mag, magerr, apply_weights=True)[source]
Calculates the position of last minimum mag relative to the length of mag array, taking into account photometric errors.
To incorporate errors, this implementation finds the minimum value in mag, then calculates the atol value based on the error of the minimum value and the error of the closest value to the minimum. It then uses np.isclose() with atol as the atol argument to find the indices of all values in mag that are within tolerance of min_mag. It selects the last index in the resulting array (which corresponds to the last minimum value in mag) and calculates its position relative to the length of mag. If there are no values within tolerance, it returns np.NaN.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The relative position where the minimum lightcurve measurement was last found.
- MicroLIA.features.longest_strike_above(time, mag, magerr, apply_weights=True)[source]
Calculates the length of the longest consecutive subsequence in mag that is bigger than the median.
This updated implementation first calculates the median of the mag array and creates a boolean mask of True for elements greater than the median plus their errors and False for elements less than or equal to the median plus their errors. It then splits the mask into groups of consecutive True values, and returns the length of the longest group as a fraction of the length of the mag array. If there are no values greater than the median plus their errors, the function returns 0.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The length of the longest consecutive subsequence in the lightcurve measurements which are larger than the median.
- MicroLIA.features.longest_strike_below(time, mag, magerr, apply_weights=True)[source]
Calculates the length of the longest consecutive subsequence in mag that is smaller than the median.
To incorporate errors, first we calculate the median of mag and create a boolean mask of True for elements smaller than the median minus their errors and False for elements greater than or equal to the median minus their errors. Then we split the mask into groups of consecutive True values, and return the length of the longest group as a fraction of the length of the mag array. If there are no values smaller than the median minus their errors, the function returns 0.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The length of the longest consecutive subsequence in the lightcurve measurements which are smaller than the median.
- MicroLIA.features.mean_change(time, mag, magerr, apply_weights=True)[source]
Calculates mean over the differences between subsequent observations, weighted by the inverse square of their errors if apply_weights is True.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The mean over the differences between all subsequent lightcurve measurements.
- MicroLIA.features.mean_abs_change(time, mag, magerr, apply_weights=True)[source]
Calculates the mean absolute change in the magnitude per unit of error.
To incorporate error we weight each absolute difference by the corresponding error, and then take the mean of the weighted differences. This would give a measure of the average absolute change in units of the error.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The mean absolute change in the lightcurve measurements.
- MicroLIA.features.mean_n_abs_max(time, mag, magerr, number_of_maxima=10, apply_weights=True)[source]
Calculates the weighted arithmetic mean of the n absolute maximum values of the time series, n=10 by design.
We incorporate errors in the calculation by sorting the absolute values of the magnitude and corresponding errors, and then taking the arithmetic mean of the top n maximum values weighted by their errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- number_of_maximaint
The number of maxima to consider. Defaults to 10.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The mean of the 10 absolute maximum values of the lightcurve.
- MicroLIA.features.mean_second_derivative(time, mag, magerr, apply_weights=True)[source]
Calculates the weighted mean value of a central approximation of the second derivative, where weights are the inverse square of the errors. Note that the first and last values of the second derivative are not included in the calculation, as they cannot be approximated using a central difference.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The mean value of a central approximation of the second derivative.
- MicroLIA.features.number_of_crossings(time, mag, magerr, apply_weights=True)[source]
Calculates the number of crossings of x on the median, m. A crossing is defined as two sequential values where the first value is lower than m and the next is greater, or vice-versa. If you set m to zero, you will get the number of zero crossings.
We incorporate errors by calculating the differences between consecutive values of the positive array and store it in the crossings variable. Finally, we multiply the crossings array with a Boolean array that checks if the difference between consecutive values of mag is greater than the corresponding error in magerr. The resulting array will have a value of 1 for each crossing that is greater than the corresponding error, and 0 for each crossing that is smaller than or equal to the error. We then sum this array to get the total number of crossings.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of crossings about the lightcurve’s median.
- MicroLIA.features.number_of_peaks(time, mag, magerr, n=7, apply_weights=True)[source]
Calculates the number of peaks of at least support n in the time series x. A peak of support n is defined as a subsequence of x where a value occurs, which is bigger than its n neighbors to the left and to the right. n = 7
Hence in the sequence:
>>> x = [3, 0, 0, 4, 0, 0, 13]
4 is a peak of support 1 and 2 because in the subsequences
>>> [0, 4, 0] >>> [0, 0, 4, 0, 0]
4 is still the highest value. Here, 4 is not a peak of support 3 because 13 is the 3th neighbour to the right of 4 and its bigger than 4.
To incorporate the error bars we first reduce the mag and magerr arrays by n elements from both ends to ensure that we can check for peaks of support n. We then iterate over the mag array and calculate the differences between the values of the mag array and its i-th neighbor to the left and to the right. We also calculate the corresponding errors for the differences using the error arrays magerr and xerr_reduced. We then check if the absolute value of the difference is greater than the corresponding error to determine if we have a peak of support n. Finally, we combine the results using logical AND to get the total number of peaks.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- nint
The support of the peak. Defaults to 7.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of peaks of at least support 7 within the lightcurve, normalized according to the size of the lightcurve.
- MicroLIA.features.ratio_recurring_points(time, mag, magerr, apply_weights=True)[source]
Calculates the ratio of unique values, that are present in the time series more than once, normalized to the number of data points.
If apply weights is set to True, the photometric errors will be used by looping over the unique values and checking if the number of values that are close to it (using the np.isclose function) is greater than 1. If so, the value is counted as a recurring point.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of unique measurements normalized according to the size of the lightcurve.
- MicroLIA.features.sample_entropy(time, mag, magerr, apply_weights=True)[source]
Calculates sample entropy: http://en.wikipedia.org/wiki/Sample_Entropy
One approach to incorporate error is to modify the distance metric used in the algorithm to account for measurement error. “Modified Sample Entropy Method in the Presence of Noise” by Zhang et al. proposes a modified version of sample entropy that uses a weighted distance metric based on both the difference in magnitudes and the difference in measurement errors between pairs of data points, but MicroLIA does not support this as the noise level may alter the value range significantly.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The sample entropy of the lightcurve.
- MicroLIA.features.sum_values(time, mag, magerr, apply_weights=True)[source]
Sums over all mag values.
If apply_weights=True, the formula for weighted mean is used to calculate the sum of the magnitudes. The weights are given by the inverse square of the magnitudes’ errors.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The sum of all the measurements, normalized to the size of the lightcurve.
- MicroLIA.features.time_reversal_asymmetry(time, mag, magerr, lag=1, apply_weights=True)[source]
Derives the time reversal asymmetric statistic introduced by Fulcher.
See: (Fulcher, B.D., Jones, N.S. (2014). Highly comparative feature-based time-series classification. Knowledge and Data Engineering, IEEE Transactions on 26, 3026–3037.)
We incorporate errors by dividing each term by the square of its corresponding magerr, which effectively gives more weight to terms with smaller errors. Note that this modification assumes that the errors are Gaussian and uncorrelated, which may not always be true in practice.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- lagint
The lag to apply. Defaults to 1.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The time reversal symmetry statistic.
- MicroLIA.features.variance(time, mag, magerr, apply_weights=True)[source]
Calculates the variance, or the weighted variance of the light curve if apply_weights=True.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The variance of the lightcurve measurements.
- MicroLIA.features.variance_larger_than_standard_deviation(time, mag, magerr, apply_weights=True)[source]
This feature denotes if the variance of x is greater than its standard deviation. Is equal to variance of x being larger than 1. 1 is True, 0 is False.
If apply_weights=True a weighting factor to the magnitude values when computing the variance and standard deviation will be used. This factor gives more weight to the more precise measurements and less weight to the less precise measurements.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- int
Whether or not the lightcurve’s variance is greater than the standard deviation, 1 for True, 0 for False.
- MicroLIA.features.variation_coefficient(time, mag, magerr, apply_weights=True)[source]
Calculates the variation coefficient (standard error / mean, gives the relative value of variation around mean) of x.
We incorporate errors by using the weighted standard deviation and weighted mean.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The lightcurve standard deviation over the mean.
- MicroLIA.features.large_standard_deviation(time, mag, magerr, r=0.3, apply_weights=True)[source]
Does time series have “large” standard deviation?
Boolean variable denoting if the standard dev of x is higher than ‘r’ times the range = difference between max and min of x. To incorporate errors we use the weighted standard deviation instead of the regular standard deviation.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- rfloat
The percentage of the range to compare with. Must be between 0 and 1. Defaults to 0.3.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- int
Whether or not the lightcurve has a large standard deviation, 1 for True, 0 for False.
- MicroLIA.features.symmetry_looking(time, mag, magerr, r=0.5, apply_weights=True)[source]
Check to see if the distribution of the mag “looks symmetric”. This is the case if:
mean(X)-median(X)| < r * (max(X)-min(X))where r is the percentage of the range to compare with.
If apply_weights=True, the weighted mean and the weighted median are used instead of the regular mean and median.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- rfloat
The percentage of the range to compare with. Must be between 0 and 1. Deaults to 0.5.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- int
Whether or not the lightcurve appears symmetric, 1 for True, 0 for False.
- MicroLIA.features.index_mass_quantile(time, mag, magerr, r=0.5, apply_weights=True)[source]
Calculates the relative index i of time series x where r% of the mass of x lies left of i. For example for r = 50% this feature will return the mass center of the time series.
Errors are incorporated into this function by weighing the contributions of each data point with its inverse variance.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- rfloat
The percentage of the range to compare with. Must be between 0 and 1. Defaults to 0.5.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The relative index of the lightcurve measurement that is to the right of the 50% of the cumulative sum.
- MicroLIA.features.number_cwt_peaks(time, mag, magerr, n=30, apply_weights=True)[source]
Number of different peaks in the magnitude array.
To estimate the numbers of peaks, x is smoothed by a ricker wavelet for widths ranging from 1 to n. This feature calculator returns the number of peaks that occur at enough width scales and with sufficiently high Signal-to-Noise-Ratio (SNR). Weights are not meant to be applied in this case.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- nint
The maximum time width to consider. Defaults to 30.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The number of peaks in the lightcurve after smoothing with a wavelet transformation.
- MicroLIA.features.permutation_entropy(time, mag, magerr, tau=1, dimension=3, apply_weights=True)[source]
Calculate the permutation entropy.
- Ref: https://www.aptech.com/blog/permutation-entropy/
Bandt, Christoph and Bernd Pompe. “Permutation entropy: a natural complexity measure for time series.” Physical review letters 88 17 (2002): 174102
In this modified version, if apply_weights=True, we compute the weights as the reciprocal of the magnitude errors and divide each count by the corresponding weight. Then we compute the weighted average probabilities and return the negative sum of the probabilities times their logarithms.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- tauint
The embedded time delay that determines the time separation between the measurements. Defaults to 1.
- dimensionint
The embedding dimension to use. Defaults to 3.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The permutation entropy of the lightcurve.
- MicroLIA.features.quantile(time, mag, magerr, r=0.75, apply_weights=True)[source]
Calculates the r quantile of the mag. This is the value of mag greater than r% of the ordered values.
Errors are not incorporated in this function.
Parameters:
- timearray
The timestamps of the corresponding mag and magerr measurements. Must be an array.
- magarray
The time-varying intensity of the lightcurve. Must be an array.
- magerrarray
Photometric error for the intensity. Must be an array.
- rfloat
The percentage of the range to compare with. Must be between 0 and 1. Defaults to 0.75.
- apply_weightsbool, optional
Whether to apply weights based on the magnitude errors. Defaults to True.
Returns:
- float
The 75th quantile of the ordered lightcurve measurements.