cloudsprite 0.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.
Files changed (70) hide show
  1. cloudsprite/__init__.py +451 -0
  2. cloudsprite/_antenna.py +83 -0
  3. cloudsprite/_auth.py +295 -0
  4. cloudsprite/_client.py +502 -0
  5. cloudsprite/_config.py +203 -0
  6. cloudsprite/_consent.py +104 -0
  7. cloudsprite/_context.py +945 -0
  8. cloudsprite/_exceptions.py +136 -0
  9. cloudsprite/_figure_models.py +158 -0
  10. cloudsprite/_figure_validation.py +168 -0
  11. cloudsprite/_filter_foster.py +165 -0
  12. cloudsprite/_filter_synthesis.py +400 -0
  13. cloudsprite/_filtering.py +134 -0
  14. cloudsprite/_impedance_matching.py +262 -0
  15. cloudsprite/_interpolation.py +47 -0
  16. cloudsprite/_lineage.py +775 -0
  17. cloudsprite/_link_budget.py +99 -0
  18. cloudsprite/_logging.py +53 -0
  19. cloudsprite/_mixed_mode.py +49 -0
  20. cloudsprite/_monte_carlo.py +193 -0
  21. cloudsprite/_noise_figure.py +44 -0
  22. cloudsprite/_pagination.py +130 -0
  23. cloudsprite/_parsers.py +75 -0
  24. cloudsprite/_publish.py +162 -0
  25. cloudsprite/_redact.py +179 -0
  26. cloudsprite/_response.py +63 -0
  27. cloudsprite/_resultset.py +65 -0
  28. cloudsprite/_rf_network.py +111 -0
  29. cloudsprite/_run_config.py +46 -0
  30. cloudsprite/_script_runner.py +217 -0
  31. cloudsprite/_script_workspace.py +271 -0
  32. cloudsprite/_sparameter_metrics.py +75 -0
  33. cloudsprite/_tdr.py +283 -0
  34. cloudsprite/_trace.py +112 -0
  35. cloudsprite/_version.py +23 -0
  36. cloudsprite/_visualizer.py +380 -0
  37. cloudsprite/_visualizer_cli.py +412 -0
  38. cloudsprite/_visualizer_preview.py +864 -0
  39. cloudsprite/_work_context.py +116 -0
  40. cloudsprite/_ws.py +577 -0
  41. cloudsprite/cli.py +300 -0
  42. cloudsprite/py.typed +0 -0
  43. cloudsprite/resources/__init__.py +1 -0
  44. cloudsprite/resources/_base.py +293 -0
  45. cloudsprite/resources/_models.py +50 -0
  46. cloudsprite/resources/cloudscripts.py +173 -0
  47. cloudsprite/resources/datasets.py +431 -0
  48. cloudsprite/resources/figures.py +282 -0
  49. cloudsprite/resources/instruments.py +295 -0
  50. cloudsprite/resources/notebooks.py +183 -0
  51. cloudsprite/resources/orbs.py +99 -0
  52. cloudsprite/resources/parameters.py +77 -0
  53. cloudsprite/resources/projects.py +182 -0
  54. cloudsprite/resources/related.py +125 -0
  55. cloudsprite/resources/reports.py +992 -0
  56. cloudsprite/resources/search.py +245 -0
  57. cloudsprite/resources/shares.py +229 -0
  58. cloudsprite/resources/sprites.py +15 -0
  59. cloudsprite/resources/tags.py +107 -0
  60. cloudsprite/resources/teams.py +86 -0
  61. cloudsprite/resources/traces.py +147 -0
  62. cloudsprite/resources/usage.py +152 -0
  63. cloudsprite/resources/visualizer_templates.py +466 -0
  64. cloudsprite/resources/workflows.py +59 -0
  65. cloudsprite-0.11.0.dist-info/METADATA +358 -0
  66. cloudsprite-0.11.0.dist-info/RECORD +70 -0
  67. cloudsprite-0.11.0.dist-info/WHEEL +5 -0
  68. cloudsprite-0.11.0.dist-info/entry_points.txt +3 -0
  69. cloudsprite-0.11.0.dist-info/licenses/LICENSE +21 -0
  70. cloudsprite-0.11.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,262 @@
