dccQuantities 1.4.6__tar.gz → 2.0.0.dev2__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.
Files changed (58) hide show
  1. {dccquantities-1.4.6 → dccquantities-2.0.0.dev2}/LICENSE +16 -19
  2. dccquantities-2.0.0.dev2/MANIFEST.in +2 -0
  3. dccquantities-2.0.0.dev2/PKG-INFO +106 -0
  4. dccquantities-2.0.0.dev2/README.md +70 -0
  5. dccquantities-2.0.0.dev2/pyproject.toml +52 -0
  6. dccquantities-2.0.0.dev2/setup.cfg +4 -0
  7. dccquantities-2.0.0.dev2/src/AbstractListType.py +27 -0
  8. dccquantities-2.0.0.dev2/src/AbstractQuantityTypeData.py +4 -0
  9. dccquantities-2.0.0.dev2/src/AbstractValueType.py +116 -0
  10. dccquantities-2.0.0.dev2/src/DccCharsXMLList.py +63 -0
  11. dccquantities-2.0.0.dev2/src/DccFormulaType.py +15 -0
  12. dccquantities-2.0.0.dev2/src/DccName.py +127 -0
  13. dccquantities-2.0.0.dev2/src/DccNoQuantity.py +126 -0
  14. dccquantities-2.0.0.dev2/src/DccQuantityTable.py +783 -0
  15. dccquantities-2.0.0.dev2/src/DccQuantityType.py +226 -0
  16. dccquantities-2.0.0.dev2/src/DccRichContentType.py +112 -0
  17. dccquantities-2.0.0.dev2/src/SiComplexList.py +42 -0
  18. dccquantities-2.0.0.dev2/src/SiHybrid.py +66 -0
  19. dccquantities-2.0.0.dev2/src/SiList.py +59 -0
  20. dccquantities-2.0.0.dev2/src/SiRealList.py +856 -0
  21. dccquantities-2.0.0.dev2/src/dccQuantities.egg-info/PKG-INFO +106 -0
  22. dccquantities-2.0.0.dev2/src/dccQuantities.egg-info/SOURCES.txt +44 -0
  23. {dccquantities-1.4.6 → dccquantities-2.0.0.dev2}/src/dccQuantities.egg-info/requires.txt +5 -2
  24. dccquantities-2.0.0.dev2/src/dccQuantities.egg-info/top_level.txt +19 -0
  25. dccquantities-2.0.0.dev2/src/dccQuantityParser.py +163 -0
  26. dccquantities-2.0.0.dev2/src/helpers.py +850 -0
  27. dccquantities-2.0.0.dev2/src/parseUncertainties.py +370 -0
  28. dccquantities-2.0.0.dev2/src/testHelpers.py +34 -0
  29. dccquantities-2.0.0.dev2/tests/test_DccCharsXMLList.py +35 -0
  30. dccquantities-2.0.0.dev2/tests/test_DccNoQuantity.py +17 -0
  31. dccquantities-2.0.0.dev2/tests/test_DccQuantityType.py +12 -0
  32. dccquantities-2.0.0.dev2/tests/test_SiList.py +15 -0
  33. dccquantities-2.0.0.dev2/tests/test_SiRealList.py +588 -0
  34. dccquantities-2.0.0.dev2/tests/test_SiRealList_parseData.py +166 -0
  35. dccquantities-2.0.0.dev2/tests/test_SiRealList_toDict.py +94 -0
  36. dccquantities-2.0.0.dev2/tests/test_dccName.py +61 -0
  37. dccquantities-2.0.0.dev2/tests/test_generateExampleTableData.py +22 -0
  38. dccquantities-2.0.0.dev2/tests/test_getAndProperties.py +56 -0
  39. dccquantities-2.0.0.dev2/tests/test_helpers.py +144 -0
  40. dccquantities-2.0.0.dev2/tests/test_parser.py +219 -0
  41. dccquantities-2.0.0.dev2/tests/test_quantityTypeCollector.py +25 -0
  42. dccquantities-2.0.0.dev2/tests/test_serilizer.py +49 -0
  43. dccquantities-2.0.0.dev2/tests/test_surfaceFlatTableGeneration.py +557 -0
  44. dccquantities-2.0.0.dev2/tests/test_tables.py +364 -0
  45. dccquantities-1.4.6/PKG-INFO +0 -55
  46. dccquantities-1.4.6/README.md +0 -29
  47. dccquantities-1.4.6/pyproject.toml +0 -3
  48. dccquantities-1.4.6/setup.cfg +0 -34
  49. dccquantities-1.4.6/src/dccQuantities.egg-info/PKG-INFO +0 -55
  50. dccquantities-1.4.6/src/dccQuantities.egg-info/SOURCES.txt +0 -15
  51. dccquantities-1.4.6/src/dccQuantities.egg-info/top_level.txt +0 -4
  52. dccquantities-1.4.6/src/dccQuantities.py +0 -1747
  53. dccquantities-1.4.6/src/dccQuantitiesConfiguration.py +0 -48
  54. dccquantities-1.4.6/src/dccQuantitiesPlot.py +0 -280
  55. dccquantities-1.4.6/tests/test_dccQuantsAndTabs.py +0 -322
  56. dccquantities-1.4.6/tests/test_tollerance.py +0 -42
  57. {dccquantities-1.4.6 → dccquantities-2.0.0.dev2}/src/__init__.py +0 -0
  58. {dccquantities-1.4.6 → dccquantities-2.0.0.dev2}/src/dccQuantities.egg-info/dependency_links.txt +0 -0
