Skip to content
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

Regressor has extra item, causing mismatch #390

Open
smeisler opened this issue Nov 2, 2022 · 8 comments
Open

Regressor has extra item, causing mismatch #390

smeisler opened this issue Nov 2, 2022 · 8 comments

Comments

@smeisler
Copy link
Contributor

smeisler commented Nov 2, 2022

Environment

  • fitlins version: 0.11
  • Running via singularity on linux HPC

Expected and Observed Behavior

I had run the same basic model (subject-level contrast maps) for different tasks in the same subjects, and it ran fine. The only difference between the models are the trial_types and resulting contrast names.

I get the following error:

Traceback (most recent call last):
  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node _design_matrix0.

Traceback:
	Traceback (most recent call last):
	  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._run_interface(runtime)
	  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/fitlins/interfaces/nistats.py", line 124, in _run_interface
	    mat = dm.make_first_level_design_matrix(
	  File "/opt/miniconda-latest/envs/neuro/lib/python3.9/site-packages/nilearn/glm/first_level/design_matrix.py", line 337, in make_first_level_design_matrix
	    assert add_regs_.shape[0] == np.size(frame_times), ValueError(
	AssertionError: Incorrect specification of additional regressors: length of regressors provided: 425, number of time-frames: 424

The number of time points in the run is indeed 424, and the confounds.tsv file also as 424 rows (not including the header column), so I am not seeing where this extra column is coming from.

I used the same fMRIPrep version to produce the different tasks, and they completed without errors. So it is unclear why this one task is causing problems while the others are not.

Steps to Reproduce

  1. run fMRIPrep 22.0.0 with --cifti-output 91k flag
  2. run fitlins to process cifti data: --space "fsLR" --drop-missing -s 5 --desc-label "" flags. Error also happens with volumetric data.
  3. Model is below:
{
   "Name":"face-model-6MP5ACompCor",
   "BIDSModelVersion":"1.0.0",
   "Description":"",
   "Input":{
      "task":["face"]
   },
   "Nodes":[
      {
         "Level":"run",
         "Name":"runFace6MP5ACompCor",
         "GroupBy":[
            "subject",
	    "session",
	    "run"
         ],
	"Transformations":{
            "Transformer":"pybids-transforms-v1",
            "Instructions":[
               {
                  "Name":"Factor",
                  "Input":[
                     "trial_type"
                  ]
               },
               {
                  "Name":"Convolve",
                  "Input":[
                     "trial_type.Happy",
                     "trial_type.Fearful",
		     "trial_type.Sad",
                     "trial_type.Neutral",
                     "trial_type.Object"
                  ],
                  "Model":"spm"
               }
            ]
         },
         "Model":{
            "X":[
               "trial_type.Happy",
               "trial_type.Fearful",
	       "trial_type.Sad",
               "trial_type.Neutral",
               "trial_type.Object",
	       "non_steady_state*",
	       "trans_x",
               "trans_y",
               "trans_z",
               "rot_x",
               "rot_y",
               "rot_z",
	       "a_comp_cor_00",
	       "a_comp_cor_01",
	       "a_comp_cor_02",
	       "a_comp_cor_03",
	       "a_comp_cor_04",
	       "cosine*",
               1
            ],
           "Type":"glm"
         },
         "Contrasts":[
            {
               "Name":"faces_gt_object",
               "ConditionList":[
                  "trial_type.Happy",
                  "trial_type.Fearful",
	          "trial_type.Sad",
                  "trial_type.Neutral",
                  "trial_type.Object"
               ],
               "Weights":[
                  0.25,
		  0.25,
		  0.25,
		  0.25,
                  -1
               ],
               "Test":"t"
            },
	    {
               "Name":"sad_gt_neutral",
               "ConditionList":[
	          "trial_type.Sad",
                  "trial_type.Neutral"
               ],
               "Weights":[
                  1,
                  -1
               ],
               "Test":"t"
            },
	    {
               "Name":"fearful_gt_neutral",
               "ConditionList":[
	          "trial_type.Fearful",
                  "trial_type.Neutral"
               ],
               "Weights":[
                  1,
                  -1
               ],
               "Test":"t"
            },
	    {
               "Name":"happy_gt_neutral",
               "ConditionList":[
	          "trial_type.Happy",
                  "trial_type.Neutral"
               ],
               "Weights":[
                  1,
                  -1
               ],
               "Test":"t"
            }
         ]
      },
     {
    "Level":"session",
	"Name":"sessionFace6MP5ACompCor",
	"GroupBy":["session",
		"subject",
		"contrast"],
	"Model":{
            "X":[1],
            "Type":"meta"
            },
	"DummyContrasts": {"Test": "t"}
     	}
   ],
   "Edges":[
	{
      "Source": "runFace6MP5ACompCor",
      "Destination": "sessionFace6MP5ACompCor"
    }
   ]
}
  1. Events file:

image

@effigies
Copy link
Collaborator

effigies commented Nov 2, 2022

Do you have a pklz crash file? If we can use nipypecli to rerun the node and drop into the debugger, that would be simplest.

@smeisler
Copy link
Contributor Author

smeisler commented Nov 2, 2022

Here is what I have in the working directory that corresponds to the crashing node:

/om2/scratch/Sun/smeisler/INSIDE_fmriprep/sub-inside7002/fitlins_wf/design_matrix/
├── _0x244397bf1abb9d04b3ef1141425a3d77.json
├── _inputs.pklz
├── mapflow
│   ├── _design_matrix0
│   │   ├── _inputs.pklz
│   │   ├── _node.pklz
│   │   ├── _report
│   │   │   └── report.rst
│   │   └── result__design_matrix0.pklz
│   └── _design_matrix1
│       ├── _inputs.pklz
│       ├── _node.pklz
│       ├── _report
│       │   └── report.rst
│       └── result__design_matrix1.pklz
├── _node.pklz
├── _report
│   └── report.rst
└── result_design_matrix.pklz

@effigies
Copy link
Collaborator

effigies commented Nov 2, 2022

I think we emit crashfiles, either in the working directory or the scratch directory. They would start with crash and either be .txt or .pklz files.

@effigies
Copy link
Collaborator

effigies commented Nov 2, 2022

Yes, it should be /om2/scratch/Sun/smeisler/INSIDE_fmriprep/sub-inside7002/crash*.

@smeisler
Copy link
Contributor Author

smeisler commented Nov 2, 2022

Yes I found the crash files there.

@effigies
Copy link
Collaborator

effigies commented Nov 2, 2022

If it's a .pklz file, run nipypecli crash -r -d <crashfile>, you'll drop into a pdb shell. (You might need to do singularity exec ... nipypecli ....)

From there you can go up a level and see the variables that are present here:

mat = dm.make_first_level_design_matrix(
frame_times=np.arange(vols) * info['repetition_time'],
add_regs=dense,
hrf_model=None, # XXX: Consider making an input spec parameter
add_reg_names=column_names,
drift_model=drift_model,
)

So you'd want to see what dense looks like, since that will have 425 rows.

@smeisler
Copy link
Contributor Author

smeisler commented Nov 2, 2022

The crash files were .txt. dense is a .h5 file called /om2/scratch/Sun/smeisler/INSIDE_fmriprep/sub-inside7002/fitlins_wf/loader/run/run-1_subject-inside7002_dense.h5 (or run-2 depending on the run)
I opened it in a h5 viewer, but it is not clear where a table is encoded.
image

@effigies
Copy link
Collaborator

effigies commented Dec 6, 2022

Ah, I'm sorry I dropped this. Apologies, the way to look at dense is with Pandas:

dense = pd.read_hdf(info['dense'], key='dense')

So:

>>> pd.read_hdf('/om2/scratch/Sun/smeisler/INSIDE_fmriprep/sub-inside7002/fitlins_wf/loader/run/run-1_subject-inside7002_dense.h5', key='dense')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants