perturbation

classes.perturbation

Exogenous stimuli for simulation experiments.

The public import location for :class:Stimulus, alongside the helpers that build one from an ontology class or from an audio file.

There is no wrapper class: the stimulus’s own methods live in :mod:tvbo.behaviour.perturbation and are attached to the generated class itself, so a stimulus carries them however it was built.

Functions

Name Description
class2metadata Build Stimulus metadata from an ontology stimulus class.
load_acoustic_stimulus_from_audiofile Load an audio file as a callable stimulus time course.

class2metadata

classes.perturbation.class2metadata(ontoclass)

Build Stimulus metadata from an ontology stimulus class.

Reads the class’s defining equation. The class name (identifier) and definition become the stimulus label and description, and every descendant Parameter is added with its default value and definition.

Parameters

Name Type Description Default
ontoclass An owlready2 stimulus class whose value, definition and parameter descendants describe the perturbation. required

Returns

Name Type Description
A datamodel Stimulus populated with the equation and parameters read
from the ontology class.

load_acoustic_stimulus_from_audiofile

classes.perturbation.load_acoustic_stimulus_from_audiofile(
    file_path,
    sampling_rate=1000,
    duration='full',
)

Load an audio file as a callable stimulus time course.

Loads the waveform, resamples it to sampling_rate, normalises it to the [-1, 1] range, optionally truncates it to duration, and fits a smoothing spline over time (in milliseconds).

Parameters

Name Type Description Default
file_path Path to the audio file to read (any format librosa supports). required
sampling_rate Target sampling rate in Hz used for resampling and for converting sample indices to milliseconds. 1000
duration "full" to keep the whole signal, or a length in milliseconds to truncate it to. 'full'

Returns

Name Type Description
A function of time (in milliseconds) that evaluates the interpolated,
normalised audio amplitude and returns 0 outside the signal’s span.

Raises

Name Type Description
ImportError If the optional librosa dependency is not installed.