Class MockUltrasoundSource

Synthetic ultrasound frame source for testing the UltrasoundClassifier pipeline without real hardware connected. Generates class-conditional grayscale patterns so an actual model can learn to distinguish them.

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.

JSON configuration:

{
  "MockUltrasound": {
    "Type": "MockUltrasoundSource",
    "Inputs": [ "Clock" ],
    "DesiredRate": 30,
    "Params": [ 5, 224, 224, 0.05 ]
  }
}

Params:

IndexDescription
0NumClasses (int, default 5).
1FrameHeight (int, default 224) — pixel rows.
2FrameWidth (int, default 224) — pixel cols.
3NoiseLevel (double, default 0.05) — std-dev of additive Gaussian noise.

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

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

Overview: On each clock tick, the source emits one Matrix<double> of shape FrameHeight × FrameWidth with pixel values in [0, 1]. The content depends on CurrentClass, an integer in [0, NumClasses) that you can change at runtime (e.g. via a Trigger block driving the same value). Each class corresponds to a deterministic spatial pattern — vertical gradient, horizontal gradient, central blob, diagonal stripes, checkerboard — plus a small amount of Gaussian noise so the frames aren't pixel-identical between ticks.

Source block: Driven by an upstream ClockBlock (the tNow double timestamp is used to seed the noise).

Typical use: place a ClockBlock at 30 Hz, this source after it, the classifier downstream, and a TriggerBuffer alongside collecting labelled segments — the same way you'd wire real ultrasound data. Cycle CurrentClass through values 0..NumClasses-1 to record fake training data; train the network; verify the predictor learns the patterns.

Constructors

MockUltrasoundSource(string, double, int, int, int, double)

Declaration
public MockUltrasoundSource(string name = "MockUltrasound", double desiredRate = 30, int numClasses = 5, int frameHeight = 224, int frameWidth = 224, double noiseLevel = 0.05)
Parameters
Type Name Description
string name
double desiredRate
int numClasses
int frameHeight
int frameWidth
double noiseLevel

Fields

_currentClass

Index of the synthetic class to render this tick. Settable at runtime — drive this from a Trigger or UI slider to switch the "gesture" being produced. Clamped to [0, NumClasses).

Declaration
[ObservableProperty]
private int _currentClass
Field Value
Type Description
int

_frameCount

Total frames emitted so far (informational, for the card UI).

Declaration
[ObservableProperty]
private long _frameCount
Field Value
Type Description
long

_frameHeight

Generated frame height in pixels.

Declaration
[ObservableProperty]
private int _frameHeight
Field Value
Type Description
int

_frameWidth

Generated frame width in pixels.

Declaration
[ObservableProperty]
private int _frameWidth
Field Value
Type Description
int

_latestWeights

Cached activation vector from the upstream weight source. Held across ticks so that frame emission can blend even when the weight source runs at a different rate than the clock (hold-last behaviour).

Declaration
private Vector<double>? _latestWeights
Field Value
Type Description
Vector<double>

_noiseLevel

Std-dev of additive Gaussian noise applied to each frame.

Declaration
[ObservableProperty]
private double _noiseLevel
Field Value
Type Description
double

_numClasses

Number of distinguishable synthetic classes.

Declaration
[ObservableProperty]
private int _numClasses
Field Value
Type Description
int

_patterns

Per-class base pattern, precomputed once at construction. Each row of this matrix is the row-major pixel buffer for one class's template; noise is added per-frame on top of the chosen template.

Declaration
private double[][] _patterns
Field Value
Type Description
double[][]

_rng

PRNG for the per-frame noise.

Declaration
private readonly Random _rng
Field Value
Type Description
Random

_sweepFrequencyHz

Frequency for the internal sweep generator (Sweep). Each channel uses sin²(2π·f·t + i·2π/N), so the channels phase-shift around the circle and the full pattern set is exercised across one period.

Declaration
[ObservableProperty]
private double _sweepFrequencyHz
Field Value
Type Description
double

_sweepStartTicks

Wall-clock anchor for the internal sweep generator.

