wavpack
Lossless archives of Intan integer data streams using the WavPack CLI.
Install the external wavpack and wvunpack programs separately. Archives
are standard WavPack files, with no Python-specific container or sidecar.
compress_dat(input_path, n_channels, sample_rate, output_path=None, *, dtype='int16', executable=None, verify=True)
¶
Compress an Intan .dat data stream into a lossless .wv archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
str or Path
|
Headerless, little-endian integer data, interleaved by sample: channel 1 at sample 1, channel 2 at sample 1, ..., channel 1 at sample 2. Pass the original binary file directly, without scaling or conversion. |
required |
n_channels
|
int
|
Number of values per sample frame actually saved in the file (1 to 4096). Use 1 for time.dat and bit-packed digitalin.dat/digitalout.dat, not the number of active digital lines. |
required |
sample_rate
|
int
|
Sampling rate of this stream in Hz, for example 20000 or 30000. |
required |
output_path
|
str or Path
|
New .wv file. Defaults to input_path with its suffix replaced by .wv. The parent directory must exist. Existing files are never overwritten. |
None
|
dtype
|
(int16, uint16, int32, uint32)
|
Original little-endian sample type. Default is "int16" for amplifier data. Use "int32" for time.dat and "uint16" for digital, analog, auxiliary, and supply streams. Unsigned values are reinterpreted as signed integers of the same width for encoding; their bits are never changed. There is no scaling, offset, or sample reordering. |
"int16"
|
executable
|
str or Path
|
Path to wavpack (wavpack.exe on Windows). By default, search PATH. |
None
|
verify
|
bool
|
Re-read and decode the archive after writing to verify recovery using WavPack's MD5 check. Default is True. The original data's MD5 is stored even if this extra verification pass is disabled. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the completed .wv archive. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Invalid recording parameters, empty input, incomplete sample frames, or an output filename without the .wv extension. |
FileNotFoundError
|
Input, output directory, or WavPack executable is missing. |
FileExistsError
|
The destination already exists, including the input itself. |
RuntimeError
|
Compression or verification fails, or the source changes during work. |
Notes
The source is never deleted. WavPack streams the recording using bounded memory; no entire-recording array is loaded into Python. A failed operation removes its temporary output. The archive stores channel count, sample rate, bit depth, and MD5. Keep info.rhd, session metadata, and each stream's dtype: WavPack stores unsigned streams as signed bit patterns; interpretation still uses the original Intan metadata. Compress each .dat stream separately. Structured spike.dat and .rhd/.rhs containers are not fixed-width streams supported by this function. Lossy and hybrid modes are not exposed.
Source code in neuro_py/raw/wavpack.py
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 | |
decompress_dat(input_path, output_path=None, *, executable=None, verify=True)
¶
Restore an Intan .dat recording from a standard lossless WavPack archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
str or Path
|
A lossless .wv archive of 16- or 32-bit integer samples, such as one created by compress_dat. Hybrid/lossy and other bit depths are rejected. |
required |
output_path
|
str or Path
|
New .dat file. Defaults to input_path with its suffix replaced by .dat. Use a different filename if the original .dat is still present. The parent directory must exist. Existing files are never overwritten. |
None
|
executable
|
str or Path
|
Path to wvunpack (wvunpack.exe on Windows). By default, search PATH. |
None
|
verify
|
bool
|
Check restored bytes against the MD5 stored in the archive. Default is True, which requires an embedded MD5 (always stored by compress_dat). WavPack's block checks remain active when False. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path to the restored, headerless .dat, with the original bytes. No dtype, channel count, or rate is needed for restoration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The output filename does not have the .dat extension. |
FileNotFoundError
|
Input, output directory, or WvUnpack executable is missing. |
FileExistsError
|
The destination already exists, including the archive itself. |
RuntimeError
|
The archive is unsupported, corrupt, changed during work, lacks an MD5 required for verification, or cannot be completely decoded. |
Notes
The archive is never deleted. Raw-output mode prevents insertion of a WAV header. Decoding streams through WvUnpack using bounded memory. Temporary output is cleaned on failure; completed output is never overwritten.
Source code in neuro_py/raw/wavpack.py
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 | |