Skip to content

Commit

Permalink
Merge pull request #199 from jhlegarreta/ImportNibabelAsNib
Browse files Browse the repository at this point in the history
STYLE: Prefer importing `nibabel` as `nib`
  • Loading branch information
ljod authored Nov 30, 2023
2 parents ba9f379 + b63d9f9 commit 90f1b53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions bin/wm_cluster_volumetric_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import argparse
import os

import nibabel
import nibabel as nib
import numpy
import vtk
from nibabel.affines import apply_affine
Expand Down Expand Up @@ -68,7 +68,7 @@ def main():
print("Output directory", args.outputDirectory, "does not exist, creating it.")
os.makedirs(outdir)

input_volume = nibabel.load(inputvol)
input_volume = nib.load(inputvol)
print(f'<{os.path.basename(__file__)}> Input volume shape:', input_volume.get_data().shape)

input_vtk_list = wma.io.list_vtk_files(inputdir)
Expand Down Expand Up @@ -182,9 +182,9 @@ def compute_stat(inpd, volume, sampling_size=None):
str_out = str_out + '\n' + str_line

if args.outputLabelmap:
volume_new = nibabel.Nifti1Image(new_voxel_data, input_volume.affine, input_volume.header)
volume_new = nib.Nifti1Image(new_voxel_data, input_volume.affine, input_volume.header)
output_labelmap = os.path.join(outdir, vtk_file_name+'.nii.gz')
nibabel.save(volume_new, output_labelmap)
nib.save(volume_new, output_labelmap)

output_file = open(output_stats_file, 'w')
output_file.write(str_out)
Expand Down
8 changes: 4 additions & 4 deletions bin/wm_tract_to_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import argparse
import os

import nibabel
import nibabel as nib
import numpy
import vtk
from nibabel.affines import apply_affine
Expand Down Expand Up @@ -149,16 +149,16 @@ def convert_cluster_to_volume(inpd, volume, measure=None):

return new_voxel_data

volume = nibabel.load(args.refvolume)
volume = nib.load(args.refvolume)
print(f'<{os.path.basename(__file__)}>', args.refvolume, ', input volume shape: ', volume.get_fdata().shape)

inpd = wma.io.read_polydata(args.inputVTK)

new_voxel_data = convert_cluster_to_volume(inpd, volume, measure=args.measure)

volume_new = nibabel.Nifti1Image(new_voxel_data, volume.affine, volume.header)
volume_new = nib.Nifti1Image(new_voxel_data, volume.affine, volume.header)

nibabel.save(volume_new, args.outputVol)
nib.save(volume_new, args.outputVol)

print('Done: save tract map to', args.outputVol)

Expand Down

0 comments on commit 90f1b53

Please sign in to comment.