ieeLabTools 0.1.1__tar.gz → 0.1.3__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,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
@@ -0,0 +1,200 @@
1
+ # Documentation
2
+
3
+ <a href="https://github.com/ieepirzy/PhySiLight-Tools/blob/main/Packages/ieeLabTools/suomidocs.md"> Dokumentaation pikaohjeet suomeksi </a>
4
+
5
+ ## Quickstart / TL;DR
6
+
7
+ ```python
8
+ from ieeLabTools.core import Yvel
9
+ import sympy as sp
10
+ import numpy as np
11
+
12
+ #Example variables and function
13
+ U, I = sp.symbols("U I")
14
+ R = U/I
15
+ calc = Yvel(R,vars=[U,I])
16
+
17
+ U_vals = np.array([1,2,3,4,5,6])
18
+ I_vals = np.array([6,5,4,3,2,1])
19
+ U_err = U_vals*0.001
20
+ I_err = I_vals*0.05
21
+ #Convert to desirable input format: m x k array-like, where k is your number of variables and m is your number of measurement events.
22
+ values = np.column_stack([U_vals, I_vals])
23
+ sigmas = np.column_stack([U_err, I_err])
24
+
25
+ sigma_R = calc.numeric(values, sigmas)
26
+ ```
27
+
28
+ >⚠ Important ⚠:
29
+ >The order of columns in `values` and `sigmas` must match the order of variables in `vars`.
30
+ >If `vars` is omitted, variables are ordered lexicographically by symbol name.
31
+
32
+ > ⚠ The current version uses the **non-covariant** general error propagation formula. Covariance-aware propagation is planned for a future release.
33
+
34
+ ## 1. YVEL: Yleinen virheen etenemisen lauseke
35
+ > YVEL = General error propagation equation in finnish.
36
+
37
+ The class Yvel implements the general error propagation equation in non-covariant form, and exposes 2 methods for working with it.
38
+
39
+ The mathematical expression for the YVEL in non-covariant from is:
40
+
41
+ $$
42
+ \sigma = \sqrt{ \sum_{i} \left( \frac{\partial f}{\partial x_{i}} \right) ^{2}\sigma_{i}^{2} }
43
+ $$
44
+
45
+ The **initializer expects a sympy object representing the function** referred to from now on as `f`.
46
+ An optional parameter for the initializer is a 1D array-like of the **variables as Sympy symbols** referred to as `var`.
47
+
48
+ For note, the covariant expression for the YVEL is:
49
+
50
+ $$
51
+ \sigma = \sqrt{ \sum_{i} \left( \frac{\partial f}{\partial x_{i}} \right) ^{2}\sigma_{i}^{2} +2 \sum_{i>j} \frac{\partial f}{\partial x_{i}} \frac{\partial f}{\partial x_{j}} \text{cov}(x_{i},x_{j}) }
52
+ $$
53
+
54
+ > Note: Adding a method to take covariance into account is planned for a future release.
55
+
56
+ ## Working principle:
57
+ After instantiation, the class immediately either assigns the given `var` or automatically detects variables from `f` using the `free_symbols()` method.
58
+
59
+ Then the class calculates the partial derivatives for each variable by looping over all entries in `var` and calling `sp.diff`.
60
+
61
+ Then a symbolic representation of the general error propagation equation is built as a Sympy object.
62
+ #### Example.
63
+
64
+ For a simplistic example, consider Ohm's law:
65
+
66
+ $$
67
+ R=\frac{U}{I}
68
+ $$
69
+
70
+ To find the deviation for $R$ using the ieeLabTools package, we will first build an instance of the Yvel class:
71
+ >Note: for correct usage, some degree of familiarity with numpy and sympy is required.
72
+
73
+ ```python
74
+ from ieeLabTools.core import Yvel
75
+ import sympy as sp
76
+
77
+ U , I = sp.symbols("U I") #Assign your symbols
78
+
79
+ R = U/I #Create the expression
80
+
81
+ instance = Yvel(R) #After this line the class has been instantiated.
82
+ ```
83
+
84
+ The Yvel class currently provides 2 methods for working with the error propagation function. The first of these is the simpler one: `symbolic()`
85
+
86
+ The `symbolic()` method simply returns the symbolic expression of the general error propagation equation for the `f` used to initialize it. As referenced earlier, this computation is implemented using `sympy`, for further details, consult the `sympy` documentation for `symbol(), diff(), lambdify() and free_symbols()` methods.
87
+
88
+ Example usage of the `symbolic()` method:
89
+ ```python
90
+ #continuing from earlier...
91
+
92
+ symbolic_expression = instance.symbolic()
93
+ #For the example function, you should see:
94
+ print(symbolic_expression)
95
+ #return this:
96
+ #sqrt(sigma_U**2/I**2 + U**2*sigma_I**2/I**4)
97
+ ```
98
+
99
+ The 2nd method exposed by the class is the `numeric()` method. This is the arguably more useful method, as it allows you to calculate the actual deviation numerically.
100
+
101
+ ### Working principle for `numeric()`
102
+
103
+ The `numeric()` method is intended to massively ease the computation of errors for functions with many variables each contributing values (and possibly errors), making the partial derivatives tedious to solve by hand.
104
+
105
+ To achieve this, I design the method with 2 principles in mind:
106
+
107
+ 1. Handle an arbitrary amount of variables and their errors, with 2 parameters.
108
+ 2. Do so in a clean, performant manner
109
+
110
+ The `numeric()` method expects the variables and arrays to be passed in a matrix (array-like) format, where for any number of variables $k$ and a measurement series of length $m$ for each variable, constituting an $m \times k$ 2D array-like.
111
+
112
+ A mathematical representation:
113
+
114
+ $$
115
+ \text{values}: m \times k \implies \begin{bmatrix}
116
+ x_{0} & x_{1} & x_{2} & x_{3} & \dots & x_{k} \\
117
+ val_{0} & val_{0} & val_{0} & val_{0} & \dots & val_{0} \\
118
+ val_{1} & val_{1} & val_{1} & val_{1} & \dots & val_{1} \\
119
+ val_{2} & val_{2} & val_{2} & val_{2} & \dots & val_{2} \\
120
+ val_{3} & val_{3} & val_{3} & val_{3} & \dots & val_{3} \\
121
+ \vdots & \vdots & \vdots & \vdots & \dots & \vdots \\
122
+ val_{m} & val_{m} & val_{m} & val_{m} & \dots & val_{m}
123
+ \end{bmatrix}
124
+ $$
125
+
126
+ $$
127
+ \text{deviations}: m \times k \implies \begin{bmatrix}
128
+ x_{0} & x_{1} & x_{2} & x_{3} & \dots & x_{k} \\
129
+ \sigma_{0} & \sigma_{0} & \sigma_{0} & \sigma_{0} & \dots & \sigma_{0} \\
130
+ \sigma_{1} & \sigma_{1} & \sigma_{1} & \sigma_{1} & \dots & \sigma_{1} \\
131
+ \sigma_{2} & \sigma_{2} & \sigma_{2} & \sigma_{2} & \dots & \sigma_{2} \\
132
+ \sigma_{3} & \sigma_{3} & \sigma_{3} & \sigma_{3} & \dots & \sigma_{3} \\
133
+ \vdots & \vdots & \vdots & \vdots & \dots & \vdots \\
134
+ \sigma_{m} & \sigma_{m} & \sigma_{m} & \sigma_{m} & \dots & \sigma_{m}
135
+ \end{bmatrix}
136
+ $$
137
+
138
+
139
+ > Note: The measurement series for all variables must be the same size
140
+ > Assumption: measurement events for all variables are equal
141
+
142
+ > Note: The series of deviations must be equal in length with its corresponding series of measurements, and each measurement series must have a corresponding deviation series.
143
+
144
+ > Note: For possible variables with 0 deviation, pass an array with all values being 0.
145
+
146
+ Internally, the method uses numpy for vectorized processing and does shape validation.
147
+
148
+ Example usage for `numeric()` continuing with the same instance of the class as in the quickstart:
149
+ ```python
150
+ #lets assume the variables from earlier have some values and deviations:
151
+ import numpy as np
152
+
153
+ #Real measurement data from a lab-course:
154
+ U_values = np.array([
155
+ 0.131, 0.165, 0.204, 0.268, 0.361, 0.505,
156
+ 0.692, 0.958, 1.370, 1.997, 2.944, 4.33, 6.74])
157
+
158
+ I_values = np.array([10/1000]*13) #mA -> A
159
+
160
+ U_errors = np.array([0.000656, 0.000826, 0.001021, 0.001341, 0.001806, 0.002526, 0.003461, 0.004791, 0.006851, 0.009986, 0.014721, 0.021651, 0.033701])
161
+
162
+ I_errors = np.zeros([13]) #good example of 0 deviations handling
163
+
164
+ # Now in order to call the method, we must remember its required parameters and construct them out of our existing arrays.
165
+ values = np.column_stack([U_values, I_values])
166
+ sigmas = np.column_stack([U_errors, I_errors])
167
+ # This constructs a 13x2 matrix for both values and sigmas, in alignment with what the method parameters expect.
168
+
169
+
170
+ # Now to find the deviations for each value we call:
171
+ deviation = instance.numeric(values,sigmas)
172
+
173
+ #with the example data you should expect something like:
174
+ print(deviation)
175
+ # "[3.82262106e-04, 3.03397612e-04, 2.45338331e-04, 1.86706393e-04,
176
+ # 5.22029629e-05, 3.65016783e-05, 2.50400639e-05, 1.69848494e-05, 1.15478775e-05,
177
+ # 7.41861776e-06,]
178
+
179
+ ```
180
+
181
+ Note: The known bug causing indeterministic ordering in Sympy's `free_symbols` method means that it is usually preferred to pass the variables explicitly, as how the script enforces deterministic ordering is by sorting the variables found by free_symbols lexographically, and as the user passes data to the `numeric()` method, must the ordering of the arrays corresponding to each measurement be in lexicographical order (the same order as the variables).
182
+
183
+ > Note: The bug arrises from the way the set() function, used in the `free_symbols` method interacts with pythons HASHSEED.
184
+ > HASHSEED being randomized for DoS-attack prevention. It is then assumed that if order matters, it is specified, hence a strong recommendation to pass the `vars` as a parameter directly.
185
+
186
+ Example of indeterministic behaviour:
187
+
188
+ ```python
189
+
190
+ # DON'T DO THIS - order may vary between runs:
191
+ calc = Yvel(R) # vars detected as [I, U] or [U, I] unpredictably
192
+ values = np.column_stack([U_vals, I_vals]) # assumes [U, I]
193
+ # ❌ Mismatch possible!
194
+
195
+ # DO THIS - explicit and deterministic:
196
+ calc = Yvel(R, vars=[U, I]) # ✅ Order guaranteed
197
+ values = np.column_stack([U_vals, I_vals])
198
+
199
+ ```
200
+
@@ -0,0 +1,42 @@
1
+ # Dokumentaatio
2
+
3
+ Saat moduulin käyttöösi suorittamalla komennon:
4
+
5
+ ```CLI
6
+ pip install ieeLabTools
7
+ ```
8
+
9
+ <a href="https://pypi.org/project/ieeLabTools/">Moduuli on julkaistu PyPi alustalle</a>
10
+
11
+ ## Pikaesimerkki:
12
+ ```python
13
+ from ieeLabTools.core import Yvel
14
+ import sympy as sp
15
+ import numpy as np
16
+
17
+ #Luodaan esimerkkimuuttujat, näiden täytyy olla sympy-symboleja
18
+ U, I = sp.symbols("U I")
19
+ R = U/I #Rakennetaan symboleista/muututjista esimerkkifunktio
20
+ calc = Yvel(R) # Tässä luodaan Yvel-objekti yllä määritetyllä funktiolla.
21
+ #TS. Jotta voit käyttää Yvel:iä niin anna sille aina aluksi näin funktio
22
+
23
+ #Esimerkki arvot ja virheet.
24
+ U_arvot = np.array([1,2,3,4,5,6])
25
+ I_arvot = np.array([6,5,4,3,2,1])
26
+ U_err = U_arvot*0.001
27
+ I_err = I_arvot*0.05
28
+
29
+ #Muutetaan np.column_stack() metodilla arvot ja virheet muotoon, jota numeerinen laskuri odottaa.
30
+ arvot = np.column_stack([U_arvot, I_arvot])
31
+ virheet = np.column_stack([U_err, I_err])
32
+
33
+ # numeric() metodi odottaa parametreikseen m x k matriisin, jossa m on mittaussarjan pituus ja k muuttujien määrä.
34
+ sigma = calc.numeric(arvot, virheet) #Tällä tavalla kutsutaan numeric() metodia.
35
+ ```
36
+
37
+ >Huom! Kaikilla muuttujilla ja virheillä tulee olla sama muoto. Eli mittaussarjoilla sama pituus.
38
+
39
+ >Huom! Jos jollakin muuttujalla ei ole virhettä, niin käytä sen virhesarjana 0-sarjaa.
40
+
41
+ Metodi toimii vain **toisistaan riippumattomille** muuttujille.
42
+ Kattavampi dokumentaatio ja läpikäyminen löytyy englanninkielisestä veriosta.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ilari Pirkkalainen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,12 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ieeLabTools
3
- Version: 0.1.1
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
3
+ Version: 0.1.3
4
+ Summary: General linear symbolic + numeric uncertainty propagation, weighted linear regression
5
+ Project-URL: Homepage, https://github.com/ieepirzy/ieeLabTools
6
+ Project-URL: Documentation, https://github.com/ieepirzy/ieeLabTools/blob/main/Docs/Documentation.md
7
+ Project-URL: Source, https://github.com/ieepirzy/ieeLabTools/blob/main/Source/core.py
8
8
  Author-email: Ilari Pirkkalainen <iladevv0@gmail.com>
