physpyx 3.0.0__tar.gz → 3.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.
- {physpyx-3.0.0 → physpyx-3.1.0}/PKG-INFO +1 -1
- {physpyx-3.0.0 → physpyx-3.1.0}/pyproject.toml +1 -1
- {physpyx-3.0.0 → physpyx-3.1.0}/pyproject.toml.orig +1 -1
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/qty.py +20 -1
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/quantity.py +33 -18
- {physpyx-3.0.0 → physpyx-3.1.0}/README.md +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/__init__.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/astronomy.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/constants.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/context.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/data/all-nuclides.csv +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/helper.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/manager.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/nuclide.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/physpyx.py +0 -0
- {physpyx-3.0.0 → physpyx-3.1.0}/src/physpyx/registry.py +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import re
|
|
2
2
|
import sys
|
|
3
|
+
from collections.abc import Iterable
|
|
3
4
|
from logging import getLogger
|
|
5
|
+
from typing import cast
|
|
4
6
|
|
|
7
|
+
from numpy import array
|
|
5
8
|
from pint._typing import Scalar
|
|
6
9
|
from pint.facets.context import Context
|
|
7
10
|
|
|
@@ -56,7 +59,7 @@ class Qty(PTManager):
|
|
|
56
59
|
|
|
57
60
|
def __call__(
|
|
58
61
|
self,
|
|
59
|
-
value: Scalar |
|
|
62
|
+
value: Scalar | Iterable[Scalar | SiunitxQuantity] | str,
|
|
60
63
|
unit: str | None = None,
|
|
61
64
|
to: str | None = None,
|
|
62
65
|
fmt: str = "g",
|
|
@@ -90,6 +93,22 @@ class Qty(PTManager):
|
|
|
90
93
|
if unit is not None:
|
|
91
94
|
logger.warning("Units are ignored when instanciating a constant")
|
|
92
95
|
value, unit, fmt = self._constants(value, fmt)
|
|
96
|
+
elif isinstance(value, Iterable):
|
|
97
|
+
if all(isinstance(item, SiunitxQuantity) for item in value):
|
|
98
|
+
value = cast(Iterable[SiunitxQuantity], value)
|
|
99
|
+
dim = {v.dimensionality for v in value}
|
|
100
|
+
if len(dim) != 1:
|
|
101
|
+
raise ValueError(
|
|
102
|
+
f"Can't create a vector with different dimensionality ({dim})"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
if unit == None:
|
|
106
|
+
unit = ""
|
|
107
|
+
if self._ureg.Unit(unit).dimensionality != dim.pop():
|
|
108
|
+
raise ValueError("Need to set unit with correct dimensionality")
|
|
109
|
+
value = array([v.fmtex(to=unit).m for v in value])
|
|
110
|
+
else:
|
|
111
|
+
value = array(value)
|
|
93
112
|
|
|
94
113
|
q = self._ureg.Quantity(
|
|
95
114
|
value,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from collections.abc import Generator, Iterator
|
|
1
|
+
from collections.abc import Generator, Iterable, Iterator
|
|
2
2
|
from logging import getLogger
|
|
3
3
|
from typing import ClassVar, Self, TypedDict, cast
|
|
4
4
|
|
|
5
|
-
from numpy import cross, linalg
|
|
5
|
+
from numpy import cross, linalg
|
|
6
6
|
from pint._typing import Magnitude, UnitLike
|
|
7
7
|
from pint.registry import Quantity
|
|
8
8
|
|
|
@@ -82,8 +82,8 @@ class SiunitxQuantity(Quantity):
|
|
|
82
82
|
return alt
|
|
83
83
|
|
|
84
84
|
def __iter__(self) -> Iterator["SiunitxQuantity"]:
|
|
85
|
-
# NOTE: this is used to set formatting options in tuple expansions
|
|
86
|
-
#
|
|
85
|
+
# NOTE: this is used to set formatting options in tuple expansions rx,
|
|
86
|
+
# ry = qty([3, 2], "kilometer", fmt=".1e")
|
|
87
87
|
for val in super().__iter__():
|
|
88
88
|
val._fmt = self._fmt
|
|
89
89
|
val._base = self._base
|
|
@@ -99,33 +99,35 @@ class SiunitxQuantity(Quantity):
|
|
|
99
99
|
elif self._preferred:
|
|
100
100
|
quantity = self._REGISTRY.to_preferred_units(self)
|
|
101
101
|
if self._compact:
|
|
102
|
+
if isinstance(self.m, Iterable):
|
|
103
|
+
raise ValueError("'compact=True' for vectors has an undefined behavior")
|
|
102
104
|
quantity = cast(SiunitxQuantity, self.to_compact())
|
|
103
105
|
|
|
104
106
|
quantity._fmt = self._fmt
|
|
105
107
|
return (
|
|
106
108
|
quantity._format_array()
|
|
107
|
-
if isinstance(quantity.m,
|
|
109
|
+
if isinstance(quantity.m, Iterable)
|
|
108
110
|
else quantity._format_scalar()
|
|
109
111
|
)
|
|
110
112
|
|
|
113
|
+
def _format_magnitude(self, m: float) -> str:
|
|
114
|
+
out = f"{m:{self._fmt}}"
|
|
115
|
+
if out.startswith("1e"):
|
|
116
|
+
return out[1:]
|
|
117
|
+
elif out.startswith("-1e"):
|
|
118
|
+
return "-" + out[2:]
|
|
119
|
+
return out
|
|
120
|
+
|
|
111
121
|
def _format_array(self) -> str:
|
|
112
122
|
if self.m.ndim != 1:
|
|
113
123
|
raise NotImplementedError
|
|
114
124
|
out = r"\begin{pmatrix}"
|
|
115
125
|
if isinstance(self.m[0], complex):
|
|
116
126
|
out += "\\\\".join(
|
|
117
|
-
|
|
118
|
-
rf"\complexnum{{{v:{self._fmt}}}}" if abs(v) > 1e-16 else r"\num{0}"
|
|
119
|
-
for v in self.m
|
|
120
|
-
]
|
|
127
|
+
rf"\complexnum{{{self._format_magnitude(m)}}}" for m in self.m
|
|
121
128
|
)
|
|
122
129
|
else:
|
|
123
|
-
out += "\\\\".join(
|
|
124
|
-
[
|
|
125
|
-
rf"\num{{{v:{self._fmt}}}}" if abs(v) > 1e-16 else r"\num{0}"
|
|
126
|
-
for v in self.m
|
|
127
|
-
]
|
|
128
|
-
)
|
|
130
|
+
out += "\\\\".join(rf"\num{{{self._format_magnitude(m)}}}" for m in self.m)
|
|
129
131
|
|
|
130
132
|
out += r"\end{pmatrix}"
|
|
131
133
|
if ustr := self._format_unit():
|
|
@@ -133,9 +135,7 @@ class SiunitxQuantity(Quantity):
|
|
|
133
135
|
return out
|
|
134
136
|
|
|
135
137
|
def _format_scalar(self) -> str:
|
|
136
|
-
out =
|
|
137
|
-
if out.startswith("1e"):
|
|
138
|
-
out = out[1:]
|
|
138
|
+
out = self._format_magnitude(self.m)
|
|
139
139
|
if ustr := self._format_unit():
|
|
140
140
|
if isinstance(self.m, complex):
|
|
141
141
|
return rf"\complexqty{{{out}}}{{{ustr}}}"
|
|
@@ -157,6 +157,21 @@ class SiunitxQuantity(Quantity):
|
|
|
157
157
|
# "PlainQuantity[Unknown]"'
|
|
158
158
|
return cast(SiunitxQuantity, super().__add__(other))
|
|
159
159
|
|
|
160
|
+
def __truediv__(self, other: object) -> "SiunitxQuantity":
|
|
161
|
+
# NOTE: to fix typing warning 'Cannot access attribute "???" for class
|
|
162
|
+
# "PlainQuantity[Unknown]"'
|
|
163
|
+
return cast(SiunitxQuantity, super().__truediv__(other))
|
|
164
|
+
|
|
165
|
+
def __mul__(self, other: object) -> "SiunitxQuantity":
|
|
166
|
+
# NOTE: to fix typing warning 'Cannot access attribute "???" for class
|
|
167
|
+
# "PlainQuantity[Unknown]"'
|
|
168
|
+
return cast(SiunitxQuantity, super().__mul__(other))
|
|
169
|
+
|
|
170
|
+
def __rmul__(self, other: object) -> "SiunitxQuantity":
|
|
171
|
+
# NOTE: to fix typing warning 'Cannot access attribute "???" for class
|
|
172
|
+
# "PlainQuantity[Unknown]"'
|
|
173
|
+
return cast(SiunitxQuantity, super().__rmul__(other))
|
|
174
|
+
|
|
160
175
|
def _format_unit(self) -> str:
|
|
161
176
|
num = ""
|
|
162
177
|
den = ""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|