Dataset objects in rsatoolbox

These exercises show how to load and structure a dataset object.

In this demo, we will first provide a walkthrough for loading a single-subject dataset from a .mat file and arranging it into an rsatoolbox dataset object.

We then demonstrate how to create dataset objects using data from multiple subjects.

[1]:
# relevant imports
import numpy as np
from scipy import io
import matplotlib.pyplot as plt
import rsatoolbox
import rsatoolbox.data as rsd # abbreviation to deal with dataset

1. Single-subject dataset example

Getting started

We will use a dataset where one subject was presented with 92 different visual stimuli while brain responses were measured in 100 voxels. The different visual stimuli (each row) are the conditions, and the voxels (each column) are the measurement channels.

[2]:
# import the measurements for the dataset
measurements = io.matlab.loadmat('92imageData/simTruePatterns.mat')
measurements = measurements['simTruePatterns']
nCond = measurements.shape[0]
nVox = measurements.shape[1]

# plot the imported data
plt.imshow(measurements,cmap='gray')
plt.xlabel('Voxels')
plt.ylabel('Conditions')
plt.title('Measurements')
[2]:
Text(0.5, 1.0, 'Measurements')
_images/demo_dataset_4_1.png

Creating the dataset object

We will now arrange the loaded data into a dataset object for use in rsatoolbox.

A dataset object contains all the information needed to calculate a representational dissimilarity matrix (RDM). Therefore, the dataest must include: - measurements: [NxP] numpy.ndarray. These are the observations (N) from each measurement channel (P). - obs_descriptors: dict that defines the condition label associated with each observation in measurements