9
9
  License: MIT
10
+ License-File: LICENSE
10
11
  Classifier: Intended Audience :: Education
11
12
  Classifier: Intended Audience :: Science/Research
12
13
  Classifier: License :: OSI Approved :: MIT License
@@ -48,4 +49,6 @@ This library is part of the **PhySiLight-Tools** ecosystem.
48
49
  pip install ieeLabTools
49
50
  ```
50
51
 
52
+ >🧪 This package was originally developed to automate general uncertainty propagation for physics lab courses, reducing >manual symbolic differentiation and repetitive numeric error calculation.
53
+
51
54
  Part of the PhySiLight-Tools physics utilities collection.
@@ -29,4 +29,6 @@ This library is part of the **PhySiLight-Tools** ecosystem.
29
29
  pip install ieeLabTools
30
30
  ```
31
31
 
32
+ >🧪 This package was originally developed to automate general uncertainty propagation for physics lab courses, reducing >manual symbolic differentiation and repetitive numeric error calculation.
33
+
32
34
  Part of the PhySiLight-Tools physics utilities collection.
@@ -0,0 +1,20 @@
1
+ """
2
+ ieeLabTools
3
+ ===========
4
+
5
+ Tools for symbolic and numeric uncertainty propagation
6
+ and weighted linear regression for laboratory data analysis.
7
+ """
8
+
9
+
10
+ from .core import (
11
+ Yvel,
12
+ WeightedLinregress,
13
+ )
14
+
15
+ __all__ = [
16
+ "Yvel",
17
+ "WeightedLinearRegression",
18
+ ]
19
+
20
+ __version__ = "0.1.2"
@@ -20,26 +20,34 @@ class Yvel():
20
20
 
