Package: cmomy
cmomyA Python package to calculate and manipulate Central (co)moments. The main
features ofcmomyare as follows:Numbaaccelerated computation of central moments and co-momentsRoutines to combine, and resample central moments.Bothnumpyarray-like andxarrayDataArray interfaces to
Data.Routines to convert between central and raw moments.Overviewcmomyis an open source package to calculate central moments and co-moments in
a numerical stable and direct way. Behind the scenes,cmomymakes use ofNumbato rapidly calculate moments. A good introduction to the type of
formulas used can be foundhere.FeaturesFast calculation of central moments and central co-moments with weightsSupport for scalar or vector inputsnumpy and xarray api'sbootstrap resamplingStatusThis package is actively used by the author. Please feel free to create a pull
request for wanted features and suggestions!Quick startUse one of the followingpipinstallcmomyorcondainstall-cconda-forgecmomyExample usage>>>importnumpyasnp>>>importcmomy>>>rng=cmomy.random.default_rng(seed=0)>>>x=rng.random(100)>>>m=x.mean()>>>mom=np.array([((x-m)**i).mean()foriinrange(4)])>>>c=cmomy.CentralMoments.from_vals(x,mom=3)>>>np.testing.assert_allclose(c.cmom(),mom,atol=1e-8)>>>c.cmom()array([ 1.    ,  0.    ,  0.0919, -0.0061])# break up into chunks>>>c=cmomy.CentralMoments.from_vals(x.reshape(-1,2),mom=3)>>>c<CentralMoments(val_shape=(2,), mom=(3,))>array([[ 5.0000e+01,  5.3019e-01,  8.0115e-02, -4.3748e-03],[ 5.0000e+01,  5.6639e-01,  1.0297e-01, -8.9911e-03]])# Reduce along an axis>>>c.reduce(axis=0).cmom()array([ 1.    ,  0.    ,  0.0919, -0.0061])# unequal chunks>>>x0,x1,x2=x[:20],x[20:60],x[60:]>>>cs=[cmomy.CentralMoments.from_vals(_,mom=3)for_in(x0,x1,x2)]>>>c=cs[0]+cs[1]+cs[2]>>>np.testing.assert_allclose(c.cmom(),mom,atol=1e-8)>>>c.cmom()array([ 1.    ,  0.    ,  0.0919, -0.0061])Note on cachingThis code makes extensive use of the numba python package. This uses a jit
compiler to speed up vital code sections. This means that the first time a
function called, it has to compile the underlying code. However, caching has
been implemented. Therefore, the very first time you run a function, it may be
slow. But all subsequent uses (including other sessions) will be already
compiled.DocumentationSee thedocumentationfor a look atcmomyin action.LicenseThis is free software. SeeLICENSE.Related workThis package is used extensively in the newest version ofthermoextrap. Seehere.ContactThe author can be reached atwpk@nist.gov.CreditsThis package was created usingCookiecutterwith theusnistgov/cookiecutter-nist-pythontemplate.ChangelogChangelog forcmomyUnreleasedSee the fragment files inchangelog.dv0.8.0 — 2024-02-20AddedAddedto_valuesmethod to access underlying array data. This should be
preferred to.valuesattribute.Addedto_numpymethod to access underlyingnumpy.ndarray.Addedto_dataarraymethod to access underlyingxarray.DataArrayinxCentralMoment sAdded submodulecmomy.randomto handle random numbers generation. This usesnumpy.random.Generatorbehind the scenes.Updatedrufflintering rulesNow usinghatchlingfor package buildingUpdate repo templateChangedNow CentralMoments and xCentralMoments ensure that data/data_flat share
memory. This may result in passed data not being the same as the internal
data, if reshaping data creates a copy.Made little used arguments keyword onlyv0.7.0 — 2023-08-11AddedNow uselazy_loaderto
speed up initial load time.Now usingmodule_utilities >=0.6.Changed fromcustom-inherittodocstring-inheritanceNow fully supports typing (passing mypy --stict and pyright)Relocated numba functions to submodulecmomy._lib.ChangedMoved tests to top level of repo (src/cmomy/teststotests)v0.5.0 — 2023-06-14AddedPackage now available on conda-forgeBumped maximum python version to 3.11v0.4.1...v0.5.0ChangedTesting now handled with nox.v0.4.0 — 2023-05-02AddedMoved module_docstrings_todocstrings. This can be used by other
modules.ChangedUpdate package layoutNew linters via pre-commitDevelopment env now handled by toxNow usemodule-utilitiesto handle caching and docfiller.v0.3.0...v0.4.0v0.3.0 - 2023-04-24Full set of changes:v0.2.2...v0.3.0v0.2.2 - 2023-04-05Full set of changes:v0.2.1...v0.2.2v0.2.1 - 2023-04-05Full set of changes:v0.2.0...v0.2.1v0.2.0 - 2023-03-22Full set of changes:v0.1.9...v0.2.0v0.1.9 - 2023-02-15Full set of changes:v0.1.8...v0.1.9v0.1.8 - 2022-12-02Full set of changes:v0.1.7...v0.1.8v0.1.7 - 2022-09-28Full set of changes:v0.1.6...v0.1.7v0.1.6 - 2022-09-27Full set of changes:v0.1.5...v0.1.6v0.1.5 - 2022-09-26Full set of changes:v0.1.4...v0.1.5v0.1.4 - 2022-09-15Full set of changes:v0.1.3...v0.1.4v0.1.3 - 2022-09-15Full set of changes:v0.1.2...v0.1.3v0.1.2 - 2022-09-13Full set of changes:v0.1.1...v0.1.2v0.1.1 - 2022-09-13Full set of changes:v0.1.0...v0.1.1v0.1.0 - 2022-09-13Full set of changes:v0.0.7...v0.1.0v0.0.7 - 2021-05-18Full set of changes:v0.0.6...v0.0.7v0.0.6 - 2021-02-03Full set of changes:v0.0.4...v0.0.6v0.0.4 - 2020-12-21Full set of changes:v0.0.3...v0.0.4This software was developed by employees of the National Institute of Standards
and Technology (NIST), an agency of the Federal Government. Pursuant to title 17
United States Code Section 105, works of NIST employees are not subject to
copyright protection in the United States and are considered to be in the public
domain. Permission to freely use, copy, modify, and distribute this software and
its documentation without fee is hereby granted, provided that this notice and
disclaimer of warranty appears in all copies.THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR
IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.Distributions of NIST software should also include copyright and licensing
statements of any third-party software that are legally bundled with the code in
compliance with the conditions of those licenses.