Because we also want to include helpful information about this dataset, we include the additional information: - descriptors: dict with metadata about this dataset object (e.g. experiment session #, subject #, experiment name). Basically general descriptions - channel_descriptors: dict that identifies each column (channel) in measurements

To start, we will note the session # (e.g. the first scanning session) and the subject # for this dataset. In addition, we will create labels for each of the 92 conditions and 100 voxels. Finally, we package this information into an rsatoolbox dataset object.

[3]:
# now create a  dataset object
des = {'session': 1, 'subj': 1}
obs_des = {'conds': np.array(['cond_' + str(x) for x in np.arange(nCond)])}
chn_des = {'voxels': np.array(['voxel_' + str(x) for x in np.arange(nVox)])}
#obs_des = {'conds': np.array(['cond_' + str(x) for x in np.arange(1,nCond+1)])} # indices from 1
#chn_des = {'conds': np.array(['voxel' + str(x) for x in np.arange(1,nVox+1)])} # indices from 1
data = rsd.Dataset(measurements=measurements,
                           descriptors=des,
                           obs_descriptors=obs_des,
                           channel_descriptors=chn_des)
print(data)
rsatoolbox.data.Dataset
measurements =
[[-2.28467120e+16 -2.89393925e+16  1.98175667e+16 -1.52670137e+16
   6.16739860e+14  2.10873889e+16  7.54719220e+15  3.91406464e+15
   2.06459753e+15  1.71183930e+15  9.25183442e+15  6.25203471e+14
  -2.61395909e+16  3.30336292e+16  9.85160565e+15  7.08693907e+15
   4.56990621e+15  1.43744616e+16  7.94155302e+15 -9.69347003e+15
   4.54740006e+13  2.52235447e+16  1.09579543e+16  2.01266145e+16
  -8.27816988e+15  1.78844114e+16 -8.56003159e+15  3.99141304e+15
   6.61310188e+14 -3.44699674e+16 -1.02998653e+16  2.17767629e+16
   8.36071759e+15  3.87267836e+16 -7.68930294e+13  2.92524184e+14
   3.61891025e+16  2.03835675e+16 -1.48229413e+16 -1.79885027e+16
   1.38548750e+16 -1.48847681e+16  8.07503594e+15 -6.08550537e+15
  -3.95331143e+16  1.47461837e+15  1.82758194e+16  2.49558214e+16
   5.57712653e+15  3.05545911e+16 -1.34602130e+16  6.08982232e+15
  -1.46623702e+16  9.11955876e+15 -1.48137929e+15 -1.00568477e+16
   2.26715542e+16 -2.28012042e+15 -8.58782504e+15 -9.49785546e+15
   6.31124116e+15 -2.60423801e+16 -1.43106427e+16  8.77650361e+15
   1.64762357e+16  1.48712641e+16  3.17720814e+16  2.16069508e+16
  -1.69194887e+15 -1.82672783e+16 -2.02618929e+16  2.48495135e+16
   9.38935166e+15  3.21551159e+15 -1.29400665e+16  1.75306456e+16
   7.90449438e+14 -9.15371517e+15  1.79781226e+16  9.92172265e+15
   1.77612622e+16  2.78527019e+16 -5.25426004e+16  1.76757204e+16
   7.16183647e+15  1.06634144e+16 -1.52156646e+16  1.34982111e+16
   4.81598375e+16  1.26590032e+16  2.71703270e+16 -6.51989799e+14
  -2.34545400e+16 -2.20572879e+16  5.45906732e+15 -1.66439349e+16
  -1.45179996e+16  4.39915410e+15  1.21833882e+16 -3.34540674e+16]
 [-3.15533906e+15  2.36874984e+16  1.13281406e+16  3.36178206e+15
   3.19077890e+15  2.90702041e+16  3.51093484e+15  9.19417433e+15
   3.75712176e+16  3.71274675e+15 -9.44757716e+15  1.77668131e+16
  -1.50005936e+16 -1.96933508e+16  6.14094828e+15 -1.40938129e+16
   2.88040697e+15 -8.12636996e+15  1.43427479e+14 -2.30740430e+16
   2.38954885e+15  6.13542878e+14 -2.59026130e+15  1.74215355e+16
  -1.83217813e+16  1.06849796e+16 -6.81596425e+15  1.77353397e+16
   1.21952649e+15 -6.00776749e+14  1.47522296e+16 -1.88711981e+16
   7.14526582e+15  9.07912658e+15  1.20053215e+16  4.78633980e+15
   4.65457950e+15 -7.88672135e+15  1.86754183e+15 -2.95653613e+16
   5.63371292e+15  9.21207027e+15 -1.39189098e+16  1.29138593e+16
  -2.68979727e+16 -1.37191718e+16  2.25856233e+16 -3.32304738e+15
  -1.16042203e+16  2.11867315e+16  1.73999964e+16 -3.85642368e+16
   1.51195008e+15 -1.07825298e+16  1.77799305e+16  2.72502607e+15
  -4.65997809e+15 -9.19492613e+15  1.57723890e+16  8.29068986e+15
  -4.40965196e+15  2.13399935e+16 -4.34153766e+15  2.75809915e+15
   4.80477557e+14  1.43391039e+16 -1.11069759e+16  1.49177043e+16
   1.81155144e+14  1.36154642e+16  2.09304558e+16 -7.74551150e+15
   2.31765757e+16  2.22507237e+16  6.25174783e+14 -2.38428583e+16
  -8.00405332e+15 -1.03731026e+16  1.17013940e+16  2.60704215e+16
   4.37330257e+15  9.15926890e+15  8.97827065e+15 -1.10075014e+15
   1.96942798e+16  1.33784661e+16 -3.25060346e+16 -2.95659706e+14
   2.16209140e+16  1.54693632e+16 -2.05287792e+16  7.80985804e+15
   6.30320920e+13 -1.92064519e+16  1.64478366e+16  1.66505869e+16
  -4.71376342e+15 -1.56629129e+16 -3.14898827e+16 -2.81117438e+16]
 [-1.32511071e+16 -2.30128487e+16  1.97146253e+16 -1.60959900e+16
  -1.59789701e+16  1.65352242e+16 -2.52544729e+16 -3.75618842e+16
   1.08802201e+16 -2.98129113e+16 -1.26843820e+16 -2.84021733e+15
  -2.17198136e+16 -1.84820991e+16  1.22698411e+15 -4.03020201e+15
   1.93083401e+16  2.93975048e+16 -3.92253744e+16  1.06591050e+16
   7.27475621e+15 -4.13684686e+16  6.66141320e+15 -7.38928850e+14
  -5.09194298e+16  6.04478373e+15  1.03028597e+16 -2.29862136e+15
   5.11759725e+15 -8.26281627e+15 -5.74948262e+15  2.24558695e+16
   2.52295230e+16 -5.25121083e+14  2.36866641e+16 -7.84681553e+15
   1.42943802e+16  2.71167997e+16 -1.19441030e+16 -4.52693246e+15
  -1.21994576e+16  7.24608504e+15 -3.80422211e+16 -2.76326040e+16
  -3.10038812e+16  4.96077219e+15  4.62117408e+15 -3.51812557e+16
   2.32703017e+16 -2.60809928e+16  1.89723846e+15 -2.17186842e+15
   1.60173340e+16 -1.63535675e+16  3.79755442e+15  8.05634803e+15
  -1.20154968e+16 -4.38473369e+16  2.18932787e+16  7.19411532e+15
   1.96487491e+15  5.57979100e+16  5.53228656e+15  8.32968202e+15
   3.63715719e+16 -4.25552546e+15 -1.55114717e+16 -2.09531296e+16
   4.97658708e+15  1.22916933e+16 -2.61111679e+16 -8.41539406e+14
  -1.19960229e+16 -6.46797205e+15 -1.80501568e+16  2.11840524e+15
  -2.18173708e+16  9.96002398e+12 -2.31718063e+16 -1.02588709e+15
   1.02438062e+16  2.78387458e+16 -3.62283226e+16 -5.55949045e+15
   2.98817239e+15  3.20772124e+16  4.93164641e+15 -1.19839679e+16
  -2.88884948e+14  2.13992598e+16  4.24354655e+15  4.83547150e+15
   9.24267635e+15 -2.64093514e+16  1.13793007e+16 -2.32227758e+16
  -1.48409817e+16  9.18213644e+15  1.76394121e+16 -3.52385384e+15]
 [-2.58811422e+16 -2.67692950e+16  7.92145299e+15 -3.13750349e+15
  -2.42870048e+16  9.03456090e+15  1.27472365e+16 -1.38975852e+15
  -2.00197390e+16 -3.38338905e+16  2.61641233e+16  8.66918471e+15
  -3.73454644e+16  3.51738183e+16  5.12896077e+16  5.31982365e+16
  -2.54707013e+16 -8.81139683e+15 -9.10815278e+15  5.12432820e+16
  -2.20998305e+16  3.75344845e+16 -1.50068507e+16  1.44575908e+16
   6.07763057e+15  3.36127708e+16 -3.90162827e+16  7.23547256e+15
   5.61947523e+16 -1.28738077e+16  6.53408938e+16 -7.69266710e+13
  -1.23652415e+16 -2.38796453e+16  1.78836416e+16 -4.84737812e+14
  -3.08333237e+16 -1.29923015e+16  4.36885199e+16 -2.73649515e+14
  -2.28945808e+16  2.27850647e+16 -2.53025813e+15 -1.16363265e+16
  -3.24089975e+16  1.65997741e+16 -3.97401527e+16 -6.80814134e+16
   2.10447473e+16  4.17357654e+16 -2.43959609e+16 -2.62244097e+16
  -5.27714325e+16 -2.17565363e+15  1.70228661e+15  1.11748360e+16
   1.79234988e+16  4.44246518e+16  5.23134624e+16 -3.03268114e+15
   2.42651856e+16  4.87419442e+16  1.90918878e+16 -4.03484860e+16
  -1.49744872e+16  1.64420229e+16 -3.18624876e+16  3.40274604e+16
  -3.49054209e+16 -5.99028003e+15  4.44988946e+16 -3.39267560e+15
  -3.18486382e+16 -1.48094368e+15  7.88217468e+15  2.87839120e+16
  -6.57419465e+16 -5.04992702e+16 -4.20097409e+16 -1.45512261e+15
  -4.63790622e+15  2.12735058e+16 -3.34821713e+16  7.90989411e+14
   1.64541697e+16  4.06768510e+16  4.53407679e+15  2.63660729e+16
   4.13283944e+16  5.94373121e+16  3.85491697e+16  3.14180746e+15
   6.42079815e+16  2.61090108e+16 -3.70856820e+15  2.40308321e+16
  -3.25909433e+16  1.52697634e+16  2.24517722e+15 -6.57959179e+16]
 [ 1.18650425e+16  1.03594396e+16  2.99229685e+16 -1.27162385e+16
  -9.58778816e+15  6.22035191e+15  6.42700040e+15  1.85971477e+16
  -4.29693509e+15 -1.51399497e+16 -1.45306667e+15  1.26354669e+16
   5.20196762e+15 -1.65736914e+16 -5.31583823e+14  1.20696689e+16
  -6.89568198e+15 -3.36597115e+15 -5.02451360e+15  2.92589319e+16
  -1.81975335e+14  1.27504010e+16  5.47243463e+15  2.01076427e+16
   7.35021975e+15  4.27792305e+15 -1.33986624e+16  5.83279615e+15
  -2.65090652e+16 -8.75327537e+15 -1.42949078e+16 -5.46280735e+15
   1.48845853e+16 -4.73479202e+15  1.64660006e+16  3.81183090e+15
  -4.43994811e+15  1.59061631e+16  4.24534506e+15 -5.65840152e+15
  -7.08453831e+15  1.54317187e+16  3.40202667e+14 -1.61671371e+15
  -4.34164509e+15  1.11645748e+16 -8.95875853e+15  1.58028768e+15
   1.66850026e+16  4.61724807e+15  2.35746888e+15 -1.35932749e+16
  -2.20368581e+16 -1.89253216e+16 -6.84574838e+15  5.61270339e+15
  -8.37643693e+15 -1.61989759e+16 -1.47183271e+16  1.05061596e+16
  -1.11009296e+16 -7.19930953e+15  1.82335928e+16  1.18950952e+16
  -2.13185290e+16  8.08667034e+15  5.36955237e+15  2.99220661e+14
  -5.08447443e+15  5.22995145e+15 -1.77853032e+16  1.98187592e+16
  -9.72886297e+15  1.20265358e+16  7.55792528e+15 -3.39005818e+15
   5.06601380e+15  1.28543006e+16 -1.78749256e+16  1.36681963e+16
  -1.86166059e+15  3.02654936e+16  2.89656552e+15 -1.59786614e+15
   1.61318293e+16  5.74253602e+14 -2.12727079e+16  1.05289645e+16
  -6.78940477e+15  3.87108321e+15  1.11633322e+16  8.38194898e+14
   1.57875121e+16 -1.11966246e+16  2.90084830e+15 -4.71021769e+15
   1.78125749e+14 -1.06693303e+16  6.64414692e+15 -1.90567905e+16]]
...

descriptors:
session = 1
subj = 1


obs_descriptors:
conds = ['cond_0' 'cond_1' 'cond_2' 'cond_3' 'cond_4' 'cond_5' 'cond_6' 'cond_7'
 'cond_8' 'cond_9' 'cond_10' 'cond_11' 'cond_12' 'cond_13' 'cond_14'
 'cond_15' 'cond_16' 'cond_17' 'cond_18' 'cond_19' 'cond_20' 'cond_21'
 'cond_22' 'cond_23' 'cond_24' 'cond_25' 'cond_26' 'cond_27' 'cond_28'
 'cond_29' 'cond_30' 'cond_31' 'cond_32' 'cond_33' 'cond_34' 'cond_35'
 'cond_36' 'cond_37' 'cond_38' 'cond_39' 'cond_40' 'cond_41' 'cond_42'
 'cond_43' 'cond_44' 'cond_45' 'cond_46' 'cond_47' 'cond_48' 'cond_49'
 'cond_50' 'cond_51' 'cond_52' 'cond_53' 'cond_54' 'cond_55' 'cond_56'
 'cond_57' 'cond_58' 'cond_59' 'cond_60' 'cond_61' 'cond_62' 'cond_63'
 'cond_64' 'cond_65' 'cond_66' 'cond_67' 'cond_68' 'cond_69' 'cond_70'
 'cond_71' 'cond_72' 'cond_73' 'cond_74' 'cond_75' 'cond_76' 'cond_77'
 'cond_78' 'cond_79' 'cond_80' 'cond_81' 'cond_82' 'cond_83' 'cond_84'
 'cond_85' 'cond_86' 'cond_87' 'cond_88' 'cond_89' 'cond_90' 'cond_91']


channel_descriptors:
voxels = ['voxel_0' 'voxel_1' 'voxel_2' 'voxel_3' 'voxel_4' 'voxel_5' 'voxel_6'
 'voxel_7' 'voxel_8' 'voxel_9' 'voxel_10' 'voxel_11' 'voxel_12' 'voxel_13'
 'voxel_14' 'voxel_15' 'voxel_16' 'voxel_17' 'voxel_18' 'voxel_19'
 'voxel_20' 'voxel_21' 'voxel_22' 'voxel_23' 'voxel_24' 'voxel_25'
 'voxel_26' 'voxel_27' 'voxel_28' 'voxel_29' 'voxel_30' 'voxel_31'
 'voxel_32' 'voxel_33' 'voxel_34' 'voxel_35' 'voxel_36' 'voxel_37'
 'voxel_38' 'voxel_39' 'voxel_40' 'voxel_41' 'voxel_42' 'voxel_43'
 'voxel_44' 'voxel_45' 'voxel_46' 'voxel_47' 'voxel_48' 'voxel_49'
 'voxel_50' 'voxel_51' 'voxel_52' 'voxel_53' 'voxel_54' 'voxel_55'
 'voxel_56' 'voxel_57' 'voxel_58' 'voxel_59' 'voxel_60' 'voxel_61'
 'voxel_62' 'voxel_63' 'voxel_64' 'voxel_65' 'voxel_66' 'voxel_67'
 'voxel_68' 'voxel_69' 'voxel_70' 'voxel_71' 'voxel_72' 'voxel_73'
 'voxel_74' 'voxel_75' 'voxel_76' 'voxel_77' 'voxel_78' 'voxel_79'
 'voxel_80' 'voxel_81' 'voxel_82' 'voxel_83' 'voxel_84' 'voxel_85'
 'voxel_86' 'voxel_87' 'voxel_88' 'voxel_89' 'voxel_90' 'voxel_91'
 'voxel_92' 'voxel_93' 'voxel_94' 'voxel_95' 'voxel_96' 'voxel_97'
 'voxel_98' 'voxel_99']


Sometimes we wish to consider only a subset of data - either a subset of observations (conditions), or subset of measurement channels. This might be to only consider the measurement channels where all the subjects have data, or conditions which occur across all subjects / sessions. Using dataset functionality, we can subset the datasets according to a subset of the conditions or channels via ‘subset_obs’ and ‘subset_channel’, respectively.

[4]:
# create an example dataset with random data, subset some conditions
nChannel = 50
nObs = 12
randomData = np.random.rand(nObs, nChannel)
des = {'session': 1, 'subj': 1}
obs_des = {'conds': np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5])}
chn_des = {'voxels': np.array(['voxel_' + str(x) for x in np.arange(nChannel)])}
data = rsd.Dataset(measurements=randomData,
                        descriptors=des,
                        obs_descriptors=obs_des,
                        channel_descriptors=chn_des
                        )
