Skip to content

Commit

Permalink
remove creation of extra warps
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf committed Jan 5, 2025
1 parent 871bd85 commit 1d30052
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 113 deletions.
44 changes: 0 additions & 44 deletions hippunfold/workflow/rules/warps.smk
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,6 @@ rule create_warps_hipp:
resources:
mem_mb=16000,
output:
warp_unfold2native=bids(
root=work,
datatype="warps",
**inputs.subj_wildcards,
label="hipp",
suffix="xfm.nii.gz",
hemi="{hemi}",
from_="unfold",
to="corobl",
mode="surface"
),
warp_native2unfold=bids(
root=work,
datatype="warps",
Expand All @@ -402,17 +391,6 @@ rule create_warps_hipp:
to="corobl",
mode="image"
),
warpitk_native2unfold=bids(
root=work,
datatype="warps",
**inputs.subj_wildcards,
label="hipp",
suffix="xfm.nii.gz",
hemi="{hemi}",
from_="corobl",
to="unfold",
mode="image"
),
group:
"subj"
log:
Expand Down Expand Up @@ -494,17 +472,6 @@ rule create_warps_dentate:
resources:
mem_mb=16000,
output:
warp_unfold2native=bids(
root=work,
datatype="warps",
**inputs.subj_wildcards,
label="dentate",
suffix="xfm.nii.gz",
hemi="{hemi}",
from_="unfold",
to="corobl",
mode="surface"
),
warp_native2unfold=bids(
root=work,
datatype="warps",
Expand All @@ -527,17 +494,6 @@ rule create_warps_dentate:
to="corobl",
mode="image"
),
warpitk_native2unfold=bids(
root=work,
datatype="warps",
**inputs.subj_wildcards,
label="dentate",
suffix="xfm.nii.gz",
hemi="{hemi}",
from_="corobl",
to="unfold",
mode="image"
),
group:
"subj"
log:
Expand Down
69 changes: 0 additions & 69 deletions hippunfold/workflow/scripts/create_warps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import nibabel as nib
import numpy as np
import naturalneighbor
from scipy.stats import zscore
from scipy.ndimage import generic_filter, binary_dilation
from astropy.convolution import convolve
Expand Down Expand Up @@ -155,74 +154,6 @@ def summary(name, array):
coord_flat_pd_unnorm = coord_flat_pd * unfold_dims[1]
coord_flat_io_unnorm = coord_flat_io * unfold_dims[2]

# add some noise to avoid perfectly overlapping datapoints!
points = np.stack(
[
coord_flat_ap_unnorm + (np.random.rand(coord_flat_ap.shape[0]) - 0.5) * 1e-6,
coord_flat_pd_unnorm + (np.random.rand(coord_flat_ap.shape[0]) - 0.5) * 1e-6,
coord_flat_io_unnorm + (np.random.rand(coord_flat_ap.shape[0]) - 0.5) * 1e-6,
],
axis=1,
)
summary("points", points)


# perform the interpolation

interp_ap = naturalneighbor.griddata(
points,
native_coords_phys[:, 0],
[[0, unfold_dims[0], 1], [0, unfold_dims[1], 1], [0, unfold_dims[2], 1]],
)
interp_pd = naturalneighbor.griddata(
points,
native_coords_phys[:, 1],
[[0, unfold_dims[0], 1], [0, unfold_dims[1], 1], [0, unfold_dims[2], 1]],
)
interp_io = naturalneighbor.griddata(
points,
native_coords_phys[:, 2],
[[0, unfold_dims[0], 1], [0, unfold_dims[1], 1], [0, unfold_dims[2], 1]],
)


# prepare maps for writing as warp file:

# combine and reshape interpolated map to 5d (4th dim singleton)
mapToNative = np.zeros(unfold_grid_phys.shape)
mapToNative[:, :, :, 0, 0] = interp_ap
mapToNative[:, :, :, 0, 1] = interp_pd
mapToNative[:, :, :, 0, 2] = interp_io
summary("mapToNative", mapToNative)

mapToNative[np.isnan(mapToNative)] = 0


# mapToNative has the absolute coordinates, but we want them relative to the
# unfolded grid, so we subtract it out:
displacementToNative = mapToNative - unfold_grid_phys
summary("dispacementToNative", displacementToNative)


# write to file
dt = unfold_phys_coords_nib.get_fdata()
dt = dt.dtype.name
warp_unfold2native_nib = nib.Nifti1Image(
displacementToNative.astype(dt),
unfold_phys_coords_nib.affine,
unfold_phys_coords_nib.header,
)
warp_unfold2native_nib.to_filename(snakemake.output.warp_unfold2native)

# write itk transform to file
f = convert_warp_to_itk(displacementToNative)
warpitk_native2unfold_nib = nib.Nifti1Image(
f.astype(dt), unfold_phys_coords_nib.affine, unfold_phys_coords_nib.header
)

warpitk_native2unfold_nib.to_filename(snakemake.output.warpitk_native2unfold)


# Part 2: native2unfold warps

# This part is easier, since we essentially have the mapping from native to unfold
Expand Down

0 comments on commit 1d30052

Please sign in to comment.