sgnts.base.base
¶
TSResourceSource
dataclass
¶
Bases: ParallelizeBase, TSSource
flowchart TD
sgnts.base.base.TSResourceSource[TSResourceSource]
sgnts.base.base.TSSource[TSSource]
sgnts.base.base._TSSource[_TSSource]
sgnts.base.base.TSSource --> sgnts.base.base.TSResourceSource
sgnts.base.base._TSSource --> sgnts.base.base.TSSource
click sgnts.base.base.TSResourceSource href "" "sgnts.base.base.TSResourceSource"
click sgnts.base.base.TSSource href "" "sgnts.base.base.TSSource"
click sgnts.base.base._TSSource href "" "sgnts.base.base._TSSource"
Source class that is entirely data driven by an external resource.
This class uses ParallelizeBase to run data generation in a separate worker thread. Subclasses either implement the resource hook API (resource_open/resource_read, and optionally resource_gap_lag) to get reconnect handling, stream-continuity bookkeeping, and outage gap synthesis from the built-in worker loop -- or override the worker_process method entirely to define data generation themselves.
The worker communicates with the main thread via queues provided by ParallelizeBase. Data should be sent as (pad, buffer) tuples to the output queue using context.output_queue.put((pad, buf)).
Important: The worker runs on a bare instance in a separate process/thread, so hooks and worker_process cannot read instance attributes directly. Configuration reaches the worker through parameter extraction: keyword-only parameters on the hooks (or same-named worker_process parameters) are automatically supplied from the matching instance attributes at construction time.
Subclasses using the resource hook API should: 1. Implement resource_open(start, end) to open the resource and return a stream handle 2. Optionally override resource_read(stream) if one delivery is not simply next(stream); return {pad_name: [SeriesBuffer, ...]} 3. Optionally implement resource_setup() to create any worker-side bookkeeping attributes the hooks rely on 4. Optionally implement resource_gap_lag(pad_name) to bound outage gap synthesis using resource-specific latency knowledge 5. Declare any extra configuration the hooks need as keyword-only parameters on the hook signatures 6. Optionally deliver a zero-length data buffer on a pad ahead of its first real data to declare the pad's backend/dtype -- needed only when the first deliveries may be all gaps (e.g. a fully masked block), so a gap-first pad can still finalize its spec correctly (see output_prototype)
Subclasses overriding worker_process instead should: 1. Send data as (pad, buffer) tuples via context.output_queue.put((pad, buf)) 2. Check context.should_stop() to know when to exit
Exception handling follows SGN's improved Parallelize pattern: exceptions in the worker are caught by the framework, printed to stdout, and cause the worker to terminate. The main thread detects abnormal termination via the internal() method.
Thread safety
This base class is deliberately NOT marked thread_safe, and
must not be: the flag is a plain inherited class attribute, so
setting it here would silently declare every subclass -- current
and future, in any downstream package -- thread safe with no
audit gate.
The built-in graph-thread machinery IS per-pad safe under
Pipeline.run(threaded=...):
internal()runs alone (all source pads depend on it). It is the only consumer of the worker output queue and the only writer of element-wide bookkeeping (latest_buffer_properties,first_buffer_properties,start/end,_pad_prototypes,_last_worker_delivery).new(pad)calls CAN run concurrently across source pads but touch only per-pad-keyed state:_next_frame_dict[pad]viaprepare_frameandbuffer_queue[pad]inset_data. Theat_eoswrite inset_datais a monotonic True-only latch, so a racy read at worst delays EOS propagation by one graph iteration.- The resource hooks and
worker_processrun on a bare worker-side instance (see above), never on graph threads, so hook-side state cannot race with pad callbacks no matter what the hooks do.
Subclasses whose element-side additions stay within the
resource hook API may therefore declare thread_safe = True
on themselves. Doing so is worthwhile: internal() can block
up to the heartbeat deadline waiting on the worker, and an
unmarked element blocks the pipeline's whole graph wave on the
event-loop thread while a marked one blocks only a pool thread.
Subclasses that override the graph-thread machinery (new,
internal, set_data, output_prototype) or add
element-side state read from those paths must re-audit against
the rules above before declaring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float | None
|
Optional[float] = None Start time in GPS seconds. Used by subclasses to determine when data generation should begin. |
None
|
end
|
float | None
|
Optional[float] = None End time in GPS seconds. Alternative to duration parameter. Cannot be given if duration is given. |
None
|
duration
|
float | None
|
Optional[float] = None Duration in seconds. Alternative to end parameter. If neither end nor duration is specified, defaults to maximum int64 value. |
None
|
in_queue_timeout
|
int
|
int = 60 Timeout in seconds when waiting for data from the worker. Used by get_data_from_queue() in the main thread. Time spent blocked in resource_open is waited out rather than counted. |
60
|
heartbeat_interval
|
float | None
|
Optional[float] = None Longest time in seconds that internal() may stall the pipeline's graph loop while accumulating a full stride of data. When the wait exceeds this, the source 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 wait for a full stride, which pins the throughput of every element in the pipeline to real time whenever this source is caught up. |
None
|
reconnect
|
bool
|
bool = True Reconnect after resource errors instead of ending the stream. With reconnect disabled a resource error ends the stream at EOS, recorded as the element's eos_error. Only applies to the resource hook API; subclasses overriding worker_process handle errors themselves. |
True
|
reconnect_backoff
|
float
|
float = 1.0 Initial backoff between reconnect attempts, in seconds. Doubles per consecutive failure up to reconnect_backoff_max. |
1.0
|
reconnect_backoff_max
|
float
|
float = 30.0 Upper bound on the reconnect backoff, in seconds. |
30.0
|
max_reconnects
|
int | None
|
int | None = 10
Consecutive failed reconnect attempts after which the worker
gives up and ends the stream at EOS -- roughly 3 minutes of
retries at the default backoff settings. The failure is
logged and recorded as the element's eos_error, and
|
10
|
reconnect_gap_lag
|
float | None
|
float | None = None How far behind wall clock to emit outage gaps on live streams while disconnected, in seconds. None defers to resource_gap_lag() per pad, falling back to DEFAULT_OUTAGE_GAP_LAG. Clamped to half of in_queue_timeout so outage gaps always flow before the pipeline's read timeout. |
None
|
Source code in src/sgnts/base/base.py
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 | |
latest_offset
property
¶
The offset through which every pad has received data from the worker (the minimum of the per-pad latest end offsets). Pads that have not received any data yet count as int64 min. Using the minimum matters when pads receive data in different block sizes: the fastest pad's progress says nothing about whether the others can fill their frames.
check_worker_terminated()
¶
A worker that set its shutdown event ended its stream -- it
reached its end, could make no further progress, or gave up on a
failing resource -- so promote the termination to EOS instead of
treating it as abnormal. A give-up still fails the run after the
drain: the stashed failure surfaces through eos_error and
Pipeline.run() raises PipelineEOSError.
Source code in src/sgnts/base/base.py
get_data_from_queue(deadline=None)
¶
Retrieve data from the worker with a timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deadline
|
float | None
|
float | None, |
None
|
Source code in src/sgnts/base/base.py
internal()
¶
Since internal() is guaranteed to be called prior to producing any data on a source pad, all setup is done here. First the resource itself is setup and the first data is pulled from the resource. Subsequent calls to internal only gets data from the resource if there is not enough data queued up to produce a result
Source code in src/sgnts/base/base.py
output_prototype(pad)
¶
Declare the pad's spec from the worker data already delivered.
A resource source can emit a gap before a pad's first real data (e.g. a priming gap when the resource delivers data starting later than the frame origin), which would otherwise finalize the pad's spec to the numpy float64 default and reject the real data's dtype when it arrives.
internal() pulls at least one buffer per pad from the worker
before any frame is emitted, and every delivery is scanned on arrival
(see _capture_pad_prototype) -- so by the time a spec is finalized
the true backend/dtype is known for any pad that has ever delivered
real data. A worker whose first delivery carries no array at all
(pure gaps, e.g. a fully masked block) can declare the pad's dtype
explicitly by sending a zero-length data buffer ahead of them; it is
recorded as the prototype and not queued as stream data. Falls back
to the base numpy default when nothing real was ever delivered.
Source code in src/sgnts/base/base.py
resource_gap_lag(pad_name, *args, **kwargs)
¶
Optional per-pad outage-gap lag, in seconds.
Runs in the worker. How far behind wall clock outage gaps may be emitted for this pad while the resource is disconnected -- i.e. the span after which absent data is declared gap rather than late. Return None (the default) to use the reconnect_gap_lag setting or DEFAULT_OUTAGE_GAP_LAG. Elements whose resource carries a latency contract should derive the lag from it. Parameters beyond the fixed (pad_name,) contract must be keyword-only and are auto-extracted from same-named instance attributes.
Source code in src/sgnts/base/base.py
resource_open(start, end, *args, **kwargs)
¶
Open the external resource, returning a stream handle.
Runs in the worker. Override together with resource_read to use the built-in resilient worker loop instead of overriding worker_process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float | None
|
float | None, resume-adjusted GPS start time in seconds: the requested start on first open, the last delivered timestamp on reconnect, or None for a live stream. |
required |
end
|
float | None
|
float | None, the requested GPS end time in seconds, or None if unbounded. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Any, a stream handle passed to resource_read. If it has a |
Any
|
close() method it is called on teardown and reconnect. |
Hook parameters beyond the fixed (start, end) contract must be keyword-only; each is auto-extracted from the same-named instance attribute (or the parameter default) and passed on every call, e.g.::
def resource_open(self, start, end, *, channels):
...
Source code in src/sgnts/base/base.py
resource_read(stream, *args, **kwargs)
¶
Read one block from the stream as pad-name -> buffers.
Runs in the worker. The default treats the stream as an iterator of such dicts. Raise StopIteration when the stream ends; any other exception triggers reconnect handling. A zero-length data buffer ahead of a pad's first data declares its dtype (see output_prototype) and bypasses continuity bookkeeping. Parameters beyond the fixed (stream,) contract must be keyword-only and are auto-extracted from same-named instance attributes.
Source code in src/sgnts/base/base.py
resource_setup(*args, **kwargs)
¶
One-time worker-side initialization before the first resource_open.
Runs in the worker, exactly once per worker. The worker operates on a bare instance that never saw init/post_init, so any worker-side bookkeeping attributes the other hooks rely on must be created here rather than at construction time. Exceptions raised here are configuration errors and fail the pipeline rather than triggering reconnect handling. All parameters must be keyword-only and are auto-extracted from same-named instance attributes.
Source code in src/sgnts/base/base.py
sample_rate(pad)
¶
sample_shape(pad)
¶
The channels per sample that a buffer should produce as a tuple (since it can be a tensor). For single channels just return ()
Source code in src/sgnts/base/base.py
set_data(out_frame, pad)
¶
This method will set data on out_frame based on the contents of the internal queue
Source code in src/sgnts/base/base.py
setup()
¶
Initialize the TSResourceSource data structures.
Source code in src/sgnts/base/base.py
worker_process(context, *, srcs, start, end, in_queue_timeout, reconnect, reconnect_backoff, reconnect_backoff_max, max_reconnects, reconnect_gap_lag, resource_config=None)
¶
Resilient worker loop driving the resource hook API.
Called repeatedly by the framework; each call performs one read (or one step of reconnect handling). On resource errors the stream is reopened with capped exponential backoff; live streams bridge the outage with gap buffers so the pipeline keeps flowing, and bounded streams resume from the last delivered timestamp. Reconnect discontinuities are bridged with explicit gaps and re-delivered spans are trimmed, keeping every pad's stream contiguous and non-overlapping.
Subclasses may instead override this method entirely to define data generation themselves; they should then send (pad, buffer) tuples via context.output_queue.put((pad, buf)) and check context.should_stop() to know when to exit.
Source code in src/sgnts/base/base.py
2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 | |
TSSink
dataclass
¶
Bases: TimeSeriesMixin[TSFrame], SinkElement[TimeSpanFrame]
flowchart TD
sgnts.base.base.TSSink[TSSink]
sgnts.base.base.TimeSeriesMixin[TimeSeriesMixin]
sgnts.base.base.TimeSeriesMixin --> sgnts.base.base.TSSink
click sgnts.base.base.TSSink href "" "sgnts.base.base.TSSink"
click sgnts.base.base.TimeSeriesMixin href "" "sgnts.base.base.TimeSeriesMixin"
A time-series sink element.
Source code in src/sgnts/base/base.py
internal()
¶
Process frames by calling child class implementation.
If the child class defines a process() method, it will be called with input frame dictionaries. Otherwise, child classes should override internal() directly.
Source code in src/sgnts/base/base.py
TSSource
dataclass
¶
Bases: _TSSource
flowchart TD
sgnts.base.base.TSSource[TSSource]
sgnts.base.base._TSSource[_TSSource]
sgnts.base.base._TSSource --> sgnts.base.base.TSSource
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 data in fixed-size buffers where the user can specify the start time and end time. If you want a data driven source consider using TSResourceSource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float | None
|
float, start time of first buffer, in seconds |
None
|
end
|
float | None
|
float, end time of the last buffer, in seconds |
None
|
duration
|
float | None
|
float, alternative to end option, specify the duration of time to be covered in seconds. Cannot be given if end is given. |
None
|
Source code in src/sgnts/base/base.py
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 | |
set_pad_buffer_params(pad, sample_shape, rate)
¶
Set variables on the pad that are needed to construct SeriesBuffers.
These should remain constant throughout the duration of the pipeline so this method may only be called once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SourcePad
|
SourcePad, the pad to setup buffers on |
required |
sample_shape
|
tuple[int, ...]
|
tuple[int, ...], the shape of a single sample of the data, or put another way, the shape of the data except for the last (time) dimension, i.e. sample_shape=data.shape[:-1] |
required |
rate
|
int
|
int, the sample rate of the data the pad will produce |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If start or end times don't align to sample boundaries at the given rate |
Source code in src/sgnts/base/base.py
TSTransform
dataclass
¶
Bases: TimeSeriesMixin[TSFrame], TransformElement[TimeSpanFrame]
flowchart TD
sgnts.base.base.TSTransform[TSTransform]
sgnts.base.base.TimeSeriesMixin[TimeSeriesMixin]
sgnts.base.base.TimeSeriesMixin --> sgnts.base.base.TSTransform
click sgnts.base.base.TSTransform href "" "sgnts.base.base.TSTransform"
click sgnts.base.base.TimeSeriesMixin href "" "sgnts.base.base.TimeSeriesMixin"
A time-series transform element.
Source code in src/sgnts/base/base.py
internal()
¶
Process frames by calling child class implementation.
If the child class defines a process() method, it will be called with input and output frame dictionaries. Otherwise, child classes should override internal() directly.
Source code in src/sgnts/base/base.py
new(pad)
¶
Return the output frame for the given pad.
It should take the source pad as an argument and return a new TSFrame or EventFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SourcePad
|
SourcePad, The source pad that is producing the transformed frame |
required |
Returns:
| Type | Description |
|---|---|
TimeSpanFrame
|
TSFrame or EventFrame, The transformed frame |
Source code in src/sgnts/base/base.py
TimeSeriesMixin
dataclass
¶
Bases: ElementLike, Generic[TSFrameLike]
flowchart TD
sgnts.base.base.TimeSeriesMixin[TimeSeriesMixin]
click sgnts.base.base.TimeSeriesMixin href "" "sgnts.base.base.TimeSeriesMixin"
Mixin that adds time-series capabilities to any SGN element.
This will produce aligned frames in preparedframes. If the adapter is not explicitly disabled, will trigger the audioadapter to queue data, and make padded or strided frames in preparedframes.
This mixin provides: - Frame alignment across multiple input pads - Optional adapter processing (overlap/stride/gap handling) - Timeout detection and EOS handling
Note
Subclasses can customize alignment behavior by setting class-level attributes: - static_unaligned_sink_pads: Declare which sink pads should not be aligned (e.g., EventFrame pads or auxiliary inputs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_age
|
float
|
float, the max age before timeout, in seconds |
100.0
|
adapter_config
|
AdapterConfig
|
AdapterConfig, holds parameters used for audioadapter behavior |
AdapterConfig()
|
unaligned
|
Sequence[str]
|
list[str], the list of unaligned sink pads. |
list()
|
Source code in src/sgnts/base/base.py
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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
earliest
property
¶
The earliest offset among all the buffers from all the pads.
is_aligned
property
¶
Check if input frames are currently aligned across all pads.
Returns:
| Type | Description |
|---|---|
bool
|
True if frames from all input pads have overlapping time ranges |
bool
|
and can be processed together. False if waiting for more data. |
latest
property
¶
The latest offset among all the buffers from all the pads.
min_latest
property
¶
The earliest offset among each pad's latest offset.
__post_init__()
¶
Initialize timeseries state.
Source code in src/sgnts/base/base.py
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 | |
configure()
¶
earliest_by_pad(pad)
¶
The earliest offset among the queued up buffers in this pad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SinkPad
|
SinkPad, the requested sink pad |
required |
Returns:
| Type | Description |
|---|---|
int
|
int, the earliest offset in the pad's buffer queue |
Source code in src/sgnts/base/base.py
input_prototype(sink_pad_name, dtype=None, device=None)
¶
A zero-length array in a sink pad's backend, for building output prototypes.
Returns namespace.zeros((0,), dtype=…, device=…) from the last complete
spec seen on sink pad sink_pad_name. dtype/device default to that
input's own; pass them to override (device only inside a Converter). Use
this inside :meth:output_prototype so namespace and device are inherited
from the data rather than hard-coded -- the reason a prototype is preferred
over constructing a SeriesDataSpec by hand.
Raises:
| Type | Description |
|---|---|
KeyError
|
if no complete spec has been seen yet on |
Source code in src/sgnts/base/base.py
internal()
¶
Align buffers from all the sink pads.
If AdapterConfig is provided, perform the requested overlap/stride streaming of frames.
Source code in src/sgnts/base/base.py
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | |
latest_by_pad(pad)
¶
The latest offset among the queued up buffers in this pad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SinkPad
|
SinkPad, the requested sink pad |
required |
Returns:
| Type | Description |
|---|---|
int
|
int, the latest offset in the pad's buffer queue |
Source code in src/sgnts/base/base.py
next_event_input()
¶
Get single EventFrame input.
Returns:
| Type | Description |
|---|---|
tuple[SinkPad, EventFrame]
|
EventFrame, the single EventFrame from inputs |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If there is not exactly one EventFrame input. |
Source code in src/sgnts/base/base.py
next_event_inputs()
¶
Get all EventFrame inputs based on input_frame_types configuration.
Returns:
| Type | Description |
|---|---|
dict[SinkPad, EventFrame]
|
dict[SinkPad, EventFrame], mapping of sink pads to EventFrame inputs |
Source code in src/sgnts/base/base.py
next_event_output()
¶
Get single EventFrame for output with offset/noffset from preparedoutoffsets.
Returns:
| Type | Description |
|---|---|
tuple[SourcePad, EventFrame]
|
EventFrame, an empty event frame ready to be populated |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If there is not exactly one event output pad. |
Source code in src/sgnts/base/base.py
next_event_outputs()
¶
Get all EventFrames for output pads configured as event outputs.
Creates EventFrame instances with offset/noffset from preparedoutoffsets for all source pads configured to produce EventFrame. The frames are automatically registered in self.outframes for return.
Returns:
| Type | Description |
|---|---|
dict[SourcePad, EventFrame]
|
dict[SourcePad, EventFrame], mapping of source pads to empty EventFrames |
Source code in src/sgnts/base/base.py
next_input()
¶
Convenience method - get single TSFrame input.
Equivalent to next_ts_input(). For transforms that only work with TSFrames.
Returns:
| Type | Description |
|---|---|
tuple[SinkPad, TSFrame]
|
TSFrame, single input frame |
Source code in src/sgnts/base/base.py
next_inputs()
¶
Convenience method - get all TSFrame inputs.
Equivalent to next_ts_inputs(). For transforms that only work with TSFrames.
Returns:
| Type | Description |
|---|---|
dict[SinkPad, TSFrame]
|
dict[SinkPad, TSFrame], dictionary of input frames |
Source code in src/sgnts/base/base.py
next_output()
¶
Convenience method - get single TSCollectFrame output.
Equivalent to next_ts_output(). For transforms that only work with TSFrames.
Note: Elements using this method must call .close() on the collector
when done populating buffers.
Returns:
| Type | Description |
|---|---|
tuple[SourcePad, TSCollectFrame]
|
tuple[SourcePad, TSCollectFrame], pad and collector for output frame |
Source code in src/sgnts/base/base.py
next_outputs()
¶
Convenience method - get all TSCollectFrame outputs.
Equivalent to next_ts_outputs(). For transforms that only work with TSFrames.
Note: Elements using this method must call .close() on each collector
when done populating buffers.
Returns:
| Type | Description |
|---|---|
dict[SourcePad, TSCollectFrame]
|
dict[SourcePad, TSCollectFrame], dictionary of collectors for output frames |
Source code in src/sgnts/base/base.py
next_ts_input()
¶
Get single TSFrame input.
Returns:
| Type | Description |
|---|---|
tuple[SinkPad, TSFrame]
|
TSFrame, the single TSFrame from inputs |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If there is not exactly one TSFrame input. |
Source code in src/sgnts/base/base.py
next_ts_inputs()
¶
Get all TSFrame inputs based on input_frame_types configuration.
Returns:
| Type | Description |
|---|---|
dict[SinkPad, TSFrame]
|
dict[SinkPad, TSFrame], mapping of sink pads to TSFrame inputs |
Source code in src/sgnts/base/base.py
next_ts_output()
¶
Get single TSCollectFrame for output with offsets from preparedoutoffsets.
Note: The caller must call .close() on the collector when done
populating buffers.
Returns:
| Type | Description |
|---|---|
SourcePad
|
tuple[SourcePad, TSCollectFrame], pad and collector for the output |
TSCollectFrame
|
frame |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If there is not exactly one TS output pad. |
Source code in src/sgnts/base/base.py
next_ts_outputs()
¶
Get all TSCollectFrames for output pads configured as TS outputs.
Creates TSFrame instances with offset/noffset from preparedoutoffsets, then creates TSCollectFrame collectors for atomic buffer population. The parent TSFrames are automatically registered in self.outframes.
Returns:
| Type | Description |
|---|---|
dict[SourcePad, TSCollectFrame]
|
dict[SourcePad, TSCollectFrame], mapping of source pads to collectors |
Source code in src/sgnts/base/base.py
output_prototype(pad)
¶
A zero-length example of what pad emits -- the one hook for telling
the framework an output's backend and dtype.
Real data describes itself ("the array is the backend"), so this is used
only to stamp this element's all-gap output frames. The framework reads
namespace, device and dtype off the returned array. Build it
from the inputs with :meth:input_prototype so the backend rides through
automatically and dtype/promotion follow the actual operation::
def output_prototype(self, pad):
# output dtype = result_type(input, factor); use your pad's name
return self.input_prototype(self.sink_pad_names[0]) * self.factor
Contract by role:
- Transform -- may change only dtype. The framework asserts the
returned prototype keeps the input's namespace+device; to change those
you must be a Converter (set
changes_backend = True). - Source -- has no inputs, so it returns a literal, e.g.
numpy.zeros(0)ortorch.zeros(0, dtype=torch.float16, device="cuda"). - Default (
None) -- "same backend and dtype as my input": the pass-through case, which is most transforms. Write nothing. Only well-defined while all inputs share one backend identity: an element combining different dtypes must declare, or preparing its output frames raisesBackendErroronce differing input specs are seen (see_output_hint).
Caveat -- an op that changes both shape and dtype (e.g. an FFT, real->complex) cannot be run on a length-0 array; declare the dtype instead of running the op::
return self.input_prototype(self.sink_pad_names[0], dtype=complex)
Returns:
| Type | Description |
|---|---|
'Array | None'
|
A zero-length array carrying the output's namespace/device/dtype, or |
'Array | None'
|
|
Source code in src/sgnts/base/base.py
pull(pad, frame)
¶
Pull data and queue for alignment.
Pull data from the input pads (source pads of upstream elements) and queue data to perform alignment once frames from all pads are pulled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SinkPad
|
SinkPad, The sink pad that is pulling the frame |
required |
frame
|
TimeSpanFrame
|
TimeSpanFrame, The frame that is pulled to sink pad |
required |
Source code in src/sgnts/base/base.py
timeout(pad)
¶
Whether pad has timed-out due to oldest buffer exceeding max age.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pad
|
SinkPad
|
SinkPad, the sink pad to check for timeout |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the pad has timed out |
Source code in src/sgnts/base/base.py
make_ts_element(sgn_element_class)
¶
Factory to create TS-enabled versions of SGN elements.
This provides a simple way to add TS capabilities to existing SGN elements so they can connect to TS pipelines. Uses a basic AdapterConfig() that works for most general-purpose applications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sgn_element_class
|
Type
|
SGN element class to enhance |
required |
Returns:
| Type | Description |
|---|---|
Type
|
New class that combines SGN element with TS capabilities |
Source code in src/sgnts/base/base.py
resolve_heartbeat_interval(heartbeat_interval)
¶
The bounded wait before a starved real-time source emits a heartbeat.
None means a quarter of the stride. float("inf") disables
heartbeats entirely: the source may stall the pipeline's graph loop
indefinitely, pinning every element at real time while it waits.