junifer 0.0.6.dev371__py3-none-any.whl → 0.0.6.dev378__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
junifer/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.6.dev371'
16
- __version_tuple__ = version_tuple = (0, 0, 6, 'dev371')
15
+ __version__ = version = '0.0.6.dev378'
16
+ __version_tuple__ = version_tuple = (0, 0, 6, 'dev378')
@@ -7,6 +7,7 @@ import uuid
7
7
  from typing import TYPE_CHECKING, Any, Optional
8
8
 
9
9
  import nibabel as nib
10
+ import numpy as np
10
11
 
11
12
  from ...pipeline import WorkDirManager
12
13
  from ...utils import logger, raise_error, run_ext_cmd
@@ -20,6 +21,26 @@ if TYPE_CHECKING:
20
21
  __all__ = ["ANTsMaskWarper"]
21
22
 
22
23
 
24
+ def _get_interpolation_method(img: "Nifti1Image") -> str:
25
+ """Get correct interpolation method for `img`.
26
+
27
+ Parameters
28
+ ----------
29
+ img : nibabel.nifti1.Nifti1Image
30
+ The image.
31
+
32
+ Returns
33
+ -------
34
+ str
35
+ The interpolation method.
36
+
37
+ """
38
+ if np.array_equal(np.unique(img.get_fdata()), [0, 1]):
39
+ return "'GenericLabel[NearestNeighbor]'"
40
+ else:
41
+ return "LanczosWindowedSinc"
42
+
43
+
23
44
  class ANTsMaskWarper:
24
45
  """Class for mask space warping via ANTs.
25
46
 
@@ -143,7 +164,7 @@ class ANTsMaskWarper:
143
164
  "antsApplyTransforms",
144
165
  "-d 3",
145
166
  "-e 3",
146
- "-n 'GenericLabel[NearestNeighbor]'",
167
+ f"-n {_get_interpolation_method(mask_img)}",
147
168
  f"-i {prewarp_mask_path.resolve()}",
148
169
  f"-r {template_space_img_path.resolve()}",
149
170
  f"-t {xfm_file_path.resolve()}",
@@ -7,6 +7,7 @@ import uuid
7
7
  from typing import TYPE_CHECKING, Any
8
8
 
9
9
  import nibabel as nib
10
+ import numpy as np
10
11
 
11
12
  from ...pipeline import WorkDirManager
12
13
  from ...utils import logger, run_ext_cmd
@@ -19,6 +20,26 @@ if TYPE_CHECKING:
19
20
  __all__ = ["FSLMaskWarper"]
20
21
 
21
22
 
23
+ def _get_interpolation_method(img: "Nifti1Image") -> str:
24
+ """Get correct interpolation method for `img`.
25
+
26
+ Parameters
27
+ ----------
28
+ img : nibabel.nifti1.Nifti1Image
29
+ The image.
30
+
31
+ Returns
32
+ -------
33
+ str
34
+ The interpolation method.
35
+
36
+ """
37
+ if np.array_equal(np.unique(img.get_fdata()), [0, 1]):
38
+ return "nn"
39
+ else:
40
+ return "spline"
41
+
42
+
22
43
  class FSLMaskWarper:
23
44
  """Class for mask space warping via FSL FLIRT.
24
45
 
@@ -71,7 +92,7 @@ class FSLMaskWarper:
71
92
  # Set applywarp command
