junifer 0.0.6.dev344__py3-none-any.whl → 0.0.6.dev349__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.dev344'
16
- __version_tuple__ = version_tuple = (0, 0, 6, 'dev344')
15
+ __version__ = version = '0.0.6.dev349'
16
+ __version_tuple__ = version_tuple = (0, 0, 6, 'dev349')
@@ -47,6 +47,8 @@ def compute_brain_mask(
47
47
  warp_data: Optional[dict[str, Any]] = None,
48
48
  mask_type: str = "brain",
49
49
  threshold: float = 0.5,
50
+ source: str = "template",
51
+ extra_input: Optional[dict[str, Any]] = None,
50
52
  ) -> "Nifti1Image":
51
53
  """Compute the whole-brain, grey-matter or white-matter mask.
52
54
 
@@ -72,6 +74,13 @@ def compute_brain_mask(
72
74
  (default "brain").
73
75
  threshold : float, optional
74
76
  The value under which the template is cut off (default 0.5).
77
+ source : {"subject", "template"}, optional
78
+ The source of the mask. If "subject", the mask is computed from the
79
+ subject's data (``VBM_GM`` or ``VBM_WM``). If "template", the mask is
80
+ computed from the template data (default "template").
81
+ extra_input : dict, optional
82
+ The other fields in the data object. Useful for accessing other data
83
+ types (default None).
75
84
 
76
85
  Returns
77
86
  -------
@@ -82,7 +91,13 @@ def compute_brain_mask(
82
91
  ------
83
92
  ValueError
84
93
  If ``mask_type`` is invalid or
85
- if ``warp_data`` is None when ``target_data``'s space is native.
94
+ if ``source`` is invalid or
95
+ if ``source="subject"`` and ``mask_type`` is invalid or
96
+ if ``warp_data`` is None when ``target_data``'s space is native or
97
+ if ``extra_input`` is None when ``source="subject"`` or
98
+ if ``VBM_GM`` or ``VBM_WM`` data types are not in ``extra_input``
99
+ when ``source="subject"`` and ``mask_type`` is ``"gm"`` or ``"wm"``
100
+ respectively.
86
101
 
87
102
  """
88
103
  logger.debug(f"Computing {mask_type} mask")