@@ -2,7 +2,7 @@
2
2
  Version 2.1, February 1999
3
3
 
4
4
  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5
+ <https://fsf.org/>
6
6
  Everyone is permitted to copy and distribute verbatim copies
7
7
  of this license document, but changing it is not allowed.
8
8
 
@@ -55,7 +55,7 @@ modified by someone else and passed on, the recipients should know
55
55
  that what they have is not the original version, so that the original
56
56
  author's reputation will not be affected by problems that might be
57
57
  introduced by others.
58
-
58
+
59
59
  Finally, software patents pose a constant threat to the existence of
60
60
  any free program. We wish to make sure that a company cannot
61
61
  effectively restrict the users of a free program by obtaining a
@@ -111,7 +111,7 @@ modification follow. Pay close attention to the difference between a
111
111
  "work based on the library" and a "work that uses the library". The
112
112
  former contains code derived from the library, whereas the latter must
113
113
  be combined with the library in order to run.
114
-
114
+
115
115
  GNU LESSER GENERAL PUBLIC LICENSE
116
116
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117
117
 
@@ -158,7 +158,7 @@ Library.
158
158
  You may charge a fee for the physical act of transferring a copy,
159
159
  and you may at your option offer warranty protection in exchange for a
160
160
  fee.
161
-
161
+
162
162
  2. You may modify your copy or copies of the Library or any portion
163
163
  of it, thus forming a work based on the Library, and copy and
164
164
  distribute such modifications or work under the terms of Section 1
@@ -216,7 +216,7 @@ instead of to this License. (If a newer version than version 2 of the
216
216
  ordinary GNU General Public License has appeared, then you can specify
217
217
  that version instead if you wish.) Do not make any other change in
218
218
  these notices.
219
-
219
+
220
220
  Once this change is made in a given copy, it is irreversible for
221
221
  that copy, so the ordinary GNU General Public License applies to all
222
222
  subsequent copies and derivative works made from that copy.
@@ -267,7 +267,7 @@ Library will still fall under Section 6.)
267
267
  distribute the object code for the work under the terms of Section 6.
268
268
  Any executables containing that work also fall under Section 6,
269
269
  whether or not they are linked directly with the Library itself.
