physpyx 0.2.0__tar.gz → 1.0.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-0.2.0 → physpyx-1.0.0}/PKG-INFO +1 -1
- {physpyx-0.2.0 → physpyx-1.0.0}/pyproject.toml +2 -1
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/__init__.py +2 -1
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/manager.py +1 -1
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/nuclide.py +4 -2
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/qty.py +46 -10
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/quantity.py +21 -2
- {physpyx-0.2.0 → physpyx-1.0.0}/README.md +0 -0
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/astronomy.py +0 -0
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/data/all-nuclides.csv +0 -0
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/helper.py +0 -0
- {physpyx-0.2.0 → physpyx-1.0.0}/src/physpyx/physpyx.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "physpyx"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "1.0.0"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name="Jérôme Dufour", email="jerome.dufour@eduvaud.ch" },
|
|
6
6
|
]
|
|
@@ -33,6 +33,7 @@ docs = [
|
|
|
33
33
|
"myst-parser>=4.0.1",
|
|
34
34
|
"sphinx-autodoc2>=0.5.0",
|
|
35
35
|
"sphinx-autobuild>=2025.8.25",
|
|
36
|
+
"sphinx-design>=0.7.0",
|
|
36
37
|
]
|
|
37
38
|
|
|
38
39
|
[build-system]
|
|
@@ -52,6 +52,6 @@ class PTManager(ABC):
|
|
|
52
52
|
outfile.write("\\ExplSyntaxOn\n")
|
|
53
53
|
error = str(exc_val).replace(" ", "~ ")
|
|
54
54
|
outfile.write(
|
|
55
|
-
f"\\msg_error:nnnnn {{
|
|
55
|
+
f"\\msg_error:nnnnn {{physpyx}} {{python_error}} {{{lineno}}} {{{error}}} {{{faulty_line}}}"
|
|
56
56
|
)
|
|
57
57
|
outfile.write("\n\\ExplSyntaxOff\n")
|
|
@@ -99,7 +99,7 @@ class DecayChannels:
|
|
|
99
99
|
self.channels = [B]
|
|
100
100
|
look_for_C = True
|
|
101
101
|
elif A.prob + B.prob > 100:
|
|
102
|
-
logger.warning(f"{symbol} skip 2nd (
|
|
102
|
+
logger.warning(f"{symbol} skip 2nd ({A.prob + B.prob:.0f}%>100%)")
|
|
103
103
|
look_for_C = False
|
|
104
104
|
else:
|
|
105
105
|
self.channels.append(B)
|
|
@@ -110,7 +110,9 @@ class DecayChannels:
|
|
|
110
110
|
if C.prob < 1:
|
|
111
111
|
logger.warning(f"{symbol} skip 3rd (<1% | none)")
|
|
112
112
|
elif A.prob + B.prob + C.prob > 100:
|
|
113
|
-
logger.warning(
|
|
113
|
+
logger.warning(
|
|
114
|
+
f"{symbol} skip 3rd ({A.prob + B.prob + C.prob:.0f}%>100%)"
|
|
115
|
+
)
|
|
114
116
|
else:
|
|
115
117
|
self.channels.append(C)
|
|
116
118
|
|
|
@@ -11,7 +11,17 @@ logger = getLogger(__name__)
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class Qty(PTManager):
|
|
14
|
+
"""
|
|
15
|
+
This class should be used as a context manager.
|
|
16
|
+
"""
|
|
17
|
+
|
|
14
18
|
def __init__(self, fname: str, context: str = ""):
|
|
19
|
+
"""
|
|
20
|
+
:param fname: name of the ".pyx" file saved on exit
|
|
21
|
+
:param context: `Pint` feature that allows unit conversion. For Instance, if
|
|
22
|
+
the parameter is set to "energy", it will be possible to convert mass to
|
|
23
|
+
energy and vice-versa.
|
|
24
|
+
"""
|
|
15
25
|
super().__init__(fname)
|
|
16
26
|
self._ureg = SiunitxUnitRegistry()
|
|
17
27
|
self._ureg.define("jour = day")
|
|
@@ -35,22 +45,29 @@ class Qty(PTManager):
|
|
|
35
45
|
else:
|
|
36
46
|
active = {}
|
|
37
47
|
with self._fname.open("w") as outfile:
|
|
38
|
-
outfile.write("\\
|
|
39
|
-
outfile.write("\\prop_gset_from_keyval:Nn \\g_pdb_pytotex_prop {\n")
|
|
48
|
+
outfile.write("\\prop_gset_from_keyval:Nn \\g_physpyx_pty_prop {\n")
|
|
40
49
|
for name, qty in sys._getframe(2).f_locals.items():
|
|
41
50
|
if isinstance(qty, SiunitxQuantity):
|
|
42
51
|
if name == "mu0":
|
|
43
52
|
qty = r"\qty[input-digits = 0123456789\pi]{4\pi e-7}{\tesla\meter\per\ampere}"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if old
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
try:
|
|
54
|
+
outfile.write(f"\t{{{name}}} = {{{str(qty)}}},\n")
|
|
55
|
+
if old := active.pop(name, None):
|
|
56
|
+
if old != str(qty):
|
|
57
|
+
logger.info(f"update {name}: {old} -> {qty}")
|
|
58
|
+
else:
|
|
59
|
+
logger.info(f"add {name}: {qty}")
|
|
60
|
+
except ValueError as e:
|
|
61
|
+
# TODO: report the correct error in
|
|
62
|
+
# PTManager.write_errorfile, not the one raised in
|
|
63
|
+
# PTManager.__exit__
|
|
64
|
+
logger.error(f"exporting {name} failed, {qty._fmt}")
|
|
65
|
+
e.add_note(f"exporting {name} failed")
|
|
66
|
+
raise e
|
|
50
67
|
|
|
51
68
|
for name, qty in active.items():
|
|
52
69
|
logger.info(f"remove {name}: {qty}")
|
|
53
|
-
outfile.write("}\n
|
|
70
|
+
outfile.write("}\n")
|
|
54
71
|
|
|
55
72
|
def __call__(
|
|
56
73
|
self,
|
|
@@ -62,6 +79,25 @@ class Qty(PTManager):
|
|
|
62
79
|
compact: bool = False,
|
|
63
80
|
preferred: bool = False,
|
|
64
81
|
) -> SiunitxQuantity:
|
|
82
|
+
"""
|
|
83
|
+
Return an instance of SiunitxQuantity
|
|
84
|
+
|
|
85
|
+
:param value: Behaves differently according to its type:
|
|
86
|
+
|
|
87
|
+
- Scalar: defines the magnitude of a scalar quantity
|
|
88
|
+
- list[Scalar]: defines the magnitudes of a numpy.NDArray quantity
|
|
89
|
+
- str: look for a constant whose name matches value
|
|
90
|
+
|
|
91
|
+
:param unit: Assigns the unit if any (ignored for constants).
|
|
92
|
+
:param to: Immediately converts unit.
|
|
93
|
+
:param fmt: Sets the amplitude "f-string" format.
|
|
94
|
+
:param base: If true, converts the unit into SI units.
|
|
95
|
+
:param compact: As described in the "Pint" documentation "returns a
|
|
96
|
+
rescaled to compact, human-readable units".
|
|
97
|
+
:param preferred: If true, attempts to convert unit into simpler one.
|
|
98
|
+
For instance (kg.m/s2 will be converted to N). Note that, this defaults
|
|
99
|
+
to "False" only here.
|
|
100
|
+
"""
|
|
65
101
|
if isinstance(value, str):
|
|
66
102
|
if unit is not None:
|
|
67
103
|
logger.warning("Units are ignored when instanciating a constant")
|
|
@@ -80,4 +116,4 @@ class Qty(PTManager):
|
|
|
80
116
|
q = self._ureg.Quantity(
|
|
81
117
|
value, unit, fmt=fmt, base=base, compact=compact, preferred=preferred
|
|
82
118
|
)
|
|
83
|
-
return q if to is None else q.
|
|
119
|
+
return q if to is None else q.fmtex(to=to)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import cast
|
|
1
|
+
from typing import cast, overload
|
|
2
2
|
from numpy import cross, ndarray, linalg
|
|
3
3
|
|
|
4
4
|
from logging import getLogger
|
|
@@ -85,6 +85,20 @@ class SiunitxQuantity(Quantity):
|
|
|
85
85
|
compact: bool = False,
|
|
86
86
|
preferred: bool = True,
|
|
87
87
|
) -> "SiunitxQuantity":
|
|
88
|
+
"""
|
|
89
|
+
Return an instance of SiunitxQuantity
|
|
90
|
+
|
|
91
|
+
:param value: defines the magnitudes of the quantity
|
|
92
|
+
:param unit: Assigns the unit if any.
|
|
93
|
+
:param fmt: Sets the amplitude "f-string" format.
|
|
94
|
+
:param base: If true, converts the unit into SI units.
|
|
95
|
+
:param compact: As described in the "Pint" documentation "returns a
|
|
96
|
+
rescaled to compact, human-readable units".
|
|
97
|
+
:param preferred: If true, attempts to convert unit into simpler one.
|
|
98
|
+
For instance (kg.m/s2 will be converted to N). Note that, this defaults
|
|
99
|
+
to "True" which means that all SiunitxQuantity resulting from
|
|
100
|
+
mathematical operations, will be converted.
|
|
101
|
+
"""
|
|
88
102
|
quantity = cast(SiunitxQuantity, super().__new__(cls, value, units))
|
|
89
103
|
quantity._fmt = fmt
|
|
90
104
|
quantity._base = base
|
|
@@ -151,6 +165,11 @@ class SiunitxQuantity(Quantity):
|
|
|
151
165
|
else:
|
|
152
166
|
return rf"\num{{{out}}}"
|
|
153
167
|
|
|
168
|
+
def __neg__(self) -> "SiunitxQuantity":
|
|
169
|
+
# NOTE: only useful to fix typing warning Cannot access attribute "???"
|
|
170
|
+
# for class "PlainQuantity[Unknown]"
|
|
171
|
+
return cast(SiunitxQuantity, super().__neg__())
|
|
172
|
+
|
|
154
173
|
def _format_unit(self) -> str:
|
|
155
174
|
num = ""
|
|
156
175
|
den = ""
|
|
@@ -183,7 +202,7 @@ class SiunitxQuantity(Quantity):
|
|
|
183
202
|
den += r"\per" + tmp
|
|
184
203
|
return num + den
|
|
185
204
|
|
|
186
|
-
def
|
|
205
|
+
def fmtex(
|
|
187
206
|
self,
|
|
188
207
|
*,
|
|
189
208
|
to: str | None = None,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|