Python Package with tools for Undergraduate Physics Laboratory
Project description
LabPartner - A Tool for Undergraduate Physics Students
Struggling with Lab? Me too!
Over the course of my undergraduate studies at the University of Manchester, UK, I had three years of lab. Now, as someone who teaches those labs alongside my PhD, I thought it would be useful to automate some of the more painful parts of lab, so the students can just focus on understanding the physics and assessing their results.
This Python is Package can:
- Propagate Errors for any Function
- Apply
Linear and QuadraticANY fit to a set of Data - Plot Results in the style of Lab Reports
It is important to acknowledge that there are other very useful tools (OriginPro, LSFR, your own code). I just wanted to try making something that works as an all-in-one system, effectively acting as a Lab Partner!
Installation
To install this package, simply type:
pip install labpartner_uom
PyPI might use labpartner-uom, but this command does the same. Someday I hope to remove the '_uom'!
Usage
The code is based on Numpy, Sympy and Matplotlib. Try to have your x, y and y error data as Numpy arrays.
Error Propagation
To propagate errors, simply write up the function and the variables which have uncertainties.
import labpartner_uom as lp
prop = lp.errorpropagator.propagate_error(func, vars)
# Example
prop = lp.errorpropagator.propagate_error("A*x**2 + B*y + C", ["x", "y"])
Data Analysis
There are a few presets which allow you to auto-analyse your results.
import labpartner_uom as lp
lp.analyse(x, y, yerr, fit="Linear")
This should print the results of the fitting, as well save a .png and .pdf of the plot.
Options of fits include: Linear, Quadratic, Gaussian, Exponential, Logarithmic, Sine, Cosine and more! You can also add your own functions to fit (see below for details)
Advanced Options - For those who want more Customisation
Function Fitting
import labpartner_uom as lp
fit = lp.fit.do_fit(lp.fit.do_fit(x, y, func, p0=p0, yerr=yerr)
# Example
my_func = "a * sin(x) + b"
fit = lp.fit.do_fit([1, 2, 3], [4, 5, 6], my_func, p0=[1, 1], yerr=[1, 1, 1])
(OLD) Linear and Quadratic Fit
import labpartner_uom as lp
fit = lp.linfit.do_linear_fit(x, y, yerr)
fit = lp.quadfit.do_quadratic_fit(x, y, yerr)
# Example
fit = lp.linfit.do_linear_fit([1, 2, 3], [4, 5, 6], [0.2, 0.2, 0.3])
fit = lp.quadfit.do_quadratic_fit([1, 2, 3], [4, 5, 6], [0.2, 0.2, 0.3])
Plotting
import labpartner_uom as lp
lp.plotter.plot(x, y, yerr=None, xlabel="x axis", ylabel="y axis", title=None, label="data", fit_type=None, figsize=(4, 3))
# Example
lp.plotter.plot([1, 2, 3], [4, 5, 6], [0.2, 0.2, 0.3])
Siddharth Sule, 2024
Based On Tom Chen's Example Package: https://github.com/tomchen/example_pypi_package
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file labpartner_uom-1.0.1.tar.gz
.
File metadata
- Download URL: labpartner_uom-1.0.1.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63be40fe31faf779b930baa9cba1c87809d98a3933f738eb9ee463ecd551771b |
|
MD5 | 4dd43c150db09ed715bb8e941a90cfff |
|
BLAKE2b-256 | b245230b2f81ceb553eabc66b5996ebe4d6be5f3d452f74c9a0a3e8587a378a9 |
File details
Details for the file labpartner_uom-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: labpartner_uom-1.0.1-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b0541d95d87ce9cca89070bd1b2c75cd0e5a6d3e8bb96041da6c53e96fafdae |
|
MD5 | 0ffd1351e10900026914ef1797faebf2 |
|
BLAKE2b-256 | 02723ddc447901cee12ae129f96cf6e997c1e5645cb64a2e22e9fa07baf930bc |