junifer 0.0.6.dev116__py3-none-any.whl → 0.0.6.dev142__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.dev116'
16
- __version_tuple__ = version_tuple = (0, 0, 6, 'dev116')
15
+ __version__ = version = '0.0.6.dev142'
16
+ __version_tuple__ = version_tuple = (0, 0, 6, 'dev142')
@@ -6,9 +6,10 @@
6
6
  from pathlib import Path
7
7
  from typing import Any, Dict, Optional, Union
8
8
 
9
- import httpx
9
+ import datalad.api as dl
10
10
  import nibabel as nib
11
11
  import numpy as np
12
+ from datalad.support.exceptions import IncompleteResultsError
12
13
  from templateflow import api as tflow
13
14
 
14
15
  from ..utils import logger, raise_error
@@ -41,61 +42,82 @@ def get_xfm(
41
42
  Raises
42
43
  ------
43
44
  RuntimeError
44
- If there is a problem fetching files.
45
+ If there is a problem cloning the xfm dataset or
46
+ if there is a problem fetching the xfm file.
45
47
 
46
48
  """
49
+ # Set default path for storage
47
50
  if xfms_dir is None:
48
51
  xfms_dir = Path().home() / "junifer" / "data" / "xfms"
49
- logger.debug(f"Creating xfm directory at: {xfms_dir.resolve()}")
50
- # Create default junifer data directory if not present
51
- xfms_dir.mkdir(exist_ok=True, parents=True)
52
+
52
53
  # Convert str to Path
53
- elif not isinstance(xfms_dir, Path):
54
+ if not isinstance(xfms_dir, Path):
54
55
  xfms_dir = Path(xfms_dir)
55
56
 
56
- # Set local file prefix
57
- xfm_file_prefix = f"{src}_to_{dst}"
58
- # Set local file dir
59
- xfm_file_dir = xfms_dir / xfm_file_prefix
60
- # Create local directory if not present
61
- xfm_file_dir.mkdir(exist_ok=True, parents=True)
62
- # Set file name with extension
63
- xfm_file = f"{src}_to_{dst}_Composite.h5"
64
- # Set local file path
65
- xfm_file_path = xfm_file_dir / xfm_file
66
- # Check if the file exists
67
- if xfm_file_path.exists():
68
- logger.info(
69
- f"Found existing xfm file for {src} to {dst} at "
70
- f"{xfm_file_path.resolve()}"
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()}"
71
63
  )
72
- return xfm_file_path
73
-
74
- # Set URL
75
- url = (
76
- "https://gin.g-node.org/juaml/human-template-xfms/raw/main/xfms/"
77
- f"{xfm_file_prefix}/{xfm_file}"
78
- )
79
- # Create the file before proceeding
80
- xfm_file_path.touch()
81
-
82
- logger.info(f"Downloading xfm file for {src} to {dst} from {url}")
83
- # Steam response
84
- with httpx.stream("GET", url) as resp:
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
85
70
  try:
86
- resp.raise_for_status()
87
- except httpx.HTTPError as exc:
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:
88
77
  raise_error(
89
- f"Error response {exc.response.status_code} while "
90
- f"requesting {exc.request.url!r}",
78
+ msg=f"Failed to clone dataset: {e.failed}",
91
79
  klass=RuntimeError,
92
80
  )
93
81
  else:
94
- with open(xfm_file_path, "ab") as f:
95
- for chunk in resp.iter_bytes():
96
- f.write(chunk)
82
+ logger.debug(
83
+ f"Successfully cloned template xfms dataset to: "
84
+ f"{xfms_dir.resolve()}"
85
+ )
97
86
 
98
- return xfm_file_path
87
+ # Set file path to retrieve
88
+ xfm_file_path = (
89
+ xfms_dir / "xfms" / f"{src}_to_{dst}" / f"{src}_to_{dst}_Composite.h5"
90
+ )
91
+
92
+ # 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
+ )
99
121
 
100
122
 
101
123
  def get_template(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: junifer
3
- Version: 0.0.6.dev116
3
+ Version: 0.0.6.dev142
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=A6Janz0-4ad7zQiLsIo-jnUkpHJjzGTt_KcVsJJLSDM,454
3
- junifer/_version.py,sha256=hwZhTBj69Hs5D0mpZrArfQX9sBRikpFw295nNR-bjrY,428
3
+ junifer/_version.py,sha256=4Ya2bEeGse7LTlbV14QOrms9mP2LRS1Dz1RcVuEhl1A,428
4
4
  junifer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  junifer/stats.py,sha256=BjQb2lfTGDP9l4UuQYmJFcJJNRfbJDGlNvC06SJaDDE,6237
6
6
  junifer/api/__init__.py,sha256=aAXW_KAEGQ8aAP5Eni2G1R4MWBF7UgjKOgM6akLuJco,252
@@ -75,7 +75,7 @@ junifer/data/coordinates.py,sha256=1HH2Kz5nzZKN6-wJRmYotPH76fPaL1yYbCt8AhONogk,1
75
75
  junifer/data/masks.py,sha256=omKOJLnUpmI1yVUkckWy9HhzbFZuYbYdOyr49xFvEwU,21640
76
76
  junifer/data/parcellations.py,sha256=mw1xa6yFWAaVktTkkpCt2ZgSUapZbPwloN2UoPdLzdg,65490
77
77
  junifer/data/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
78
- junifer/data/template_spaces.py,sha256=7I2Hgy-Wh-Uqm_vOvpYQ5H9CFg1Qn5YRX4QU-HZAloc,5796
78
+ junifer/data/template_spaces.py,sha256=9uZuFztBGNZk3mhUI2h0oQMajjx6Wv31Fx11pGlDI20,6510
79
79
  junifer/data/utils.py,sha256=dIdhCJMJHoXsjTjEMi2b-NXyCiSKsFZQt-5Ca00Obd4,1330
80
80
  junifer/data/VOIs/meta/AutobiographicalMemory_VOIs.txt,sha256=9af38naeL18Tlt_gy_ep6vyTAxOB336JYjbo5FvP8PQ,686
81
81
  junifer/data/VOIs/meta/CogAC_VOIs.txt,sha256=Sr5_E712OLdeQRyUcDNM0wLBvZIyO6gc9Q7KkyJHX1A,398
@@ -321,10 +321,10 @@ junifer/utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
321
321
  junifer/utils/tests/test_fs.py,sha256=WQS7cKlKEZ742CIuiOYYpueeAhY9PqlastfDVpVVtvE,923
322
322
  junifer/utils/tests/test_helpers.py,sha256=k5qqfxK8dFyuewTJyR1Qn6-nFaYNuVr0ysc18bfPjyU,929
323
323
  junifer/utils/tests/test_logging.py,sha256=duO4ou365hxwa_kwihFtKPLaL6LC5XHiyhOijrrngbA,8009
324
- junifer-0.0.6.dev116.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
325
- junifer-0.0.6.dev116.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
326
- junifer-0.0.6.dev116.dist-info/METADATA,sha256=M0l1c7ePF_90X00b6ipVuKpgWWoWSHhq6Q2mYhP8r2Q,8448
327
- junifer-0.0.6.dev116.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
328
- junifer-0.0.6.dev116.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
329
- junifer-0.0.6.dev116.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
330
- junifer-0.0.6.dev116.dist-info/RECORD,,
324
+ junifer-0.0.6.dev142.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
325
+ junifer-0.0.6.dev142.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
326
+ junifer-0.0.6.dev142.dist-info/METADATA,sha256=1jRuKSbFgf9ThbqiBCG--BNeA0Ov7Y_HnkU2EO2Xvys,8448
327
+ junifer-0.0.6.dev142.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
328
+ junifer-0.0.6.dev142.dist-info/entry_points.txt,sha256=6O8ru0BP-SP7YMUZiizFNoaZ2HvJpadO2G7nKk4PwjI,48
329
+ junifer-0.0.6.dev142.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
330
+ junifer-0.0.6.dev142.dist-info/RECORD,,