Skip to content

Commit

Permalink
Trying to fix up examples for nibabel
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Dec 21, 2023
1 parent b52a93d commit ee92cf2
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated data files
ammon_TO_anubis.npy
labs/fmri_data.nii
labs/localizer_paradigm.csv
labs/need_data/results/
labs/zmap.nii
4 changes: 2 additions & 2 deletions examples/compute_fmri_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
# Show Z-map image
mean_map = multi_session_model.means[0]
plot_map(z_map.get_fdata(),
z_map.get_affine(),
z_map.affine,
anat=mean_map.get_fdata(),
anat_affine=mean_map.get_affine(),
anat_affine=mean_map.affine,
cmap=cm.cold_hot,
threshold=2.5,
black_bg=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/data/README_mni_basal_ganglia.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The script to extract the data was::
'AtlasGrey.mnc')
atlas_img = nib.load(atlas_fname)
# Data is in fact uint8, but with trivial float scaling
data = atlas_img.get_data().astype(np.uint8)
data = np.array(atlas_img.dataobj).astype(np.uint8)
bg_data = np.zeros_like(data)
for code in (14, 16, 39, 53): # LR striatum, LR caudate
in_mask = data == code
Expand Down
2 changes: 1 addition & 1 deletion examples/labs/need_data/demo_blob_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# prepare the data
nim = load(input_image)
mask_image = Nifti1Image((nim.get_fdata() ** 2 > 0).astype('u8'),
nim.get_affine())
nim.affine)
domain = grid_domain_from_image(mask_image)
data = nim.get_fdata()
values = data[data != 0]
Expand Down
2 changes: 1 addition & 1 deletion examples/labs/need_data/demo_roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

# prepare the data
nim = load(input_image)
affine = nim.get_affine()
affine = nim.affine
shape = nim.shape
data = nim.get_fdata()
values = data[data != 0]
Expand Down
2 changes: 1 addition & 1 deletion examples/labs/need_data/demo_ward_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
label_image = path.join(write_dir, 'label.nii')
wdata = mask - 1
wdata[mask] = u
save(Nifti1Image(wdata, load(mask_image).get_affine()), label_image)
save(Nifti1Image(wdata, load(mask_image).affine), label_image)
print(f"Label image written in {label_image}")
2 changes: 1 addition & 1 deletion examples/labs/need_data/example_roi_and_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
get_second_level_dataset()

mask = load(mask_path)
mask_array, affine = mask.get_fdata() > 0, mask.get_affine()
mask_array, affine = mask.get_fdata() > 0, mask.affine

# timing
n_scans = 128
Expand Down
4 changes: 2 additions & 2 deletions examples/labs/need_data/first_level_fiac.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def length_p_vector(con, p):
if contrast_id == 'Effects_of_interest':
vmax = max(- z_map.get_fdata().min(), z_map.get_fdata().max())
vmin = - vmax
plot_map(z_map.get_fdata(), z_map.get_affine(),
anat=mean_map.get_fdata(), anat_affine=mean_map.get_affine(),
plot_map(z_map.get_fdata(), z_map.affine,
anat=mean_map.get_fdata(), anat_affine=mean_map.affine,
cmap=cm.cold_hot,
vmin=vmin,
vmax=vmax,
Expand Down
2 changes: 1 addition & 1 deletion examples/labs/need_data/localizer_glm_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
vmax = max(- z_map.get_fdata().min(), z_map.get_fdata().max())
if index > 0:
plt.clf()
plot_map(z_map.get_fdata(), z_map.get_affine(),
plot_map(z_map.get_fdata(), z_map.affine,
cmap=cm.cold_hot,
vmin=- vmax,
vmax=vmax,
Expand Down
4 changes: 2 additions & 2 deletions examples/labs/need_data/one_sample_t_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

# Compute a population-level mask as the intersection of individual masks
grp_mask = Nifti1Image(intersect_masks(mask_images).astype(np.int8),
load(mask_images[0]).get_affine())
load(mask_images[0]).affine)

# concatenate the individual images
first_level_image = concat_images(betas)
Expand All @@ -76,7 +76,7 @@
# look at the result
vmax = max(- z_map.get_fdata().min(), z_map.get_fdata().max())
vmin = - vmax
plot_map(z_map.get_fdata(), z_map.get_affine(),
plot_map(z_map.get_fdata(), z_map.affine,
cmap=cm.cold_hot,
vmin=vmin,
vmax=vmax,
Expand Down
4 changes: 2 additions & 2 deletions examples/labs/need_data/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# First example, with a anatomical template
img = load(os.path.join(data_dir, 'spmT_0029.nii.gz'))
data = img.get_fdata()
affine = img.get_affine()
affine = img.affine

viz.plot_map(data, affine, cut_coords=(-52, 10, 22),
threshold=2.0, cmap=viz.cm.cold_hot)
Expand All @@ -41,7 +41,7 @@
anat_img = load(example_data.get_filename('neurospin', 'sulcal2000',
'nobias_anubis.nii.gz'))
anat = anat_img.get_fdata()
anat_affine = anat_img.get_affine()
anat_affine = anat_img.affine
except OSError as e:
# File does not exist: the data package is not installed
print(e)
Expand Down
6 changes: 3 additions & 3 deletions examples/labs/need_data/viz3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
vmin, vmax = brain_map.get_fdata().min(), brain_map.get_fdata().max()

# make a simple 2D plot
plot_map(brain_map.get_fdata(), brain_map.get_affine(),
plot_map(brain_map.get_fdata(), brain_map.affine,
cmap=cm.cold_hot,
vmin=vmin,
vmax=vmax,
Expand All @@ -46,7 +46,7 @@

# More plots using 3D
if True: # replace with False to skip this
plot_map(brain_map.get_fdata(), brain_map.get_affine(),
plot_map(brain_map.get_fdata(), brain_map.affine,
cmap=cm.cold_hot,
vmin=vmin,
vmax=vmax,
Expand All @@ -56,7 +56,7 @@

from nipy.labs import viz3d
try:
viz3d.plot_map_3d(brain_map.get_fdata(), brain_map.get_affine(),
viz3d.plot_map_3d(brain_map.get_fdata(), brain_map.affine,
cmap=cm.cold_hot,
vmin=vmin,
vmax=vmax,
Expand Down

0 comments on commit ee92cf2

Please sign in to comment.