Source code for hetero.stims.elementary

import numpy as np

[docs] def null(n_timesteps: int, **kwargs: dict) -> np.ndarray: """Generats a null (zero) stimulus. Parameters ---------- n_timesteps : int Number of timesteps to generate. Returns ------- np.ndarray of shape (n_timesteps, 1) A zero 1-dimensional array. """ return np.zeros(size=(n_timesteps, 1), dtype=float)
[docs] def sin(n_timesteps: int, h: float = 0.05, freq: float = 1., phase: float = 0.) -> np.ndarray: """Generates a sinusoidal input of given frequency. Parameters ---------- n_timesteps : int Number of timesteps to generate. h : float, optional Time delta between two discrete timesteps, by default 0.05. freq : float, optional Oscillation frequency, by default 1. phase : float, optional Oscillation starting phase in radian, by default 0. Returns ------- np.ndarray of shape (n_timesteps, 1) A 1-dimensional array. """ if phase == 0: phase += 1e-6 # for numerical stability of autocorr ts = np.linspace(0, n_timesteps*h, n_timesteps, endpoint=False) return np.sin(2*np.pi*freq * ts + phase).reshape(n_timesteps, 1)
[docs] def sign(n_timesteps: int, h: float = 0.05, freq: float = 1., phase: float = 0.) -> np.ndarray: """Generates a signal that is the sign of a sinusoidal input of given frequency. Parameters ---------- n_timesteps : int Number of timesteps to generate. h : float, optional Time delta between two discrete timesteps, by default 0.05. freq : float, optional Oscillation frequency, by default 1. phase : float, optional Oscillation starting phase in radian, by default 0. Returns ------- np.ndarray of shape (n_timesteps, 1) A 1-dimensional array. """ if phase == 0: phase += 1e-6 # for numerical stability of autocorr ts = np.linspace(0, n_timesteps*h, n_timesteps, endpoint=False) return np.sign(np.sin(2*np.pi*freq * ts + phase)).reshape(n_timesteps, 1)
[docs] def sinabs(n_timesteps: int, h: float = 0.05, freq: float = 1., phase: float = 0.) -> np.ndarray: """Generates the abs of a sinusoidal input of given frequency. Parameters ---------- n_timesteps : int Number of timesteps to generate. h : float, optional Time delta between two discrete timesteps, by default 0.05. freq : float, optional Oscillation frequency, by default 1. phase : float, optional Oscillation starting phase in radian, by default 0. Returns ------- np.ndarray of shape (n_timesteps, 1) A 1-dimensional array. """ if phase == 0: phase += 1e-6 # for numerical stability of autocorr ts = np.linspace(0, n_timesteps*h, n_timesteps, endpoint=False) return np.abs(np.sin(2*np.pi*freq * ts + phase)).reshape(n_timesteps, 1)
[docs] def constant(n_timesteps: int, amplitude: float = 1., h: float = 0.05, **kwargs: dict) -> np.ndarray: """Generates a constant amplitude input Parameters ---------- n_timesteps : int Number of timesteps to generate. amplitude : float, optional Input amplitude. h : float, optional Time delta between two discrete timesteps, by default 0.05. (unused: a constant input does not depend on time) Returns ------- np.ndarray of shape (n_timesteps, 1) A 1-dimensional array. """ return np.ones((n_timesteps, 1), dtype=float) * amplitude