Esempio n. 1
0
def mean_bundle_weight(folder_name, bundle_file_name):

    if not os.path.exists(bundle_file_name):
        mean_bundle = np.nan
    else:
        bundle = load_trk(bundle_file_name, "same", bbox_valid_check=False)
        bundle = bundle.streamlines
        bvec_file = load_dwi_files(folder_name)[6]
        mean_vols = weighting_streamlines(folder_name,
                                          bundle,
                                          bvec_file,
                                          weight_by='AxPasi7')
        mean_bundle = np.nanmean(mean_vols)

    return mean_bundle
Esempio n. 2
0
def calc_cc_part_val(streamlines, mask, affine, calc_type='mean'):
    from dipy.tracking import utils
    from dipy.tracking.streamline import Streamlines
    from weighted_tracts import weighting_streamlines

    masked_streamlines = utils.target(streamlines, affine, mask)

    masked_streamlines = Streamlines(masked_streamlines)

    weights = weighting_streamlines(dir_name,
                                    masked_streamlines,
                                    affine,
                                    show=False,
                                    weight_by='3_2_AxPasi7')

    if 'mean' in calc_type:
        val = np.nanmean(weights)
    elif 'median' in calc_type:
        val = np.nanmedian(weights)

    return val
Esempio n. 3
0
        os.path.join(main_fec, '*/'))
    all_subj_folders = []
    for sfol in subj_folder[::]:
        for folder_name in glob(os.path.join(sfol, '*/'))[::]:
            dir_name = folder_name + 'streamlines'
            gtab, data, affine, labels, white_matter, nii_file, bvec_file = load_dwi_files(
                folder_name, small_delta=15)

            #tract_path = f'{dir_name}{n}_wholebrain_5d_labmask_msmt.trk'
            for tfiles in glob(os.path.join(dir_name, '*')):
                if 'wholebrain_4d_labmask.trk' in tfiles:
                    tract_path = os.path.join(dir_name, tfiles)
                    continue
            streamlines = load_ft(tract_path, nii_file)
            mean_vol_per_tract = weighting_streamlines(folder_name,
                                                       streamlines,
                                                       bvec_file,
                                                       weight_by='3_2_AxPasi7')
            vox_vol = vol_map(streamlines, affine, mean_vol_per_tract,
                              white_matter.shape)

            empty_header = nib.Nifti1Header()
            #vol_img = nib.Nifti1Image(vox_vol,affine,empty_header)
            #vol_file_name = folder_name+f'{n}_ADD_along_streamlines.nii'
            #nib.save(vol_img,vol_file_name)

            vox_vol_masked = vox_vol * white_matter
            masked_vol_img = nib.Nifti1Image(vox_vol_masked, affine,
                                             empty_header)
            masked_vol_file_name = os.path.join(
                folder_name, 'ADD_along_streamlines_WMmasked.nii')
            nib.save(masked_vol_img, masked_vol_file_name)
Esempio n. 4
0
        for subj in os.listdir(group):
            folder_name = os.path.join(group, subj)
            full_bund_name = f'{subj}_{file_bundle_name}'
            bundle_file_name = rf'{folder_name}\streamlines\{full_bund_name}.trk'

            if not os.path.exists(bundle_file_name):
                print('Moving on!')
                vec_mean.append(np.nan)
                vec_median.append(np.nan)
                continue

            bundle = load_trk(bundle_file_name, "same", bbox_valid_check=False)
            bundle = bundle.streamlines
            bvec_file = load_dwi_files(folder_name)[6]
            mean_vols = weighting_streamlines(
                folder_name,
                bundle,
                bvec_file,
                weight_by='ADD_along_streamlines_WMmasked')

            vec_mean.append(np.nanmean(mean_vols))
            vec_median.append(np.nanmedian(mean_vols))
        val_dict[bundle_name + '_mean_' +
                 str.split(group, os.sep)[-2]] = vec_mean
        val_dict[bundle_name + '_median_' +
                 str.split(group, os.sep)[-2]] = vec_median

table_vals = pd.DataFrame(val_dict, index=os.listdir(group))

table_vals.to_excel(os.path.join(main_folder, 'values_avaraged_volume.xlsx'))
Esempio n. 5
0
from weighted_tracts import weighting_streamlines, load_ft, load_dwi_files
from all_subj import all_subj_names, all_subj_folders

subj = all_subj_folders
names = all_subj_names
masks = ['cc_cortex_cleaned', 'wholebrain']
weight_by = '1.5_2_AxPasi5'

for n, s in zip(names, subj):
    folder_name = r'C:\Users\Admin\my_scripts\Ax3D_Pack\V6\after_file_prep' + s
    dir_name = folder_name + '\streamlines'
    gtab, data, affine, labels, white_matter, nii_file, bvec_file = load_dwi_files(
        folder_name)

    for m in masks:
        tract_path = dir_name + n + '_' + m + '.trk'
        streamlines = load_ft(tract_path, nii_file)
        fig_name = m + '_example'
        weighting_streamlines(folder_name,
                              streamlines,
                              bvec_file,
                              weight_by='1.5_2_AxPasi5',
                              hue=[0.0, 1.0],
                              saturation=[0.0, 1.0],
                              scale=[2, 7],
                              fig_type=fig_name)
Esempio n. 6
0
if __name__ == "__main__":
    main_folder = r'F:\Hila\balance\eo\after'

    bundle_name = 'SCP'
    file_bundle_name = bundle_name + r'_mct01rt20_4d'

    for subj in os.listdir(main_folder):
        folder_name = os.path.join(main_folder, subj)
        full_bund_name = f'{subj}_{file_bundle_name}'
        bundle_file_name = rf'{folder_name}\streamlines\{full_bund_name}.trk'

        if not os.path.exists(bundle_file_name):
            print('Moving on!')
            continue

        bundle = load_trk(bundle_file_name, "same", bbox_valid_check=False)
        bundle = bundle.streamlines
        bvec_file = load_dwi_files(folder_name)[6]
        mean_vols = weighting_streamlines(folder_name,
                                          bundle,
                                          bvec_file,
                                          weight_by='AxPasi7')

        mean_bundle = np.nanmean(mean_vols)
        median_bundle = np.nanmedian(mean_vols)

        print(
            f'{subj} mean value for {bundle_name} : {mean_bundle:.2f}\n {subj} median value for {bundle_name} : {median_bundle:.2f} \n'
        )