def reconstruction(conn_model, gtab, dwi_data, B0_mask): """ Estimate a tensor model from dwi data. Parameters ---------- conn_model : str Connectivity reconstruction method (e.g. 'csa', 'tensor', 'csd', 'sfm'). gtab : Obj DiPy object storing diffusion gradient information. dwi_data : array 4D array of dwi data. B0_mask : str File path to B0 brain mask. Returns ------- mod_fit : ndarray Fitted connectivity reconstruction model. mod : obj Connectivity reconstruction model. References ---------- .. [1] Soares, J. M., Marques, P., Alves, V., & Sousa, N. (2013). A hitchhiker’s guide to diffusion tensor imaging. Frontiers in Neuroscience. https://doi.org/10.3389/fnins.2013.00031 """ from pynets.dmri.estimation import ( csa_mod_est, csd_mod_est, sfm_mod_est, tens_mod_est, ) if conn_model == "csa" or conn_model == "CSA": [mod_fit, mod] = csa_mod_est(gtab, dwi_data, B0_mask) elif conn_model == "csd" or conn_model == "CSD": [mod_fit, mod] = csd_mod_est(gtab, dwi_data, B0_mask) elif conn_model == "sfm" or conn_model == "SFM": [mod_fit, mod] = sfm_mod_est(gtab, dwi_data, B0_mask) elif conn_model == "ten" or conn_model == "tensor" or \ conn_model == "TEN": [mod_fit, mod] = tens_mod_est(gtab, dwi_data, B0_mask) else: try: raise ValueError( "Error: No valid reconstruction model specified. See the " "`-mod` flag." ) except ValueError: import sys sys.exit(0) del dwi_data return mod_fit, mod
def test_tens_mod_est(dmri_estimation_data): """Test tensor ODF model estimation.""" gtab = dmri_estimation_data['gtab'] dwi_file = dmri_estimation_data['dwi_file'] dwi_img = nib.load(dwi_file) B0_mask_file = dmri_estimation_data['B0_mask'] dwi_data = dwi_img.get_fdata() [mod_odf, model] = \ tens_mod_est(gtab, dwi_data, B0_mask_file) assert mod_odf is not None assert model is not None
def test_tens_mod_est(dmri_estimation_data): """Test tensor ODF model estimation.""" gtab = dmri_estimation_data['gtab'] dwi_img = dmri_estimation_data['dwi_img'] B0_mask_img = dmri_estimation_data['B0_mask_img'] B0_mask_file = tempfile.NamedTemporaryFile(mode='w+', suffix='.nii.gz') nib.save(B0_mask_img, B0_mask_file.name) dwi_data = dwi_img.get_fdata() [mod_odf, model] = \ tens_mod_est(gtab, dwi_data, B0_mask_file.name) assert mod_odf is not None assert model is not None B0_mask_file.close()
def reconstruction(conn_model, gtab, dwi_file, wm_in_dwi): try: import cPickle as pickle except ImportError: import _pickle as pickle from pynets.dmri.estimation import tens_mod_est, csa_mod_est, csd_mod_est dwi_img = nib.load(dwi_file) data = dwi_img.get_fdata() if conn_model == 'tensor': mod = tens_mod_est(gtab, data, wm_in_dwi) elif conn_model == 'csa': mod = csa_mod_est(gtab, data, wm_in_dwi) elif conn_model == 'csd': mod = csd_mod_est(gtab, data, wm_in_dwi) else: raise ValueError('Error: Either no seeds supplied, or no valid seeds found in white-matter interface') return mod
def reconstruction(conn_model, gtab, dwi_file, wm_in_dwi): ''' Estimate a tensor model from dwi data. Parameters ---------- conn_model : str Connectivity reconstruction method (e.g. 'csa', 'tensor', 'csd'). gtab : Obj DiPy object storing diffusion gradient information. dwi_file : str File path to diffusion weighted image. wm_in_dwi : str File path to white-matter tissue segmentation Nifti1Image. Returns ------- mod : obj Connectivity reconstruction model. ''' try: import cPickle as pickle except ImportError: import _pickle as pickle from pynets.dmri.estimation import tens_mod_est, csa_mod_est, csd_mod_est dwi_img = nib.load(dwi_file) data = dwi_img.get_fdata() if conn_model == 'tensor': mod = tens_mod_est(gtab, data, wm_in_dwi) elif conn_model == 'csa': mod = csa_mod_est(gtab, data, wm_in_dwi) elif conn_model == 'csd': mod = csd_mod_est(gtab, data, wm_in_dwi) else: raise ValueError( 'Error: Either no seeds supplied, or no valid seeds found in white-matter interface' ) return mod