File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 11"""
22TemplateFlow's Python Client
33"""
4+ from json import loads
45from datalad import api
56from datalad .support .exceptions import IncompleteResultsError
67from .conf import TF_HOME
@@ -51,3 +52,28 @@ def templates():
5152 templates = [str (p .name )[4 :] for p in TF_HOME .glob ('tpl-*' )]
5253
5354 return sorted (templates )
55+
56+
57+ def get_metadata (template_id ):
58+ """
59+ Fetch one file from one template
60+
61+ >>> get_metadata('MNI152Lin')['Name']
62+ 'Linear ICBM Average Brain (ICBM152) Stereotaxic Registration Model'
63+
64+ """
65+
66+ filepath = TF_HOME / ('tpl-%s' % template_id ) / 'template_description.json'
67+
68+ # Ensure that template is installed and file is available
69+ try :
70+ api .get (str (filepath ))
71+ except IncompleteResultsError as exc :
72+ if exc .failed [0 ]['message' ] == 'path not associated with any dataset' :
73+ from .conf import TF_GITHUB_SOURCE
74+ api .install (path = str (TF_HOME ), source = TF_GITHUB_SOURCE , recursive = True )
75+ api .get (str (filepath ))
76+ else :
77+ raise
78+
79+ return loads (filepath .read_text ())
You can’t perform that action at this time.
0 commit comments