/ proof-of-concept / benchcompress
Sign in
proof-of-concept / benchcompress
176 lines · 5.7 KBBlameHistoryRaw
1import numpy as np
2import lindi
3from typing import cast
4from ..._filters import bandpass_filter
5from ..._analysis import estimate_noise_level
8SOURCE_FILE = "real/__init__.py"
10tags = ["integer", "continuous", "neurophysiology", "real"]
13def _load_real_000876(
14 *, num_samples: int, num_channels: int, start_channel: int
15) -> np.ndarray:
16 """Load data from DANDI dataset 000876.
18 Args:
19 num_samples: Number of samples to load
20 num_channels: Number of channels to load
21 start_channel: Starting channel index
23 Returns:
24 Array of shape (num_samples, num_channels) containing the loaded data
25 """
26 nwb_url = "https://api.dandiarchive.org/api/assets/7e1de06d-d478-40e2-9b64-9dd04eafaa4c/download/"
27 h5f = lindi.LindiH5pyFile.from_hdf5_file(nwb_url)
28 ds = h5f["/acquisition/ElectricalSeriesAP/data"]
29 assert isinstance(ds, lindi.LindiH5pyDataset)
30 ret = ds[:num_samples, start_channel : start_channel + num_channels]
31 return cast(np.ndarray, ret)
34def _load_real_000409(
35 *, num_samples: int, num_channels: int, start_channel: int
36) -> np.ndarray:
37 """Load data from DANDI dataset 000409.
39 Args:
40 num_samples: Number of samples to load
41 num_channels: Number of channels to load
42 start_channel: Starting channel index
44 Returns:
45 Array of shape (num_samples, num_channels) containing the loaded data
46 """
47 nwb_url = "https://api.dandiarchive.org/api/assets/c04f6b30-82bf-40e1-9210-34f0bcd8be24/download/"
48 h5f = lindi.LindiH5pyFile.from_hdf5_file(nwb_url)
49 ds = h5f["/acquisition/ElectricalSeriesAp/data"]
50 assert isinstance(ds, lindi.LindiH5pyDataset)
51 ret = ds[:num_samples, start_channel : start_channel + num_channels]
52 return cast(np.ndarray, ret)
55def _load_real_001290(
56 *, num_samples: int, num_channels: int, start_channel: int
57) -> np.ndarray:
58 """Load data from DANDI dataset 001290.
60 Args:
61 num_samples: Number of samples to load
62 num_channels: Number of channels to load
63 start_channel: Starting channel index
65 Returns:
66 Array of shape (num_samples, num_channels) containing the loaded data
67 """
68 nwb_url = "https://api.dandiarchive.org/api/assets/78c99d23-da88-4ecd-9086-c488a126eac5/download/"
69 h5f = lindi.LindiH5pyFile.from_hdf5_file(nwb_url)
70 ds = h5f["/acquisition/ElectricalSeriesAPImec/data"]
71 assert isinstance(ds, lindi.LindiH5pyDataset)
72 ret = ds[:num_samples, start_channel : start_channel + num_channels]
73 return cast(np.ndarray, ret)
76def _create_filtered_version(X: np.ndarray) -> np.ndarray:
77 """Create filtered version of a dataset using bandpass filtering and quantization.
79 Args:
80 X: Input signal array
82 Returns:
83 Filtered and quantized signal array
84 """
85 v = 0.25 # step size for quantization
86 lowcut = 300
87 highcut = 6000
88 sampling_frequency = 30000
90 # Bandpass filter
91 X_filt = bandpass_filter(
92 X - np.median(X),
93 sampling_frequency=sampling_frequency,
94 lowcut=lowcut,
95 highcut=highcut,
96 )
98 # Normalize by noise level
99 noise_level = estimate_noise_level(X_filt, sampling_frequency=sampling_frequency)
100 X_filt_normalized = X_filt / noise_level
102 # Quantize
103 X2b = X_filt_normalized / v
104 X2 = np.round(X2b).astype(np.int16)
106 return X2
109datasets = [
110 {
111 "name": "real-000876-ch45",
112 "version": "1",
113 "description": "Raw extracellular electrophysiology recording from DANDI:000876.",
114 "create": lambda: _load_real_000876(
115 num_samples=500_000, num_channels=1, start_channel=45
116 ).flatten(),
117 "tags": tags,
118 "source_file": SOURCE_FILE,
119 },
120 {
121 "name": "real-000409-ch101",
122 "version": "1",
123 "description": "Raw extracellular electrophysiology recording from DANDI:000409.",
124 "create": lambda: _load_real_000409(
125 num_samples=500_000, num_channels=1, start_channel=101
126 ).flatten(),
127 "tags": tags,
128 "source_file": SOURCE_FILE,
129 },
130 {
131 "name": "real-001290-ch0",
132 "version": "1",
133 "description": "Raw extracellular electrophysiology recording from DANDI:001290.",
134 "create": lambda: _load_real_001290(
135 num_samples=500_000, num_channels=1, start_channel=0
136 ).flatten(),
137 "tags": tags,
138 "source_file": SOURCE_FILE,
139 },
140 {
141 "name": "real-000876-ch45-filtered",
142 "version": "1",
143 "description": "Preprocessed version of real-000876-ch45. Bandpass filtered (300-6000 Hz).",
144 "create": lambda: _create_filtered_version(
145 _load_real_000876(
146 num_samples=500_000, num_channels=1, start_channel=45
147 ).flatten()
148 ),
149 "tags": ["continuous", "neurophysiology", "filtered"],
150 "source_file": SOURCE_FILE,
151 },
152 {
153 "name": "real-000409-ch101-filtered",
154 "version": "1",
155 "description": "Preprocessed version of real-000409-ch101. Bandpass filtered (300-6000 Hz).",
156 "create": lambda: _create_filtered_version(
157 _load_real_000409(
158 num_samples=500_000, num_channels=1, start_channel=101
159 ).flatten()
160 ),
161 "tags": ["continuous", "neurophysiology", "filtered"],
162 "source_file": SOURCE_FILE,
163 },
164 {
165 "name": "real-001290-ch0-filtered",
166 "version": "1",
167 "description": "Preprocessed version of real-001290-ch0. Bandpass filtered (300-6000 Hz).",
168 "create": lambda: _create_filtered_version(
169 _load_real_001290(
170 num_samples=500_000, num_channels=1, start_channel=0
171 ).flatten()
172 ),
173 "tags": ["continuous", "neurophysiology", "filtered"],
174 "source_file": SOURCE_FILE,
175 },
↑↓ move↵openescclose