Package: loess
The LOESS PackageSmoothing via robust locally-weighted regression in one or two dimensionsLOESS is the Python implementation byCappellari et al. (2013)of the
algorithm byCleveland (1979)for the one-dimensional case andCleveland & Devlin (1988)for the two-dimensional case.ContentsThe LOESS PackageAttributionInstallationDocumentationloess_1dPurposeCalling SequenceInput ParametersOptional KeywordsOutput Parametersloess_2dPurposeCalling SequenceInput ParametersOptional KeywordsOutput ParametersLicenseChangelogAttributionIf you use this software for your research, please cite the LOESS package ofCappellari et al. (2013b),
where the implementation was described. The BibTeX entry for the paper is:@ARTICLE{Cappellari2013b,
    author = {{Cappellari}, M. and {McDermid}, R.~M. and {Alatalo}, K. and
        {Blitz}, L. and {Bois}, M. and {Bournaud}, F. and {Bureau}, M. and
        {Crocker}, A.~F. and {Davies}, R.~L. and {Davis}, T.~A. and
        {de Zeeuw}, P.~T. and {Duc}, P.-A. and {Emsellem}, E. and {Khochfar}, S. and
        {Krajnovi{\'c}}, D. and {Kuntschner}, H. and {Morganti}, R. and
        {Naab}, T. and {Oosterloo}, T. and {Sarzi}, M. and {Scott}, N. and
        {Serra}, P. and {Weijmans}, A.-M. and {Young}, L.~M.},
    title = "{The ATLAS$^{3D}$ project - XX. Mass-size and mass-{$\sigma$}
        distributions of early-type galaxies: bulge fraction drives kinematics,
        mass-to-light ratio, molecular gas fraction and stellar initial mass
        function}",
    journal = {MNRAS},
    eprint = {1208.3523},
     year = 2013,
    volume = 432,
    pages = {1862-1893},
      doi = {10.1093/mnras/stt644}
}Installationinstall with:pip install loessWithout writing access to the globalsite-packagesdirectory, use:pip install --user loessTo upgradeloessto the latest version use:pip install --upgrade loessDocumentationFull documentation is contained in the individual files docstrings.Usage examples are contained in the directoryloess/exampleswhich is copied bypipwithin the global foldersite-packages.What follows is the documentation of the two main procedures of theloesspackage, extracted from their Python docstrings.loess_1dPurposeOne-dimensional LOESS smoothing via robust locally-weighted regression.This function is the implementation byCappellari et al. (2013)of the
algorithm byCleveland (1979).Calling Sequencexout,yout,wout=loess_1d(x,y,xnew=None,degree=1,frac=0.5,npoints=None,rotate=False,sigy=None)Input Parametersx: array_like with shape (n,)Vector ofxcoordinate.y: array_like with shape (n,)Vector ofycoordinate to be LOESS smoothed.Optional Keywordsxnew: array_like with shape (m,), optionalVector of coordinates at which to compute the smoothedyvalues.degree: {1, 2}, optionaldegree of the local 1-dim polynomial approximation (defaultdegree=1).frac: float, optionalFraction of points to consider in the local approximation (defaultfrac=0.5).
Typical values are betweenfrac~0.2-0.8. Note that the values are
weighted by a Gaussian function of their distance from the point under
consideration. This implies that the effective fraction of points
contributing to a given value is much smaller thatfrac.npoints: int, optionalNumber of points to consider in the local approximation.
This is an alternative to usingfrac=npoints/x.size.rotate: bool, optionalRotate the(x, y)coordinates to have the maximum variance along thexaxis. This is useful to give comparable contribution to the
errors in thexandyvariables. It can be used to asses the
sensitivity of the solution to the assumption that errors are only iny.sigy: array_like with shape (n,)1-sigma errors for theyvalues. If this keyword is used
the biweight fit is done assuming those errors. If this keyword
isnotused, the biweight fit determines the errors inyfrom the scatter of the neighbouring points.Output Parametersxout: array_like with shape (n,)Vector ofxcoordinates for theyoutvalues.
Ifrotate=False(default) thenxout=x.When passing as input thexnewcoordinates thenxout=xnewand both have shape(m,).yout: array_like with shape (n,)Vector of smoothedyvalues at the coordinatesxout.When passing as input thexnewcoordinates this contains the
smoothed values at the coordinatesxnewand has shape(m,).wout: array_like with shape (n,)Vector of biweights used in the local regressions. This can be used to
identify outliers:wout=0for outliers with deviations>4sigma.When passing as input thexnewcoordinates, this output is
meaningless and is arbitrarily set to unity.loess_2dPurposeTwo-dimensional LOESS smoothing via robust locally-weighted regression.This function is the implementation byCappellari et al. (2013)of the
algorithm byCleveland (1979)for the one-dimensional case andCleveland & Devlin (1988)for the two-dimensional case.Calling Sequencezout,wout=loess_2d(x,y,z,xnew=None,ynew=None,degree=1,frac=0.5,npoints=None,rescale=False,sigz=None)Input Parametersx: array_like with shape (n,)vector ofxcoordinates.y: array_like with shape (n,)vector ofycoordinates.z: array_like with shape (n,)vector ofzcoordinates to be LOESS smoothed.Optional Keywordsxnew: array_like with shape (m,), optionalVector with thexcoordinates at which to compute the smoothedzvalues.ynew: array_like with shape (m,), optionalVector with theycoordinates at which to compute the smoothedzvalues.degree: {1, 2}, optionaldegree of the local 2-dim polynomial approximation (defaultdegree=1).frac: float, optionalFraction of points to consider in the local approximation (defaultfrac=0.5).
Typical values are betweenfrac~0.2-0.8. Note that the values are
weighted by a Gaussian function of their distance from the point under
consideration. This implies that the effective fraction of points
contributing to a given value is much smaller thatfrac.npoints: int, optionalNumber of points to consider in the local approximation.
This is an alternative to usingfrac=npoints/x.size.rescale: bool, optionalRotate the(x, y)coordinates to make thexaxis the axis of
maximum variance. Subsequently scale the coordinates to have equal
variance along both axes. Then perform the local regressions.
This is recommended when the distribution of points is elongated or
when the units are very different for the two axes.sigz: array_like with shape (n,)1-sigma errors for thezvalues. If this keyword is used
the biweight fit is done assuming these errors. If this keyword
isnotused, the biweight fit determines the errors inzfrom the scatter of the neighbouring points.Output Parameterszout: array_like with shape (n,)Vector of smoothedzvalues at the coordinates(x, y), or at(xnew, ynew)if the latter are given as input. In the latter casezouthas shape(m,).wout: array_like with shape (n,)Vector of biweights used in the local regressions. This can be used to
identify outliers:wout=0for outliers with deviations>4sigma.When passing as input the(xnew, ynew)coordinates, this output is
meaningless and is arbitrarily set to unity.LicenseOther/Proprietary LicenseCopyright (c) 2010-2022 Michele CappellariThis software is provided as is without any warranty whatsoever.
Permission to use, for non-commercial purposes is granted.
Permission to modify for personal or internal use is granted,
provided this copyright and disclaimer are included in all
copies of the software. All other rights are reserved.
In particular, redistribution of the code is not allowed.ChangelogV2.1.2: MC, Oxford, 31 January 2022Fixed incorrect results with integer input coordinates in bothloess_1dandloess_2d. Thanks to Peter Weilbacher (aip.de)
for the report and fix.V2.1.0: MC, Oxford, 20 July 2021Support output coordinates different from the input ones.Updatedloess_1d_exampleandloess_2d_example.V2.0.6: MC, Oxford, 21 May 2018Dropped support for Python 2.7.V2.0.5: MC, Oxford, 18 January 2018Fixed FutureWarning in Numpy 1.14.V2.0.4: MC, Oxford, 18 April 2016Fixed deprecation warning in Numpy 1.11.V2.0.3: MC, Oxford, 8 December 2014Updated documentation. Minor polishing.V2.0.2: MC, Oxford, 3 November 2014Returns weights also when frac=0 for consistency.V2.0.1: MC, Oxford, 10 July 2014Removed SciPy dependency.V2.0.0: MC, Oxford, 26 February 2014Translated from IDL into Python.V1.3.4: MC, Paranal, 7 November 2013Include SIGZ and WOUT keywords. Updated documentation.V1.3.3: MC, Oxford, 31 October 2013Use CAP_POLYFIT_2D.Removed /QUARTIC keyword and replaced by DEGREE keyword like CAP_LOESS_1D.V1.3.2: MC, Oxford, 12 October 2013Test whether input (X,Y,Z) have the same size.Included NPOINTS keyword.V1.1.4: MC, Oxford, 16 May 2013Updated documentation.V1.1.3: MC, Oxford, 2 December 2011Check when outliers don’t change to stop iteration.V1.1.2: MC, Oxford, 25 July 2011Return values unchanged if FRAC=0.V1.1.1: MC, Oxford, 07 March 2011Fix: use ABS() for proper computation of “r”.V1.1.0: MC, Vicenza, 30 December 2010Rescale after rotating to axis of maximum variance.V1.0.0: Michele Cappellari, Oxford, 15 December 2010Written and tested.