Declaration
private readonly long _sweepStartTicks
Field Value
Type Description
long

_weightSource

In weighted mode, selects which input drives the per-pattern blend: upstream Vector messages (training), manual slider values (precise testing), or an internal sine-bank generator (hands-free demo).

Declaration
[ObservableProperty]
private WeightSource _weightSource
Field Value
Type Description
WeightSource

_weightedMode

When true, frame generation blends all pattern templates weighted by the most recently received upstream activation vector (_latestWeights) instead of selecting a single template by CurrentClass. Useful for testing regression pipelines where the image must be a continuous function of the regression target — e.g. driven by a SinGenerator producing per-channel activations.

Declaration
[ObservableProperty]
private bool _weightedMode
Field Value
Type Description
bool
Remarks

In weighted mode the source needs two inputs: a clock (for timing) and a Vector source (for weights). Wire the activation source as a second input alongside the clock; the block distinguishes them by message type (Vector → weight update; anything else → clock tick → emit frame).

Properties

CurrentClass

Index of the synthetic class to render this tick. Settable at runtime — drive this from a Trigger or UI slider to switch the "gesture" being produced. Clamped to [0, NumClasses).

Declaration
[ExcludeFromCodeCoverage]
public int CurrentClass { get; set; }
Property Value
Type Description
int

DumpFilePrefix

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

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

FrameCount

Total frames emitted so far (informational, for the card UI).

Declaration
[ExcludeFromCodeCoverage]
public long FrameCount { get; set; }
Property Value
Type Description
long

FrameHeight

Generated frame height in pixels.

Declaration
[ExcludeFromCodeCoverage]
public int FrameHeight { get; set; }
Property Value
Type Description
int

FrameWidth

Generated frame width in pixels.

Declaration
[ExcludeFromCodeCoverage]
public int FrameWidth { get; set; }
Property Value
Type Description
int

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

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

ManualChannels

Per-channel manual weight items, bound to sliders in the card view when WeightSource is Manual. Resized automatically when NumClasses changes.

Declaration
public ObservableCollection<ManualChannelItem> ManualChannels { get; }
Property Value
Type Description
ObservableCollection<ManualChannelItem>

NoiseLevel

Std-dev of additive Gaussian noise applied to each frame.

Declaration
[ExcludeFromCodeCoverage]
public double NoiseLevel { get; set; }
Property Value
Type Description
double

NumClasses

Number of distinguishable synthetic classes.

Declaration
[ExcludeFromCodeCoverage]
public int NumClasses { get; set; }
Property Value
Type Description
int

SweepFrequencyHz

Frequency for the internal sweep generator (Sweep). Each channel uses sin²(2π·f·t + i·2π/N), so the channels phase-shift around the circle and the full pattern set is exercised across one period.

Declaration
[ExcludeFromCodeCoverage]
public double SweepFrequencyHz { get; set; }
Property Value
Type Description
double

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

Visualization scope for the generated frames.

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

WeightSource

In weighted mode, selects which input drives the per-pattern blend: upstream Vector messages (training), manual slider values (precise testing), or an internal sine-bank generator (hands-free demo).

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

WeightedMode

When true, frame generation blends all pattern templates weighted by the most recently received upstream activation vector (_latestWeights) instead of selecting a single template by CurrentClass. Useful for testing regression pipelines where the image must be a continuous function of the regression target — e.g. driven by a SinGenerator producing per-channel activations.

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

In weighted mode the source needs two inputs: a clock (for timing) and a Vector source (for weights). Wire the activation source as a second input alongside the clock; the block distinguishes them by message type (Vector → weight update; anything else → clock tick → emit frame).

Methods

BuildTemplate(int, int)

Pick or build the base template for this frame, before noise. Label mode returns the single template indexed by CurrentClass; weighted mode picks a weight source — upstream Vector, manual sliders, or internal sweep — and blends the per-class templates by those weights. Weights are clamped to [0, 1] so the composite stays in pixel range.

Declaration
private double[]? BuildTemplate(int h, int w)
Parameters
Type Name Description
int h
int w
Returns
Type Description
double[]

