Skip to content

Instantly share code, notes, and snippets.

@wmvanvliet
Created April 3, 2015 08:43
Show Gist options
  • Save wmvanvliet/2bcd03751c28b77a0306 to your computer and use it in GitHub Desktop.
Save wmvanvliet/2bcd03751c28b77a0306 to your computer and use it in GitHub Desktop.
Test moving between references
import numpy as np
from numpy.testing import assert_allclose
nchannels, nsamples = 10, 100
data = np.random.rand(nchannels, nsamples)
# Average reference
data_avg = data - np.mean(data, axis=0)
# Referenced to channel 0
data0 = data - data[0]
# Referenced to channel 5
data5 = data - data[5]
# References to the mean of channels 0 and 5
data05 = data - np.mean(data[[0, 5]], axis=0)
# Can we move from a custom reference to an average reference?
assert_allclose(data0 - np.mean(data0, axis=0), data_avg)
assert_allclose(data5 - np.mean(data5, axis=0), data_avg)
assert_allclose(data05 - np.mean(data05, axis=0), data_avg)
# Can be move from an average reference to custom reference?
assert_allclose(data_avg - data_avg[0], data0)
assert_allclose(data_avg - data_avg[5], data5)
assert_allclose(data_avg - np.mean(data_avg[[0, 5]], axis=0), data05)
# Can be move from a custom reference to another custom reference?
assert_allclose(data0 - data0[5], data5)
assert_allclose(data5 - data5[0], data0)
assert_allclose(data05 - data05[0], data0)
assert_allclose(data05 - data05[5], data5)
assert_allclose(data0 - np.mean(data0[[0, 5]], axis=0), data05)
assert_allclose(data5 - np.mean(data5[[0, 5]], axis=0), data05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment