This library contains the code usefull in physics lab
Project description
Physicslab-coda
A Python library for data analysis in physics laboratories, including:
- linear interpolation with uncertainties
- statistical variables
- common statistical tests (χ², t-Student, F-test, etc.)
The goal is to provide ready-to-use tools for students and researchers working with experimental data.
Statistics
Interpolation
Class for linear interpolation with experimental uncertainties.
-
linear_function(x, a, b)
Simple linear function. -
erry_var_errx_null(x, y, erry, verbose=False)
Linear interpolation with variable error on Y and negligible error on X. -
linear_interpolation(x, y, errx, erry, threshold=30, tries=10, verbose=False)
Linear interpolation with variable errors on both X and Y.
Automatically chooses the best approximation depending on error magnitudes.
StatisticalVariables
Class for calculating basic statistical variables.
r(x, y)
Computes the sample correlation coefficient.
StatisticalTests
Class for applying common statistical tests.
-
chi2(parameters, y_original, y_calculated, erry)
Compute chi-squared. -
reduced_chi2(parameters, y_original, y_calculated, erry)
Compute reduced chi-squared. -
post_error(parameters, y_original, y_calculated)
Compute posterior error. -
r_t_student(x, y)
Compute Student’s t-value for correlation. -
t_student(mean, stddev, n, mu)
Compute Student’s t-value for a sample. -
f_test(var1, var2, n1, n2)
Perform F-test to compare two variances. -
double_var_t_student(mean1, mean2, var1, var2, n1, n2)
Student’s t-test for two samples with different variances.
Installation
git clone https://github.com/yourusername/physics-lab-data-analysis.git
cd physics-lab-data-analysis
pip install -r requirements.txt
Usage Example
import numpy as np
from physicslab-coda import Interpolation, StatisticalVariables, StatisticalTests
# Example data
x = np.array([1, 2, 3, 4])
y = np.array([2.1, 4.2, 5.9, 8.2])
erry = np.array([0.1, 0.2, 0.1, 0.3])
errx = np.array([0.05, 0.05, 0.05, 0.05])
# Linear interpolation
interp = Interpolation()
a, b, s_a, s_b = interp.linear_interpolation(x, y, errx, erry, verbose=True)
print("a =", a, " b =", b, " σa =", s_a, " σb =", s_b)
# Correlation coefficient
r = StatisticalVariables.r(x, y)
print("r =", r)
# Reduced chi-squared
tests = StatisticalTests()
y_fit = a + b*x
rchi2, df = tests.reduced_chi2(parameters=2, y_original=y, y_calculated=y_fit, erry=erry)
print("Reduced χ² =", rchi2, " with degrees of freedom =", df)
Author
Andrea Codarin
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file physicslab_coda-0.2.0.tar.gz.
File metadata
- Download URL: physicslab_coda-0.2.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95052fd88d84cfbf846a6ad06951caaeb951a5852cb54c3dbd07447b17cc311f
|
|
| MD5 |
165a5633bc00bef559da96b6aa70c52d
|
|
| BLAKE2b-256 |
54a0e09e59a328d101f1a67d7b16a1f69fe39ebd23776f47ac261c404eed54b0
|
File details
Details for the file physicslab_coda-0.2.0-py3-none-any.whl.
File metadata
- Download URL: physicslab_coda-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
501c05b1a6d2f71e1e617ae7b8b4de1ad46c9262c51c0e4c2e0392684bb2e707
|
|
| MD5 |
9b9141e87dc597b3524ef7d52de58c53
|
|
| BLAKE2b-256 |
b7d06ec1f5e33f7eda63a8a4dad12e37d929cbdda96482b8ec1a3db3874a6802
|