ComputeSweepWeights()

Compute the synthetic per-channel activation vector for Sweep mode. Each channel uses sin²(2π·f·t + i·2π/N) so the bank sweeps with a complete phase rotation across the channels — every two-finger and rest-only combination appears at some point in the cycle.

Declaration
private Vector<double> ComputeSweepWeights()
Returns
Type Description
Vector<double>

ConfigureInput(IServiceProvider, JsonModel)

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

Dispose()

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

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

FillPattern(double[], int, int, int)

Fill buf (row-major, h × w) with the deterministic pattern for class cls. Values are normalised to [0, 1].

Declaration
private static void FillPattern(double[] buf, int cls, int h, int w)
Parameters
Type Name Description
double[] buf
int cls
int h
int w

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

ManualWeightsAsVector()

Snapshot ManualChannels values as a Vector.

Declaration
private Vector<double> ManualWeightsAsVector()
Returns
Type Description
Vector<double>

OnCurrentClassChanged(int)

Executes the logic for when CurrentClass just changed.

Declaration
private void OnCurrentClassChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

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

OnCurrentClassChanged(int, int)

Executes the logic for when CurrentClass just changed.

Declaration
private void OnCurrentClassChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

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

OnCurrentClassChanging(int)

Executes the logic for when CurrentClass is changing.

Declaration
private void OnCurrentClassChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

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

OnCurrentClassChanging(int, int)

Executes the logic for when CurrentClass is changing.

Declaration
private void OnCurrentClassChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

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

OnFrameCountChanged(long)

Executes the logic for when FrameCount just changed.

Declaration
private void OnFrameCountChanged(long value)
Parameters
Type Name Description
long value

The new property value that was set.

Remarks

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

OnFrameCountChanged(long, long)

Executes the logic for when FrameCount just changed.

