The tools package holds general astronomy functions or algorithms that are likely of use to users, but either not related to functionality in an existing package or of general use across multiple packages.
Note
For functions and classes that are more developer-oriented, the correct package is astropy.utils. astropy.tools is intended primarily for functionality that is astronomy-specific and/or of use to users.
Below are the reference documentation for the tools sub-packages. All public functions and classes in these packages will be imported into the astropy.tools package, so the recommended usage is e.g. from astropy.tools import sigma_clip or import astropy.tools instead of from astropy.tools.misc import sigma_clip or similar.
This module contains simple algorithmic functionality common in astronomy or used in multiple places throughout Astropy, but are not complex enough to necessarily warrant their own module.
This package should generally not be used directly. Everything in __all__ is imported into astropy.tools, and hence that package should be used for access.
Perform sigma-clipping on the provided data.
This performs the sigma clipping algorithm - i.e. the data will be iterated over, each time rejecting points that are more than a specified number of standard deviations discrepant.
| Parameters : | data : array-like
sig : float
iters : int or None
cenfunc : callable
varfunc : callable
maout : bool or ‘copy’
|
|---|---|
| Returns : | filtereddata : numpy.ndarray or numpy.masked.MaskedArray
mask : boolean array
|
Examples
This will generate random variates from a Gaussian distribution and return only the points that are within 2 sample standard deviation from the median:
>>> from astropy.tools.alg import sigma_clip
>>> from numpy.random import randn
>>> randvar = randn(10000)
>>> data,mask = sigma_clip(randvar,2,1)
This will clipping on a similar distribution, but for 3 sigma relative to the sample mean, will clip until converged, and produces a numpy.masked.MaskedArray:
>>> from astropy.tools.alg import sigma_clip
>>> from numpy.random import randn
>>> from numpy import mean
>>> randvar = randn(10000)
>>> maskedarr = sigma_clip(randvar,3,None,mean,maout=True)