21
21
  self.f = f
22
22
 
23
+ # Assign from user declared variables or find variables automatically
23
24
  if vars is not None:
24
25
  self.vars = vars
25
26
  else:
26
- self.vars = list(f.free_symbols)
27
-
27
+ self.vars = sorted(f.free_symbols, key=lambda s: s.name)
28
+
29
+ #print(f"variables:{self.vars}") #debug print
30
+
31
+ # Find partials with sp.diff, looping over the function with each variable
28
32
  self.partials = []
29
33
  for v in self.vars:
30
34
  self.partials.append(sp.diff(self.f,v))
31
35
 
32
-
36
+ #Creating sigmas for all variables
33
37
  self.sigmas = []
34
38
  for v in self.vars:
35
- sigma = sp.Symbol(f"sigma_{v.name}")
39
+ sigma = sp.Symbol(f"σ{v.name}")
36
40
  self.sigmas.append(sigma)
37
-
41
+
42
+ # Construct symbolical sympy object
38
43
  self.symbolic_f = sp.sqrt(
39
44
  sum((partial*var)**2 for partial, var in zip(self.partials,self.sigmas))
40
45
  )
41
-
46
+
47
+ # Lambdify object to make it
42
48
  self.fn = sp.lambdify([*self.vars, *self.sigmas], self.symbolic_f, "numpy")
