Contents
Dataset basics
- For CoSMoMVPA's copyright information and license terms, #
- see the COPYING file distributed with CoSMoMVPA. #
% Set data path, load dataset, set targets and chunks, and add labels as % sample attributes % Set the data path config = cosmo_config(); data_path = fullfile(config.tutorial_data_path, 'ak6', 's01'); % Set the filename to the glm_T_stats_perrun NIFTI file; assign % the filename to a variable named 'fn' % >@@> fn = fullfile(data_path, 'glm_T_stats_perrun.nii'); % <@@< % Load data using cosmo_fmri_dataset, and assign the result to a variable % named 'ds' % >@@> ds = cosmo_fmri_dataset(fn); % <@@< % set ds.sa.targets (trial conditions) to the 60x1 column vector: % [ 1 2 3 4 5 6 1 2 3 ... 5 6 ]' % >@@> targets = repmat((1:6)', 10, 1); ds.sa.targets = targets; % <@@< % sanity check cosmo_check_dataset(ds); % set ds.sa.chunks (acquisition run number) to the 60x1 column vector: % [ 1 1 1 1 1 1 2 2 2 ... 10 10 ]' % >@@> chunks = zeros(60, 1); for i = 1:10 idxs = (i - 1) * 6 + (1:6); chunks(idxs) = i; end ds.sa.chunks = chunks; % ( alternative: ds.sa.chunks = ceil((1:60)'/6); ) % <@@< % sanity check cosmo_check_dataset(ds); % Add ds.sa.labels as sample attributes as a 60x1 cell with strings % The order is {monkey, lemur, mallard, warbler, ladybug, and lunamoth}, % repeated 10 times % >@@> labels = repmat({ 'monkey' 'lemur' 'mallard' 'warbler' 'ladybug' 'lunamoth'}, 10, 1); ds.sa.labels = labels; % <@@< % sanity check cosmo_check_dataset(ds);
Overview of the dataset
fprintf('\nOverview of dataset:\n');
cosmo_disp(ds);
Overview of dataset:
.a                                                                   
  .vol                                                               
    .mat                                                             
      [ -3         0         0       121                             
         0         3         0      -114                             
         0         0         3     -11.1                             
         0         0         0         1 ]                           
    .xform                                                           
      'scanner_anat'                                                 
    .dim                                                             
      [ 80        80        43 ]                                     
  .fdim                                                              
    .labels                                                          
      { 'i'                                                          
        'j'                                                          
        'k' }                                                        
    .values                                                          
      { [ 1         2         3  ...  78        79        80 ]@1x80  
        [ 1         2         3  ...  78        79        80 ]@1x80  
        [ 1         2         3  ...  41        42        43 ]@1x43 }
.sa                                                                  
  .targets                                                           
    [ 1                                                              
      2                                                              
      3                                                              
      :                                                              
      4                                                              
      5                                                              
      6 ]@60x1                                                       
  .chunks                                                            
    [  1                                                             
       1                                                             
       1                                                             
       :                                                             
      10                                                             
      10                                                             
      10 ]@60x1                                                      
  .labels                                                            
    { 'monkey'                                                       
      'lemur'                                                        
      'mallard'                                                      
          :                                                          
      'warbler'                                                      
      'ladybug'                                                      
      'lunamoth' }@60x1                                              
.samples                                                             
  [ 0         0         0  ...  0         0         0                
    0         0         0  ...  0         0         0                
    0         0         0  ...  0         0         0                
    :         :         :       :         :         :                
    0         0         0  ...  0         0         0                
    0         0         0  ...  0         0         0                
    0         0         0  ...  0         0         0 ]@60x275200    
.fa                                                                  
  .i                                                                 
    [ 1         2         3  ...  78        79        80 ]@1x275200  
  .j                                                                 
    [ 1         1         1  ...  80        80        80 ]@1x275200  
  .k                                                                 
    [ 1         1         1  ...  43        43        43 ]@1x275200  
Apply mask to dataset
fn_mask = fullfile(data_path, 'vt_mask.nii'); % Load mask using cosmo_fmri_dataset and store in ds_mask % >@@> ds_mask = cosmo_fmri_dataset(fn_mask); % <@@< % sanity check: ensure the same feature attributes assert(isequal(ds_mask.fa, ds.fa)); % Now slice the dataset using cosmo_slice, where the third argument must be % 2 to indicate the slicing of features (not samples). % Assign the result to a variable 'ds_masked'. % >@@> mask_indices = find(ds_mask.samples); ds_masked = cosmo_slice(ds, mask_indices, 2); cosmo_disp(ds_masked); % <@@<
.a                                                                   
  .vol                                                               
    .mat                                                             
      [ -3         0         0       121                             
         0         3         0      -114                             
         0         0         3     -11.1                             
         0         0         0         1 ]                           
    .xform                                                           
      'scanner_anat'                                                 
    .dim                                                             
      [ 80        80        43 ]                                     
  .fdim                                                              
    .labels                                                          
      { 'i'                                                          
        'j'                                                          
        'k' }                                                        
    .values                                                          
      { [ 1         2         3  ...  78        79        80 ]@1x80  
        [ 1         2         3  ...  78        79        80 ]@1x80  
        [ 1         2         3  ...  41        42        43 ]@1x43 }
.sa                                                                  
  .targets                                                           
    [ 1                                                              
      2                                                              
      3                                                              
      :                                                              
      4                                                              
      5                                                              
      6 ]@60x1                                                       
  .chunks                                                            
    [  1                                                             
       1                                                             
       1                                                             
       :                                                             
      10                                                             
      10                                                             
      10 ]@60x1                                                      
  .labels                                                            
    { 'monkey'                                                       
      'lemur'                                                        
      'mallard'                                                      
          :                                                          
      'warbler'                                                      
      'ladybug'                                                      
      'lunamoth' }@60x1                                              
.samples                                                             
  [ 0         0         0  ...  0.669      1.78      2.42            
    0         0         0  ...   1.06      1.61     0.943            
    0         0         0  ...   1.51      1.75      3.08            
    :         :         :         :          :        :              
    0         0         0  ...  0.491       1.1      1.78            
    0         0         0  ...  0.687      1.88      2.72            
    0         0         0  ...   2.86      4.04      4.28 ]@60x400   
.fa                                                                  
  .i                                                                 
    [ 51        53        54  ...  28        29        29 ]@1x400    
  .j                                                                 
    [ 24        24        24  ...  25        25        26 ]@1x400    
  .k                                                                 
    [ 2         2         2  ...  9         9         9 ]@1x400      
Now use cosmo_fmri_dataset with all input parameters
% We do exactly the same as above, but shorter: % Load the dataset again using cosmo_fmri_dataset, but now use the % 'mask','targets','chunks' parameters. % Assign the result to ds_masked_alt % >@@> ds_masked_alt = cosmo_fmri_dataset(fn, 'mask', fn_mask, ... 'targets', targets, ... 'chunks', chunks); % <@@< % set labels again ds_masked_alt.sa.labels = labels; % check ds_masked and ds_masked_alt are the same assert(isequal(ds_masked_alt, ds_masked));