def test_simulate_model_bos_np_array_R(): bo = se.simulate_model_bos(n_samples=10, sample_rate=1000, locs=locs, sample_locs=n_elecs, cov=R) assert isinstance(bo, se.Brain)
iter_val = 5 append_d = pd.DataFrame() param_grid = [(p, m, n) for p in m_patients for m in m_elecs for n in n_elecs] for p, m, n in param_grid: d = [] for i in range(iter_val): # create brain objects with m_patients and loop over the number of model locations and subset locations to build model model_bos = [ se.simulate_model_bos(n_samples=1000, sample_rate=100, locs=locs, sample_locs=m, noise=.3) for x in range(p) ] # create model from subsampled gray locations model = se.Model(model_bos, locs=locs) # brain object locations subsetted entirely from both model and gray locations sub_locs = locs.sample(n).sort_values(['x', 'y', 'z']) # simulate brain object bo = se.simulate_bo(n_samples=1000, sample_rate=100, locs=locs, noise=.3)
our simulated brain objects. Then, we will create a model from these brain objects and plot it. """ # Code source: Lucy Owen & Andrew Heusser # License: MIT import supereeg as se # simulate 100 locations locs = se.simulate_locations(n_elecs=100) # simulate correlation matrix R = se.create_cov(cov='toeplitz', n_elecs=len(locs)) # create list of simulated brain objects model_bos = [ se.simulate_model_bos(n_samples=1000, sample_rate=1000, cov=R, locs=locs, sample_locs=10) for x in range(3) ] # create model from subsampled gray locations model = se.Model(model_bos, locs=locs) # plot the model model.plot_data()
[ 19., -57., -23.], [ 19., 23., -3.], [ 39., -57., 17.], [ 39., 3., 37.], [ 59., -17., 17.]]) # number of timeseries samples n_samples = 10 # number of subjects n_subs = 6 # number of electrodes n_elecs = 5 # simulate correlation matrix data = [se.simulate_model_bos(n_samples=10, sample_rate=10, locs=locs, sample_locs = n_elecs, set_random_seed=123, noise=0) for x in range(n_subs)] # test model to compare test_model = se.Model(data=data[0:3], locs=locs, rbf_width=20, n_subs=3) def test_create_model_1bo(): model = se.Model(data=data[0], locs=locs) assert isinstance(model, se.Model) def test_create_model_2bo(): model = se.Model(data=data[0:2], locs=locs) assert isinstance(model, se.Model) def test_create_model_superuser(): locs = np.random.multivariate_normal(np.zeros(3), np.eye(3), size=10)
import pytest bo = se.load('example_data') bo_s = bo.get_slice(sample_inds=[0, 1, 2]) locs = np.array([[-61., -77., -3.], [-41., -77., -23.], [-21., -97., 17.], [-21., -37., 77.], [-21., 63., -3.], [-1., -37., 37.], [-1., 23., 17.], [19., -57., -23.], [19., 23., -3.], [39., -57., 17.], [39., 3., 37.], [59., -17., 17.]]) n_samples = 10 n_subs = 3 n_elecs = 10 data = [ se.simulate_model_bos(n_samples=10, sample_rate=10, locs=locs, sample_locs=n_elecs) for x in range(n_subs) ] test_bo = data[0] test_model = se.Model(data=data, locs=locs) bo = se.load('example_data') def test_load_example_data(): bo = se.load('example_data') assert isinstance(bo, se.Brain) def test_load_example_filter(): bo = se.load('example_filter') assert isinstance(bo, se.Brain)
# import libraries import matplotlib.pyplot as plt import supereeg as se # simulate 100 locations locs = se.simulate_locations(n_elecs=100) # simulate correlation matrix R = se.create_cov(cov='toeplitz', n_elecs=len(locs)) # simulate brain objects for the model that subsample n_elecs for each synthetic patient model_bos = [ se.simulate_model_bos(n_samples=1000, sample_rate=1000, locs=locs, sample_locs=10, cov='toeplitz') for x in range(3) ] # create the model object model = se.Model(data=model_bos, locs=locs, n_subs=3) model.plot_data() # brain object locations subsetted sub_locs = locs.sample(10).sort_values(['x', 'y', 'z']) # simulate a new brain object using the same covariance matrix bo = se.simulate_bo(n_samples=1000, sample_rate=1000, locs=sub_locs,
n_subs = 3 # number of electrodes n_elecs = 5 # full brain object to parse and compare bo_full = se.simulate_bo(n_samples=10, sessions=2, sample_rate=10, locs=locs) # create brain object from subset of locations sub_locs = bo_full.locs.iloc[6:] sub_data = bo_full.data.iloc[:, sub_locs.index] bo = se.Brain(data=sub_data.as_matrix(), sessions=bo_full.sessions, locs=sub_locs, sample_rate=10, meta={'brain object locs sampled': 2}) # simulate correlation matrix data = [ se.simulate_model_bos(n_samples=10, locs=locs, sample_locs=n_elecs) for x in range(n_subs) ] # test model to compare test_model = se.Model(data=data, locs=locs, rbf_width=100) bo_nii = se.Brain(_gray(20)) nii = _brain_to_nifti(bo_nii, _gray(20)) a = np.array([[1, 2, 3], [4, 5, 6], [ 7, 8, 9, ]]) b = np.array([[-1, 2, 2], [-4, 5, 5], [ -7, 8,
import os import supereeg as se import numpy as np import pandas as pd import nibabel as nib nii = se.load('example_nifti') locs = np.array([[-61., -77., -3.], [-41., -77., -23.], [-21., -97., 17.], [-21., -37., 77.], [-21., 63., -3.], [-1., -37., 37.], [-1., 23., 17.], [19., -57., -23.], [19., 23., -3.], [39., -57., 17.], [39., 3., 37.], [59., -17., 17.]]) data = [ se.simulate_model_bos(n_samples=10, sample_rate=10, locs=locs, sample_locs=3) for x in range(2) ] # test model to compare mo = se.Model(data=data, locs=locs) bo = data[0] nii_bo = se.Nifti(bo) nii_mo = se.Nifti(mo) def test_nifti(): assert isinstance(nii, se.Nifti) assert issubclass(nii.__class__, nib.nifti1.Nifti1Image)