# select a subset of the dataset: select data only from conditions 0:4
sub_data = data.subset_obs(by='conds', value=[0,1,2,3,4])
print(sub_data)
rsatoolbox.data.Dataset
measurements =
[[0.91863267 0.4846205  0.33593029 0.75119766 0.19551113 0.6198097
  0.50750475 0.12601606 0.47426061 0.5989329  0.0637164  0.94045044
  0.48710383 0.11057852 0.51008086 0.63837393 0.22056416 0.74386461
  0.94673388 0.98933934 0.80076636 0.43450966 0.09145941 0.48246455
  0.97571431 0.0635358  0.78716189 0.14841272 0.97617542 0.84753924
  0.86312071 0.30659987 0.56769031 0.83987536 0.2818678  0.61745352
  0.20236613 0.44194742 0.20136011 0.70478929 0.81369772 0.64082679
  0.58836394 0.4405892  0.58239543 0.88344139 0.14956161 0.73649931
  0.07653746 0.6726465 ]
 [0.80857067 0.62109056 0.88911834 0.41281895 0.2843382  0.72506928
  0.24971596 0.74377068 0.44387595 0.95477941 0.11043901 0.20102694
  0.4691736  0.81217928 0.22625212 0.68598281 0.69745939 0.49944524
  0.09048105 0.17302212 0.03534    0.60489602 0.78473337 0.04339872
  0.12817508 0.97542835 0.73614003 0.68608745 0.60052989 0.45384906
  0.7319914  0.9108467  0.6451067  0.72519248 0.45035369 0.69334366
  0.89539668 0.67290762 0.45551939 0.73347497 0.86775028 0.70390631
  0.96396717 0.72575174 0.90231668 0.94888631 0.75305097 0.15161616
  0.24388444 0.42559024]
 [0.99463    0.7871737  0.00510883 0.90533818 0.34414145 0.87676274
  0.90090695 0.66464074 0.80805482 0.3795309  0.49106335 0.05626103
  0.36658312 0.77038479 0.02500445 0.91319373 0.97778999 0.04531324
  0.11354879 0.0270773  0.10091272 0.528405   0.2763205  0.43958702
  0.44085968 0.38832208 0.54363565 0.88348489 0.20552766 0.04725506
  0.60503729 0.49566768 0.03416483 0.58658341 0.21417494 0.6150961
  0.32287173 0.67745245 0.11717401 0.39365258 0.56746953 0.21409535
  0.58133892 0.6062052  0.30311154 0.99881597 0.79324476 0.18337897
  0.96021361 0.04825896]
 [0.70884632 0.34913842 0.66450166 0.12453117 0.80291267 0.48307244
  0.51101695 0.80950692 0.94541203 0.82537595 0.20717741 0.48837849
  0.84521378 0.6439665  0.89353236 0.54638502 0.94552672 0.07002941
  0.72363799 0.23143915 0.76395865 0.39109327 0.36776614 0.99335617
  0.37354769 0.18578341 0.46206491 0.40761945 0.15367134 0.7590718
  0.47022282 0.71788545 0.51746472 0.05831365 0.6858456  0.729735
  0.44895425 0.45508462 0.65512142 0.67499738 0.01107883 0.85872151
  0.79262727 0.69867842 0.23109404 0.45902497 0.24012692 0.6461516
  0.52494413 0.15775344]
 [0.89851854 0.5301304  0.78672419 0.51305432 0.59109453 0.22274539
  0.34489178 0.53899105 0.51567676 0.2264872  0.52928424 0.55714172
  0.76873307 0.11287781 0.22560035 0.91261951 0.11444147 0.99674029
  0.35454559 0.37508182 0.59065883 0.20548459 0.86919923 0.78711871
  0.43178635 0.47816341 0.66977181 0.98515721 0.41170667 0.48214332
  0.68420563 0.87726592 0.62036541 0.41407428 0.40599126 0.19867021
  0.33153751 0.33947008 0.65283258 0.23155158 0.69000544 0.41037279
  0.10046487 0.18179493 0.53129739 0.09693436 0.35318275 0.58960321
  0.30855255 0.69447926]]
