Cortical Labs API: Applications Models and Types
Overview
This module defines reusable types and Pydantic models used across applications for configuration and data representation. These types provide:
Annotated constraints: Type aliases with built-in validation to ensure parameter values stay within safe operational ranges (e.g., stimulation amplitudes between 0 (exclusive) to 3 (inclusive) µA, pulse widths in 20 µs steps).
Custom UI rendering: Special formatting hints for the web-based configuration editor, providing enhanced input controls like channel pickers and duration entries.
Frozen models: Immutable Pydantic models with strict validation that prevent accidental modification and ensure configuration integrity throughout application execution.
Key Categories
Base Models
FrozenBaseModel: Recommended base class for all configuration models, providing immutability and strict field validation.
Stimulation Types
Constrained types for defining electrical stimulation parameters within hardware limits:
StimAmplitudeMicroAmps: range (0.0, 3.0] µA in absolute termsStimPulseWidthMicroSeconds: range (0, 10000] µs in 20 µs stepsStimFrequencyHz: range (0.0, 200.0] HzStimmableChannel: Valid channel numbers (0-63, excluding 0, 4, 7, 56, 63)ChannelList: Lists of channels with custom picker UI
Important: Total charge delivered per stim pulse should not exceed 3 nC.
Composite Models
StimPulseComponentModel: Single-phase pulse definition with amplitude and widthStimDesignModel: Multi-component pulse designs with automatic validation and custom UIStimFrequencyRangeHzModel: Min/max frequency ranges with validationSizeIntModel: 2D integer dimensions for layouts and grids
General Types
DurationSeconds: A non-negative integer formatted as separate hours, minutes, and seconds entries in the config UI
These types streamline application development by handling validation, serialization, and providing a consistent interface to the configuration editor.
cl.app.model
A literal type representing all stimulatable channel numbers (0-63, excluding non-stimulatable channels: 0, 4, 7, 56, 63).
A stimulatable channel number, defined as an integer between 0 and 63, excluding the invalid channels: 0, 4, 7, 56, and 63.
An annotated version of STIMMABLE_CHANNELS with a name and description for use in Pydantic models.
A valid list of channel numbers, defined as a list containing between 1 and 59 valid channel numbers. This will be rendered with a custom interface in the config UI.
A valid stimulation amplitude, defined as a float greater than 0.0 and less than or equal to 3.0 microamperes. 1.0 microamperes is a commonly used default value.
A valid stimulation frequency, defined as a float greater than 0.0 and not more than 200.0 Hz.
A valid stimulation pulse width, defined as an integer greater than 0 and less than or equal to 10000 microseconds, in steps of 20 microseconds. 160 microseconds is a commonly used default value.
A positive integer representing a duration in seconds. This will be rendered with a custom HH:MM:SS format in the config UI.
A Pydantic BaseModel with frozen (immutable) instances, and extra fields forbidden.
This is the recommended base class for all configuration models and sub-models to be used to define application configurations, for maximum compatibility with the applications configuration web UI.
Base class for positive 2D integer size configurations.
A single component of a stimulation pulse, either a negative or positive leading-edge phase.
Configuration for a single stimulation design.
List of stimulation pulse components that make up the stimulation design. Must contain between 1 and 3 components.
A valid stimulation frequency range in Hz.