Amplifier Source
- class gpype.backend.sources.base.amplifier_source.AmplifierSource[source]
Bases:
SourceBase class for amplifier-based data acquisition sources.
Provides hardware device management, sampling rate configuration, and multi-channel data acquisition setup for BCI applications.
Not every amplifier numbers its samples in band, and the asymmetry is deliberate rather than an oversight – it reads like one, so:
BCI Core-8 appends an INDEX and a QUALITY channel to every frame, so its stream carries its own position. It can, because the BLE driver reports a per-sample counter and a validity flag, which is what makes loss visible: a gap in the numbering is the only evidence that samples never arrived.
The GDS amplifiers have no equivalent. Their counter replaces a measured channel rather than adding one (channel 1 on g.HIamp, channel 16 on g.USBamp, and there only when all 16 are acquired), it is appended only on g.Nautilus, and it overruns at 1,000,000 rather than at
channels.INDEX_MODULUS. So an index for them could only be synthesised by counting arrivals here – which is exactlyMasterPriority.COUNTED: a valid timeline, but not a loss-aware one, and dressing it as DEVICE would claim an accuracy it does not have while costing a real electrode.They therefore reach Sync as counted streams and are numbered there. Both families drive the timeline identically regardless: whoever holds mastership feeds the estimator, and Sync fills in when the holder is in another process. See Sync._report.
- class Configuration[source]
Bases:
ConfigurationConfiguration class for AmplifierSource parameters.
- class Keys[source]
Bases:
KeysConfiguration keys for amplifier source settings.
- SAMPLING_RATE = 'sampling_rate'
Sampling rate configuration key
- ENABLE_OSCAR = 'enable_oscar'
Whether OSCAR artifact removal runs on this stream
- __init__(sampling_rate, **kwargs)[source]
Initialize configuration with sampling rate validation.
- Parameters:
sampling_rate (
float) – Sampling rate in Hz. Must be positive or Constants.INHERITED for runtime determination.**kwargs – Additional configuration parameters.
- Raises:
ValueError – If sampling_rate is not positive and not INHERITED.
- STREAM_WATCH_INTERVAL_S = 0.5
How often a running source asks its driver whether acquisition has ended on an error, in seconds. See _start_stream_watch.
- attach_timeline(timeline)[source]
Bind this source to the pipeline’s timeline.
- Parameters:
timeline – Timeline manager owned by the pipeline.
- Return type:
- __init__(sampling_rate, channel_count, frame_size, enable_oscar=False, **kwargs)[source]
Initialize amplifier source with acquisition parameters.
- Parameters:
sampling_rate (
float) – Sampling rate in Hz. Must be positive or Constants.INHERITED for runtime determination.channel_count (
int) – Number of data channels to acquire.frame_size (
int) – Number of samples per data frame.enable_oscar (
bool) – Run OSCAR artifact removal on this stream. A real typed parameter on the class that is actually constructed, so it is recognised, catalogued and serialised – which is what makesGNautilus(enable_oscar=True)silently building no OSCAR structurally impossible rather than merely unlikely. Seemiddle_nodes.**kwargs – Additional arguments for parent Source class.
- property oscar_delay_samples
OSCAR’s total added delay, in samples at the input rate.
None where this amplifier was not built with
enable_oscar, and None before the pipeline’sstart()has run OSCAR’s ownsetup()– the delay is a property of the fitted model, not of the configuration, so it cannot be known any earlier. Once set, it is exact: gtec_oscar’s owndelay_samples_input_fs, notK, the decimation factor that at 250 Hz reads 2 while the real delay is 83 samples (seeOscar.setup, D-NODE-65).- Returns:
The delay, or None.
- middle_nodes()[source]
Nodes this amplifier wants between its Link and its Sync.
The OSCAR slot, and the one part of a source’s shape the wrapper cannot derive from a port or a configuration key – because it holds nodes, not a boolean. wrapping.SourceChain asks every core it carries; only an amplifier answers with anything.
The position is load-bearing in both directions, and
assembly.source_nodesrecords why: before Sync, because the model still needs the in-bandmaster_index,validandhost_timechannels that Sync consumes; after Link, because a sending Link returns nothing, so the work lands on the server.- Return type:
- Returns:
[Oscar()]where this amplifier was asked for artifact removal, otherwise nothing.
- open_for_attestation()[source]
Open the device early, so the entitlement gate can challenge it.
Default: reopen a handle a previous
stop()released, where the source recorded how (_device_factory, the GDS sources), and otherwise do nothing. A source that cannot open its handle cheaply, or has not been taught to, is left exactly as it was – so adding this hook can only make a gate verdict more informed, never less.The GDS sources need only the reopen. They open their device in the constructor, so the gate finds a handle on a first start – the bench recorded
FULLfor a g.USBamp, a g.HIamp and a g.Nautilus on 2026-09-24. Butstop()releases it andstart()reopened it only after the gate, so a pipeline started a second time was resolved with no handle and marked.Why it exists. Pipeline.start() resolves both entitlement gates before any node starts, and it is right to: a sink writes its header at start(), so a verdict reached later would stamp the wrong mark into the artifact, silently. But the device gate challenges self._device, and every amplifier opens its handle inside its own start() – which runs after the gate. So the challenge list was empty by construction, every run.
Measured 2026-09-06 on a BCI Core-8: a streaming, attestable amplifier on a licensed machine still resolved attestation: limited, reason “no g.tec amplifier in this pipeline” – evaluate()’s empty-list branch – while the same handle challenged by hand answered verified=True, detail=OK. Zero challenges were issued during start().
_begin_deferred_device_check’s docstring already states the intended behaviour: “The amplifier is a source. Its handle is challenged inside start(), before any sink writes a header. Blocking is right: the pipeline has nothing to do until the device answers anyway.” This hook is what makes that true.
Implement it only where the open is idempotent. Every implementation must be safe to call twice, because the source’s own start() will run afterwards and must reuse the handle rather than open a second one – an amplifier is an exclusive resource and a second handle is refused.
Never raises. A device that cannot be opened here is not a licensing decision: the run continues unattested and the source’s own start() reports the failure properly, with its own error type and message. Swallowing it here would replace a clear connection error with a confusing entitlement one.
- Return type:
- device_serial()[source]
Return the serial of the device this source actually opened.
Prefers the open handle over the stored configuration, because they answer different questions: the configuration says which device was asked for, and for
serial=None– the common case – that is nothing at all, while the handle knows which one answered.- Return type:
- Returns:
The serial, or “” when no device is open and none was configured. Never raises: this runs on the setup path, and a source with no serial to report is a normal state rather than an error.
- channel_units()[source]
Physical unit of each channel this source emits, or None.
Beside
device_serial(): a hook a concrete amplifier overrides, read once its ownsetup()has resolved the final channel layout – the measured channels plus whatever extras are enabled plus the appended arrival-stamp channel – so the list this returns has one entry per channel of that layout, not of the configuredchannel_countalone.The base implementation declares nothing, which is what every amplifier did before this existed. An override must read its numbers from the driver’s own documented scaling (a vendor header, an SDK constant), never from memory: a wrong unit is worse than none, because it is believed. A channel with no fixed physical unit – a bit-encoded flag, a validity indicator – is None, same as one this method simply does not know.
- master_candidacy()[source]
Claim as a device.
An amplifier is the better clock in any pipeline containing one, and it must win regardless of how fast it starts producing.
- Returns:
(rate, DEVICE), or None if no usable rate is set.