ieeLabTools 0.1.2__tar.gz → 0.1.4__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.
- ieelabtools-0.1.4/.github/workflows/publish.yml +40 -0
- ieelabtools-0.1.4/.github/workflows/tests.yml +28 -0
- ieelabtools-0.1.4/.gitignore +207 -0
- {ieelabtools-0.1.2 → ieelabtools-0.1.4/Docs}/Documentation.md +200 -172
- ieelabtools-0.1.4/Docs/suomidocs.md +42 -0
- ieelabtools-0.1.4/LICENSE +21 -0
- ieelabtools-0.1.4/PKG-INFO +183 -0
- ieelabtools-0.1.4/README.md +160 -0
- ieelabtools-0.1.4/ieeLabTools/__init__.py +20 -0
- {ieelabtools-0.1.2 → ieelabtools-0.1.4}/ieeLabTools/core.py +170 -155
- ieelabtools-0.1.4/pyproject.toml +36 -0
- ieelabtools-0.1.4/tests/__init__.py +0 -0
- ieelabtools-0.1.4/tests/test_core.py +365 -0
- ieelabtools-0.1.2/PKG-INFO +0 -53
- ieelabtools-0.1.2/README.md +0 -34
- ieelabtools-0.1.2/ieeLabTools/__init__.py +0 -3
- ieelabtools-0.1.2/pyproject.toml +0 -30
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.12"
|
|
16
|
+
|
|
17
|
+
- name: Build package
|
|
18
|
+
run: |
|
|
19
|
+
pip install hatchling
|
|
20
|
+
python -m hatchling build
|
|
21
|
+
|
|
22
|
+
- uses: actions/upload-artifact@v4
|
|
23
|
+
with:
|
|
24
|
+
name: dist
|
|
25
|
+
path: dist/
|
|
26
|
+
|
|
27
|
+
publish:
|
|
28
|
+
needs: build
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
environment: pypi
|
|
31
|
+
permissions:
|
|
32
|
+
id-token: write
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/download-artifact@v4
|
|
35
|
+
with:
|
|
36
|
+
name: dist
|
|
37
|
+
path: dist/
|
|
38
|
+
|
|
39
|
+
- name: Publish to PyPI
|
|
40
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["**"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["**"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install package and test dependencies
|
|
25
|
+
run: pip install -e ".[dev]"
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: pytest tests/ -v --tb=short
|
|
@@ -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__/
|
|
@@ -1,172 +1,200 @@
|
|
|
1
|
-
# Documentation
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
The
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
$$
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
R
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
\
|
|
122
|
-
|
|
123
|
-
\
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
#
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
+
|