junifer 0.0.6.dev418__py3-none-any.whl → 0.0.6.dev445__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.
@@ -6,22 +6,18 @@
6
6
  from pathlib import Path
7
7
  from typing import Any, Optional, Union
8
8
 
9
- import datalad.api as dl
10
9
  import nibabel as nib
11
10
  import numpy as np
12
- from datalad.support.exceptions import IncompleteResultsError
13
11
  from templateflow import api as tflow
14
12
 
15
13
  from ..utils import logger, raise_error
16
- from .utils import closest_resolution
14
+ from .utils import check_dataset, closest_resolution, fetch_file_via_datalad
17
15
 
18
16
 
19
17
  __all__ = ["get_template", "get_xfm"]
20
18
 
21
19
 
22
- def get_xfm(
23
- src: str, dst: str, xfms_dir: Union[str, Path, None] = None
24
- ) -> Path: # pragma: no cover
20
+ def get_xfm(src: str, dst: str) -> Path: # pragma: no cover
25
21
  """Fetch warp files to convert from ``src`` to ``dst``.
26
22
 
27
23
  Parameters
@@ -30,94 +26,24 @@ def get_xfm(
30
26
  The template space to transform from.
31
27
  dst : str
32
28
  The template space to transform to.
33
- xfms_dir : str or pathlib.Path, optional
34
- Path where the retrieved transformation files are stored.
35
- The default location is "$HOME/junifer/data/xfms" (default None).
36
29
 
37
30
  Returns
38
31
  -------
39
32
  pathlib.Path
40
33
  The path to the transformation file.
41
34
 
42
- Raises
43
- ------
44
- RuntimeError
45
- If there is a problem cloning the xfm dataset or
46
- if there is a problem fetching the xfm file.
47
-
48
35
  """
49
- # Set default path for storage
50
- if xfms_dir is None:
51
- xfms_dir = Path().home() / "junifer" / "data" / "xfms"
52
-
53
- # Convert str to Path
54
- if not isinstance(xfms_dir, Path):
55
- xfms_dir = Path(xfms_dir)
56
-
57
- # Check if the template xfms dataset is installed at storage path
58
- is_installed = dl.Dataset(xfms_dir).is_installed()
59
- # Use existing dataset
60
- if is_installed:
61
- logger.debug(
62
- f"Found existing template xfms dataset at: {xfms_dir.resolve()}"
63
- )
64
- # Set dataset
65
- dataset = dl.Dataset(xfms_dir)
66
- # Clone a fresh copy
67
- else:
68
- logger.debug(f"Cloning template xfms dataset to: {xfms_dir.resolve()}")
69
- # Clone dataset
70
- try:
71
- dataset = dl.clone(
72
- "https://github.com/juaml/human-template-xfms.git",
73
- path=xfms_dir,
74
- result_renderer="disabled",
75
- )
76
- except IncompleteResultsError as e:
77
- raise_error(
78
- msg=f"Failed to clone dataset: {e.failed}",
79
- klass=RuntimeError,
80
- )
81
- else:
82
- logger.debug(
83
- f"Successfully cloned template xfms dataset to: "
84
- f"{xfms_dir.resolve()}"
85
- )
86
-
36
+ # Get dataset
37
+ dataset = check_dataset()
87
38
  # Set file path to retrieve
88
39
  xfm_file_path = (
89
- xfms_dir / "xfms" / f"{src}_to_{dst}" / f"{src}_to_{dst}_Composite.h5"
40
+ dataset.pathobj
41
+ / "xfms"
42
+ / f"{src}_to_{dst}"
43
+ / f"{src}_to_{dst}_Composite.h5"
90
44
  )
91
-
92
45
  # Retrieve file
93
- try:
94
- got = dataset.get(xfm_file_path, result_renderer="disabled")
95
- except IncompleteResultsError as e:
96
- raise_error(
97
- msg=f"Failed to get file from dataset: {e.failed}",
98
- klass=RuntimeError,
99
- )
100
- else:
101
- file_path = Path(got[0]["path"])
102
- # Conditional logging based on file fetch
103
- status = got[0]["status"]
104
- if status == "ok":
105
- logger.info(
106
- f"Successfully fetched xfm file for {src} to {dst} at "
107
- f"{file_path.resolve()}"
108
- )
109
- return file_path
110
- elif status == "notneeded":
111
- logger.info(
112
- f"Found existing xfm file for {src} to {dst} at "
113
- f"{file_path.resolve()}"
114
- )
115
- return file_path
116
- else:
117
- raise_error(
118
- f"Failed to fetch xfm file for {src} to {dst} at "
119
- f"{file_path.resolve()}"
120
- )
46
+ return fetch_file_via_datalad(dataset=dataset, file_path=xfm_file_path)
121
47
 