72
93
  applywarp_cmd = [
73
94
  "applywarp",
74
- "--interp=nn",
95
+ f"--interp={_get_interpolation_method(mask_img)}",
75
96
  f"-i {prewarp_mask_path.resolve()}",
76
97
  # use resampled reference
77
98
  f"-r {target_data['reference']['path'].resolve()}",
@@ -165,33 +165,18 @@ def compute_brain_mask(
165
165
  )
166
166
 
167
167
  mask_name = f"template_{target_std_space}_for_compute_brain_mask"
168
-
169
- # Warp template to correct space (MNI to MNI)
170
- if template_space != "native" and template_space != target_std_space:
171
- logger.debug(
172
- f"Warping template to {target_std_space} space using ANTs."
173
- )
174
- template = ANTsMaskWarper().warp(
175
- mask_name=mask_name,
176
- mask_img=template,
177
- src=template_space,
178
- dst=target_std_space,
179
- target_data=target_data,
180
- warp_data=None,
181
- )
182
-
183
168
  # Resample and warp template if target space is native
184
169
  if target_data["space"] == "native" and template_space != "native":
185
170
  if warp_data["warper"] == "fsl":
186
171
  resampled_template = FSLMaskWarper().warp(
187
- mask_name=f"template_{target_std_space}_for_compute_brain_mask",
172
+ mask_name=mask_name,
188
173
  mask_img=template,
189
174
  target_data=target_data,
190
175
  warp_data=warp_data,
191
176
  )
192
177
  elif warp_data["warper"] == "ants":
193
178
  resampled_template = ANTsMaskWarper().warp(
194
- mask_name=f"template_{target_std_space}_for_compute_brain_mask",
179
+ mask_name=mask_name,
195
180
  # use template here
196
181
  mask_img=template,
197
182
  src=target_std_space,
@@ -199,11 +184,25 @@ def compute_brain_mask(
199
184
  target_data=target_data,
200
185
  warp_data=warp_data,
201
186
  )
202
- # Resample template to target image
203
187
  else:
188
+ # Warp template to correct space
189
+ if template_space != target_std_space:
190
+ logger.debug(
191
+ f"Warping template to {target_std_space} space using ANTs."
192
+ )
193
+ template = ANTsMaskWarper().warp(
194
+ mask_name=mask_name,
195
+ mask_img=template,
196
+ src=template_space,
197
+ dst=target_std_space,
198
+ target_data=target_data,
199
+ warp_data=None,
200
+ )
204
201
  # Resample template to target image
205
202
  resampled_template = nimg.resample_to_img(
206
- source_img=template, target_img=target_data["data"]
203
+ source_img=template,
204
+ target_img=target_data["data"],
205
+ interpolation=_get_interpolation_method(template),
207
206
  )
208
207
 
209
208
  # Threshold resampled template and get mask
@@ -561,6 +560,7 @@ class MaskRegistry(BasePipelineDataRegistry, metaclass=Singleton):
561
560
  mask_img = nimg.resample_to_img(
562
561
  source_img=mask_img,
563
562
  target_img=target_data["data"],
563
+ interpolation=_get_interpolation_method(mask_img),
564
564
  )
565
565
  # Starting with new mask
566
566
  else:
@@ -632,6 +632,7 @@ class MaskRegistry(BasePipelineDataRegistry, metaclass=Singleton):
632
632
  mask_img = nimg.resample_to_img(
633
633
  source_img=mask_img,
634
634
  target_img=target_img,
635
+ interpolation=_get_interpolation_method(mask_img),
635
636
  )
636
637
  else:
637
638
  # Warp mask if target space is native as
@@ -761,3 +762,23 @@ def _load_ukb_mask(name: str) -> Path:
761
762
  mask_fname = _masks_path / "ukb" / mask_fname
762
763
 
763
764
  return mask_fname
765
+
766
+
767
+ def _get_interpolation_method(img: "Nifti1Image") -> str:
768
+ """Get correct interpolation method for `img`.
769
+
770
+ Parameters
771
+ ----------
772
+ img : nibabel.nifti1.Nifti1Image
773
+ The image.
774
+
775
+ Returns
776
+ -------
777
+ str
778
+ The interpolation method.
779
+
780
+ """
781
+ if np.array_equal(np.unique(img.get_fdata()), [0, 1]):
782
+ return "nearest"
783
+ else:
784
+ return "continuous"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: junifer
3
- Version: 0.0.6.dev371
3
+ Version: 0.0.6.dev378
4
4
  Summary: JUelich NeuroImaging FEature extractoR
5
5
  Author-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
6
6
  Maintainer-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
@@ -1,6 +1,6 @@
1
1
  junifer/__init__.py,sha256=2McgH1yNue6Z1V26-uN_mfMjbTcx4CLhym-DMBl5xA4,266
2
2
  junifer/__init__.pyi,sha256=SsTvgq2Dod6UqJN96GH1lCphH6hJQQurEJHGNhHjGUI,508
3
- junifer/_version.py,sha256=onk4xlkzaS1Ll-ut-FU2OO_R2pb-yHUL5TWaWF6Lxt0,428
3
+ junifer/_version.py,sha256=oYfebrtAvhll95HaoOLZCO0IYYGaqQpsY-CgDqPH8w4,428
4
4
  junifer/conftest.py,sha256=PWYkkRDU8ly2lYwv7VBKMHje4et6HX7Yey3Md_I2KbA,613
5
5
  junifer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  junifer/stats.py,sha256=e9aaagMGtgpRfW3Wdpz9ocpnYld1IWylCDcjFUgX9Mk,6225
@@ -104,9 +104,9 @@ junifer/data/coordinates/VOIs/meta/extDMN_VOIs.txt,sha256=Ogx1QvqZcnXDM3ncF2ha78
104
104
  junifer/data/coordinates/tests/test_coordinates.py,sha256=_c2P4oaDGpsmui5gJBe_jN6HLGiKxONkYPR69sRBUlU,4219
105
105
  junifer/data/masks/__init__.py,sha256=eEEhHglyVEx1LrqwXjq3cOmjf4sTsgBstRx5-k7zIQU,180
106
106
  junifer/data/masks/__init__.pyi,sha256=lcgr8gmWDPibC4RxnWBXb8DDpIkO73Aax09u6VXiJJI,114
107
- junifer/data/masks/_ants_mask_warper.py,sha256=Mwgc2_ZMf28vS_-fviRvZnHyT7JoQ1cQLozo7nUZSyM,5350
108
- junifer/data/masks/_fsl_mask_warper.py,sha256=VApp-ofGBKePNmCdgTg1HoEA66lMQiAPT0ihkhB2ezY,2415
109
- junifer/data/masks/_masks.py,sha256=NBkcIhjiSPoBE8J2BGkSfoun9Kpc2k_b2AhSf-E5cjU,27672
107
+ junifer/data/masks/_ants_mask_warper.py,sha256=JLK2Jh2AOAiv_NoUGhRoTBEhRFXPRXTDPmQGH9vBSok,5805
108
+ junifer/data/masks/_fsl_mask_warper.py,sha256=YZOMlRgQ7_4shnXNc_05tmwDk5xHI-1wqle-RdNsJ34,2857
109
+ junifer/data/masks/_masks.py,sha256=ZR0pfwIBiyJ3tGKo0mHW5Pu5asaZHeTvYbgJrUwZh24,28172
110
110
  junifer/data/masks/tests/test_masks.py,sha256=W0bzRB5Bp-iGO44VtEmaf7BuT-joe_2tQI0lma5NQHA,16090
111
111
  junifer/data/masks/ukb/UKB_15K_GM_template.nii.gz,sha256=jcX1pDOrDsoph8cPMNFVKH5gZYio5G4rJNpOFXm9wJI,946636
112
112
  junifer/data/masks/vickery-patil/CAT12_IXI555_MNI152_TMP_GS_GMprob0.2_clean.nii.gz,sha256=j6EY8EtRnUuRxeKgD65Q6B0GPEPIALKDJEIje1TfnAU,88270
@@ -341,10 +341,10 @@ junifer/utils/tests/test_config.py,sha256=7ltIXuwb_W4Mv_1dxQWyiyM10XgUAfsWKV6D_i
341
341
  junifer/utils/tests/test_fs.py,sha256=WQS7cKlKEZ742CIuiOYYpueeAhY9PqlastfDVpVVtvE,923
342
342
  junifer/utils/tests/test_helpers.py,sha256=k5qqfxK8dFyuewTJyR1Qn6-nFaYNuVr0ysc18bfPjyU,929
343
343
  junifer/utils/tests/test_logging.py,sha256=duO4ou365hxwa_kwihFtKPLaL6LC5XHiyhOijrrngbA,8009
344
- junifer-0.0.6.dev371.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
345
- junifer-0.0.6.dev371.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
346
- junifer-0.0.6.dev371.dist-info/METADATA,sha256=UHywu8RLD9o6oUt1r5pQlfxWb9AG3nogaV_kfRJe778,8429
347
- junifer-0.0.6.dev371.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
348
- junifer-0.0.6.dev371.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
349
- junifer-0.0.6.dev371.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
350
- junifer-0.0.6.dev371.dist-info/RECORD,,
344
+ junifer-0.0.6.dev378.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
345
+ junifer-0.0.6.dev378.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
346
+ junifer-0.0.6.dev378.dist-info/METADATA,sha256=1i1ttfHKfKnLZhJQxPgbjBGDS5rw3l7O1R0OtIldFO4,8429
347
+ junifer-0.0.6.dev378.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
348
+ junifer-0.0.6.dev378.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
349
+ junifer-0.0.6.dev378.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
350
+ junifer-0.0.6.dev378.dist-info/RECORD,,