Declaration
private void OnFrameCountChanged(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that was replaced.

long newValue

The new property value that was set.

Remarks

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

OnFrameCountChanging(long)

Executes the logic for when FrameCount is changing.

Declaration
private void OnFrameCountChanging(long value)
Parameters
Type Name Description
long value

The new property value being set.

Remarks

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

OnFrameCountChanging(long, long)

Executes the logic for when FrameCount is changing.

Declaration
private void OnFrameCountChanging(long oldValue, long newValue)
Parameters
Type Name Description
long oldValue

The previous property value that is being replaced.

long newValue

The new property value being set.

Remarks

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

OnFrameHeightChanged(int)

Executes the logic for when FrameHeight just changed.

Declaration
private void OnFrameHeightChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

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

OnFrameHeightChanged(int, int)

Executes the logic for when FrameHeight just changed.

Declaration
private void OnFrameHeightChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

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

OnFrameHeightChanging(int)

Executes the logic for when FrameHeight is changing.

Declaration
private void OnFrameHeightChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

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

OnFrameHeightChanging(int, int)

Executes the logic for when FrameHeight is changing.

Declaration
private void OnFrameHeightChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

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

OnFrameWidthChanged(int)

Executes the logic for when FrameWidth just changed.

Declaration
private void OnFrameWidthChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

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

OnFrameWidthChanged(int, int)

Executes the logic for when FrameWidth just changed.

Declaration
private void OnFrameWidthChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

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

OnFrameWidthChanging(int)

Executes the logic for when FrameWidth is changing.

Declaration
private void OnFrameWidthChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

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

OnFrameWidthChanging(int, int)

Executes the logic for when FrameWidth is changing.

Declaration
private void OnFrameWidthChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

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

OnNoiseLevelChanged(double)

Executes the logic for when NoiseLevel just changed.

Declaration
private void OnNoiseLevelChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

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

OnNoiseLevelChanged(double, double)

Executes the logic for when NoiseLevel just changed.

Declaration
private void OnNoiseLevelChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

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

OnNoiseLevelChanging(double)

Executes the logic for when NoiseLevel is changing.

Declaration
private void OnNoiseLevelChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

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

OnNoiseLevelChanging(double, double)

Executes the logic for when NoiseLevel is changing.

Declaration
private void OnNoiseLevelChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

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

OnNumClassesChanged(int)

Executes the logic for when NumClasses just changed.

Declaration
private void OnNumClassesChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

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

OnNumClassesChanged(int, int)

Executes the logic for when NumClasses just changed.

Declaration
private void OnNumClassesChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

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

OnNumClassesChanging(int)

Executes the logic for when NumClasses is changing.

Declaration
private void OnNumClassesChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

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

OnNumClassesChanging(int, int)

Executes the logic for when NumClasses is changing.

Declaration
private void OnNumClassesChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

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

OnReceive(object, object)

Routes incoming messages:

  • Vector<double> → cache as the latest activation weights for weighted mode. Does not trigger a frame emission — the clock drives that. Useful when the weight source's rate doesn't match the clock's; the cache acts as hold-last interpolation.
  • Anything else (typically a clock tick — double timestamp) → emit one frame using the current mode's blending rule.
Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender
object data
Overrides
BaseBlock.OnReceive(object, object)

OnSweepFrequencyHzChanged(double)

Executes the logic for when SweepFrequencyHz just changed.

Declaration
private void OnSweepFrequencyHzChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

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

OnSweepFrequencyHzChanged(double, double)

Executes the logic for when SweepFrequencyHz just changed.

Declaration
private void OnSweepFrequencyHzChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

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

OnSweepFrequencyHzChanging(double)

Executes the logic for when SweepFrequencyHz is changing.

Declaration
private void OnSweepFrequencyHzChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

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

OnSweepFrequencyHzChanging(double, double)

Executes the logic for when SweepFrequencyHz is changing.

Declaration
private void OnSweepFrequencyHzChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

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

OnWeightSourceChanged(WeightSource)

Executes the logic for when WeightSource just changed.

Declaration
private void OnWeightSourceChanged(WeightSource value)
Parameters
Type Name Description
WeightSource value

The new property value that was set.

Remarks

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

OnWeightSourceChanged(WeightSource, WeightSource)

Executes the logic for when WeightSource just changed.

Declaration
private void OnWeightSourceChanged(WeightSource oldValue, WeightSource newValue)
Parameters
Type Name Description
WeightSource oldValue

The previous property value that was replaced.

WeightSource newValue

The new property value that was set.

Remarks

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

OnWeightSourceChanging(WeightSource)

Executes the logic for when WeightSource is changing.

Declaration
private void OnWeightSourceChanging(WeightSource value)
Parameters
Type Name Description
WeightSource value

The new property value being set.

Remarks

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

OnWeightSourceChanging(WeightSource, WeightSource)

Executes the logic for when WeightSource is changing.

Declaration
private void OnWeightSourceChanging(WeightSource oldValue, WeightSource newValue)
Parameters
Type Name Description
WeightSource oldValue

The previous property value that is being replaced.

WeightSource newValue

The new property value being set.

Remarks

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

OnWeightedModeChanged(bool)

Executes the logic for when WeightedMode just changed.

Declaration
private void OnWeightedModeChanged(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 WeightedMode is changed.

OnWeightedModeChanged(bool, bool)

Executes the logic for when WeightedMode just changed.

Declaration
private void OnWeightedModeChanged(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 WeightedMode is changed.

OnWeightedModeChanging(bool)

Executes the logic for when WeightedMode is changing.

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

The new property value being set.

Remarks

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

OnWeightedModeChanging(bool, bool)

Executes the logic for when WeightedMode is changing.

Declaration
private void OnWeightedModeChanging(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 WeightedMode is changed.

RebuildManualChannels()

Resize ManualChannels to match NumClasses, preserving the current values where indices overlap. New entries are added at zero so a "Manual" override doesn't suddenly flash a channel to active when NumClasses grows.

Declaration
private void RebuildManualChannels()

RebuildPatterns()

Precompute one grayscale template per class. Six patterns are defined; if NumClasses exceeds six, additional classes are generated by varying the diagonal stripe period — they remain deterministic and distinguishable.

Declaration
private void RebuildPatterns()

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.