setu-neural-eeg / scripts /validate_pipeline.py
arushsinghal's picture
Add files using upload-large-folder tool
4fcc185 verified
Raw History Blame Contribute Delete
930 Bytes
import sys,json,inspect
import numpy as np
from bci_data import cached,preprocess,montage
x,y,names=cached(1,'train');p=preprocess(x[:2]);assert p.shape==(2,64,400)
changed=x[:2].copy();changed[:,:,:128]+=1e6;changed[:,:,640:]-=1e6
assert np.array_equal(preprocess(changed),p),'Outside-window contamination'
for k in ['distributed','language']:
for n in [64,32,16,8]:
idx=montage(names,n,k);assert len(idx)==n and len(set(idx))==n and min(idx)>=0 and max(idx)<64
assert preprocess(x[:2],idx).shape==(2,n,400)
try:cached(1,'test')
except PermissionError:pass
else:raise AssertionError('Test gate failed')
assert np.isfinite(p).all()
# CAR commutes with independent linear filtering to numerical tolerance.
assert abs(p.mean(1)).max()<1e-4
json.dump({'strict_crop':True,'test_gate':True,'montages':True,'finite_signals':True,'shape':[2,64,400]},open('reports/pipeline_tests.json','w'),indent=2)
print('Pipeline checks passed')