Skip to content

Commit

Permalink
Convert reference to a datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
fraimondo committed Nov 25, 2024
1 parent e80f78b commit deb8306
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion junifer/data/coordinates/_fsl_coordinates_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def warp(
f"{pretransform_coordinates_path.resolve()}",
"| img2imgcoord -mm",
f"-src {target_data['path'].resolve()}",
f"-dest {target_data['reference_path'].resolve()}",
f"-dest {target_data['reference']["path"].resolve()}",
f"-warp {warp_data['path'].resolve()}",
f"> {transformed_coords_path.resolve()};",
f"sed -i 1d {transformed_coords_path.resolve()}",
Expand Down
12 changes: 8 additions & 4 deletions junifer/data/masks/_ants_mask_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def warp(
dst : str
The data type or template space to warp to.
`"native"` is the only allowed data type and it uses the resampled
T1w found in ``target_data.reference_path``. The
``"reference_path"`` key is added when :class:`.SpaceWarper` is
used.
T1w found in ``target_data.reference``. The

Check failure on line 53 in junifer/data/masks/_ants_mask_warper.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

junifer/data/masks/_ants_mask_warper.py:53:56: W291 Trailing whitespace

Check failure on line 53 in junifer/data/masks/_ants_mask_warper.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

junifer/data/masks/_ants_mask_warper.py:53:56: W291 Trailing whitespace
``"reference"`` key is added when :class:`.SpaceWarper` is
used or if the data is provided native space.
target_data : dict
The corresponding item of the data object to which the mask
will be applied.
Expand Down Expand Up @@ -88,6 +88,10 @@ def warp(
# Warp data check
if warp_data is None:
raise_error("No `warp_data` provided")
if "reference" not in target_data:
raise_error("No `reference` provided")
if "path" not in target_data["reference"]:
raise_error("No `path` provided in `reference`")

logger.debug("Using ANTs for mask transformation")

Expand All @@ -105,7 +109,7 @@ def warp(
"-n 'GenericLabel[NearestNeighbor]'",
f"-i {prewarp_mask_path.resolve()}",
# use resampled reference
f"-r {target_data['reference_path'].resolve()}",
f"-r {target_data['reference']["path"].resolve()}",
f"-t {warp_data['path'].resolve()}",
f"-o {warped_mask_path.resolve()}",
]
Expand Down
2 changes: 1 addition & 1 deletion junifer/data/masks/_fsl_mask_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def warp(
"--interp=nn",
f"-i {prewarp_mask_path.resolve()}",
# use resampled reference
f"-r {target_data['reference_path'].resolve()}",
f"-r {target_data['reference']["path"].resolve()}",
f"-w {warp_data['path'].resolve()}",
f"-o {warped_mask_path.resolve()}",
]
Expand Down
11 changes: 8 additions & 3 deletions junifer/data/parcellations/_ants_parcellation_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def warp(
dst : str
The data type or template space to warp to.
`"T1w"` is the only allowed data type and it uses the resampled T1w
found in ``target_data.reference_path``. The ``"reference_path"``
key is added when :class:`.SpaceWarper` is used.
found in ``target_data.reference``. The ``"reference"``
key is added if the :class:`.SpaceWarper` is used or if the
data is provided in native space.
target_data : dict
The corresponding item of the data object to which the parcellation
will be applied.
Expand Down Expand Up @@ -87,6 +88,10 @@ def warp(
# Warp data check
if warp_data is None:
raise_error("No `warp_data` provided")
if "reference" not in target_data:
raise_error("No `reference` provided")
if "path" not in target_data["reference"]:
raise_error("No `path` provided in `reference`")

logger.debug("Using ANTs for parcellation transformation")

Expand All @@ -108,7 +113,7 @@ def warp(
"-n 'GenericLabel[NearestNeighbor]'",
f"-i {prewarp_parcellation_path.resolve()}",
# use resampled reference
f"-r {target_data['reference_path'].resolve()}",
f"-r {target_data['reference']["path"].resolve()}",
f"-t {warp_data['path'].resolve()}",
f"-o {warped_parcellation_path.resolve()}",
]
Expand Down
2 changes: 1 addition & 1 deletion junifer/data/parcellations/_fsl_parcellation_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def warp(
"--interp=nn",
f"-i {prewarp_parcellation_path.resolve()}",
# use resampled reference
f"-r {target_data['reference_path'].resolve()}",
f"-r {target_data['reference']["path"].resolve()}",
f"-w {warp_data['path'].resolve()}",
f"-o {warped_parcellation_path.resolve()}",
]
Expand Down
2 changes: 2 additions & 0 deletions junifer/datagrabber/pattern_validation_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"mandatory": ["pattern", "format"],
"optional": ["mappings"],
},
"reference": {"mandatory": ["pattern"], "optional": []},
"prewarp_space" : {"mandatory": [], "optional": []},
},
},
"Warp": {
Expand Down
4 changes: 2 additions & 2 deletions junifer/preprocess/warping/_ants_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def preprocess(
-------
dict
The ``input`` dictionary with modified ``data`` and ``space`` key
values and new ``reference_path`` key whose value points to the
values and new ``reference`` key whose value points to the
reference file used for warping.
Raises
Expand Down Expand Up @@ -129,7 +129,7 @@ def preprocess(
# Load nifti
input["data"] = nib.load(apply_transforms_out_path)
# Save resampled reference path
input["reference_path"] = resample_image_out_path
input["reference"] = {"path": resample_image_out_path}
# Keep pre-warp space for further operations
input["prewarp_space"] = input["space"]
# Use reference input's space as warped input's space
Expand Down
4 changes: 2 additions & 2 deletions junifer/preprocess/warping/_fsl_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def preprocess(
-------
dict
The ``input`` dictionary with modified ``data`` and ``space`` key
values and new ``reference_path`` key whose value points to the
values and new ``reference`` key whose value points to the
reference file used for warping.
Raises
Expand Down Expand Up @@ -116,7 +116,7 @@ def preprocess(
# Load nifti
input["data"] = nib.load(applywarp_out_path)
# Save resampled reference path
input["reference_path"] = flirt_out_path
input["reference"] = {"path": flirt_out_path}
# Keep pre-warp space for further operations
input["prewarp_space"] = input["space"]
# Use reference input's space as warped input's space
Expand Down

0 comments on commit deb8306

Please sign in to comment.