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"
11def _load_real_000876(
12 *, num_samples: int, num_channels: int, start_channel: int
13) -> np.ndarray:
14 """Load data from DANDI dataset 000876.
16 Args:
17 num_samples: Number of samples to load
18 num_channels: Number of channels to load
19 start_channel: Starting channel index
21 Returns:
22 Array of shape (num_samples, num_channels) containing the loaded data
23 """
24 nwb_url = "https://api.dandiarchive.org/api/assets/7e1de06d-d478-40e2-9b64-9dd04eafaa4c/download/"
25 h5f = lindi.LindiH5pyFile.from_hdf5_file(nwb_url)
26 ds = h5f["/acquisition/ElectricalSeriesAP/data"]
27 assert isinstance(ds, lindi.LindiH5pyDataset)
28 ret = ds[:num_samples, start_channel : start_channel + num_channels]
29 return cast(np.ndarray, ret)
32def _load_real_000409(
33 *, num_samples: int, num_channels: int, start_channel: int
34) -> np.ndarray:
35 """Load data from DANDI dataset 000409.
37 Args:
38 num_samples: Number of samples to load
39 num_channels: Number of channels to load
40 start_channel: Starting channel index
42 Returns:
43 Array of shape (num_samples, num_channels) containing the loaded data
44 """
45 nwb_url = "https://api.dandiarchive.org/api/assets/c04f6b30-82bf-40e1-9210-34f0bcd8be24/download/"
46 h5f = lindi.LindiH5pyFile.from_hdf5_file(nwb_url)
47 ds = h5f["/acquisition/ElectricalSeriesAp/data"]
48 assert isinstance(ds, lindi.LindiH5pyDataset)
49 ret = ds[:num_samples, start_channel : start_channel + num_channels]
50 return cast(np.ndarray, ret)
53def _load_real_001290(
54 *, num_samples: int, num_channels: int, start_channel: int
55) -> np.ndarray:
56 """Load data from DANDI dataset 001290.
58 Args:
59 num_samples: Number of samples to load
60 num_channels: Number of channels to load
61 start_channel: Starting channel index
63 Returns:
64 Array of shape (num_samples, num_channels) containing the loaded data
65 """
66 nwb_url = "https://api.dandiarchive.org/api/assets/78c99d23-da88-4ecd-9086-c488a126eac5/download/"
67 h5f = lindi.LindiH5pyFile.from_hdf5_file(nwb_url)
68 ds = h5f["/acquisition/ElectricalSeriesAPImec/data"]
69 assert isinstance(ds, lindi.LindiH5pyDataset)
70 ret = ds[:num_samples, start_channel : start_channel + num_channels]
71 return cast(np.ndarray, ret)
74def _create_filtered_version(X: np.ndarray) -> np.ndarray:
75 """Create filtered version of a dataset using bandpass filtering and quantization.
77 Args:
78 X: Input signal array
80 Returns:
81 Filtered and quantized signal array
82 """
83 v = 0.25 # step size for quantization
84 lowcut = 300
85 highcut = 6000
86 sampling_frequency = 30000
88 # Bandpass filter
89 X_filt = bandpass_filter(
90 X - np.median(X),
91 sampling_frequency=sampling_frequency,
92 lowcut=lowcut,
93 highcut=highcut,
94 )
96 # Normalize by noise level
97 noise_level = estimate_noise_level(X_filt, sampling_frequency=sampling_frequency)
98 X_filt_normalized = X_filt / noise_level
100 # Quantize
101 X2b = X_filt_normalized / v
102 X2 = np.round(X2b).astype(np.int16)
104 return X2
107datasets = [
108 {
109 "name": "real-000876-ch45",
110 "version": "1",
111 "description": "Raw extracellular electrophysiology recording from DANDI:000876.",
112 "create": lambda: _load_real_000876(
113 num_samples=500_000, num_channels=1, start_channel=45
114 ).flatten(),
115 "tags": ["continuous", "neurophysiology"],
116 "source_file": SOURCE_FILE,
117 },
118 {
119 "name": "real-000409-ch101",
120 "version": "1",
121 "description": "Raw extracellular electrophysiology recording from DANDI:000409.",
122 "create": lambda: _load_real_000409(
123 num_samples=500_000, num_channels=1, start_channel=101
124 ).flatten(),
125 "tags": ["continuous", "neurophysiology"],
126 "source_file": SOURCE_FILE,
127 },
128 {
129 "name": "real-001290-ch0",
130 "version": "1",
131 "description": "Raw extracellular electrophysiology recording from DANDI:001290.",
132 "create": lambda: _load_real_001290(
133 num_samples=500_000, num_channels=1, start_channel=0
134 ).flatten(),
135 "tags": ["continuous", "neurophysiology"],
136 "source_file": SOURCE_FILE,
137 },
138 {
139 "name": "real-000876-ch45-filtered",
140 "version": "1",
141 "description": "Preprocessed version of real-000876-ch45. Bandpass filtered (300-6000 Hz).",
142 "create": lambda: _create_filtered_version(
143 _load_real_000876(
144 num_samples=500_000, num_channels=1, start_channel=45
145 ).flatten()
146 ),
147 "tags": ["continuous", "neurophysiology", "filtered"],
148 "source_file": SOURCE_FILE,
149 },
150 {
151 "name": "real-000409-ch101-filtered",
152 "version": "1",
153 "description": "Preprocessed version of real-000409-ch101. Bandpass filtered (300-6000 Hz).",
154 "create": lambda: _create_filtered_version(
155 _load_real_000409(
156 num_samples=500_000, num_channels=1, start_channel=101
157 ).flatten()
158 ),
159 "tags": ["continuous", "neurophysiology", "filtered"],
160 "source_file": SOURCE_FILE,
161 },
162 {
163 "name": "real-001290-ch0-filtered",
164 "version": "1",
165 "description": "Preprocessed version of real-001290-ch0. Bandpass filtered (300-6000 Hz).",
166 "create": lambda: _create_filtered_version(
167 _load_real_001290(
168 num_samples=500_000, num_channels=1, start_channel=0
169 ).flatten()
170 ),
171 "tags": ["continuous", "neurophysiology", "filtered"],
172 "source_file": SOURCE_FILE,
173 },
174]