49
+
50
+ # Number of variables for later
43
51
  self.k = len(self.vars)
44
52
 
45
53
  def symbolic(self):
@@ -57,27 +65,34 @@ class Yvel():
57
65
 
58
66
  Returns: numpy array length m
59
67
  """
68
+
69
+ # Assign into numpy arrays from input format
60
70
  values = np.array(values, dtype=float)
61
71
  sigmas = np.array(sigmas, dtype=float)
62
72
 
73
+ # Check correct shape
63
74
  if values.shape != sigmas.shape:
64
75
  raise ValueError("Measurement and uncertainty matrices must have same shape.")
65
76
  m, k = values.shape
66
77
  if k != self.k:
67
78
  raise ValueError(f"Expected {self.k} variables, got {k} columns.")
68
79
 
80
+ # transpose for correct internal representation
69
81
  vt = values.T
70
82
  st = sigmas.T
71
83
 
72
- # build argument list
84
+ # build argument list, pairing value with deviation.
73
85
  args = [vt[i] for i in range(k)] + [st[i] for i in range(k)]
74
-
86
+ #print(f"arguments:{args}") #debug print
87
+ # pass args to lambidified sympy object, representing the function
75
88
  return self.fn(*args)
76
89
 
77
90
  def covariant_numeric(self,values,sigmas):
78
91
  return NotImplementedError
79
92
 
80
- class weightedLinregress():
93
+
94
+ class WeightedLinregress():
95
+ # Rework this to be stateless..
81
96
  def __init__(self, y_sigma,x,y):
82
97
  """