270
-
270
+
271
271
  6. As an exception to the Sections above, you may also combine or
272
272
  link a "work that uses the Library" with the Library to produce a
273
273
  work containing portions of the Library, and distribute that work
@@ -329,7 +329,7 @@ restrictions of other proprietary libraries that do not normally
329
329
  accompany the operating system. Such a contradiction means you cannot
330
330
  use both them and the Library together in an executable that you
331
331
  distribute.
332
-
332
+
333
333
  7. You may place library facilities that are a work based on the
334
334
  Library side-by-side in a single library together with other library
335
335
  facilities not covered by this License, and distribute such a combined
@@ -370,7 +370,7 @@ subject to these terms and conditions. You may not impose any further
370
370
  restrictions on the recipients' exercise of the rights granted herein.
371
371
  You are not responsible for enforcing compliance by third parties with
372
372
  this License.
373
-
373
+
374
374
  11. If, as a consequence of a court judgment or allegation of patent
375
375
  infringement or for any other reason (not limited to patent issues),
376
376
  conditions are imposed on you (whether by court order, agreement or
@@ -422,7 +422,7 @@ conditions either of that version or of any later version published by
422
422
  the Free Software Foundation. If the Library does not specify a
423
423
  license version number, you may choose any version ever published by
424
424
  the Free Software Foundation.
425
-
425
+
426
426
  14. If you wish to incorporate parts of the Library into other free
427
427
  programs whose distribution conditions are incompatible with these,
428
428
  write to the author to ask for permission. For software which is
@@ -456,7 +456,7 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456
456
  DAMAGES.
457
457
 
458
458
  END OF TERMS AND CONDITIONS
459
-
459
+
460
460
  How to Apply These Terms to Your New Libraries
461
461
 
462
462
  If you develop a new library, and you want it to be of the greatest
@@ -471,7 +471,7 @@ convey the exclusion of warranty; and each file should have at least the
471
471
  "copyright" line and a pointer to where the full notice is found.
472
472
 
473
473
  <one line to give the library's name and a brief idea of what it does.>
474
- Copyright (C) 2024 Benedikt
474
+ Copyright (C) <year> <name of author>
475
475
 
476
476
  This library is free software; you can redistribute it and/or
477
477
  modify it under the terms of the GNU Lesser General Public
@@ -484,9 +484,7 @@ convey the exclusion of warranty; and each file should have at least the
484
484
  Lesser General Public License for more details.
485
485
 
486
486
  You should have received a copy of the GNU Lesser General Public
487
- License along with this library; if not, write to the Free Software
488
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
489
- USA
487
+ License along with this library; if not, see <https://www.gnu.org/licenses/>.
490
488
 
491
489
  Also add information on how to contact you by electronic and paper mail.
492
490
 
@@ -495,10 +493,9 @@ school, if any, to sign a "copyright disclaimer" for the library, if
495
493
  necessary. Here is a sample; alter the names:
496
494
 
497
495
  Yoyodyne, Inc., hereby disclaims all copyright interest in the
498
- library `Frob' (a library for tweaking knobs) written by James Random
499
- Hacker.
496
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
500
497
 
501
- <signature of Ty Coon>, 1 April 1990
502
- Ty Coon, President of Vice
498
+ <signature of Moe Ghoul>, 1 April 1990
499
+ Moe Ghoul, President of Vice
503
500
 
504
- That's all there is to it!
501
+ That's all there is to it!
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ include LICENSE
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: dccQuantities
3
+ Version: 2.0.0.dev2
4
+ Summary: Python classes for working with DDC calibration data
5
+ Author: Vanessa Stehr, Thomas Bruns
6
+ Author-email: Benedikt Seeger <benedikt.seeger@ptb.de>
7
+ License-Expression: LGPL-2.1-or-later
8
+ Project-URL: Homepage, https://gitlab1.ptb.de/digitaldynamicmeasurement/dccQuantities
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy
18
+ Requires-Dist: scipy
19
+ Requires-Dist: uncertainties
20
+ Requires-Dist: requests
21
+ Requires-Dist: pylatexenc
22
+ Requires-Dist: odfpy
23
+ Requires-Dist: openpyxl
24
+ Requires-Dist: pandas
25
+ Requires-Dist: dsiUnits>=2.5.2
26
+ Requires-Dist: dccXMLJSONConv==3.0.0.dev7
27
+ Requires-Dist: metas_unclib
28
+ Requires-Dist: pythonnet
29
+ Requires-Dist: pycountry
30
+ Provides-Extra: dccquantitiesplot
31
+ Requires-Dist: bokeh; extra == "dccquantitiesplot"
32
+ Provides-Extra: testing
33
+ Requires-Dist: pytest==7.4.1; extra == "testing"
34
+ Requires-Dist: pytest-cov==4.1.0; extra == "testing"
35
+ Dynamic: license-file
36
+
37
+ # dccQuantities
38
+
39
+ dccQuantities is a Python library designed for users of PTB’s Digital Calibration Certificates (DCC) in XML format. It provides an object‑oriented interface to parse, serialize, and manipulate calibration data with full support for uncertainties and units. Arithmetic works naturally on scalars, scalar‑vector mixes, and same‑length vectors element‑wise, preserving uncertainty propagation and metadata throughout.
40
+
41
+ ---
42
+
43
+ ## Key Features
44
+
45
+ - **DCC XML Parsing & Serialization**
46
+ Import certificates from XML into Python objects and export back to XML, JSON, CSV, Excel, or pandas DataFrames.
47
+
48
+ - **Uncertainty & Unit Awareness**
49
+ All quantity objects wrap values as `ufloat` (via `metas_unclib`) and units via `dsiUnits`, ensuring correct propagation in calculations.
50
+
51
+ - **Object‑Oriented Arithmetic**
52
+ Standard operators (`+`, `-`, `*`, `/`, `**`) are overloaded on:
53
+ - **`DccQuantityType`**: single or tabulated quantities
54
+ - **`SiRealList`**, **`SiComplexList`**, **`SiHybrid`**: 1D/2D arrays
55
+
56
+ - **Tables & Fancy Indexing**
57
+ The classes `DccLongTable` and `DccFlatTable` transparently implement numpy like indexing on efficient table structures described in the [table document](doc/tabellen/tables-de.md). Fancy indexing is supported, return type are always new tables.
58
+ ---
59
+
60
+ ## Installation
61
+
62
+ From PyPI (core functionality):
63
+ ```bash
64
+ pip install dccQuantities
65
+ ```
66
+
67
+ For development and testing:
68
+ ```bash
69
+ git clone https://gitlab1.ptb.de/digitaldynamicmeasurement/dccQuantities.git
70
+ cd dccQuantities
71
+ pip install -e .[testing]
72
+ ```
73
+
74
+ ## Under the Hood (Test‑Driven Behavior)
75
+
76
+ The library’s design is guided by its test suite:
77
+
78
+ 1. **Core Parsing** (`tests/test_parser.py`): reads `<DccQuantityTable>` and `<DccQuantityType>` elements, building Python objects.
79
+ 2. **Naming** (`tests/test_dccName.py`): parses and normalizes `<DccName>` entries for multilingual support.
80
+ 3. **Quantity Discovery** (`tests/test_quantityTypeCollector.py`): auto‑registers data handlers via `AbstractQuantityTypeData` subclasses.
81
+ 5. **List Types** (`tests/test_SiRealList_*.py`): handles real, complex, and hybrid lists, including broadcasting and label merging.
82
+ 6. **Table Flattening** (`tests/test_tables.py`): cover the tables.
83
+ 7. **Round‑Trip Serialization** (`tests/test_serilizer.py`): ensures parse→serialize yields equivalent XML.
84
+ 8. **JSON Interchange** (`tests/test_dccQuantTabJSONDumpingAndLoadingFromFile.json`): lossless JSON dump/load.
85
+
86
+ ---
87
+
88
+ ## Contributing & Contact
89
+
90
+ We welcome improvements, bug reports, and new features. To contribute:
91
+
92
+ 1. **Fork** the repository.
93
+ 2. **Create** a feature branch.
94
+ 3. **Add** tests for new functionality.
95
+ 4. **Submit** a merge request.
96
+
97
+ We highly encourage direct personal contact for design discussions or questions. Feel free to create Issues, even if you think your question/comment is not worth an issue, it is allways!
98
+
99
+ Or reach out to the maintainer:
100
+ - **Benedikt Seeger**: benedikt.seeger@ptb.de
101
+ directly
102
+
103
+ ## License
104
+
105
+ This project is licensed under the [LGPL‑2.1‑or‑later](LICENSE).
106
+
@@ -0,0 +1,70 @@
1
+ # dccQuantities
2
+
3
+ dccQuantities is a Python library designed for users of PTB’s Digital Calibration Certificates (DCC) in XML format. It provides an object‑oriented interface to parse, serialize, and manipulate calibration data with full support for uncertainties and units. Arithmetic works naturally on scalars, scalar‑vector mixes, and same‑length vectors element‑wise, preserving uncertainty propagation and metadata throughout.
4
+
5
+ ---
6
+
7
+ ## Key Features
8
+
9
+ - **DCC XML Parsing & Serialization**
10
+ Import certificates from XML into Python objects and export back to XML, JSON, CSV, Excel, or pandas DataFrames.
11
+
12
+ - **Uncertainty & Unit Awareness**
13
+ All quantity objects wrap values as `ufloat` (via `metas_unclib`) and units via `dsiUnits`, ensuring correct propagation in calculations.
14
+
15
+ - **Object‑Oriented Arithmetic**
16
+ Standard operators (`+`, `-`, `*`, `/`, `**`) are overloaded on:
17
+ - **`DccQuantityType`**: single or tabulated quantities
18
+ - **`SiRealList`**, **`SiComplexList`**, **`SiHybrid`**: 1D/2D arrays
19
+
20
+ - **Tables & Fancy Indexing**
21
+ The classes `DccLongTable` and `DccFlatTable` transparently implement numpy like indexing on efficient table structures described in the [table document](doc/tabellen/tables-de.md). Fancy indexing is supported, return type are always new tables.
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ From PyPI (core functionality):
27
+ ```bash
28
+ pip install dccQuantities
29
+ ```
30
+
31
+ For development and testing:
32
+ ```bash
33
+ git clone https://gitlab1.ptb.de/digitaldynamicmeasurement/dccQuantities.git
34
+ cd dccQuantities
35
+ pip install -e .[testing]
36
+ ```
37
+
38
+ ## Under the Hood (Test‑Driven Behavior)
39
+
40
+ The library’s design is guided by its test suite:
41
+
42
+ 1. **Core Parsing** (`tests/test_parser.py`): reads `<DccQuantityTable>` and `<DccQuantityType>` elements, building Python objects.
43
+ 2. **Naming** (`tests/test_dccName.py`): parses and normalizes `<DccName>` entries for multilingual support.
44
+ 3. **Quantity Discovery** (`tests/test_quantityTypeCollector.py`): auto‑registers data handlers via `AbstractQuantityTypeData` subclasses.
45
+ 5. **List Types** (`tests/test_SiRealList_*.py`): handles real, complex, and hybrid lists, including broadcasting and label merging.
46
+ 6. **Table Flattening** (`tests/test_tables.py`): cover the tables.
47
+ 7. **Round‑Trip Serialization** (`tests/test_serilizer.py`): ensures parse→serialize yields equivalent XML.
48
+ 8. **JSON Interchange** (`tests/test_dccQuantTabJSONDumpingAndLoadingFromFile.json`): lossless JSON dump/load.
49
+
50
+ ---
51
+
52
+ ## Contributing & Contact
53
+
54
+ We welcome improvements, bug reports, and new features. To contribute:
55
+
56
+ 1. **Fork** the repository.
57
+ 2. **Create** a feature branch.
58
+ 3. **Add** tests for new functionality.
59
+ 4. **Submit** a merge request.
60
+
61
+ We highly encourage direct personal contact for design discussions or questions. Feel free to create Issues, even if you think your question/comment is not worth an issue, it is allways!
62
+
63
+ Or reach out to the maintainer:
64
+ - **Benedikt Seeger**: benedikt.seeger@ptb.de
65
+ directly
66
+
67
+ ## License
68
+
69
+ This project is licensed under the [LGPL‑2.1‑or‑later](LICENSE).
70
+
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dccQuantities"
7
+ version = "2.0.0.dev2"
8
+ description = "Python classes for working with DDC calibration data"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+
12
+ # SPDX license expression + point at your LICENSE file
13
+ license = "LGPL-2.1-or-later"
14
+ license-files = ["LICENSE"]
15
+
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Operating System :: OS Independent",
22
+ ]
23
+
24
+ authors = [
25
+ { name = "Benedikt Seeger", email = "benedikt.seeger@ptb.de" },
26
+ { name = "Vanessa Stehr" },
27
+ { name = "Thomas Bruns" },
28
+ ]
29
+ urls = { "Homepage" = "https://gitlab1.ptb.de/digitaldynamicmeasurement/dccQuantities" }
30
+
31
+ dependencies = [
32
+ "numpy",
33
+ "scipy",
34
+ "uncertainties",
35
+ "requests",
36
+ "pylatexenc",
37
+ "odfpy",
38
+ "openpyxl",
39
+ "pandas",
40
+ "dsiUnits>=2.5.2",
41
+ "dccXMLJSONConv==3.0.0.dev7",
42
+ "metas_unclib",
43
+ "pythonnet",
44
+ "pycountry",
45
+ ]
46
+
47
+ [project.optional-dependencies]
48
+ dccQuantitiesPlot = ["bokeh"]
49
+ testing = [
50
+ "pytest==7.4.1",
51
+ "pytest-cov==4.1.0",
52
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,27 @@
1
+ from __future__ import annotations
2
+ from collections import defaultdict # for type annotation recursion
3
+
4
+ from AbstractQuantityTypeData import AbstractQuantityTypeData
5
+ from AbstractValueType import AbstractValueType
6
+ from typing import Union #for python 3.8/3.9 compatibility
7
+
8
+
9
+ class AbstractListType(AbstractQuantityTypeData):
10
+ def __init__(self, children: list[Union[AbstractListType,AbstractValueType]]) -> None:
11
+ super().__init__()
12
+ self.children = children
13
+
14
+ def toJsonDict(self):
15
+ result = defaultdict(list)
16
+ for child in self.children:
17
+ childJson = child.toJsonDict()
18
+ for key, value in childJson.items():
19
+ result[key].append(value)
20
+ return dict(result)
21
+
22
+
23
+ def flatten(self):
24
+ pass
25
+
26
+ def __len__(self):
27
+ return len(self.children)
@@ -0,0 +1,4 @@
1
+ class AbstractQuantityTypeData:
2
+ def __init__(self) -> None:
3
+ self._sorted=None
4
+ pass
@@ -0,0 +1,116 @@
1
+ from datetime import datetime
2
+ from dsiUnits import dsiUnit
3
+ from numpy.core.defchararray import endswith
4
+
5
+ from AbstractQuantityTypeData import AbstractQuantityTypeData
6
+ from typing import Union #for python 3.8/3.9 compatibility
7
+ import numpy as np
8
+ from metas_unclib import *
9
+ from helpers import dccConfiguration
10
+
11
+ class AbstractValueType(AbstractQuantityTypeData):
12
+ def __init__(
13
+ self,
14
+ label: list[str] = None,
15
+ unit: list[Union[str , dsiUnit]] = None,
16
+ dateTime: list[datetime] = None,
17
+ _originType: str = None,
18
+ _uncInfo: dict = None,
19
+ ) -> None:
20
+ super().__init__()
21
+ self.label = label
22
+ self.unit = []
23
+ self._originType = _originType
24
+ self._uncInfo = _uncInfo
25
+ if isinstance(unit,str):
26
+ unit=[unit]
27
+ if unit:
28
+ for item in unit:
29
+ if isinstance(item, dsiUnit):
30
+ self.unit.append(item)
31
+ elif isinstance(item, str):
32
+ self.unit.append(dsiUnit(item))
33
+ self.dateTime = dateTime
34
+
35
+ def serilizeDataToJSON(self):
36
+ if isinstance(self.data, np.ndarray):
37
+ dType = self.data.dtype
38
+ length = self.data.size
39
+ # check if data is a number so we will not have any uncer
40
+ if np.issubdtype(dType, np.number):
41
+ # we have number type so we defensively don't have any uncer
42
+ if length > 1:
43
+ flattValues = list(self.data.flat)
44
+ flattUncs = None
45
+ else:
46
+ flattValues = self.data.flat[0]
47
+ flattUncs = None
48
+ # check if data is a object if yes check witch type of object
49
+ if dType == object:
50
+ flattarray = self.data.flat
51
+ objType = type(flattarray[0]) # flatten the array so we can get an first element and inspect it's type
52
+ if objType == ufloat:
53
+ # Define a vectorized function to extract the membervar.
54
+ vec_values = np.vectorize(lambda x: x.value)
55
+ vec_uncs = np.vectorize(lambda x: x.stdunc)
56
+ if length>1:
57
+ flattValues = list(vec_values(flattarray))
58
+ flattUncs = list(vec_uncs(flattarray))
59
+ else:
60
+ flattValues = vec_values(flattarray)[0]
61
+ flattUncs = vec_uncs(flattarray)[0]
62
+ # okay now we can create the json
63
+ suffix = "" if length ==1 and not self._originType.endswith('XMLList') else "XMLList"
64
+ resultjson = {"si:value"+suffix: flattValues,}
65
+ if flattUncs and self._uncInfo != None:
66
+ kfactor=self._uncInfo['coverageFactor']
67
+ covP = self._uncInfo['coverageProbability']
68
+ distribution =self._uncInfo['distribution']
69
+ lens=np.array([len(kfactor),len(covP),len(distribution)])
70
+ if np.all(lens==1):
71
+ kfactor=kfactor[0]
72
+ covP=covP[0]
73
+ distribution=distribution[0]
74
+ if not np.all(kfactor==1.0):
75
+ # we should create expanded uncs now
76
+
77
+ if not "originalUnc" in self._uncInfo:
78
+ # we had no original uncer so wie calculate expanded unc
79
+ uncValues=(np.array(flattUncs) * kfactor).tolist()
80
+ if suffix=='':
81
+ try:
82
+ uncValues=uncValues[0]
83
+ except TypeError:
84
+ # if we cant suscribe it it must be int or float
85
+ pass
86
+ else:
87
+ uncValues=self._uncInfo["originalUnc"]
88
+ if suffix=='':
89
+ try:
90
+ uncValues=uncValues[0]
91
+ except TypeError:
92
+ # if we cant suscribe it it must be int or float
93
+ pass
94
+
95
+ resultjson["si:measurementUncertaintyUnivariate"+suffix] = {
96
+ "si:expandedMU"+suffix:{
97
+ "si:valueExpandedMU" + suffix:uncValues,
98
+ "si:coverageFactor"+suffix:kfactor,
99
+ "si:coverageProbability"+suffix:covP,
100
+ "si:distribution"+suffix:distribution
101
+ }
102
+ }
103
+ else:
104
+ resultjson["si:measurementUncertaintyUnivariate"+suffix] = {
105
+ "si:standardMU"+suffix:{
106
+ "si:valueStandardMU" + suffix: flattUncs,
107
+ "si:distribution"+suffix:distribution
108
+ }
109
+ }
110
+
111
+ #TODO deal with coverra
112
+ return resultjson
113
+ else:
114
+ raise ValueError("Data is not a numpy array")
115
+
116
+
@@ -0,0 +1,63 @@
1
+ import warnings
2
+ from AbstractQuantityTypeData import AbstractQuantityTypeData
3
+ from typing import Union #for python 3.8/3.9 compatibility
4
+
5
+ class DccCharsXMLList(AbstractQuantityTypeData):
6
+ def __init__(self, data: list[str]) -> None:
7
+ super().__init__()
8
+ self.data = data
9
+
10
+ def __len__(self) -> int:
11
+ return len(self.data)
12
+
13
+ def __str__(self) -> str:
14
+ return self.data.__str__()
15
+
16
+ def __repr__(self) -> str:
17
+ params = {key: value for key, value in vars(self).items() if value is not None}
18
+ paramStr = ", ".join(f"{key}={repr(value)}" for key, value in params.items())
19
+ return f"DccCharsXMLList.DccCharsXMLList({paramStr})"
20
+
21
+ def __add__(self, other):
22
+ if isinstance(other, DccCharsXMLList):
23
+ return DccCharsXMLList(data=self.data + other.data)
24
+ elif isinstance(other, list):
25
+ warnings.warn("Concatenating DccCharsXMLList and list!", RuntimeWarning)
26
+ return DccCharsXMLList(data=self.data + other)
27
+ else:
28
+ raise TypeError(
29
+ "unsupported operand for +: "
30
+ f"'{type(self).__name__}' and '{type(other).__name__}'"
31
+ )
32
+
33
+ def __radd__(self, other):
34
+ if isinstance(other, DccCharsXMLList):
35
+ return DccCharsXMLList(data=other.data + self.data)
36
+ elif isinstance(other, list):
37
+ warnings.warn("Concatenating DccCharsXMLList and list!", RuntimeWarning)
38
+ return DccCharsXMLList(data=other + self.data)
39
+ else:
40
+ raise TypeError(
41
+ "unsupported operand for +: "
42
+ f"'{type(other).__name__}' and '{type(self).__name__}'"
43
+ )
44
+
45
+ def toJsonDict(self) -> list:
46
+ return {'dcc:charsXMLList': self.data}
47
+
48
+
49
+ @property
50
+ def sorted(self) -> bool:
51
+ if self._sorted is None:
52
+ self._sorted=all(self.data[i] <= self.data[i + 1] for i in range(len(self.data) - 1))
53
+ """Check if the list of strings is sorted in ascending order."""
54
+ return self._sorted
55
+
56
+
57
+ def parse(jsonDict: Union[dict, list]):
58
+ if isinstance(jsonDict, list):
59
+ return DccCharsXMLList(data=jsonDict)
60
+ elif isinstance(jsonDict, dict):
61
+ return NotImplemented
62
+
63
+ return DccCharsXMLList(data=jsonDict)
@@ -0,0 +1,15 @@
1
+ from helpers import parseAttributes
2
+
3
+
4
+ class DccMathml:
5
+ def __init__(self, content, id: None, refId: None, refType: None) -> None:
6
+ self.content = content
7
+ self.id = id
8
+ self.refId = refId
9
+ self.refType = refType
10
+
11
+ def parseDccMathml(jsonDict):
12
+ dccMathmlArgs = parseAttributes(jsonDict=jsonDict)
13
+ dccMathmlArgs['content'] = jsonDict['$']
14
+
15
+ return DccMathml(**dccMathmlArgs)