Thanks for the response! I will try and provide some more hopefully relevant info:
DM_glm
GLM_dir = os.path.join(source_dir, 'GLM', sub)
DM_glm = FirstLevelModel(t_r = tr, slice_time_ref = 0, noise_model = 'ar1', standardize = False,
hrf_model = 'spm', drift_model = None, high_pass = 0.01,
target_affine=func_img_dm.affine,
mask_img = resampled_brainmask,
subject_label = sub, memory_level = 12,
minimize_memory = True, verbose = 2, n_jobs = -13,
memory = os.path.join(GLM_dir, 'cache'))
DM_glm = DM_glm.fit(run_imgs = smooth_img_path_dm, design_matrices = X)
contrast_list
# DM contrast design
# Easy Decision (VD1, VD2 < VD3, VD4) (3 * VD1 < VD2, VD3, VD4)
# Difficult Decision (VD1, VD2 > VD3, VD4) (3 * VD1 > VD2, VD3, VD4)
contrast_list = ['- VD1 - VD2 + VD3 + VD4', '(3 * - VD1) + VD2 + VD3 + VD4',
'VD1 + VD2 - VD3 - VD4', '(3 * VD1) - VD2 - VD3 - VD4']
GLM_dir
is a directory
sub
is the subject naming scheme
The error message in its entirety looks something like this:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[110], line 4
1 print('--------saving BIDS files--------')
3 # Save GLM to BIDS
----> 4 save_glm_to_bids(SnackDM_glm, contrast_list, contrast_types = 't', out_dir = GLM_dir, prefix = f'{sub}_task-SnackDM')
File ~/miniconda3/envs/SNACK/lib/python3.11/site-packages/nilearn/interfaces/bids/glm.py:325, in save_glm_to_bids(model, contrasts, contrast_types, out_dir, prefix)
322 # Model metadata
323 # TODO: Determine optimal mapping of model metadata to BIDS fields.
324 metadata_file = os.path.join(out_dir, f"{prefix}statmap.json")
--> 325 _generate_model_metadata(metadata_file, model)
327 dset_desc_file = os.path.join(out_dir, "dataset_description.json")
328 _generate_dataset_description(dset_desc_file, model_level)
File ~/miniconda3/envs/SNACK/lib/python3.11/site-packages/nilearn/interfaces/bids/glm.py:124, in _generate_model_metadata(out_file, model)
117 model_metadata = {
118 "Description": "A statistical map generated by Nilearn.",
119 **data_attributes,
120 "ModelParameters": model_attributes,
121 }
123 with open(out_file, "w") as f_obj:
--> 124 json.dump(model_metadata, f_obj, indent=4, sort_keys=True)
File ~/miniconda3/lib/python3.11/json/__init__.py:179, in dump(obj, fp, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
173 iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
174 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
175 separators=separators,
176 default=default, sort_keys=sort_keys, **kw).iterencode(obj)
177 # could accelerate with writelines in some versions of Python, at
178 # a debuggability cost
--> 179 for chunk in iterable:
180 fp.write(chunk)
File ~/miniconda3/lib/python3.11/json/encoder.py:432, in _make_iterencode.<locals>._iterencode(o, _current_indent_level)
430 yield from _iterencode_list(o, _current_indent_level)
431 elif isinstance(o, dict):
--> 432 yield from _iterencode_dict(o, _current_indent_level)
433 else:
434 if markers is not None:
File ~/miniconda3/lib/python3.11/json/encoder.py:406, in _make_iterencode.<locals>._iterencode_dict(dct, _current_indent_level)
404 else:
405 chunks = _iterencode(value, _current_indent_level)
--> 406 yield from chunks
407 if newline_indent is not None:
408 _current_indent_level -= 1
File ~/miniconda3/lib/python3.11/json/encoder.py:406, in _make_iterencode.<locals>._iterencode_dict(dct, _current_indent_level)
404 else:
405 chunks = _iterencode(value, _current_indent_level)
--> 406 yield from chunks
407 if newline_indent is not None:
408 _current_indent_level -= 1
File ~/miniconda3/lib/python3.11/json/encoder.py:439, in _make_iterencode.<locals>._iterencode(o, _current_indent_level)
437 raise ValueError("Circular reference detected")
438 markers[markerid] = o
--> 439 o = _default(o)
440 yield from _iterencode(o, _current_indent_level)
441 if markers is not None:
File ~/miniconda3/lib/python3.11/json/encoder.py:180, in JSONEncoder.default(self, o)
161 def default(self, o):
162 """Implement this method in a subclass such that it returns
163 a serializable object for ``o``, or calls the base implementation
164 (to raise a ``TypeError``).
(...)
178
179 """
--> 180 raise TypeError(f'Object of type {o.__class__.__name__} '
181 f'is not JSON serializable')
TypeError: Object of type ndarray is not JSON serializable
Hope this helps! Thanks again!