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