1
+ """Lossless, single-frequency conjugate matching with ideal lumped elements or stubs."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ from dataclasses import dataclass
7
+ from typing import Literal
8
+
9
+ import numpy as np
10
+ from numpy.typing import ArrayLike
11
+
12
+ from cloudsprite._exceptions import ValidationError
13
+ from cloudsprite._link_budget import _positive
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class MatchingComponent:
18
+ """Ideal reactive element: kind is inductor/capacitor; value is H/F respectively.
19
+
20
+ Connection to the circuit is determined by the containing LMatch's series
21
+ or shunt field. A missing element is represented by None, never an infinite
22
+ capacitance/inductance or a zero-valued physical part.
23
+ """
24
+
25
+ kind: Literal["inductor", "capacitor"]
26
+ value: float
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class LMatch:
31
+ """One ideal L match at frequency_hz, with source/load/reference in ohms.
32
+
33
+ Topology is read from source toward load: series-shunt places the shunt
34
+ across the load; shunt-series places it across the input. The loaded input
35
+ impedance equals conjugate(source_impedance_ohm), for maximum available
36
+ power transfer. Reference impedance normalizes the equations; it does not
37
+ override the source or imply that a complex-source match has zero ordinary S11.
38
+ Series reactance is in ohms, shunt susceptance in siemens. Both signs of the
39
+ solutions are returned, so a topology can appear twice. Parts are ideal,
40
+ without parasitics, loss, bandwidth or power-rating predictions.
41
+ """
42
+
43
+ frequency_hz: float
44
+ source_impedance_ohm: complex
45
+ load_impedance_ohm: complex
46
+ reference_impedance_ohm: float
47
+ topology: Literal["series-shunt", "shunt-series"]
48
+ series: MatchingComponent | None
49
+ shunt: MatchingComponent | None
50
+ series_reactance_ohm: float
51
+ shunt_susceptance_s: float
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class StubMatch:
56
+ """One lossless single-stub match, with all impedances in ohms.
57
+
58
+ Position is measured from the load toward the source, and both position_m
59
+ and length_m are in the first half wavelength [0, wavelength/2). The stub
60
+ and main line share line_impedance_ohm and propagation_velocity_m_s. A
61
+ series stub inserts its input impedance in series with the transformed
62
+ load; a shunt stub adds its input admittance in parallel. The input at the
63
+ stub plane equals the conjugate source impedance. An already matched load
64
+ returns the canonical zero-position, zero-reactance solution; many other
65
+ positions are then equivalent. No dispersion, end effects or losses.
66
+ """
67
+
68
+ frequency_hz: float
69
+ source_impedance_ohm: complex
70
+ load_impedance_ohm: complex
71
+ reference_impedance_ohm: float
72
+ line_impedance_ohm: float
73
+ propagation_velocity_m_s: float
74
+ connection: Literal["shunt", "series"]
75
+ termination: Literal["open", "short"]
76
+ position_m: float
77
+ length_m: float
78
+
79
+
80
+ def _points(
81
+ frequency: ArrayLike, source: ArrayLike | None, load: ArrayLike, reference: float
82
+ ) -> list[tuple[float, complex, complex]]:
83
+ _positive(reference_impedance_ohm=reference)
84
+ try:
85
+ raw_f = np.asarray(frequency)
86
+ if np.iscomplexobj(raw_f):
87
+ raise ValueError
88
+ arrays = [
89
+ np.asarray(raw_f, dtype=float),
90
+ np.asarray(reference if source is None else source, dtype=complex),
91
+ np.asarray(load, dtype=complex),
92
+ ]
93
+ if any(a.ndim > 1 or a.size == 0 or not np.all(np.isfinite(a)) for a in arrays):
94
+ raise ValueError
95
+ f, zs, zl = np.broadcast_arrays(*arrays)
96
+ if np.any(f <= 0) or np.any(zs.real <= 0) or np.any(zl.real <= 0):
97
+ raise ValueError
98
+ except (ValueError, TypeError) as exc:
99
+ raise ValidationError(
100
+ "Use positive finite frequencies and finite impedances with positive real parts; scalars or matching 1-D vectors."
101
+ ) from exc
102
+ for impedance in (zs / reference, zl / reference):
103
+ magnitude = np.abs(impedance)
104
+ if np.any(magnitude < 1e-100) or np.any(magnitude > 1e100) or np.any(impedance.real / magnitude < 1e-12):
105
+ raise ValidationError("Impedance magnitude or Q is outside the numerically supported range.")
106
+ return [(float(a), complex(b), complex(c)) for a, b, c in zip(f.flat, zs.flat, zl.flat)]
107
+
108
+
109
+ def _component(value: float, omega: float, *, shunt: bool) -> MatchingComponent | None:
110
+ if value == 0:
111
+ return None
112
+ inductive = value < 0 if shunt else value > 0
113
+ if shunt:
114
+ scaled = -1 / (omega * value) if inductive else value / omega
115
+ else:
116
+ scaled = value / omega if inductive else -1 / (omega * value)
117
+ if not math.isfinite(scaled) or scaled <= 0:
118
+ raise ValidationError("Component value is outside floating-point range.")
119
+ return MatchingComponent("inductor" if inductive else "capacitor", scaled)
120
+
121
+
122
+ def l_network_match(
123
+ load_impedance_ohm: ArrayLike,
124
+ frequency_hz: ArrayLike,
125
+ *,
126
+ source_impedance_ohm: ArrayLike | None = None,
127
+ reference_impedance_ohm: float = 50.0,
128
+ ) -> tuple[LMatch, ...]:
129
+ """Synthesize every realizable ideal L-network conjugate match.
130
+
131
+ Args:
132
+ load_impedance_ohm: Complex passive load, scalar or 1-D frequency vector.
133
+ frequency_hz: Positive scalar or matching vector in Hz.
134
+ source_impedance_ohm: Complex passive source, default reference impedance.
135
+ reference_impedance_ohm: Positive real normalization impedance in ohms.
136
+ Normalized impedance magnitudes must be 1e-100..1e100, and
137
+ Re(Z)/abs(Z) at least 1e-12 for numerical conditioning.
138
+
139
+ Returns:
140
+ Flat tuple ordered by input frequency, then series-shunt/shunt-series,
141
+ then negative/positive root. Each vector entry is an independent design,
142
+ not a broadband fit. Infeasible topologies are omitted; degenerate zero
143
+ elements are None. Equations solve Re(Zin)=Re(Zsource) and
144
+ Im(Zin)=-Im(Zsource), as in Orfanidis, Electromagnetic Waves and
145
+ Antennas, section 13.11. Inputs are never modified.
146
+ """
147
+ results: list[LMatch] = []
148
+ for f, source, load in _points(frequency_hz, source_impedance_ohm, load_impedance_ohm, reference_impedance_ohm):
149
+ zs, zl = source / reference_impedance_ohm, load / reference_impedance_ohm
150
+ yl, yt = 1 / zl, 1 / zs.conjugate()
151
+ candidates: list[tuple[Literal["series-shunt", "shunt-series"], float, float]] = []
152
+ # Re(1/(g+j*b)) = g/(g*g+b*b) = Rs.
153
+ d = yl.real / zs.real - yl.real**2
154
+ if d >= 0:
155
+ roots = (0.0,) if d == 0 else (-math.sqrt(d), math.sqrt(d))
156
+ for b in roots:
157
+ candidates.append(("series-shunt", -zs.imag + b / (yl.real / zs.real), b - yl.imag))
158
+ # Re(1/(Rl+j*x)) = Rl/(Rl*Rl+x*x) = Re(1/conj(Zs)).
159
+ d = zl.real / yt.real - zl.real**2
160
+ if d >= 0:
161
+ roots = (0.0,) if d == 0 else (-math.sqrt(d), math.sqrt(d))
162
+ for x in roots:
163
+ candidates.append(("shunt-series", x - zl.imag, yt.imag + x / (zl.real / yt.real)))
164
+ for topology, x, b in candidates:
165
+ x *= reference_impedance_ohm
166
+ b /= reference_impedance_ohm
167
+ results.append(
168
+ LMatch(
169
+ f,
170
+ source,
171
+ load,
172
+ reference_impedance_ohm,
173
+ topology,
174
+ _component(x, 2 * math.pi * f, shunt=False),
175
+ _component(b, 2 * math.pi * f, shunt=True),
176
+ x,
177
+ b,
178
+ )
179
+ )
180
+ return tuple(results)
181
+
182
+
183
+ def single_stub_match(
184
+ load_impedance_ohm: ArrayLike,
185
+ frequency_hz: ArrayLike,
186
+ *,
187
+ source_impedance_ohm: ArrayLike | None = None,
188
+ reference_impedance_ohm: float = 50.0,
189
+ line_impedance_ohm: float = 50.0,
190
+ connection: Literal["shunt", "series"] = "shunt",
191
+ termination: Literal["open", "short"] = "short",
192
+ propagation_velocity_m_s: float = 299792458.0,
193
+ ) -> tuple[StubMatch, ...]:
194
+ """Find single-stub conjugate matches using closed-form transmission-line equations.
195
+
196
+ Args:
197
+ load_impedance_ohm: Complex passive load, scalar or 1-D vector.
198
+ frequency_hz: Positive frequency/frequencies in Hz; independent designs.
199
+ source_impedance_ohm: Source impedance(s), default reference impedance.
200
+ reference_impedance_ohm: Positive real reference in ohms.
201
+ line_impedance_ohm: Positive real characteristic impedance in ohms.
202
+ connection: Shunt admittance or series impedance stub.
203
+ termination: Open or short circuit at the far end of the stub.
204
+ propagation_velocity_m_s: Positive phase velocity in metres/second.
205
+
206
+ Returns:
207
+ Flat tuple with up to two matches per frequency, ordered by position.
208
+ No solutions at an infeasible frequency (possible for a complex source
209
+ or source resistance different from line Z0). Uses
210
+ z(d)=(zL*cos(beta*d)+j*sin(beta*d))/(cos(beta*d)+j*zL*sin(beta*d)),
211
+ and its admittance dual, avoiding tan's quarter-wave singularity.
212
+ See Orfanidis, Electromagnetic Waves and Antennas, section 13.8.
213
+ """
214
+ _positive(line_impedance_ohm=line_impedance_ohm, propagation_velocity_m_s=propagation_velocity_m_s)
215
+ if connection not in ("shunt", "series") or termination not in ("open", "short"):
216
+ raise ValidationError("connection must be shunt/series and termination open/short.")
217
+ results: list[StubMatch] = []
218
+ for f, source, load in _points(frequency_hz, source_impedance_ohm, load_impedance_ohm, reference_impedance_ohm):
219
+ q, target = load / line_impedance_ohm, source.conjugate() / line_impedance_ohm
220
+ if not all(1e-100 <= abs(value) <= 1e100 for value in (q, target)):
221
+ raise ValidationError("Line-normalized impedances are outside the numerically supported range.")
222
+ if connection == "shunt":
223
+ q, target = 1 / q, 1 / target
224
+ a, b = (1 - abs(q) ** 2) / 2, -q.imag
225
+ c = (1 + abs(q) ** 2) / 2 - q.real / target.real
226
+ radius = math.hypot(a, b)
227
+ if radius == 0:
228
+ if not math.isclose(c, 0, abs_tol=1e-14):
229
+ continue
230
+ angles = [0.0]
231
+ else:
232
+ ratio = -c / radius
233
+ if abs(ratio) > 1 + 1e-14:
234
+ continue
235
+ delta, phase = math.acos(max(-1.0, min(1.0, ratio))), math.atan2(b, a)
236
+ angles = sorted({((phase + sign * delta) / 2) % math.pi for sign in (-1, 1)})
237
+ for theta in angles:
238
+ co, si = math.cos(theta), math.sin(theta)
239
+ transformed = (q * co + 1j * si) / (co + 1j * q * si)
240
+ if not math.isclose(transformed.real, target.real, rel_tol=1e-8):
241
+ raise ValidationError("Stub position is ill-conditioned for this impedance ratio.")
242
+ required = target.imag - transformed.imag
243
+ # Series short: x=tan(l); series open: x=-cot(l).
244
+ # Shunt open: b=tan(l); shunt short: b=-cot(l).
245
+ tangent = (connection == "series") == (termination == "short")
246
+ length_angle = (math.atan(required) if tangent else math.atan2(-1.0, required)) % math.pi
247
+ scale = propagation_velocity_m_s / f / (2 * math.pi)
248
+ results.append(
249
+ StubMatch(
250
+ f,
251
+ source,
252
+ load,
253
+ reference_impedance_ohm,
254
+ line_impedance_ohm,
255
+ propagation_velocity_m_s,
256
+ connection,
257
+ termination,
258
+ theta * scale,
259
+ length_angle * scale,
260
+ )
261
+ )
262
+ return tuple(results)
@@ -0,0 +1,47 @@
1
+ """X-axis alignment with interpolation for trace arithmetic."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import warnings
6
+ from typing import TYPE_CHECKING
7
+
8
+ import numpy as np
9
+
10
+ if TYPE_CHECKING:
11
+ from cloudsprite._trace import Trace
12
+
13
+
14
+ def align_traces(t1: "Trace", t2: "Trace") -> tuple[np.ndarray, np.ndarray, np.ndarray]:
15
+ """Align two traces to a common x-axis. Returns (y1_aligned, y2_aligned, x_common)."""
16
+ x1, x2 = t1.x, t2.x
17
+
18
+ if np.array_equal(x1, x2):
19
+ return t1.y.copy(), t2.y.copy(), x1.copy()
20
+
21
+ x_min = max(x1.min(), x2.min())
22
+ x_max = min(x1.max(), x2.max())
23
+
24
+ if x_min >= x_max:
25
+ raise ValueError("Traces have no overlapping x-axis range")
26
+
27
+ if x1.min() < x_min or x1.max() > x_max:
28
+ warnings.warn(
29
+ f"Trace '{t1.name}' trimmed from range [{x1.min():.4g} – {x1.max():.4g}] "
30
+ f"to overlap [{x_min:.4g} – {x_max:.4g}]"
31
+ )
32
+ if x2.min() < x_min or x2.max() > x_max:
33
+ warnings.warn(
34
+ f"Trace '{t2.name}' trimmed from range [{x2.min():.4g} – {x2.max():.4g}] "
35
+ f"to overlap [{x_min:.4g} – {x_max:.4g}]"
36
+ )
37
+
38
+ n1_overlap = np.sum((x1 >= x_min) & (x1 <= x_max))
39
+ n2_overlap = np.sum((x2 >= x_min) & (x2 <= x_max))
40
+ n_points = max(n1_overlap, n2_overlap)
41
+
42
+ x_common = np.linspace(x_min, x_max, n_points)
43
+
44
+ y1_interp = np.interp(x_common, x1, t1.y)
45
+ y2_interp = np.interp(x_common, x2, t2.y)
46
+
47
+ return y1_interp, y2_interp, x_common