Class ChannelSelector

Selects or filters channels from an input vector or matrix. Inactive channels can either be set to zero or removed from the output.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

Block entry for a larger pipeline. Params is not used. Select active channels on the card or through the channel-selection API; the channel mask is not restored from this JSON.

{
  "ChannelSelector": {
    "Type": "channelselector",
    "Inputs": ["Signal"]
  }
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
ChannelSelector
Inherited Members
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public class ChannelSelector : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Modes:

  • Zero mode (DeleteChannel=false): Inactive channels output 0
  • Delete mode (DeleteChannel=true): Inactive channels are removed from output

Input types:

  • MathNet.Numerics.LinearAlgebra.Vector<T>: Each element is one channel.
  • MathNet.Numerics.LinearAlgebra.Matrix<T> [timesteps × channels]: Each column is one channel. The activation mask is applied column-wise. In delete mode, inactive columns are removed; in zero mode, inactive columns are zeroed.

Thread-safe for concurrent access to channel activations.

Constructors

ChannelSelector(string, double)

Declaration
public ChannelSelector(string name, double desiredRate = 0)
Parameters
Type Name Description
string name
double desiredRate

Fields

_channelActivations

Declaration
private bool[] _channelActivations
Field Value
Type Description
bool[]

_deleteChannel

Gets or sets whether inactive channels should be deleted (true) or set to zero (false).

Declaration
[ObservableProperty]
private bool _deleteChannel
Field Value
Type Description
bool

_deleteModeBuffer

Declaration
private readonly List<double> _deleteModeBuffer
Field Value
Type Description
List<double>

_lock

Declaration
private readonly object _lock
Field Value
Type Description
object

_numberOfChannels

Declaration
private int _numberOfChannels
Field Value
Type Description
int

_zeroModeBuffer

Declaration
private double[]? _zeroModeBuffer
Field Value
Type Description
double[]

Properties

ActiveChannelCount

Gets the number of currently active channels.

Declaration
public int ActiveChannelCount { get; }
Property Value
Type Description
int

ChannelActivations

Gets the current channel activation states.

Declaration
public IReadOnlyList<bool> ChannelActivations { get; }
Property Value
Type Description
IReadOnlyList<bool>

DeleteChannel

Gets or sets whether inactive channels should be deleted (true) or set to zero (false).

Declaration
[ExcludeFromCodeCoverage]
public bool DeleteChannel { get; set; }
Property Value
Type Description
bool

DumpFilePrefix

Recordings from this block are named <block>_selected.csv.

Declaration
protected override string DumpFilePrefix { get; }
Property Value
Type Description
string
Overrides
BaseBlock.DumpFilePrefix

NumberOfChannels

Gets the number of channels detected from the input.

Declaration
public int NumberOfChannels { get; private set; }
Property Value
Type Description
int

OutputDimension

Gets the output dimension based on current settings.

Declaration
public int OutputDimension { get; }
Property Value
Type Description
int

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
Remarks

Blocks own their scope as a public Viz property rather than inheriting one, so the base class has no way to reach it. Overriding this is what lets the rate below be wired up automatically. With correct publication metadata, the bundle derives the time axis for one vector per publication or fixed-size contiguous sample packets from the feed shape.

When a plot needs a rate that publication frequency and feed shape cannot express (for example, variable-sized packets or overlapping windows), declare it with Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block with several bundles must configure each one; this hook exposes only one bundle.

Viz

Scope for visualizing the output signal.

Declaration
public BlockVisualization Viz { get; }
Property Value
Type Description
BlockVisualization

Methods

ConfigureInput(IServiceProvider, JsonModel)

Declaration
public static ChannelSelector ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
ChannelSelector

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

EnsureChannelCount(int)

Detects channel count changes and resizes the activation array, preserving existing activations where possible.

Declaration
private void EnsureChannelCount(int channelCount)
Parameters
Type Name Description
int channelCount

GenerateMatrixOutput(Matrix<double>)

Applies the channel activation mask to a [timesteps × channels] matrix. In delete mode, inactive columns are removed. In zero mode, they are zeroed.

Declaration
private Matrix<double> GenerateMatrixOutput(Matrix<double> input)
Parameters
Type Name Description
Matrix<double> input
Returns
Type Description
Matrix<double>

GenerateVectorOutput(Vector<double>)

Declaration
private Vector<double> GenerateVectorOutput(Vector<double> input)
Parameters
Type Name Description
Vector<double> input
Returns
Type Description
Vector<double>

IsChannelActive(int)

Gets whether a specific channel is active.

Declaration
public bool IsChannelActive(int index)
Parameters
Type Name Description
int index
Returns
Type Description
bool

OnDeleteChannelChanged(bool)

Executes the logic for when DeleteChannel just changed.

Declaration
private void OnDeleteChannelChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of DeleteChannel is changed.

OnDeleteChannelChanged(bool, bool)

Executes the logic for when DeleteChannel just changed.

Declaration
private void OnDeleteChannelChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of DeleteChannel is changed.

OnDeleteChannelChanging(bool)

Executes the logic for when DeleteChannel is changing.

Declaration
private void OnDeleteChannelChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of DeleteChannel is changed.

OnDeleteChannelChanging(bool, bool)

Executes the logic for when DeleteChannel is changing.

Declaration
private void OnDeleteChannelChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of DeleteChannel is changed.

OnReceive(object, object?)

Processes incoming data from an upstream block. Must be implemented by derived classes.

Declaration
protected override void OnReceive(object sender, object? value)
Parameters
Type Name Description
object sender

The publishing block, or whatever else delivered the value.

object value

The payload. Blocks are wired by config rather than by type, so an implementation has to check the run-time type and reject or handle a shape it cannot use. Status is updated automatically from publication activity; it is not a per-value validation result.

Overrides
BaseBlock.OnReceive(object, object)
Remarks

Called on the dispatching thread, not the UI thread.

SetAllChannels(bool)

Sets all channels to active or inactive.

Declaration
public void SetAllChannels(bool active)
Parameters
Type Name Description
bool active

SetChannel(int, bool)

Sets a specific channel's activation state.

Declaration
public void SetChannel(int index, bool active)
Parameters
Type Name Description
int index
bool active

ToggleChannel(int)

Toggles a specific channel's activation state.

Declaration
public void ToggleChannel(int index)
Parameters
Type Name Description
int index

UpdateChannelActivations(IEnumerable<bool>)

Updates the activation state of each channel.

Declaration
public void UpdateChannelActivations(IEnumerable<bool> activations)
Parameters
Type Name Description
IEnumerable<bool> activations

Events

ActivationsChanged

Event raised when channel activations change.

Declaration
public event Action? ActivationsChanged
Event Type
Type Description
Action

NumberOfChannelsChanged

Event raised when the number of channels changes.

Declaration
public event Action<int>? NumberOfChannelsChanged
Event Type
Type Description
Action<int>

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.