83
98
  Parameters
@@ -120,11 +135,8 @@ class weightedLinregress():
120
135
  Wxx = np.sum(w * self.x * self.x)
121
136
  Wxy = np.sum(w * self.x * self.y)
122
137
 
123
-
124
-
125
138
  D = W * Wxx - Wx**2
126
139
 
127
-
128
140
  slope = (W * Wxy - Wx * Wy) / D
129
141
  intercept = (Wxx * Wy - Wx * Wxy) / D
130
142
 
@@ -133,7 +145,7 @@ class weightedLinregress():
133
145
 
134
146
  return slope, intercept, slope_err, intercept_err
135
147
 
136
- class ortDistanceRegress():
148
+ class OrtDistanceRegress():
137
149
  def __init__(self,x,y,x_sigma,y_sigma):
138
150
 
139
151
  """
@@ -0,0 +1,22 @@
1
+ from Source import Yvel
2
+ import sympy as sp
3
+ import numpy as np
4
+
5
+ #Example variables and function
6
+ U, I = sp.symbols("U I")
7
+ R = U/I
8
+ print(R.free_symbols)
9
+ calc = Yvel(R)
10
+ print(calc)
11
+ print(calc.symbolic())
12
+ U_vals = np.array([1,2,3,4,5,6])
13
+ I_vals = np.array([6,5,4,3,2,1])
14
+ U_err = U_vals*0.001
15
+ I_err = I_vals*0.05
16
+ #Convert to desirable input format: m x k array-like, where k is your number of variables and m is your number of measurement events.
17
+ values = np.column_stack([U_vals, I_vals])
18
+ sigmas = np.column_stack([U_err, I_err])
19
+
20
+ sigma_R = calc.numeric(values, sigmas)
21
+
22
+ print(sigma_R)
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "ieeLabTools"
3
- version = "0.1.1"
4
- description = "General symbolic + numeric uncertainty propagation, weighted linear regression"
3
+ version = "0.1.3"
4
+ description = "General linear symbolic + numeric uncertainty propagation, weighted linear regression"
5
5
  authors = [
6
6
  { name = "Ilari Pirkkalainen", email = "iladevv0@gmail.com" }
7
7
  ]
@@ -21,9 +21,9 @@ classifiers = [
21
21
  ]
22
22
 
23
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"
24
+ Homepage = "https://github.com/ieepirzy/ieeLabTools"
25
+ Documentation = "https://github.com/ieepirzy/ieeLabTools/blob/main/Docs/Documentation.md"
26
+ Source = "https://github.com/ieepirzy/ieeLabTools/blob/main/Source/core.py"
27
27
 
28
28
  [build-system]
29
29
  requires = ["hatchling"]
@@ -1,3 +0,0 @@
1
- from .core import Yvel, weightedLinregress, ortDistanceRegress
2
-
3
- __all__ = ["Yvel", "weightedLinregress","ortDistanceRegress"]