plotastrodata 1.10.2__py3-none-any.whl → 1.11.0__py3-none-any.whl
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.
- plotastrodata/__init__.py +1 -1
- plotastrodata/_type_utils.py +100 -0
- plotastrodata/analysis_utils.py +716 -273
- plotastrodata/const_utils.py +40 -36
- plotastrodata/coord_utils.py +113 -58
- plotastrodata/ext_utils.py +38 -14
- plotastrodata/fft_utils.py +220 -114
- plotastrodata/fits_utils.py +153 -68
- plotastrodata/fitting_utils.py +250 -98
- plotastrodata/los_utils.py +97 -35
- plotastrodata/matrix_utils.py +16 -9
- plotastrodata/noise_utils.py +194 -70
- plotastrodata/other_utils.py +74 -52
- plotastrodata/plot_utils.py +1522 -585
- {plotastrodata-1.10.2.dist-info → plotastrodata-1.11.0.dist-info}/METADATA +3 -13
- plotastrodata-1.11.0.dist-info/RECORD +19 -0
- {plotastrodata-1.10.2.dist-info → plotastrodata-1.11.0.dist-info}/WHEEL +1 -1
- plotastrodata-1.10.2.dist-info/RECORD +0 -18
- {plotastrodata-1.10.2.dist-info → plotastrodata-1.11.0.dist-info}/licenses/LICENSE +0 -0
- {plotastrodata-1.10.2.dist-info → plotastrodata-1.11.0.dist-info}/top_level.txt +0 -0
plotastrodata/__init__.py
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Internal helpers for preserving numeric output precision."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import field
|
|
4
|
+
import numpy as np
|
|
5
|
+
from typing import Annotated, Any, Callable, Literal, overload
|
|
6
|
+
from pydantic import WrapValidator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Shared input types; validated settings are separate from uncoerced inputs.
|
|
10
|
+
RealScalar = float | np.floating | np.integer
|
|
11
|
+
RealSequence = list[RealScalar] | tuple[RealScalar, ...] | np.ndarray
|
|
12
|
+
PositionPair = tuple[RealScalar, RealScalar] | list[RealScalar] | np.ndarray
|
|
13
|
+
Position = str | PositionPair
|
|
14
|
+
Positions = Position | list[Position] | tuple[Position, ...]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _validate_float(value: Any, handler: Callable) -> float | np.longdouble:
|
|
18
|
+
"""Preserve extended precision before Pydantic coerces other values."""
|
|
19
|
+
return value if isinstance(value, np.longdouble) else handler(value)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
ValidatedFloat = Annotated[float | np.longdouble,
|
|
23
|
+
WrapValidator(_validate_float)]
|
|
24
|
+
|
|
25
|
+
# Raw analysis inputs retain their containers and scalar types.
|
|
26
|
+
BeamInput = np.ndarray | list[RealScalar | None] | tuple[RealScalar | None,
|
|
27
|
+
RealScalar | None,
|
|
28
|
+
RealScalar | None]
|
|
29
|
+
# Plotting converts inputs to lists and validates shape/completeness separately.
|
|
30
|
+
ValidatedBeamTriple = list[ValidatedFloat | None]
|
|
31
|
+
ValidatedBeams = ValidatedBeamTriple | list[ValidatedBeamTriple]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
_FloatNormalizationInput = int | float | np.integer | np.floating | np.ndarray
|
|
36
|
+
_FloatNormalizationResult = int | float | np.integer | np.longdouble | np.ndarray
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@overload
|
|
40
|
+
def _normalize_float(value: _FloatNormalizationInput, *,
|
|
41
|
+
force_float: bool = False,
|
|
42
|
+
array_output: Literal[True]
|
|
43
|
+
) -> np.ndarray: ...
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@overload
|
|
47
|
+
def _normalize_float(value: np.ndarray, *,
|
|
48
|
+
force_float: bool = False,
|
|
49
|
+
array_output: None = None
|
|
50
|
+
) -> np.ndarray: ...
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@overload
|
|
54
|
+
def _normalize_float(value: float | np.floating, *,
|
|
55
|
+
force_float: bool = False,
|
|
56
|
+
array_output: Literal[False] | None = None
|
|
57
|
+
) -> float | np.longdouble: ...
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@overload
|
|
61
|
+
def _normalize_float(value: _FloatNormalizationInput, *,
|
|
62
|
+
force_float: bool = False,
|
|
63
|
+
array_output: bool | None = None
|
|
64
|
+
) -> _FloatNormalizationResult: ...
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _normalize_float(value: _FloatNormalizationInput, *,
|
|
68
|
+
force_float: bool = False,
|
|
69
|
+
array_output: bool | None = None
|
|
70
|
+
) -> _FloatNormalizationResult:
|
|
71
|
+
"""Normalize a real numerical result at its public output boundary.
|
|
72
|
+
|
|
73
|
+
By default, convert ordinary NumPy floating scalars to Python floats,
|
|
74
|
+
leaving integers and arrays unchanged. Extended-precision floating
|
|
75
|
+
scalars retain their precision.
|
|
76
|
+
|
|
77
|
+
force_float converts scalar integers to Python floats as well.
|
|
78
|
+
array_output=True preserves or restores array form via np.asarray;
|
|
79
|
+
False unwraps a zero-dimensional temporary before scalar normalization;
|
|
80
|
+
None preserves the result's existing scalar/array form. Arrays with
|
|
81
|
+
dimensions greater than zero always remain arrays. Array dtypes are
|
|
82
|
+
never changed by force_float, including for zero-dimensional arrays
|
|
83
|
+
retained with array_output=True or None.
|
|
84
|
+
"""
|
|
85
|
+
if array_output is True:
|
|
86
|
+
return np.asarray(value)
|
|
87
|
+
if isinstance(value, np.ndarray):
|
|
88
|
+
if array_output is not False or value.ndim != 0:
|
|
89
|
+
return value
|
|
90
|
+
value = value[()]
|
|
91
|
+
if isinstance(value, np.longdouble):
|
|
92
|
+
return value
|
|
93
|
+
if force_float or isinstance(value, np.floating):
|
|
94
|
+
return float(value)
|
|
95
|
+
return value
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _internal_field() -> Any:
|
|
99
|
+
"""Create a fresh field for internal state populated after initialization."""
|
|
100
|
+
return field(init=False, default=None, repr=False, compare=False)
|