Ephys Modules API
This section details the pipeline for processing electrophysiological data (Neuralynx/ONIX).
Ephys Data Manager
ace_neuro.ephys.ephys_data_manager.EphysDataManager
Bases: ABC
Abstract base class for ephys data managers. Manages the import of raw ephys data and processes it into channels. Stores the processed channels in self.channels, where the key is the channel name and the value is a Channel object.
Source code in src/ace_neuro/ephys/ephys_data_manager.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
__init__(ephys_directory=None, auto_import_ephys_block=True, auto_process_block=True, auto_compute_phases=True, level='CRITICAL', channels=None, remove_artifacts=False)
Initialize the EphysDataManager and optionally load data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ephys_directory
|
Optional[Union[str, Path]]
|
Path to directory containing ephys data. |
None
|
auto_import_ephys_block
|
bool
|
If True, automatically import raw ephys data. |
True
|
auto_process_block
|
bool
|
If True, automatically process block into channels. |
True
|
auto_compute_phases
|
bool
|
If True, automatically compute phase for all channels. |
True
|
level
|
Union[str, int]
|
Logging level string. |
'CRITICAL'
|
channels
|
Optional[List[str]]
|
Channel names to process (optional). |
None
|
remove_artifacts
|
bool
|
If True, apply artifact removal during processing. |
False
|
Source code in src/ace_neuro/ephys/ephys_data_manager.py
can_handle(directory)
abstractmethod
classmethod
Return True if this class can handle the format in the given directory.
compute_phase(channel)
Compute instantaneous phase using Hilbert transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Channel
|
Channel object with signal data. |
required |
Returns:
| Type | Description |
|---|---|
Channel
|
Channel object with phases attribute populated. |
Source code in src/ace_neuro/ephys/ephys_data_manager.py
compute_phases_all_channels()
Compute instantaneous phase for all loaded channels.
create(ephys_directory, **kwargs)
classmethod
Factory method to create the appropriate subclasses for the directory.
Source code in src/ace_neuro/ephys/ephys_data_manager.py
filter_ephys(channel_name, n=2, cut=[0.5, 4], ftype='butter', btype='bandpass', replace_signal=True)
Apply a frequency filter to a channel's signal.
Supports FIR and Butterworth filter types with configurable cutoff frequencies and band types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_name
|
str
|
Name of the channel to filter. |
required |
n
|
int
|
Filter order (Butterworth) or number of taps (FIR). |
2
|
cut
|
Union[float, List[float], ndarray]
|
Cutoff frequency or [low, high] for bandpass. |
[0.5, 4]
|
ftype
|
str
|
Filter type ('butter', 'butterworth', or 'fir'). |
'butter'
|
btype
|
str
|
Band type ('low', 'high', 'band', 'bandpass'). |
'bandpass'
|
replace_signal
|
bool
|
If True, overwrite signal; else store in signal_filtered. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Filtered signal as 1D numpy array. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If channel is not found in loaded channels. |
Source code in src/ace_neuro/ephys/ephys_data_manager.py
get_channel(channel_name)
Return a single channel by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_name
|
str
|
Name of the channel to retrieve. |
required |
get_channels()
get_sync_timestamps(channel_name=None)
abstractmethod
Extract raw hardware sync timestamps from an ephys channel. To be overridden by subclasses.
import_ephys_block(ephys_directory)
abstractmethod
process_ephys_block_to_channels(channels=None, remove_artifacts=False)
abstractmethod
Process raw ephys data into Channel objects.
Block processor
ace_neuro.ephys.block_processor.BlockProcessor
Processes a Neo Block containing raw ephys data into Channel objects.
Handles the conversion of segmented Neuralynx recordings into continuous signal arrays, including artifact removal and event extraction.
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
Logger
|
Logger instance for debug output. |
ephys_block |
Block
|
Neo Block object containing raw ephys segments. |
Source code in src/ace_neuro/ephys/block_processor.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
__init__(ephys_block, logger)
Initialize a BlockProcessor with an ephys Block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ephys_block
|
Block
|
Neo Block object containing raw ephys data. |
required |
logger
|
Logger
|
Logger instance for debug/info messages. |
required |
Source code in src/ace_neuro/ephys/block_processor.py
process_raw_ephys(channels, remove_artifacts=False)
Convert raw ephys data into processed Channel objects.
Iterates through requested channel names, extracts signal data from all segments, and optionally removes artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
Union[str, List[str]]
|
Channel name string or list of channel names to process. |
required |
remove_artifacts
|
bool
|
If True, apply artifact removal to each channel. |
False
|
Returns:
| Type | Description |
|---|---|
Dict[str, Channel]
|
Dict mapping channel names to Channel objects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ephys_block has not been loaded. |
Source code in src/ace_neuro/ephys/block_processor.py
remove_artifacts(channel, volt_threshold=1500, time_threshold=60, hannNum=75)
Remove high-amplitude artifacts from a channel using Hann window smoothing.
Identifies samples exceeding the voltage threshold, fills short gaps between artifact regions, and applies a Hann window to smooth transitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Channel
|
Channel object to process (modified in-place). |
required |
volt_threshold
|
float
|
Voltage threshold in µV for artifact detection. |
1500
|
time_threshold
|
float
|
Maximum gap duration (seconds) to fill between artifacts. |
60
|
hannNum
|
int
|
Size of the Hann window for smoothing artifact edges. |
75
|
Source code in src/ace_neuro/ephys/block_processor.py
Channel
ace_neuro.ephys.channel.Channel
Represents a single electrophysiology recording channel.
Stores signal data, timing information, and associated events for one channel of an ephys recording.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Channel identifier (e.g., "PFCLFPvsCBEEG"). |
signal |
ndarray
|
Raw signal data as numpy array. |
sampling_rate |
float
|
Sampling frequency in Hz. |
time_vector |
ndarray
|
Timestamps corresponding to each sample. |
events |
Dict[str, Any]
|
Dict containing event labels and timestamps. |
signal_filtered |
Optional[ndarray]
|
Filtered signal data (set after filtering). |
phases |
Optional[ndarray]
|
Instantaneous phase values (set after phase computation). |
Source code in src/ace_neuro/ephys/channel.py
__init__(name, signal, sampling_rate, time_vector, events)
Initialize a Channel with signal data and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Channel identifier string. |
required |
signal
|
ndarray
|
1D numpy array of signal values. |
required |
sampling_rate
|
float
|
Sampling frequency in Hz. |
required |
time_vector
|
ndarray
|
1D numpy array of timestamps (same length as signal). |
required |
events
|
Dict[str, Any]
|
Dict with 'labels' and 'timestamps' arrays for event markers. |
required |