...

descriptors:
session = 1
subj = 1


obs_descriptors:
conds = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]


channel_descriptors:
voxels = ['voxel_0' 'voxel_1' 'voxel_2' 'voxel_3' 'voxel_4' 'voxel_5' 'voxel_6'
 'voxel_7' 'voxel_8' 'voxel_9' 'voxel_10' 'voxel_11' 'voxel_12' 'voxel_13'
 'voxel_14' 'voxel_15' 'voxel_16' 'voxel_17' 'voxel_18' 'voxel_19'
 'voxel_20' 'voxel_21' 'voxel_22' 'voxel_23' 'voxel_24' 'voxel_25'
 'voxel_26' 'voxel_27' 'voxel_28' 'voxel_29' 'voxel_30' 'voxel_31'
 'voxel_32' 'voxel_33' 'voxel_34' 'voxel_35' 'voxel_36' 'voxel_37'
 'voxel_38' 'voxel_39' 'voxel_40' 'voxel_41' 'voxel_42' 'voxel_43'
 'voxel_44' 'voxel_45' 'voxel_46' 'voxel_47' 'voxel_48' 'voxel_49']


Additionally, you might want to split the data in a certain way and analyze the splits as separate datasets. For instance, if your data is organized such that there are different ROIs, you might wish to perform the subsequent analyses separately for each ROI. Similarly, you could split the observations. This is supported with ‘split_obs’ and ‘split_channel’ options on the dataset object.

