ieeLabTools 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: ieeLabTools
3
+ Version: 0.1.0
4
+ Summary: General symbolic + numeric uncertainty propagation, weighted linear regression
5
+ Project-URL: Homepage, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools
6
+ Project-URL: Documentation, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/README.md
7
+ Project-URL: Source, https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/ieeLabTools/core.py
8
+ Author-email: Ilari Pirkkalainen <iladevv0@gmail.com>
9
+ License: MIT
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Requires-Python: >=3.9
16
+ Requires-Dist: numpy
17
+ Requires-Dist: sympy
18
+ Description-Content-Type: text/markdown
19
+
20
+ # ieeLabTools
21
+
22
+ Tools for **laboratory data analysis**, including:
23
+
24
+ - **General symbolic & numeric uncertainty propagation**
25
+ - **Weighted linear regression** (uncertainties in `y`)
26
+ - Designed for physics, engineering, and other quantitative lab work
27
+
28
+ This library is part of the **PhySiLight-Tools** ecosystem.
29
+
30
+ ---
31
+
32
+ ## ✨ Features
33
+
34
+ | Feature | Description |
35
+ |--------|-------------|
36
+ | `Yvel` | Propagate measurement uncertainties using partial derivatives |
37
+ | Symbolic mode | Generates algebraic uncertainty expressions via SymPy |
38
+ | Numeric mode | Evaluates uncertainty for data arrays of any length |
39
+ | LaTeX output(WIP) | Pretty-print formulas for lab reports |
40
+ | WeightedLinearRegression | Weighted least-squares fit (supports `y`-errors) |
41
+ | ODR support | *Not implemented yet* (planned) |
42
+
43
+ ---
44
+
45
+ ## 📦 Installation
46
+
47
+ ```bash
48
+ pip install ieeLabTools
49
+ ```
50
+
51
+ Part of the PhySiLight-Tools physics utilities collection.
@@ -0,0 +1,32 @@
1
+ # ieeLabTools
2
+
3
+ Tools for **laboratory data analysis**, including:
4
+
5
+ - **General symbolic & numeric uncertainty propagation**
6
+ - **Weighted linear regression** (uncertainties in `y`)
7
+ - Designed for physics, engineering, and other quantitative lab work
8
+
9
+ This library is part of the **PhySiLight-Tools** ecosystem.
10
+
11
+ ---
12
+
13
+ ## ✨ Features
14
+
15
+ | Feature | Description |
16
+ |--------|-------------|
17
+ | `Yvel` | Propagate measurement uncertainties using partial derivatives |
18
+ | Symbolic mode | Generates algebraic uncertainty expressions via SymPy |
19
+ | Numeric mode | Evaluates uncertainty for data arrays of any length |
20
+ | LaTeX output(WIP) | Pretty-print formulas for lab reports |
21
+ | WeightedLinearRegression | Weighted least-squares fit (supports `y`-errors) |
22
+ | ODR support | *Not implemented yet* (planned) |
23
+
24
+ ---
25
+
26
+ ## 📦 Installation
27
+
28
+ ```bash
29
+ pip install ieeLabTools
30
+ ```
31
+
32
+ Part of the PhySiLight-Tools physics utilities collection.
@@ -0,0 +1,3 @@
1
+ from .core import Yvel, WeightedLinearRegression
2
+
3
+ __all__ = ["Yvel", "WeightedLinearRegression"]
@@ -0,0 +1,159 @@
1
+ import sympy as sp
2
+ import numpy as np
3
+
4
+ class Yvel():
5
+
6
+ def __init__(self,f,vars=None):
7
+ """
8
+
9
+
10
+ Parameters
11
+ ----------
12
+ f : Sympy expression representing the function
13
+ vars : list/tuple of Sympy symbols (optional) The default is None.
14
+
15
+ Returns
16
+ -------
17
+ None.
18
+
19
+ """
20
+
21
+ self.f = f
22
+
23
+ if vars is not None:
24
+ self.vars = vars
25
+ else:
26
+ self.vars = list(f.free_symbols)
27
+
28
+ self.partials = []
29
+ for v in self.vars:
30
+ self.partials.append(sp.diff(self.f,v))
31
+
32
+
33
+ self.sigmas = []
34
+ for v in self.vars:
35
+ sigma = sp.Symbol(f"sigma_{v.name}")
36
+ self.sigmas.append(sigma)
37
+
38
+ self.symbolic_f = sp.sqrt(
39
+ sum((partial*var)**2 for partial, var in zip(self.partials,self.sigmas))
40
+ )
41
+
42
+ self.fn = sp.lambdify([*self.vars, *self.sigmas], self.symbolic_f, "numpy")
43
+ self.k = len(self.vars)
44
+
45
+ def symbolic(self):
46
+ """Return symbolic uncertainty expression."""
47
+ return self.symbolic_f
48
+
49
+ def numeric(self,values,sigmas):
50
+ """
51
+ Returns the numerical uncertainties of a measurement series, using the non-covariant general error propagation equation. \n
52
+ Expects
53
+
54
+ values: 2D array-like (m x k)
55
+ sigmas: 2D array-like (m x k)
56
+ where k is your number of variables and m is the length of measurement data
57
+
58
+ Returns: numpy array length m
59
+ """
60
+ values = np.array(values, dtype=float)
61
+ sigmas = np.array(sigmas, dtype=float)
62
+
63
+ if values.shape != sigmas.shape:
64
+ raise ValueError("Measurement and uncertainty matrices must have same shape.")
65
+ m, k = values.shape
66
+ if k != self.k:
67
+ raise ValueError(f"Expected {self.k} variables, got {k} columns.")
68
+
69
+ vt = values.T
70
+ st = sigmas.T
71
+
72
+ # build argument list
73
+ args = [vt[i] for i in range(k)] + [st[i] for i in range(k)]
74
+
75
+ return self.fn(*args)
76
+
77
+ def covariant_numeric(self,values,sigmas):
78
+ return NotImplementedError
79
+
80
+ class weightedLinregress():
81
+ def __init__(self, y_sigma,x,y):
82
+ """
83
+ Parameters
84
+ ----------
85
+ y_sigma : 1D array-like of y -axis errors/deviations
86
+ x : 1D array-like of measurements for x
87
+ y: 1D array-like of measurements for y
88
+
89
+ Returns
90
+ -------
91
+ None.
92
+
93
+ ---
94
+ Initializes the class.
95
+
96
+ """
97
+ self.x = np.array(x, float)
98
+ self.y = np.array(y, float)
99
+ self.y_err = np.array(y_sigma, float)
100
+
101
+ def fit(self):
102
+
103
+ """
104
+ Method finds the characteristics of the fitted line, with weighting from errors.
105
+
106
+ Expects: None
107
+
108
+ Returns:
109
+
110
+ slope: the fitted slope
111
+ intercept: the fitted intercept
112
+ slope_err: uncertainty in the slope
113
+ intercept_err: uncertainty in the interception
114
+ """
115
+
116
+ w = 1 / self.y_err**2
117
+ W = np.sum(w)
118
+ Wx = np.sum(w * self.x)
119
+ Wy = np.sum(w * self.y)
120
+ Wxx = np.sum(w * self.x * self.x)
121
+ Wxy = np.sum(w * self.x * self.y)
122
+
123
+
124
+
125
+ D = W * Wxx - Wx**2
126
+
127
+
128
+ slope = (W * Wxy - Wx * Wy) / D
129
+ intercept = (Wxx * Wy - Wx * Wxy) / D
130
+
131
+ slope_err = np.sqrt(W / D)
132
+ intercept_err = np.sqrt(Wxx / D)
133
+
134
+ return slope, intercept, slope_err, intercept_err
135
+
136
+ class ortDistanceRegress():
137
+ def __init__(self,x,y,x_sigma,y_sigma):
138
+
139
+ """
140
+ Parameters
141
+ ----------
142
+ y_sigma : 1D array-like of y -axis errors
143
+ x_sigma : 1D array-like of x -axis errors
144
+ x : 1D array-like of measurements for x
145
+ y: 1D array-like of measurements for y
146
+
147
+ Returns
148
+ -------
149
+ None.
150
+
151
+ ---
152
+ Initializes the class.
153
+
154
+ """
155
+ return NotImplementedError
156
+
157
+ def calculate(self):
158
+ return NotImplementedError
159
+
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "ieeLabTools"
3
+ version = "0.1.0"
4
+ description = "General symbolic + numeric uncertainty propagation, weighted linear regression"
5
+ authors = [
6
+ { name = "Ilari Pirkkalainen", email = "iladevv0@gmail.com" }
7
+ ]
8
+ license = { text = "MIT" }
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "sympy",
13
+ "numpy"
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Intended Audience :: Education",
19
+ "Intended Audience :: Science/Research",
20
+ "Topic :: Scientific/Engineering",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools"
25
+ Documentation = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/README.md"
26
+ Source = "https://github.com/ieepirzy/PhySiLight-Tools/tree/main/Packages/ieeLabTools/ieeLabTools/core.py"
27
+
28
+ [build-system]
29
+ requires = ["hatchling"]
30
+ build-backend = "hatchling.build"