From 8fd846e4591219eec22178c6a19ce8575d930e42 Mon Sep 17 00:00:00 2001 From: Matt Cieslak Date: Thu, 25 Apr 2024 13:59:31 -0400 Subject: [PATCH] [ENH] Add recon workflow for hbcd beta (#735) add recon workflow for hbcd beta --- qsiprep/data/pipelines/hbcd_scalar_maps.json | 122 +++++++++++++++++++ qsiprep/interfaces/scalar_mapping.py | 14 ++- 2 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 qsiprep/data/pipelines/hbcd_scalar_maps.json diff --git a/qsiprep/data/pipelines/hbcd_scalar_maps.json b/qsiprep/data/pipelines/hbcd_scalar_maps.json new file mode 100644 index 00000000..bd43962b --- /dev/null +++ b/qsiprep/data/pipelines/hbcd_scalar_maps.json @@ -0,0 +1,122 @@ +{ + "name": "hbcd_postproc_beta", + "space" : "T1w", + "atlases": [ ], + "anatomical": [ ], + "nodes": [ + { + "name": "dipy_dki", + "software": "Dipy", + "action": "DKI_reconstruction", + "input": "qsiprep", + "qsirecon_suffix": "DIPYDKI", + "parameters": { + "write_mif": false, + "write_fibgz": false + } + }, + { + "name": "tortoise_dtmapmri", + "software": "TORTOISE", + "action": "estimate", + "qsirecon_suffix": "TORTOISE_model-MAPMRI", + "input": "qsiprep", + "parameters": { + "estimate_tensor_separately": true, + "big_delta": null, + "small_delta": null, + "estimate_tensor": { + "bval_cutoff": 1200, + "write_cs": true}, + "estimate_mapmri": { + "map_order": 4} + } + }, + { + "name": "tortoise_fullshell_tensor", + "software": "TORTOISE", + "action": "estimate", + "qsirecon_suffix": "TORTOISE_model-tensor", + "input": "qsiprep", + "parameters": { + "estimate_tensor_separately": true, + "big_delta": null, + "small_delta": null, + "estimate_tensor": { + "bval_cutoff": 4000, + "write_cs": true} + } + }, + { + "name": "fit_noddi", + "action": "fit_noddi", + "software": "AMICO", + "input": "qsiprep", + "qsirecon_suffix": "NODDI", + "parameters": { + "isExvivo": false, + "dPar": 1.7E-3, + "dIso": 3.0E-3 + } + }, + { + "name": "dsistudio_gqi", + "software": "DSI Studio", + "action": "reconstruction", + "input": "qsiprep", + "qsirecon_suffix": "DSIStudio", + "parameters": { + "method": "gqi" + } + }, + { + "name": "autotrackgqi", + "software": "DSI Studio", + "action": "autotrack", + "input": "dsistudio_gqi", + "qsirecon_suffix": "DSIStudio", + "parameters": { + "track_id": "Fasciculus,Cingulum,Aslant,Corticos,Thalamic_R,Reticular,Optic,Fornix,Corpus", + "tolerance": "22,26,30", + "track_voxel_ratio": 2.0, + "yield_rate": 0.000001 + } + }, + { + "name": "gqi_scalars", + "software": "DSI Studio", + "action": "export", + "input": "dsistudio_gqi", + "qsirecon_suffix": "DSIStudio" + }, + { + "name": "bundle_means", + "software": "qsiprep", + "action": "bundle_map", + "input": "autotrackgqi", + "scalars_from": [ + "gqi_scalars", + "dipy_dki", + "fit_noddi", + "tortoise_fullshell_tensor", + "tortoise_dtmapmri" + ] + }, + { + "name": "template_map", + "software": "qsiprep", + "action": "template_map", + "input": "qsiprep", + "scalars_from": [ + "gqi_scalars", + "dipy_dki", + "fit_noddi", + "tortoise_fullshell_tensor", + "tortoise_dtmapmri" + ], + "parameters": { + "interpolation": "NearestNeighbor" + } + } + ] +} diff --git a/qsiprep/interfaces/scalar_mapping.py b/qsiprep/interfaces/scalar_mapping.py index e46fdb9c..396e3ce5 100644 --- a/qsiprep/interfaces/scalar_mapping.py +++ b/qsiprep/interfaces/scalar_mapping.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: +import logging import os.path as op import subprocess @@ -22,6 +23,7 @@ ) from nipype.utils.filemanip import fname_presuffix +LOGGER = logging.getLogger("nipype.interface") from .bids import get_bids_params @@ -198,9 +200,15 @@ def calculate_mask_stats( if weighting_vector is not None: results["weighted_mean"] = np.sum(voxel_data * weighting_vector) nz_weighting_vector = weighting_vector.copy() - nz_weighting_vector[np.isnan(nz_voxel_data)] = np.nan - nz_weighting_vector = nz_weighting_vector / np.nansum(nz_weighting_vector) - results["masked_weighted_mean"] = np.nansum(nz_voxel_data * nz_weighting_vector) + try: + nz_weighting_vector[np.isnan(nz_voxel_data)] = np.nan + nz_weighting_vector = nz_weighting_vector / np.nansum(nz_weighting_vector) + results["masked_weighted_mean"] = np.nansum(nz_voxel_data * nz_weighting_vector) + except Exception as exc: + LOGGER.warn( + f"Error calculating weighted mean of {variable_name} in {mask_name}\n{exc}" + ) + results["masked_weighted_mean"] = np.nan return results