Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

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.
    Output: r (sample correlation coefficient)

  • mean(x)
    Computes the mean of a data set.
    Output: mean (data set mean)

  • var(x, sample=True)
    Computes the sample variance of a data set.
    Output: var (data set variance)

  • sdev(x, sample=True)
    Computes the sample standard deviation of a data set.
    Output: sdev (data set standard deviation)

  • post_var(f, parameters, x, y)
    Computes the posterior variance of a data set.
    Output: pv (data set posterior variance)

  • cov(x, y, sample=True)
    Computes the sample covariance of a data set.
    Output: cov (data set covariance)


StatisticalTests

Class for applying common statistical tests.

  • chi_sqrd(f, parameters, x, y, erry)
    Compute chi-squared.
    Output: chi2 (chi-squared value), df (degrees of freedom)

  • reduced_chi_sqrd(f, parameters, x, y, erry)
    Compute reduced chi-squared.
    Output: reduced_chi2 (reduced chi-squared value), df (degrees of freedom)

  • post_error(f, parameters, x, y)
    Compute posterior error.
    Output: pe (posterior error), df (degrees of freedom)

  • r_t_student(x, y)
    Compute Student’s t-value for correlation.
    Output: t (t-value), df (degrees of freedom)

  • t_student(x, mu)
    Compute Student’s t-value for a sample mean.
    Output: t (t-value), df (degrees of freedom)

  • alternative_f_test(f_0, f_a, v_0, v_a, x, y)
    Perform F-test to compare two models.
    Output: f_test (F-test value), df1, df2 (degrees of freedom)

  • t_student_comp(x, y)
    Student’s t-test for two samples with different variances.
    Output: t (t-value), df (degrees of freedom)


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
stat_vars = StatisticalVariables()
r = stat_vars.r(x, y)
print("r =", r)

# Reduced chi-squared
tests = StatisticalTests()
y_fit = a + b*x
rchi2, df = tests.reduced_chi_sqrd(lambda x: a + b*x, parameters=2, x=x, y=y, erry=erry)
print("Reduced χ² =", rchi2, " with degrees of freedom =", df)

Author

Andrea Codarin

Metadata

Release files for physicslab-coda 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for physicslab-coda 0.2.1
File Size Uploaded Provenance
physicslab_coda-0.2.1.tar.gz 3.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for physicslab-coda 0.2.1
File Interpreter ABI Platform
physicslab_coda-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / physicslab_coda-0.2.1.tar.gz

Download URL physicslab_coda-0.2.1.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
443f8cc05d075fbde0fe10aafd46c8a2ac527da83d41daf133c25141641d7af4
BLAKE2b-256 checksum
How to use checksums
6a3279b9644a54f54832480870bb6f23bd3642a17ec15988585241b426eda3dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / physicslab_coda-0.2.1-py3-none-any.whl

Download URL physicslab_coda-0.2.1-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
660d4164c8636f0d3356f9b420b585192413bc0e0d7e3dc613805ce2eb60eb15
BLAKE2b-256 checksum
How to use checksums
08f0d73130c7fda445dbd2fc1af9147079db773e9319eea162e099b92309820d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for physicslab-coda 0.2.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page