sgnts.sources.fake_series
¶
FakeSeriesSource
dataclass
¶
Bases: TSSource
flowchart TD
sgnts.sources.fake_series.FakeSeriesSource[FakeSeriesSource]
sgnts.base.base.TSSource[TSSource]
sgnts.base.base._TSSource[_TSSource]
sgnts.base.base.TSSource --> sgnts.sources.fake_series.FakeSeriesSource
sgnts.base.base._TSSource --> sgnts.base.base.TSSource
click sgnts.sources.fake_series.FakeSeriesSource href "" "sgnts.sources.fake_series.FakeSeriesSource"
click sgnts.base.base.TSSource href "" "sgnts.base.base.TSSource"
click sgnts.base.base._TSSource href "" "sgnts.base.base._TSSource"
A time-series source that generates fake data in fixed-size buffers.
If start is not specified the current GPS time will be used as the
start time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signals
|
dict[str, dict[str, Any]] | None
|
dict, keyed by source pad name, defining the signals to be produced on that pad. The expected values are: signal_type:
str, currently supported types: (1) 'white': white
noise data. (2) 'sin' or 'sine': sine wave data. (3)
'impulse': creates an impulse data, where the value is
one at one sample point, and everywhere else is zero.
(4) 'const': constant values as specified by user.
(5) 'square' or 'toggle': a 50%-duty square wave
alternating between exactly 0 and These parameters may be specified directly as keyword arguments during class init, in which case they will be used as the defaults for undefined parameters in the signals dict. |
None
|
ngap
|
int
|
int, the frequency to generate gap buffers, will generate a gap buffer every ngap buffers. ngap=0: do not generate gap buffers. ngap=-1: generates gap buffers randomly. |
0
|
random_seed
|
Optional[int]
|
int, set the random seed, used for 'white' and 'impulse' signals. |
None
|
real_time
|
bool
|
bool, run the source in "real time", such that frames are produced at the rate corresponding to their relative offsets. In real-time mode, start will default to the current GPS time if not otherwise specified. |
False
|
heartbeat_interval
|
Optional[float]
|
Optional[float], longest time in seconds this source may stall the pipeline's graph loop waiting for a frame's span to become due in real-time mode. Past that, it emits a zero-length heartbeat frame instead, so the rest of the pipeline keeps ticking and elements that have fallen behind can catch up (at roughly stride / heartbeat_interval times real time). Defaults to a quarter of the stride. Set to float("inf") to always sleep out the full frame, which pins the throughput of every element in the pipeline to real time. Only meaningful with real_time=True. |
None
|
Notes
Thread safety:
Marked thread_safe = True. With
Pipeline.run(threaded=N) the pad callbacks for this
element are dispatched onto worker threads.
Pad layout: N source pads (no sink pads). The N source
pads' ``new`` callbacks CAN run concurrently in the same
wave — that is the per-pad concurrency to keep safe.
``internal`` runs alone.
Per-pad concurrency analysis of ``new``:
- ``self.cnt[pad] += 1`` — per-pad-keyed dict mutation.
Distinct keys per call → safe under concurrent calls.
- ``np.random.randn`` / ``np.sin`` / ``np.full`` /
``np.zeros`` etc. — these release the GIL during the
bulk array fill, so the work itself parallelizes.
- ``self._next_frame_dict`` / ``self._new_buffer_dict``
from ``prepare_frame``: per-pad-keyed (the keying lives
in the parent ``_TSSource``).
**Reproducibility caveat (important):** ``np.random.randn``
and friends draw from NumPy's *global* RNG. The global RNG
is internally thread-safe (no crash), but concurrent
``new`` calls from multiple source pads consume samples
from the shared stream in unspecified order. With threading
enabled, ``random_seed`` no longer determines the per-pad
output. If you need reproducible random output under
threading, either keep this element single-pad, run the
pipeline without ``threaded=...``, or migrate the source
to per-pad ``np.random.default_rng()`` instances.
**Future editors MUST preserve thread safety**: keep all
per-pad state per-pad-keyed. Do NOT call
``np.random.seed(...)`` from ``new``/``internal`` (it
mutates the global RNG state and would race with any
other code in the process that uses it).
Source code in src/sgnts/sources/fake_series.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
create_data(pad, buf)
¶
Create the fake data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SourcePad
|
SourcePad, the source pad generating data. |
required |
buf
|
SeriesBuffer
|
SeriesBuffer, the buffer to create the data for. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array, the fake data array. |
Source code in src/sgnts/sources/fake_series.py
new(pad)
¶
New buffers are created on "pad" with an instance specific count and a name derived from the pad name. "EOS" is set if we have surpassed the requested end time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SourcePad
|
SourcePad, the source pad to generate TSFrames. |
required |
Returns:
| Type | Description |
|---|---|
TSFrame
|
TSFrame, the TSFrame that carries the buffers with fake data. |
Source code in src/sgnts/sources/fake_series.py
output_prototype(pad)
¶
Declare the numpy spec this pad emits.
FakeSeriesSource is numpy, but ngap makes its first frame an all-gap
frame (ngap > 0 gaps at cnt == 0; ngap == -1 gaps randomly), so
the spec can't always be inferred from data -- declare it. Backend/device
enforcement only checks numpy/cpu, so the dtype here only needs to match
what gaps should materialize as.