-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect ttl pkl.py
More file actions
32 lines (26 loc) · 1.17 KB
/
Copy pathinspect ttl pkl.py
File metadata and controls
32 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pickle
import numpy as np
from pathlib import Path
pkl_path = Path("/Users/jiahuan/Desktop/test_data/SC data/Sorting/NP-SC05-d1-2x2x96/ttl×tamps.pkl")
with open(pkl_path, "rb") as f:
data = pickle.load(f)
# 对每个 segment 分析各 channel 的特征
for seg_name in ['ttl1', 'ttl2', 'ttl3', 'ttl4', 'ttl5']:
TTL = data['ttl'][seg_name]
ts = data['ts_ttl'][seg_name.replace('ttl', 'ts_ttl')]
print(f"\n{'=' * 60}")
print(f"Segment: {seg_name} shape={TTL.shape} "
f"t=[{ts[0]:.1f}, {ts[-1]:.1f}]s")
print(f"{'ch':>4} {'min':>8} {'max':>8} {'range':>8} {'n_transitions':>14}")
thresholds = (TTL.min(axis=0) + TTL.max(axis=0)) / 2
binary = (TTL > thresholds).astype(np.int8)
for ch in range(TTL.shape[1]):
vmin = int(TTL[:, ch].min())
vmax = int(TTL[:, ch].max())
vrange = vmax - vmin
diff = np.diff(binary[:, ch].astype(np.int16))
n_rise = int((diff == 1).sum())
n_fall = int((diff == -1).sum())
marker = " ←← ACTIVE" if vrange > 1000 else ""
print(f" {ch:>2} {vmin:>8} {vmax:>8} {vrange:>8} "
f"rise={n_rise:5d} fall={n_fall:5d}{marker}")