[Node] Error on "mriqc_wf.dwiMRIQC.ComputeIQMs.datasink"

Just as an update on this, I ended up writing the small Python utility to sanitize NaN values in JSON files, but it turns out this is not what is raising the issue for me.

When I check the crash log, this is what I get:

Node: mriqc_wf.anatMRIQC.ComputeIQMs.datasink
Working directory: /scratch/mriqc_wf/anatMRIQC/ComputeIQMs/_in_file_..data..sub-38..anat..sub-38_space-MNI152NLin2009cAsym_res-2_desc-preproc_T1w.nii.gz/datasink

Node inputs:

_outputs = {'qi_2': 0.0}
acq_id = <undefined>
dataset = <unset>
dismiss_entities = ['part']
in_file = /data/sub-38/anat/sub-38_space-MNI152NLin2009cAsym_res-2_desc-preproc_T1w.nii.gz
metadata = {'Resolution': 'Template MNI152NLin2009cAsym (2.0x2.0x2.0 mm^3), curated by TemplateFlow 23.1.0', 'SkullStripped': False}
modality = T1w
out_dir = /out
provenance = {'md5sum': 'c43e21c9608ccda1d0dd1e32cebffdc5', 'version': '24.1.0.dev0+g3fe90466.d20240417', 'software': 'mriqc', 'settings': {'testing': False}, 'warnings': {'small_air_mask': True, 'large_rot_frame': True}}
rec_id = <undefined>
root = {'summary_csf_mean': 153.9373, 'summary_csf_median': 89.0, 'summary_csf_p95': 454.0, 'summary_csf_p05': 0.0, 'summary_csf_k': -1.3813, 'summary_csf_stdv': 170.1005, 'summary_csf_mad': 131.9516, 'summary_csf_n': 68109.5750447787, 'summary_gm_mean': 550.3031, 'summary_gm_median': 535.0, 'summary_gm_p95': 827.0, 'summary_gm_p05': 297.0, 'summary_gm_k': -0.9245, 'summary_gm_stdv': 169.4326, 'summary_gm_mad': 168.8041, 'summary_gm_n': 104437.57099339308, 'summary_wm_mean': 981.6483, 'summary_wm_median': 994.0, 'summary_wm_p95': 1043.0, 'summary_wm_p05': 871.0, 'summary_wm_k': 0.1604, 'summary_wm_stdv': 51.928, 'summary_wm_mad': 41.109, 'summary_wm_n': 85015.85414913118, 'summary_bg_mean': 0.0, 'summary_bg_median': 0.0, 'summary_bg_p95': 0.0, 'summary_bg_p05': 0.0, **'summary_bg_k': nan**, 'summary_bg_stdv': 0.0, 'summary_bg_mad': 0.0, 'summary_bg_n': 425471.0, 'snr_csf': 0.5232162553235187, 'snr_wm': 19.14177619038615, 'snr_gm': 3.15758265325029, 'snr_total': 7.607525032986653, 'snrd_csf': -1.0, 'snrd_wm': -1.0, 'snrd_gm': -1.0, 'snrd_total': -1.0, 'cnr': 2.5901250537402323, 'fber': -1.0, 'efc': 0.822, 'wm2max': 0.9339389213671632, 'qi_1': 0.0, 'cjv': 0.4573270152505447, 'fwhm_x': 2.77502, 'fwhm_y': 2.928585, 'fwhm_z': 2.826965, 'fwhm_avg': 2.843523333333333, 'icvs_csf': 0.26443850628874715, 'icvs_gm': 0.40548359398455835, 'icvs_wm': 0.3300778997266945, 'rpve_csf': 4.11642406088599, 'rpve_gm': 4.095713126758409, 'rpve_wm': 4.180395826409897, 'size_x': 97, 'size_y': 115, 'size_z': 97, 'spacing_x': 2.0, 'spacing_y': 2.0, 'spacing_z': 2.0, 'inu_range': 0.018933320045471214, 'inu_med': 0.25616756081581116, 'tpm_overlap_csf': 0.25478921608094895, 'tpm_overlap_gm': 0.5756801633183153, 'tpm_overlap_wm': 0.6040912214838626, 'qi_2': 0.0, 'bids_meta': {'subject_id': '38', 'modality': 'T1w', 'Resolution': 'Template MNI152NLin2009cAsym (2.0x2.0x2.0 mm^3), curated by TemplateFlow 23.1.0', 'SkullStripped': False, 'dataset': '<unset>'}, 'provenance': {'md5sum': 'c43e21c9608ccda1d0dd1e32cebffdc5', 'version': '24.1.0.dev0+g3fe90466.d20240417', 'software': 'mriqc', 'settings': {'testing': False}, 'warnings': {'small_air_mask': True, 'large_rot_frame': True}}}
run_id = <undefined>
session_id = <undefined>
subject_id = 38
task_id = <undefined>

Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/nipype/pipeline/plugins/linear.py", line 47, in run
    node.run(updatehash=updatehash)
  File "/opt/conda/lib/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/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 datasink.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/lib/python3.11/site-packages/nipype/interfaces/base/core.py", line 397, in run
	    runtime = self._run_interface(runtime)
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/opt/conda/lib/python3.11/site-packages/mriqc/interfaces/bids.py", line 188, in _run_interface
	    json.dumps(
	  File "/opt/conda/lib/python3.11/site-packages/simplejson/__init__.py", line 395, in dumps
	    **kw).encode(obj)
	          ^^^^^^^^^^^
	  File "/opt/conda/lib/python3.11/site-packages/simplejson/encoder.py", line 300, in encode
	    chunks = list(chunks)
	             ^^^^^^^^^^^^
	  File "/opt/conda/lib/python3.11/site-packages/simplejson/encoder.py", line 714, in _iterencode
	    for chunk in _iterencode_dict(o, _current_indent_level):
	  File "/opt/conda/lib/python3.11/site-packages/simplejson/encoder.py", line 645, in _iterencode_dict
	    yield _floatstr(value)
	          ^^^^^^^^^^^^^^^^
	  File "/opt/conda/lib/python3.11/site-packages/simplejson/encoder.py", line 351, in floatstr
	    raise ValueError(
	ValueError: Out of range float values are not JSON compliant: nan

Apparently the problem is not with opening, but rather with saving a JSON file containing NaNs. The offending field seems to be 'summary_bg_k': nan.

Any idea from where this nan comes from? I am running mriqc on a dataset preprocessed with fMRIprep – could this be the cause?

Pinging @oesteban in case he knows more.

Thanks!