Skip to content

[WIP] update transparent plotting demo #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
93 changes: 2 additions & 91 deletions demos/MoAE/moae_03_slice_display.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,104 +18,15 @@

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

subLabel = '01';

opt.pipeline.type = 'stats';

opt.dir.raw = fullfile(this_dir, 'inputs', 'raw');
opt.dir.derivatives = fullfile(this_dir, 'outputs', 'derivatives');
opt.dir.preproc = fullfile(opt.dir.derivatives, 'bidspm-preproc');

opt.dir.roi = fullfile(opt.dir.derivatives, 'bidspm-roi');
opt.dir.stats = fullfile(opt.dir.derivatives, 'bidspm-stats');

opt.model.file = fullfile(this_dir, 'models', 'model-MoAE_smdl.json');

% Specify the result to compute
opt.results(1).nodeName = 'run_level';

opt.results(1).name = 'listening';
% MONTAGE FIGURE OPTIONS
opt.results(1).montage.do = true();
opt.results(1).montage.slices = -4:2:16; % in mm
% axial is default 'sagittal', 'coronal'
opt.results(1).montage.orientation = 'axial';
% will use the MNI T1 template by default but the underlay image can be changed.
opt.results(1).montage.background = ...
fullfile(spm('dir'), 'canonical', 'avg152T1.nii');
opt.subjects = {'01'};

opt = checkOptions(opt);

use_schema = false;
BIDS_ROI = bids.layout(opt.dir.roi, 'use_schema', use_schema);

filter = struct('sub', subLabel, ...
'hemi', 'R', ...
'desc', 'auditoryCortex');

rightRoiFile = bids.query(BIDS_ROI, 'data', filter);

filter.hemi = 'L';

leftRoiFile = bids.query(BIDS_ROI, 'data', filter);

% we get the con image to extract data
ffxDir = getFFXdir(subLabel, opt);
maskImage = spm_select('FPList', ffxDir, '^.*_mask.nii$');
bf = bids.File(spm_file(maskImage, 'filename'));
conImage = spm_select('FPList', ffxDir, ['^con_' bf.entities.label '.nii$']);

%% Layers to put on the figure
layers = sd_config_layers('init', {'truecolor', 'dual', 'contour', 'contour'});

% Layer 1: Anatomical map
[anat_normalized_file, anatRange] = return_normalized_anat_file(opt, subLabel);
layers(1).color.file = anat_normalized_file;
layers(1).color.range = [0 anatRange(2)];

layers(1).color.map = gray(256);

%% Layer 2: Dual-coded layer
%
% - contrast estimates color-coded;

layers(2).color.file = conImage;

color_map_folder = fullfile(fileparts(which('map_luminance')), '..', 'mat_maps');
load(fullfile(color_map_folder, 'diverging_bwr_iso.mat'));
layers(2).color.map = diverging_bwr;

layers(2).color.range = [-4 4];
layers(2).color.label = '\beta_{listening} - \beta_{baseline} (a.u.)';

%% Layer 2: Dual-coded layer
%
% - t-statistics opacity-coded

spmTImage = spm_select('FPList', ffxDir, ['^spmT_' bf.entities.label '.nii$']);
layers(2).opacity.file = spmTImage;

layers(2).opacity.range = [2 3];
layers(2).opacity.label = '| t |';

%% Layer 3 and 4: Contour of ROI

layers(3).color.file = rightRoiFile{1};
layers(3).color.map = [0 0 0];
layers(3).color.line_width = 2;

layers(4).color.file = leftRoiFile{1};
layers(4).color.map = [1 1 1];
layers(4).color.line_width = 2;

%% Settings
settings = sd_config_settings('init');

% we reuse the details for the SPM montage
settings.slice.orientation = opt.results(1).montage.orientation;
settings.slice.disp_slices = -15:3:18;
settings.fig_specs.n.slice_column = 4;
settings.fig_specs.title = opt.results(1).name;

%% Display the layers
[settings, p] = sd_display(layers, settings);
transparentMontage(opt);
26 changes: 0 additions & 26 deletions demos/MoAE/return_normalized_anat_file.m

This file was deleted.

2 changes: 1 addition & 1 deletion lib/slice_display
Submodule slice_display updated 1 files
+2 −2 sd_display.m
1 change: 1 addition & 0 deletions src/bids_model/BidsModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
end

function results = getResults(obj)
% return results from all nodes

results = struct([]);
idx = 1;
Expand Down
14 changes: 7 additions & 7 deletions src/defaults/defaultResultsStructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
% load(fullfile(color_map_folder, 'diverging_bwr_iso.mat'));

layers{2} = struct('color', struct('file', [], ... % con image
'map', 'diverging_bwr_iso', ...
'range', [-4 4]), ...
'label', '\beta_{listening} - \beta_{baseline} (a.u.)', ...
'opacity', struct('file', [], ... % spmT image
'range', [-4 4], ...
'label', ''), ...
'opacity', struct('file', [], ... % assume spmT image
'range', [2 3], ...
'label', '| t |'));
'label', ''), ...
'type', 'dual');

layers{3} = struct('color', struct('file', [], ... % spmT mask thresholded at 0.05 FWD
'map', [0 0 0], ...
'line_width', 2));
'map', 'w', ...
'line_width', 1));

result.sdConfig.layers = layers;

Expand Down
70 changes: 70 additions & 0 deletions src/stats/results/checkMontage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function [opt, BIDS] = checkMontage(opt, iRes, node, BIDS, subLabel)
%
% Check values for create a slice montage.
%
% Set default values if they are missing.
%
% USAGE::
%
% [opt, BIDS] = checkMontage(opt, iRes, node, BIDS, subLabel)
%
%

% (C) Copyright 2019 bidspm developers

if nargin < 4
BIDS = '';
subLabel = '';
end

if isfield(opt.results(iRes), 'montage') && any(opt.results(iRes).montage.do)

background = opt.results(iRes).montage.background;

% TODO refactor with getInclusiveMask
if isstruct(background)

if ismember(lower(node.Level), {'run', 'session', 'subject'})

if isempty(BIDS)
BIDS = bids.layout(opt.dir.preproc, ...
'use_schema', false, ...
'index_dependencies', false, ...
'filter', struct('sub', {opt.subjects}));
end

background.sub = subLabel;
background.space = opt.space;
file = bids.query(BIDS, 'data', background);

if iscell(file)
if isempty(file)
% let checkMaskOrUnderlay figure it out
file = '';

elseif numel(file) == 1
file = file{1};

elseif numel(file) > 1
file = file{1};

msg = sprintf('More than 1 overlay image found for %s.\n Taking the first one.', ...
bids.internal.create_unordered_list(background));
id = 'tooManyMontageBackground';
logger('WARNING', msg, 'id', id, 'options', opt, 'filename', mfilename());
end

end

background = file;

end

end

background = checkMaskOrUnderlay(background, opt, 'background');
opt.results(iRes).montage.background = background;

end

end
21 changes: 13 additions & 8 deletions src/stats/results/renameSpmT.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ function renameSpmT(result)
%

% (C) Copyright 2023 bidspm developers
outputFiles = spm_select('FPList', result.dir, '^spmT_[0-9].*_sub-.*nii$');
prefixes = {'spmT', 'spmF'};
for i_prefix = 1:numel(prefixes)

for iFile = 1:size(outputFiles, 1)
outputFiles = spm_select('FPList', result.dir, ['^' prefixes{i_prefix} '_[0-9].*_sub-.*nii$']);

source = deblank(outputFiles(iFile, :));
for iFile = 1:size(outputFiles, 1)

basename = spm_file(source, 'basename');
split = strfind(basename, '_sub');
bf = bids.File(basename(split + 1:end));
source = deblank(outputFiles(iFile, :));

target = spm_file(source, 'basename', bf.filename);
basename = spm_file(source, 'basename');
split = strfind(basename, '_sub');
bf = bids.File(basename(split + 1:end));

target = spm_file(source, 'basename', bf.filename);

movefile(source, target);
end

movefile(source, target);
end
end
Loading
Loading