Skip to content

Commit

Permalink
Merge pull request #30 from Remi-Gau/fix_demos
Browse files Browse the repository at this point in the history
[FIX] improve matlab demos and setup
  • Loading branch information
Kendrick Kay authored Mar 21, 2022
2 parents 16fe476 + 8af1a27 commit 0d835eb
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 50 deletions.
37 changes: 36 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# data folder
data/

# example output folders
example*outputs

# various output
figures/
report.html
Expand Down Expand Up @@ -116,6 +119,38 @@ venv.bak/
.mypy_cache/

# mat and npy files
*.mat
*.npy

## added from https://github.com/github/gitignore/blob/main/Global/MATLAB.gitignore
# Windows default autosave extension
*.asv

# OSX / *nix default autosave extension
*.m~

# Compiled MEX binaries (all platforms)
*.mex*

# Packaged app and toolbox files
*.mlappinstall
*.mltbx

# Generated helpsearch folders
helpsearch*/

# Simulink code generation folders
slprj/
sccprj/

# Matlab code generation folders
codegen/

# Simulink autosave extension
*.autosave

# Simulink cache files
*.slxc

# Octave session info
octave-workspace

4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "matlab/fracridge"]
path = matlab/fracridge
url = https://github.com/nrdg/fracridge.git
datalad-url = https://github.com/nrdg/fracridge.git
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ raising a Github issue.

## MATLAB

To use the GLMsingle toolbox, add it to your MATLAB path:
addpath(genpath('GLMsingle/matlab'));
To install:

```bash
git clone --recurse-submodules https://github.com/cvnlab/GLMsingle.git
```

