Preprocessing Reference
Crane provides various preprocessing utilities to prepare neural data for modeling and analysis.
Preprocessors
Spectrogram
Bases: Module
Spectrogram Preprocessor, computes the spectrogram of iEEG data using STFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segment_length
|
float
|
The length of each segment (in seconds) for the STFT. |
required |
p_overlap
|
float
|
The proportion of overlap between segments (between 0 and 1). |
required |
min_frequency
|
float
|
The minimum frequency (in Hz) to include in the spectrogram. |
required |
max_frequency
|
float
|
The maximum frequency (in Hz) to include in the spectrogram. |
required |
window
|
Literal['hann', 'boxcar']
|
The type of window to use for the STFT. |
required |
remove_line_noise
|
bool
|
Whether to remove line noise frequencies (e.g., 50/60 Hz). |
required |
output_dim
|
int, default=-1
|
The dimension of the output features. If -1, the output feature dimension will be the same as the number of frequency bins. Otherwise, they will be projected to this dimension. |
-1
|
Source code in crane/preprocess/spectrogram.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 | |
forward(data, *, z_score=True)
Perform the forward pass of the SpectrogramPreprocessor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
A tensor of shape (batch_size, n_electrodes, n_samples) representing the iEEG data. |
required |
sampling_rate
|
int
|
An integer representing the sampling rate of the iEEG data. |
required |
z_score
|
bool
|
Whether to apply z-score normalization to the spectrogram. Default is True. |
True
|
Returns:
| Type | Description |
|---|---|
CraneFeature
|
torch.Tensor: The processed spectrogram with shape (batch_size, n_electrodes, n_timebins, n_freqs or output_dim). |
Source code in crane/preprocess/spectrogram.py
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 | |
laplacian_rereference(data, remove_non_laplacian=True)
Apply Laplacian rereferencing to a batch of neural data (subtract the mean of the neighbors, as determined by the electrode labels)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
CraneFeature
|
CraneFeature containing the neural data and channel information |
required |
remove_non_laplacian
|
bool
|
if True, remove the non-laplacian electrodes from the data; if false, keep them without rereferencing |
True
|
Returns:
| Type | Description |
|---|---|
CraneFeature
|
rereferenced_data,updated_channels (tuple[torch.Tensor, list of str or ChannelDict]): A tuple containing: rereferenced_data (torch.Tensor): torch tensor of shape (batch_size, n_electrodes_rereferenced, n_samples) or (n_electrodes_rereferenced, n_samples) updated_channels (list of str or ChannelDict): list of electrode labels or ChannelDict of length n_electrodes_rereferenced (n_electrodes_rereferenced could be different from n_electrodes if remove_non_laplacian is True) |
Source code in crane/preprocess/rereference.py
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 | |
subset_electrodes(data, *, max_n_electrodes=None, subset=None)
Subset channel electrodes, consistent across a batch.
Exactly one of max_n_electrodes or subset must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
CraneFeature
|
The input feature data. |
required |
max_n_electrodes
|
int
|
Maximum number of randomly selected electrodes to subset to. |
None
|
subset
|
Sequence[int | str] | None
|
Optional list of electrode indices or IDs to subset to. If None, a random subset is chosen. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
CraneFeature |
CraneFeature
|
The subsetted feature data. |
Source code in crane/preprocess/subset.py
10 11 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 | |