@@ -90,6 +105,12 @@ def compute_brain_mask(
90
105
  if mask_type not in ["brain", "gm", "wm"]:
91
106
  raise_error(f"Unknown mask type: {mask_type}")
92
107
 
108
+ if source not in ["subject", "template"]:
109
+ raise_error(f"Unknown mask source: {source}")
110
+
111
+ if source == "subject" and mask_type not in ["gm", "wm"]:
112
+ raise_error(f"Unknown mask type: {mask_type} for subject space")
113
+
93
114
  # Check pre-requirements for space manipulation
94
115
  if target_data["space"] == "native":
95
116
  # Warp data check
@@ -101,25 +122,50 @@ def compute_brain_mask(
101
122
  # Set space to fetch template using
102
123
  target_std_space = target_data["space"]
103
124
 
104
- # Fetch template in closest resolution
105
- template = get_template(
106
- space=target_std_space,
107
- target_img=target_data["data"],
108
- extra_input=None,
109
- template_type=mask_type,
110
- )
111
-
112
- # Resample and warp template if target space is native
113
- if target_data["space"] == "native":
114
- resampled_template = ANTsMaskWarper().warp(
115
- mask_name=f"template_{target_std_space}_for_compute_brain_mask",
116
- # use template here
117
- mask_img=template,
118
- src=target_std_space,
119
- dst="native",
120
- target_data=target_data,
121
- warp_data=warp_data,
125
+ if source == "subject":
126
+ key = f"VBM_{mask_type.upper()}"
127
+ # Check for extra inputs
128
+ if extra_input is None:
129
+ raise_error(
130
+ f"No extra input provided, requires `{key}` "
131
+ "data type to infer target template data and space."
132
+ )
133
+ # Check for missing data type
134
+ if key not in extra_input:
135
+ raise_error(
136
+ f"Cannot compute {mask_type} from subject's data. "
137
+ f"Missing {key} in extra input."
138
+ )
139
+ template = extra_input[key]["data"]
140
+ template_space = extra_input[key]["space"]
141
+ else:
142
+ # Fetch template in closest resolution
143
+ template = get_template(
144
+ space=target_std_space,
145
+ target_img=target_data["data"],
146
+ extra_input=None,
147
+ template_type=mask_type,
122
148
  )
149
+ template_space = target_std_space
150
+ # Resample and warp template if target space is native
151
+ if target_data["space"] == "native" and template_space != "native":
152
+ if warp_data["warper"] == "fsl":
153
+ resampled_template = FSLMaskWarper().warp(
154
+ mask_name=f"template_{target_std_space}_for_compute_brain_mask",
155
+ mask_img=template,
156
+ target_data=target_data,
157
+ warp_data=warp_data,
158
+ )
159
+ elif warp_data["warper"] == "ants":
160
+ resampled_template = ANTsMaskWarper().warp(
161
+ mask_name=f"template_{target_std_space}_for_compute_brain_mask",
162
+ # use template here
163
+ mask_img=template,
164
+ src=target_std_space,
165
+ dst="native",
166
+ target_data=target_data,
167
+ warp_data=warp_data,
168
+ )
123
169
  # Resample template to target image
124
170
  else:
125
171
  resampled_template = resample_to_img(
@@ -503,7 +549,10 @@ class MaskRegistry(BasePipelineDataRegistry, metaclass=Singleton):
503
549
  # custom compute_brain_mask
504
550
  elif mask_name == "compute_brain_mask":
505
551
  mask_img = mask_object(
506
- target_data, warper_spec, **mask_params
552
+ target_data=target_data,
553
+ warp_data=warper_spec,
554
+ extra_input=extra_input,
555
+ **mask_params,
507
556
  )
508
557
  # custom registered; arm kept for clarity
509
558
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: junifer
3
- Version: 0.0.6.dev344
3
+ Version: 0.0.6.dev349
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=RGqwir9l9V0H5xa7pR6U_haLUliwgh-8bgB2fta2Qfs,428
3
+ junifer/_version.py,sha256=aHBrRVpok6-bqJl1ZQ6KAqY2zMxvhfYBv8BAfrUa6tE,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
@@ -106,7 +106,7 @@ junifer/data/masks/__init__.py,sha256=eEEhHglyVEx1LrqwXjq3cOmjf4sTsgBstRx5-k7zIQ
106
106
  junifer/data/masks/__init__.pyi,sha256=lcgr8gmWDPibC4RxnWBXb8DDpIkO73Aax09u6VXiJJI,114
107
107
  junifer/data/masks/_ants_mask_warper.py,sha256=Mwgc2_ZMf28vS_-fviRvZnHyT7JoQ1cQLozo7nUZSyM,5350
108
108
  junifer/data/masks/_fsl_mask_warper.py,sha256=VApp-ofGBKePNmCdgTg1HoEA66lMQiAPT0ihkhB2ezY,2415
109
- junifer/data/masks/_masks.py,sha256=QZ3bgxwir7W2XS3k1OuOjIeFRv9fpP4YM7gM1EfagQM,23560
109
+ junifer/data/masks/_masks.py,sha256=8w-J-ZBKuik99gk9tYHntbmanpx_Mbu9oUujzxO7y1w,25874
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.dev344.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
345
- junifer-0.0.6.dev344.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
346
- junifer-0.0.6.dev344.dist-info/METADATA,sha256=TjbEy9EnZ5YtMFwT1hq6xet_EhJvrEUnqpH6-2uz64c,8429
347
- junifer-0.0.6.dev344.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
348
- junifer-0.0.6.dev344.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
349
- junifer-0.0.6.dev344.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
350
- junifer-0.0.6.dev344.dist-info/RECORD,,
344
+ junifer-0.0.6.dev349.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
345
+ junifer-0.0.6.dev349.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
346
+ junifer-0.0.6.dev349.dist-info/METADATA,sha256=rzDvV7h-fyKVUrFJWcNNyC6UFs-Y1fXs-7xT6loyXKs,8429
347
+ junifer-0.0.6.dev349.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
348
+ junifer-0.0.6.dev349.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
349
+ junifer-0.0.6.dev349.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
350
+ junifer-0.0.6.dev349.dist-info/RECORD,,