[5]:
# Split by channels
nChannel = 3
nChannelVox = 10 # three ROIs, each with 10 voxels
nObs = 4
randomData = np.random.rand(nObs, nChannel*nChannelVox)
des = {'session': 1, 'subj': 1}
obs_des = {'conds': np.array([0, 1, 2, 3])}
chn_des = ['ROI1', 'ROI2', 'ROI3'] * nChannelVox
chn_des = {'ROIs': np.array(chn_des)}
data = rsd.Dataset(measurements=randomData,
                        descriptors=des,
                        obs_descriptors=obs_des,
                        channel_descriptors=chn_des
                        )
split_data = data.split_channel(by='ROIs')
print(split_data)
[rsatoolbox.data.Dataset(
measurements =
[[2.72517419e-01 6.29869066e-01 1.61217030e-04 6.91723973e-01
  7.05569326e-01 9.50770933e-01 7.89382007e-01 9.78685869e-01
  2.90501341e-01 7.03136292e-01]
 [2.01005582e-01 5.46987762e-01 4.84408356e-01 5.88773463e-01
  8.38763394e-01 5.84621828e-01 8.63289698e-03 4.01037703e-01
  4.55127908e-01 3.64116665e-01]
 [1.69157574e-01 8.80178106e-01 4.75415837e-01 4.66419825e-01
  4.85189987e-02 9.62232648e-01 7.74986919e-01 9.11800689e-01
  7.01191521e-01 3.20210323e-02]
 [9.20122144e-01 5.68003364e-02 2.01368202e-01 2.44601779e-01
  1.52852082e-01 5.83556175e-01 6.09733866e-01 2.05660245e-01
  8.96234776e-01 3.81140491e-01]]
descriptors =
{'session': 1, 'subj': 1, 'ROIs': 'ROI1'}
obs_descriptors =
{'conds': array([0, 1, 2, 3])}
channel_descriptors =
{'ROIs': ['ROI1', 'ROI1', 'ROI1', 'ROI1', 'ROI1', 'ROI1', 'ROI1', 'ROI1', 'ROI1', 'ROI1']}
, rsatoolbox.data.Dataset(
measurements =
[[0.48887379 0.94426476 0.79195955 0.11657703 0.44759874 0.49354955
  0.99405703 0.7597353  0.67750543 0.35842448]
 [0.48076803 0.48219176 0.69379026 0.79769113 0.986308   0.14662148
  0.12584384 0.27262398 0.14069117 0.71801102]
 [0.53121227 0.38996244 0.94361384 0.25981166 0.99963737 0.56341388
  0.20072944 0.51929482 0.77211341 0.76669663]
 [0.02856832 0.56713845 0.5022231  0.77638167 0.9456683  0.79228282
  0.47154943 0.03014779 0.07366922 0.7761286 ]]
descriptors =
{'session': 1, 'subj': 1, 'ROIs': 'ROI2'}
obs_descriptors =
{'conds': array([0, 1, 2, 3])}
channel_descriptors =
{'ROIs': ['ROI2', 'ROI2', 'ROI2', 'ROI2', 'ROI2', 'ROI2', 'ROI2', 'ROI2', 'ROI2', 'ROI2']}
, rsatoolbox.data.Dataset(
measurements =
[[0.2247359  0.03075053 0.98014391 0.70226989 0.85731247 0.46654314
  0.26387401 0.22773515 0.42498146 0.74526147]
 [0.70863469 0.55009993 0.20466565 0.64714747 0.82247528 0.67812818
  0.59701587 0.73316271 0.22733862 0.65243424]
 [0.99901607 0.0605083  0.3499693  0.60444848 0.99995232 0.82589276
  0.83958596 0.24297735 0.22850155 0.25867374]
 [0.09076963 0.64408221 0.16040078 0.93010608 0.71173121 0.25981076
  0.74035623 0.41395826 0.76055803 0.66228303]]
descriptors =
{'session': 1, 'subj': 1, 'ROIs': 'ROI3'}
obs_descriptors =
{'conds': array([0, 1, 2, 3])}
channel_descriptors =
{'ROIs': ['ROI3', 'ROI3', 'ROI3', 'ROI3', 'ROI3', 'ROI3', 'ROI3', 'ROI3', 'ROI3', 'ROI3']}
]

2. Multi-subject dataset example

First, we generate random data for a number of subjects. For simplicity, here we set each subject to have the same number of voxels and conditions.

[6]:
# create a datasets with random data
nVox = 50 # 50 voxels/electrodes/measurement channels
nCond = 10 # 10 conditions
nSubj = 5 # 5 different subjects
randomData = np.random.rand(nCond, nVox, nSubj)

We can then create a list of dataset objects by appending each dataset for each subject.

[7]:
obs_des = {'conds': np.array(['cond_' + str(x) for x in np.arange(nCond)])}
chn_des = {'voxels': np.array(['voxel_' + str(x) for x in np.arange(nVox)])}

data = [] # list of dataset objects
for i in np.arange(nSubj):
    des = {'session': 1, 'subj': i+1}
    # append the dataset object to the data list
    data.append(rsd.Dataset(measurements=randomData[:,:,i],
                        descriptors=des,
                        obs_descriptors=obs_des,
                        channel_descriptors=chn_des
                        )
               )
[ ]: