Skip to content

Commit

Permalink
ENH: Restore correlation plots
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Dec 19, 2018
1 parent f165116 commit 760830d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fitlins/interfaces/visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,24 @@ def _visualize(self, data, out_name):


class DesignCorrelationPlotInputSpec(VisualizationInputSpec):
explanatory_variables = traits.Range(
low=0, desc='Number of explanatory variables')
contrast_info = traits.List(traits.Dict)


class DesignCorrelationPlot(Visualization):
input_spec = DesignCorrelationPlotInputSpec

def _visualize(self, data, out_name):
contrast_matrix = pd.DataFrame({c['name']: c['weights'][0]
for c in self.inputs.contrast_info})
all_cols = list(data.columns)
evs = set(contrast_matrix.index)
if set(contrast_matrix.index) != all_cols[:len(evs)]:
ev_cols = [col for col in all_cols if col in evs]
confound_cols = [col for col in all_cols if col not in evs]
data = data[ev_cols + confound_cols]
plot_and_save(out_name, plot_corr_matrix,
data.drop(columns='constant').corr(),
self.inputs.explanatory_variables)
len(evs))


class ContrastMatrixPlotInputSpec(VisualizationInputSpec):
Expand Down
16 changes: 16 additions & 0 deletions fitlins/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, space, exclude_pattern=None,
iterfield='data',
name='plot_design')

plot_corr = pe.MapNode(
DesignCorrelationPlot(image_type='svg'),
iterfield=['data', 'contrast_info'],
name='plot_corr')

plot_l1_contrast_matrix = pe.MapNode(
ContrastMatrixPlot(image_type='svg'),
iterfield=['data', 'contrast_info'],
Expand All @@ -104,6 +109,13 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, space, exclude_pattern=None,
run_without_submitting=True,
name='ds_design')

ds_corr = pe.MapNode(
BIDSDataSink(base_directory=out_dir, fixed_entities={'suffix': 'corr'},
path_patterns=image_pattern),
iterfield=['entities', 'in_file'],
run_without_submitting=True,
name='ds_corr')

ds_l1_contrasts = pe.MapNode(
BIDSDataSink(base_directory=out_dir, fixed_entities={'suffix': 'contrasts'},
path_patterns=image_pattern),
Expand Down Expand Up @@ -185,9 +197,13 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, space, exclude_pattern=None,
(select_entities, ds_design, [('out', 'entities')]),
(plot_design, ds_design, [('figure', 'in_file')]),
(select_contrasts, plot_l1_contrast_matrix, [('out', 'contrast_info')]),
(select_contrasts, plot_corr, [('out', 'contrast_info')]),
(model, plot_l1_contrast_matrix, [('design_matrix', 'data')]),
(model, plot_corr, [('design_matrix', 'data')]),
(select_entities, ds_l1_contrasts, [('out', 'entities')]),
(select_entities, ds_corr, [('out', 'entities')]),
(plot_l1_contrast_matrix, ds_l1_contrasts, [('figure', 'in_file')]),
(plot_corr, ds_corr, [('figure', 'in_file')]),
])

# Set up higher levels
Expand Down

0 comments on commit 760830d

Please sign in to comment.