This release is a pre-release and may not be stable for production use.
Betterfit
Installation
pip install betterfit
Getting Started
Refer to getting_started.py:
# getting_started.py
import matplotlib.pyplot as plt
import sympy as smp
from uncertainties import ufloat
from betterfit import Dataset, LinearFit
# create immutable datasets
resistance_data = Dataset.fromiter(symbol='R',
values=[2000, 1800, 1600, 1400, 1200, 1000, 900],
errors=10)
length_data = Dataset.fromiter(symbol=smp.Symbol('l'),
values=[160, 172, 192, 223, 254, 298, 327],
errors=[1.5, 2.4, 2, 2.3, 2.1, 3, 5])
length_data = length_data.multiply(1e-3)
# define quantities as sympy symbols
R, l, d = smp.symbols('R l d')
# define an expression depending on these symbols
phi = smp.atan(l / d)
# perform linear fit
linearfit = LinearFit()
linearfit.add_constant(symbol=d,
value=ufloat(0.535, 0.01))
linearfit.add_datasets(resistance_data, length_data)
slope, yintercept = linearfit.fit(x_expr=1 / phi,
y_expr=R)
# linearfit.fit return sympy symbols representing the slope and yintercept
# the values can be accessed through linearfit[slope] and linearfit[yintercept]
print(f'slope: {linearfit[slope]:.3g}')
print(f'yintercept: {linearfit[yintercept]:.3g}')
# similarily, values of expressions can be accessed through linearfit[expr]
print(f'phi: {linearfit[phi]}')
# plot setup
fig, ax = plt.subplots()
ax.set_title('Example Linear Fit with Weighted Least Squares')
ax.set_xlabel(r'$\frac{1}{\phi}$ [$s$]')
ax.set_ylabel(r'$R$ [$\Omega$]')
# plot fit
linearfit.plot_on(ax,
x=1 / phi,
y=R,
fmt='o',
label='data')
linearfit.plot_fit_on(ax)
ax.legend()
plt.show()
Metadata
Release files for betterfit 0.0.2a3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| betterfit-0.0.2a3.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| betterfit-0.0.2a3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / betterfit-0.0.2a3.tar.gz
| Download URL | betterfit-0.0.2a3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46adc75ba94aeac0fe5dd34ec9b1d713e81dd49e1bffaee93efbddd62a99c888
|
|
BLAKE2b-256 checksum How to use checksums |
a82ff382daca2d37e86c78672cc66310c1dfaa29752a9dd36a3914d461ac0b71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2024.
Transparency logRelease files / betterfit-0.0.2a3-py3-none-any.whl
| Download URL | betterfit-0.0.2a3-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd42d7ec10f039811f8c0552004097836917b516af4e0087b2571a89c3bfd6ae
|
|
BLAKE2b-256 checksum How to use checksums |
8b5e7eba40013ae729f464efc3fdc7096a7b8c8d400bffefe7e772a415b23366
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 27, 2024.
Transparency log