Utilities#
This sub-package contains helpful utilities for Lightkurve.
BitSet#
A set-like class for bitwise data with support for integer representation
- class lkdata.utils.bitset.BitSet(iterable=None)[source]#
Bases:
MutableSet,HashableA data type for bitwise objects.
This datatype combines the utility of sets and the succinct representation of integer numbers as used for data quality flags in astronomical data. Integers are treated as sets of their constituent powers of 2.
- static breakdown(item)[source]#
Breaks down a given item into a single set of bitwise components
- Return type:
- Parameters:
- itemUnion[int, str, Iterable]
An integer, binary integer, or collection of integers to be broken down
Uncertainty#
The uncertainty developed for lkdata is based on the astropy.nddata.NDUncertainty module, as of the v7.0.0 release.
Uncertainty class and methods for use with numerical lkdata objects This code is modified from astropy.nddata.nduncertainty v7.0.0 release distributed under the following MIT license:
Licensed under a 3-clause BSD style license - see LICENSE.rst Copyright (c) 2011-2024, Astropy Developers All rights reserved.
- exception lkdata.utils.uncertainty.IncompatibleUncertaintiesException[source]#
Bases:
ExceptionThis exception should be used to indicate cases in which uncertainties with two different classes can not be propagated.
- exception lkdata.utils.uncertainty.MissingDataAssociationException[source]#
Bases:
ExceptionThis exception should be used to indicate that an uncertainty instance has not been associated with a parent
NDDataobject.
- class lkdata.utils.uncertainty.NDUncertainty(array=None, copy=True)[source]#
Bases:
objectThis is the metaclass for uncertainty classes used with
NDData.- Parameters:
- arrayany type, optional
The array or value (the parameter name is due to historical reasons) of the uncertainty.
numpy.ndarrayorNDUncertaintysubclasses are recommended. If thearrayislist-like ornumpy.ndarray-like it will be cast to a plainnumpy.ndarray. Default isNone.- copy
bool, optional Indicates whether to save the
arrayas a copy.Truecopies it before saving, whileFalsetries to save every parameter as reference. Note however that it is not always possible to save the input as reference. Default isTrue.
- Raises:
- IncompatibleUncertaintiesException
If given another
NDUncertainty-like class asarrayif theiruncertainty_typeis different.
- property array#
numpy.ndarray: the uncertainty’s value.
- property parent_nddata#
NDData: reference toNDDatainstance with this uncertainty.In case the reference is not set uncertainty propagation will not be possible since propagation might need the uncertain data besides the uncertainty.
- propagate(operation, other_nddata, result_data, correlation, axis=None)[source]#
Calculate the resulting uncertainty given an operation on the data.
- Parameters:
- operationcallable
The operation that is performed on the
NDData. Supported arenumpy.add,numpy.subtract,numpy.multiplyandnumpy.true_divide(ornumpy.divide).- other_nddata
NDDatainstance The second operand in the arithmetic operation.
- result_datandarray
The result of the arithmetic operations on the data.
- correlation
numpy.ndarrayor number The correlation (rho) is defined between the uncertainties in sigma_AB = sigma_A * sigma_B * rho. A value of
0means uncorrelated operands.- axisint or tuple of ints, optional
Axis over which to perform a collapsing operation.
- Returns:
- resulting_uncertainty
NDUncertaintyinstance Another instance of the same
NDUncertaintysubclass containing the uncertainty of the result.
- resulting_uncertainty
- Raises:
- ValueError
If the
operationis not supported or if correlation is not zero but the subclass does not support correlated uncertainties.
Notes
First this method checks if a correlation is given and the subclass implements propagation with correlated uncertainties. Then the second uncertainty is converted (or an Exception is raised) to the same class in order to do the propagation. Then the appropriate propagation method is invoked and the result is returned.
- property shape#
bool: Supports uncertainty propagation with correlated uncertainties?
- class lkdata.utils.uncertainty.Uncertainty(array=None, copy=True)[source]#
Bases:
_VariancePropagationMixin,NDUncertaintyStandard deviation uncertainty assuming first order gaussian error propagation.
This class implements uncertainty propagation for
addition,subtraction,multiplicationanddivisionwith other instances ofUncertainty. Also support for correlation is possible but requires the correlation as input. It cannot handle correlation determination itself.- Parameters:
- args, kwargs
see
NDUncertainty
Examples
Uncertaintyshould always be associated with anNDData-like instance, either by creating it during initialization:>>> from astropy.nddata import NDData, Uncertainty >>> ndd = NDData([1,2,3], ... uncertainty=Uncertainty([0.1, 0.1, 0.1])) >>> ndd.uncertainty Uncertainty([0.1, 0.1, 0.1])
or by setting it manually on the
NDDatainstance:>>> ndd.uncertainty = Uncertainty([0.2], copy=True) >>> ndd.uncertainty Uncertainty([0.2])
the uncertainty
arraycan also be set directly:>>> ndd.uncertainty.array = 2 >>> ndd.uncertainty Uncertainty(2)
True:Uncertaintyallows to propagate correlated uncertainties.correlationmust be given, this class does not implement computing it by itself.
- property uncertainty_type#
"std":Uncertaintyimplements standard deviation.
Exceptions#
Contains all lightkurve exceptions.
- exception lkdata.utils.exceptions.LightkurveDeprecationWarning[source]#
Bases:
LightkurveWarningClass for all Lightkurve deprecation warnings.