8000 FIX: Handle correct contrasts and intercepts being passed from PyBIDS by effigies · Pull Request #387 · poldracklab/fitlins · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FIX: Handle correct contrasts and intercepts being passed from PyBIDS #387

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

Merged
merged 4 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fitlins/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def get_parser():

def run_fitlins(argv=None):
import re
import nipype
from nipype import logging as nlogging

warnings.showwarning = _warn_redirect
Expand All @@ -279,6 +280,9 @@ def run_fitlins(argv=None):
for ign in opts.ignore or ()
]

if opts.debug:
nipype.config.set('execution', 'remove_unnecessary_outputs', False)

log_level = 25 + 5 * (opts.quiet - opts.verbose)
logger.setLevel(log_level)
nlogging.getLogger('nipype.workflow').setLevel(log_level)
Expand Down
24 changes: 16 additions & 8 deletions fitlins/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def sample_model_dict():
},
"Model": {"X": ["trial_type.ice_cream", "trial_type.cake", "food_sweats"]},
"DummyContrasts": {
"Conditions": ["trial_type.ice_cream", "trial_type.cake"],
"Contrasts": ["trial_type.ice_cream", "trial_type.cake"],
"Test": "t",
},
"Contrasts": [
Expand All @@ -69,13 +69,16 @@ def sample_model_dict():
},
{
"Level": "dataset",
"Name": "all_food_good_food",
"Name": "dataset",
"GroupBy": ["contrast"],
"Model": {"X": [1]},
"DummyContrasts": {
"Conditions": ["icecream_gt_cake", "eating_vs_baseline"],
"Test": "t",
},
"Model": {"X": [1], "Type": "glm"},
"DummyContrasts": {"Test": "t"},
},
{
"Level": "dataset",
"Name": "all_food_good_food",
"GroupBy": [],
"Model": {"X": ["trial_type.ice_cream", "trial_type.cake"], "Type": "glm"},
"Contrasts": [
{
"Name": "all_food_good_food",
Expand All @@ -90,9 +93,14 @@ def sample_model_dict():
{"Source": "run", "Destination": "subject"},
{
"Source": "subject",
"Destination": "all_food_good_food",
"Destination": "dataset",
"Filter": {"contrast": ["icecream_gt_cake", "eating_vs_baseline"]},
},
{
"Source": "subject",
"Destination": "all_food_good_food",
"Filter": {"contrast": ["trial_type.ice_cream", "trial_type.cake"]},
},
],
}

Expand Down
2 changes: 2 additions & 0 deletions fitlins/interfaces/afni.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def save_tsnr(self, runtime, rbetas, rvars):
# find the name of the constant column
if 'constant' in mat.columns:
const_name = 'constant'
elif 'intercept' in mat.columns:
const_name = 'intercept'
else:
const_name = mat.columns[np.isclose(mat, 1).all(0)].values[0]
const_idx = np.where(np.array(vol_labels) == const_name)[0]
Expand Down
7 changes: 7 additions & 0 deletions fitlins/interfaces/nistats.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ def _run_interface(self, runtime):
add_reg_names=column_names,
drift_model=drift_model,
)
# Can get two intercepts from input and nilearn ("constant")
# Normalize to "intercept" unless that exists and is really non-1
# Force to be exactly 1, in case of weird rounding errors
intercept = 'intercept' in mat or 'constant' in mat
mat.drop(columns=['intercept', 'constant'], errors='ignore', inplace=True)
if intercept:
mat['intercept'] = np.ones(mat.shape[0], dtype='u1')

mat.to_csv('design.tsv', sep='\t')
self._results['design_matrix'] = os.path.join(runtime.cwd, 'design.tsv')
Expand Down
2 changes: 1 addition & 1 deletion fitlins/interfaces/visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _visualize(self, data, out_name):
plot_and_save(
out_name,
plot_corr_matrix,
data.drop(columns='constant', errors='ignore').corr(),
data.drop(columns=['intercept', 'constant'], errors='ignore').corr(),
len(evs),
)

Expand Down
2 chan 7DAF ges: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install_requires =
nilearn~=0.9.1
pandas>=0.19
tables>=3.2.1
pybids~=0.15.1
pybids~=0.15.4
jinja2

[options.extras_require]
Expand Down
0