122
48
 
123
49
  def get_template(
@@ -190,7 +116,7 @@ def get_template(
190
116
 
191
117
  logger.info(
192
118
  f"Downloading template {space} ({template_type} in "
193
- f"resolution {resolution}"
119
+ f"resolution {resolution})"
194
120
  )
195
121
  # Retrieve template
196
122
  try:
@@ -224,9 +150,11 @@ def get_template(
224
150
  )
225
151
  except Exception: # noqa: BLE001
226
152
  raise_error(
227
- f"Template {space} ({template_type}) with resolution {resolution} "
228
- "not found",
153
+ msg=(
154
+ f"Template {space} ({template_type}) with resolution "
155
+ f"{resolution}) not found"
156
+ ),
229
157
  klass=RuntimeError,
230
158
  )
231
159
  else:
232
- return nib.load(template_path) # type: ignore
160
+ return nib.load(template_path)
junifer/data/utils.py CHANGED
@@ -5,14 +5,22 @@
5
5
  # License: AGPL
6
6
 
7
7
  from collections.abc import MutableMapping
8
+ from pathlib import Path
8
9
  from typing import Optional, Union
9
10
 
11
+ import datalad.api as dl
10
12
  import numpy as np
13
+ from datalad.support.exceptions import IncompleteResultsError
11
14
 
12
- from ..utils import logger, raise_error
15
+ from ..utils import config, logger, raise_error
13
16
 
14
17
 
15
- __all__ = ["closest_resolution", "get_native_warper"]
18
+ __all__ = [
19
+ "check_dataset",
20
+ "closest_resolution",
21
+ "fetch_file_via_datalad",
22
+ "get_native_warper",
23
+ ]
16
24
 
17
25
 
18
26
  def closest_resolution(
@@ -114,3 +122,96 @@ def get_native_warper(
114
122
  )
115
123
 
116
124
  return possible_warpers[0]
125
+
126
+
127
+ def check_dataset() -> dl.Dataset:
128
+ """Get or install junifer-data dataset.
129
+
130
+ Returns
131
+ -------
132
+ datalad.api.Dataset
133
+ The junifer-data dataset.
134
+
135
+ Raises
136
+ ------
137
+ RuntimeError
138
+ If there is a problem cloning the dataset.
139
+
140
+ """
141
+ # Check config and set default if not passed
142
+ data_dir = config.get("data.location")
143
+ if data_dir is not None:
144
+ data_dir = Path(data_dir)
145
+ else:
146
+ data_dir = Path().home() / "junifer_data"
147
+
148
+ # Check if the dataset is installed at storage path;
149
+ # else clone a fresh copy
150
+ if dl.Dataset(data_dir).is_installed():
151
+ logger.debug(f"Found existing junifer-data at: {data_dir.resolve()}")
152
+ return dl.Dataset(data_dir)
153
+ else:
154
+ logger.debug(f"Cloning junifer-data to: {data_dir.resolve()}")
155
+ # Clone dataset
156
+ try:
157
+ dataset = dl.clone(
158
+ "https://github.com/juaml/junifer-data.git",
159
+ path=data_dir,
160
+ result_renderer="disabled",
161
+ )
162
+ except IncompleteResultsError as e:
163
+ raise_error(
164
+ msg=f"Failed to clone junifer-data: {e.failed}",
165
+ klass=RuntimeError,
166
+ )
167
+ else:
168
+ logger.debug(
169
+ f"Successfully cloned junifer-data to: "
170
+ f"{data_dir.resolve()}"
171
+ )
172
+ return dataset
173
+
174
+
175
+ def fetch_file_via_datalad(dataset: dl.Dataset, file_path: Path) -> Path:
176
+ """Fetch `file_path` from `dataset` via datalad.
177
+
178
+ Parameters
179
+ ----------
180
+ dataset : datalad.api.Dataset
181
+ The datalad dataset to fetch files from.
182
+ file_path : pathlib.Path
183
+ The file path to fetch.
184
+
185
+ Returns
186
+ -------
187
+ pathlib.Path
188
+ Resolved fetched file path.
189
+
190
+ Raises
191
+ ------
192
+ RuntimeError
193
+ If there is a problem fetching the file.
194
+
195
+ """
196
+ try:
197
+ got = dataset.get(file_path, result_renderer="disabled")
198
+ except IncompleteResultsError as e:
199
+ raise_error(
200
+ msg=f"Failed to get file from dataset: {e.failed}",
201
+ klass=RuntimeError,
202
+ )
203
+ else:
204
+ got_path = Path(got[0]["path"])
205
+ # Conditional logging based on file fetch
206
+ status = got[0]["status"]
207
+ if status == "ok":
208
+ logger.info(f"Successfully fetched file: {got_path.resolve()}")
209
+ return got_path
210
+ elif status == "notneeded":
211
+ logger.debug(f"Found existing file: {got_path.resolve()}")
212
+ return got_path
213
+ else:
214
+ raise_error(
215
+ msg=f"Failed to fetch file: {got_path.resolve()}",
216
+ klass=RuntimeError,
217
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: junifer
3
- Version: 0.0.6.dev418
3
+ Version: 0.0.6.dev445
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>
@@ -38,7 +38,6 @@ Requires-Dist: nilearn<=0.10.4,>=0.10.3
38
38
  Requires-Dist: sqlalchemy<=2.1.0,>=2.0.25
39
39
  Requires-Dist: ruamel.yaml<0.19,>=0.17
40
40
  Requires-Dist: h5py>=3.10
41
- Requires-Dist: httpx[http2]<0.28.0,>=0.26.0
42
41
  Requires-Dist: tqdm<4.67.0,>=4.66.1
43
42
  Requires-Dist: templateflow>=23.0.0
44
43
  Requires-Dist: lapy<2.0.0,>=1.0.0
@@ -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=OMl11BkdBDrB0BmEbZRQU35sDln0nRvukbppZ7DGaBQ,428
3
+ junifer/_version.py,sha256=BvD--u8WQlVv5BSuYt8l4VpOAPHUHWapEY83eY04RtE,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
@@ -48,7 +48,7 @@ junifer/cli/parser.py,sha256=jLinKVcZeuyTnxjB2p5sj8555DO5rcPcWKgZCtgFARY,8498
48
48
  junifer/cli/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  junifer/cli/utils.py,sha256=AbPQC0Kl-tHMNKiPxp_01gLAGD3IGoLbsq3rXyPMM-c,3116
50
50
  junifer/cli/tests/test_cli.py,sha256=AYL4my12GmFRCbI3JV7-rju32heYxAqbXNwnV8PwqVY,10982
51
- junifer/cli/tests/test_cli_utils.py,sha256=orbBhWaaIxTgB_JzURYH8CvAYqrwle043zHWoVaj6cM,2746
51
+ junifer/cli/tests/test_cli_utils.py,sha256=f_x0IIzZD8GGnZtVp8vSMywl-BNVdenl2pT79dWqchs,2712
52
52
  junifer/cli/tests/test_parser.py,sha256=5A6yI2t9Ou5w--wpEzXY7mdcVMWWFZaTNLPQ6yLU9gI,6113
53
53
  junifer/cli/tests/data/gmd_mean.yaml,sha256=Ohb_C5cfQMK-59U9O1ZhejXyBtzLc5Y4cv8QyYq2azg,330
54
54
  junifer/cli/tests/data/gmd_mean_htcondor.yaml,sha256=f7NLv_KIJXTiPNFmOWl2Vw8EfwojhfkGtwbh5prbd6w,417
@@ -75,12 +75,12 @@ junifer/data/__init__.pyi,sha256=qYszjUYcbFi_2zO23MnbA2HhTW-Ad2oh1pqPQYd6yt0,542
75
75
  junifer/data/_dispatch.py,sha256=O524U1R4MtbGhGJsL0HSh9EqisapBFJWK7uupXrJuMg,6158
76
76
  junifer/data/pipeline_data_registry_base.py,sha256=G8bE3WTj4D_rKC4ZKZe6E48Sd96CGea1PS3SxmTgGK4,2010
77
77
  junifer/data/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
78
- junifer/data/template_spaces.py,sha256=wkxaDA_I_W5FB42GPxOKrl_A_fp0Crdrh6wFux27_NA,7147
79
- junifer/data/utils.py,sha256=5r-0QGQCNZvDM1tVcl9xyrIdgAO85mww0plpM1RUaGA,3247
78
+ junifer/data/template_spaces.py,sha256=qa-qPDVF0TqyeY1KnOD5bQ6EY4V5jUBloRn52KIy7s0,4690
79
+ junifer/data/utils.py,sha256=u35ni7lSD5PxmhpHPjZBzzLuYSZQ0Q7lJBdTfWjcgzI,6093
80
80
  junifer/data/coordinates/__init__.py,sha256=ffM8rwcHLgHAWixJbKrATrbUKzX940V1UF6RAxZdUMg,186
81
81
  junifer/data/coordinates/__init__.pyi,sha256=Z-Ti5XD3HigkZ8uYN6oYsLqw40-F1GvTVQ5QAy08Wng,88
82
82
  junifer/data/coordinates/_ants_coordinates_warper.py,sha256=5RWDC-nI3VG9lkSJ-_y_hlDtjPctKSJokQOp3v8ozwY,2956
83
- junifer/data/coordinates/_coordinates.py,sha256=fBXVvuTxYLTNBSrQiTCiQsxpT0SdbQze3DYuGGgz_mY,12501
83
+ junifer/data/coordinates/_coordinates.py,sha256=khgX0wYThgWGqvkTfVqFkgMtnp3AN9-Lyt5oovAcW_w,13386
84
84
  junifer/data/coordinates/_fsl_coordinates_warper.py,sha256=5h7rwiPMYBQlA3sMZUImcpnNLLWvIp2-bAEaaHtzX9c,2409
85
85
  junifer/data/coordinates/VOIs/meta/AutobiographicalMemory_VOIs.txt,sha256=9af38naeL18Tlt_gy_ep6vyTAxOB336JYjbo5FvP8PQ,686
86
86
  junifer/data/coordinates/VOIs/meta/CogAC_VOIs.txt,sha256=Sr5_E712OLdeQRyUcDNM0wLBvZIyO6gc9Q7KkyJHX1A,398
@@ -101,13 +101,13 @@ junifer/data/coordinates/VOIs/meta/WM_VOIs.txt,sha256=6uyH5nsv9i5bKS_aEYCgg3wgE7
101
101
  junifer/data/coordinates/VOIs/meta/eMDN_VOIs.txt,sha256=p5D4GdBuGl1d5IbXhsuj3XIU6UGMxhzCR-T8Dwfxz30,382
102
102
  junifer/data/coordinates/VOIs/meta/eSAD_VOIs.txt,sha256=DwgDEFSZoAojG5RP6HpSvlRPpXItBzx8ms-1zoSxKRk,268
103
103
  junifer/data/coordinates/VOIs/meta/extDMN_VOIs.txt,sha256=Ogx1QvqZcnXDM3ncF2ha78br8xwQ5wklSjHygtoLpyI,317
104
- junifer/data/coordinates/tests/test_coordinates.py,sha256=_c2P4oaDGpsmui5gJBe_jN6HLGiKxONkYPR69sRBUlU,4219
104
+ junifer/data/coordinates/tests/test_coordinates.py,sha256=mjHm90Fgytv47F2vPQHW58jRy6LLbAttizEeg1zjxmA,4196
105
105
  junifer/data/masks/__init__.py,sha256=eEEhHglyVEx1LrqwXjq3cOmjf4sTsgBstRx5-k7zIQU,180
106
106
  junifer/data/masks/__init__.pyi,sha256=lcgr8gmWDPibC4RxnWBXb8DDpIkO73Aax09u6VXiJJI,114
107
107
  junifer/data/masks/_ants_mask_warper.py,sha256=JLK2Jh2AOAiv_NoUGhRoTBEhRFXPRXTDPmQGH9vBSok,5805
108
108
  junifer/data/masks/_fsl_mask_warper.py,sha256=YZOMlRgQ7_4shnXNc_05tmwDk5xHI-1wqle-RdNsJ34,2857
109
- junifer/data/masks/_masks.py,sha256=K-A1cr9TAeVzFPGgn4FUmwIo6LBP0xQb1Q4NW6WTWVo,28166
110
- junifer/data/masks/tests/test_masks.py,sha256=W0bzRB5Bp-iGO44VtEmaf7BuT-joe_2tQI0lma5NQHA,16090
109
+ junifer/data/masks/_masks.py,sha256=ykspETk2nBVMuIU9eLynIRKcSgDg42CEFUsAhCWcxek,28971
110
+ junifer/data/masks/tests/test_masks.py,sha256=T-WpJvBlAqMIRWF8ODkQBmmBSj-7XUNeTdH3qlsWJC8,16207
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
113
113
  junifer/data/masks/vickery-patil/CAT12_IXI555_MNI152_TMP_GS_GMprob0.2_clean_3mm.nii.gz,sha256=crb_y7YO1vjjf2PwbRJUm8KamPK6fx1y0B_l-E3g8FY,12862
@@ -116,8 +116,8 @@ junifer/data/parcellations/__init__.py,sha256=6-Ysil3NyZ69V6rWx4RO15_d-iDKizfbHu
116
116
  junifer/data/parcellations/__init__.pyi,sha256=lhBHTbMDizzqUqVHrx2eyfPFodrTBgMFeTgxfESSkQ8,140
117
117
  junifer/data/parcellations/_ants_parcellation_warper.py,sha256=YUCJC0_wutGw7j_n9JRU3LCwm9Ttg5PIlJUgqejfRhs,5806
118
118
  junifer/data/parcellations/_fsl_parcellation_warper.py,sha256=JfJ022flg5OR48P4OAALVHHQgTVxdMBXT-fAqBl3nUM,2679
119
- junifer/data/parcellations/_parcellations.py,sha256=JUUglL0ZM_UKL5jTG1q-3x6Fd3CUO6Hl4YAGAUsGtmI,67019
120
- junifer/data/parcellations/tests/test_parcellations.py,sha256=ESQI-KWsepmgKB2BWWWUxjkpjOWeIZhhlKxNuTsRPJg,39268
119
+ junifer/data/parcellations/_parcellations.py,sha256=a3Z1Ygb9AYOZC9FuB7Aj32eeaB2eDI-F6KSebo_zoak,50121
120
+ junifer/data/parcellations/tests/test_parcellations.py,sha256=bDoIYC8XAcHI3vEPPMkf7Gex7apnvEqNGRhUENaPgho,36699
121
121
  junifer/data/tests/test_data_utils.py,sha256=136iGPjGecCxyqgUwU8VZMHoE6imcYJ0WNC32PDGK4g,1063
122
122
  junifer/data/tests/test_template_spaces.py,sha256=ZEicEcLqOJ-NpuBZ5SYh4yZ0xZRkhYHnYXiC_YSxjrY,3219
123
123
  junifer/datagrabber/__init__.py,sha256=EHIK-lbjuvkt0V8ypFvLSt85OAAXSkaxBmVlCbNNz8M,323
@@ -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.dev418.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
345
- junifer-0.0.6.dev418.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
346
- junifer-0.0.6.dev418.dist-info/METADATA,sha256=MzAouL0FarJWSZvtphozKmMIpgp4QIKt22JJMF2rqNU,8429
347
- junifer-0.0.6.dev418.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
348
- junifer-0.0.6.dev418.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
349
- junifer-0.0.6.dev418.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
350
- junifer-0.0.6.dev418.dist-info/RECORD,,
344
+ junifer-0.0.6.dev445.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
345
+ junifer-0.0.6.dev445.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
346
+ junifer-0.0.6.dev445.dist-info/METADATA,sha256=HR2aD6lGERZB17sq9_WuyV_IDv_zm3Q0TuPxj3M3YpQ,8385
347
+ junifer-0.0.6.dev445.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
348
+ junifer-0.0.6.dev445.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
349
+ junifer-0.0.6.dev445.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
350
+ junifer-0.0.6.dev445.dist-info/RECORD,,