This will also clone [`fracridge`](https://github.com/nrdg/fracridge) as a submodule.

You will also need to download and add fracridge to your path.
It is available here: https://github.com/nrdg/fracridge
To use the GLMsingle toolbox, add it and `fracridge` to your MATLAB path by running the `setup.m` script.

## Example scripts

Expand Down
1 change: 1 addition & 0 deletions matlab/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
download
26 changes: 26 additions & 0 deletions matlab/examples/download_data.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function download_data(URL, input_file)

if ~exist(input_file, 'file')

% this fails on some machines ubuntu 18.04
if ispc
system(sprintf('curl -L --output %s %s', input_file, URL))

else
try
urlwrite(URL, input_file);
catch
this_dir = fileparts(mfilename('fullfile'));
if exist(fullfile(this_dir, 'download'), 'file')
% remove eventual previously incomplete downloads
delete(fullfile(this_dir, 'download'))
end
system(sprintf('wget --verbose %s', URL));
movefile(fullfile(this_dir, 'download'), input_file);
end

end

end

end
40 changes: 19 additions & 21 deletions matlab/examples/example1.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,32 @@

%% Add dependencies and download the example dataset

% We will assume that the current working directory is the directory that
% contains this script.

% Add path to GLMsingle
addpath(genpath('../../matlab'));

% You also need fracridge repository to run this code. For example, you
% could do:
% git clone https://github.com/nrdg/fracridge.git
% and then do:
% addpath('fracridge')

% Start fresh
clear
clc
close all

this_dir = fileparts(mfilename('fullpath'));

% Add path to GLMsingle
run(fullfile(this_dir, '..', '..', 'setup.m'));

% Name of directory to which outputs will be saved
outputdir = 'example1outputs';
outputdir = fullfile(this_dir, 'example1outputs');

% Download files to data directory
if ~exist('./data','dir')
input_dir = fullfile(this_dir, 'data');
if ~exist(input_dir, 'dir')
mkdir('data')
end

if ~exist('./data/nsdcoreexampledataset.mat','file')
% download data with curl
system('curl -L --output ./data/nsdcoreexampledataset.mat https://osf.io/k89b2/download')
end
load('./data/nsdcoreexampledataset.mat')
input_file = fullfile(input_dir, 'nsdcoreexampledataset.mat');
URL = 'https://osf.io/k89b2/download';

download_data(URL, input_file);

load(input_file)

% Data comes from the NSD dataset (subj01, nsd01 scan session).
% https://www.biorxiv.org/content/10.1101/2021.02.22.432340v1.full.pdf

Expand Down Expand Up @@ -198,7 +194,9 @@
% "example1outputs/GLMsingle". If these outputs don't already exist, we
% will perform the time-consuming call to GLMestimatesingletrial.m;
% otherwise, we will just load from disk.
if ~exist([outputdir '/GLMsingle'],'dir')
if ~exist(fullfile(outputdir, 'GLMsingle', 'TYPEB_FITHRF.mat'),'file') || ...
~exist(fullfile(outputdir, 'GLMsingle', 'TYPEC_FITHRF_GLMDENOISE.mat'),'file') || ...
~exist(fullfile(outputdir, 'GLMsingle', 'TYPED_FITHRF_GLMDENOISE_RR.mat'),'file')

[results] = GLMestimatesingletrial(design,data,stimdur,tr,[outputdir '/GLMsingle'],opt);

Expand Down Expand Up @@ -293,7 +291,7 @@

% If these outputs don't already exist, we will perform the call to
% GLMestimatesingletrial.m; otherwise, we will just load from disk.
if ~exist([outputdir '/GLMbaseline'],'dir')
if ~exist(fullfile(outputdir, 'GLMbaseline', 'TYPEB_FITHRF.mat'),'file')

[ASSUME_HRF] = GLMestimatesingletrial(design,data,stimdur,tr,[outputdir '/GLMbaseline'],opt);
models.ASSUME_HRF = ASSUME_HRF{2};
Expand Down
39 changes: 18 additions & 21 deletions matlab/examples/example2.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,31 @@

%% Add dependencies and download the data

% We will assume that the current working directory is the directory that
% contains this script.

% Add path to GLMsingle
addpath(genpath('../../matlab'));

% You also need fracridge repository to run this code. For example, you
% could do:
% git clone https://github.com/nrdg/fracridge.git
% and then do:
% addpath('fracridge')

% Start fresh
clear
clc
close all

this_dir = fileparts(mfilename('fullpath'));

% Add path to GLMsingle
run(fullfile(this_dir, '..', '..', 'setup.m'));

% Name of directory to which outputs will be saved
outputdir = 'example2outputs';
outputdir = fullfile(this_dir, 'example2outputs');

% Download files to data directory
if ~exist('./data','dir')
input_dir = fullfile(this_dir, 'data');
if ~exist(input_dir, 'dir')
mkdir('data')
end

if ~exist('./data/nsdflocexampledataset.mat','file')
% download data with curl
system('curl -L --output ./data/nsdflocexampledataset.mat https://osf.io/g42tm/download')
end
load('./data/nsdflocexampledataset.mat')
input_file = fullfile(input_dir, 'nsdflocexampledataset.mat');
URL = 'https://osf.io/g42tm/download';

download_data(URL, input_file);

load(input_file)
% Data comes from the NSD dataset (subj01, floc experiment, runs 1-4).
% https://www.biorxiv.org/content/10.1101/2021.02.22.432340v1.full.pdf

Expand Down Expand Up @@ -205,7 +200,9 @@
% "example2outputs/GLMsingle". If these outputs don't already exist, we
% will perform the time-consuming call to GLMestimatesingletrial.m;
% otherwise, we will just load from disk.
if ~exist([outputdir '/GLMsingle'],'dir')
if ~exist(fullfile(outputdir, 'GLMsingle', 'TYPEB_FITHRF.mat'),'file') || ...
~exist(fullfile(outputdir, 'GLMsingle', 'TYPEC_FITHRF_GLMDENOISE.mat'),'file') || ...
~exist(fullfile(outputdir, 'GLMsingle', 'TYPED_FITHRF_GLMDENOISE_RR.mat'),'file')

[results] = GLMestimatesingletrial(design,data,stimdur,tr,[outputdir '/GLMsingle'],opt);

Expand Down Expand Up @@ -298,7 +295,7 @@

% If these outputs don't already exist, we will perform the call to
% GLMestimatesingletrial.m; otherwise, we will just load from disk.
if ~exist([outputdir '/GLMbaseline'],'dir')
if ~exist(fullfile(outputdir, 'GLMbaseline', 'TYPEB_FITHRF.mat'),'file')

[ASSUME_HRF] = GLMestimatesingletrial(design,data,stimdur,tr,[outputdir '/GLMbaseline'],opt);
models.ASSUME_HRF = ASSUME_HRF{2};
Expand Down
1 change: 1 addition & 0 deletions matlab/fracridge
Submodule fracridge added at 1ac49c
18 changes: 15 additions & 3 deletions setup.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
% This script adds GLMsingle to the MATLAB path.

% Add GLMsingle to the MATLAB path (in case the user has not already done so).
path0 = strrep(which('setup.m'),'/setup.m','/matlab');
addpath(genpath(path0));
clear path0;
GLMsingle_dir = fileparts(mfilename('fullfile'));

addpath(fullfile(GLMsingle_dir, 'matlab'));
addpath(fullfile(GLMsingle_dir, 'matlab', 'utilities'));

% if the submodules were installed we try to add their code to the path
addpath(fullfile(GLMsingle_dir, 'matlab', 'fracridge', 'matlab'));

% check that the dependencies are in the path
tmp = which('fracridge.m');
if isempty(tmp)
error('fracridge is missing. Please install from: https://github.com/nrdg/fracridge.git')
end

clear GLMsingle_dir;

0 comments on commit 0d835eb

Please sign in to comment.