|
| 1 | +from pathlib import Path |
| 2 | +from typing import List, Union, Optional |
| 3 | + |
| 4 | +from spikeinterface.core import BinaryRecordingExtractor |
| 5 | +from spikeinterface.core.core_tools import define_function_from_class |
| 6 | + |
| 7 | + |
| 8 | +class WhiteMatterRecordingExtractor(BinaryRecordingExtractor): |
| 9 | + """ |
| 10 | + RecordingExtractor for the WhiteMatter binary format. |
| 11 | +
|
| 12 | + The recording format is a raw binary file containing int16 data, |
| 13 | + with an 8-byte header offset. |
| 14 | +
|
| 15 | + Parameters |
| 16 | + ---------- |
| 17 | + file_path : Path |
| 18 | + Path to the binary file. |
| 19 | + sampling_frequency : float |
| 20 | + The sampling frequency. |
| 21 | + num_channels : int |
| 22 | + Number of channels in the recording. |
| 23 | + channel_ids : list or None, default: None |
| 24 | + A list of channel ids. If None, channel_ids = list(range(num_channels)). |
| 25 | + is_filtered : bool or None, default: None |
| 26 | + If True, the recording is assumed to be filtered. If None, `is_filtered` is not set. |
| 27 | + """ |
| 28 | + |
| 29 | + mode = "file" |
| 30 | + |
| 31 | + # Specific parameters for WhiteMatter format |
| 32 | + DTYPE = "int16" |
| 33 | + GAIN_TO_UV = 6.25e3 / 32768 |
| 34 | + OFFSET_TO_UV = 0.0 |
| 35 | + FILE_OFFSET = 8 |
| 36 | + TIME_AXIS = 0 |
| 37 | + # This extractor is based on a single example file without a formal specification from WhiteMatter. |
| 38 | + # The parameters above are currently assumed to be constant for all WhiteMatter files. |
| 39 | + # If you encounter issues with this extractor, these assumptions may need to be revisited. |
| 40 | + |
| 41 | + def __init__( |
| 42 | + self, |
| 43 | + file_path: Union[str, Path], |
| 44 | + sampling_frequency: float, |
| 45 | + num_channels: int, |
| 46 | + channel_ids: Optional[List] = None, |
| 47 | + is_filtered: Optional[bool] = None, |
| 48 | + ): |
| 49 | + super().__init__( |
| 50 | + file_paths=[file_path], |
| 51 | + sampling_frequency=sampling_frequency, |
| 52 | + num_channels=num_channels, |
| 53 | + dtype=self.DTYPE, |
| 54 | + time_axis=self.TIME_AXIS, |
| 55 | + file_offset=self.FILE_OFFSET, |
| 56 | + gain_to_uV=self.GAIN_TO_UV, |
| 57 | + offset_to_uV=self.OFFSET_TO_UV, |
| 58 | + is_filtered=is_filtered, |
| 59 | + channel_ids=channel_ids, |
| 60 | + ) |
| 61 | + |
| 62 | + |
| 63 | +# Define function equivalent for convenience |
| 64 | +read_whitematter = define_function_from_class(source_class=WhiteMatterRecordingExtractor, name="read_whitematter") |
0 commit comments