YAXIL API¶
Functions¶
-
yaxil.auth(alias=None, url=None, cfg='~/.xnat_auth')¶ Read connection details from an xnat_auth XML file
- Example:
>>> import yaxil >>> auth = yaxil.auth('xnatastic') >>> auth.url, auth.username, auth.password ('https://www.xnatastic.org/', 'username', '********')
Parameters: - alias (str) – XNAT alias
- url (str) – XNAT URL
- cfg (str) – Configuration file
Returns: Named tuple of (url, username, password)
Return type:
-
yaxil.session(*args, **kwds)¶ Create a session context to avoid explicitly passing authentication to every function.
Example:
import yaxil auth = yaxil.XnatAuth(url='...', username='...', password='...') with yaxil.session(auth) as sess: aid = sess.accession('AB1234C') experiment = sess.experiment('AB1234C') sess.download('AB1234C', [1,3,14], out_dir='./dicomz')
Parameters: auth ( yaxil.XnatAuth) – XNAT authenticationReturns: YAXIL session object Return type: yaxil.session.Session
-
yaxil.subjects(auth, label=None, project=None)¶ Retrieve Subject tuples for subjects returned by this function.
- Example:
>>> import yaxil >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> yaxil.subjects(auth, 'AB1234C') Subject(uri=u'/data/experiments/XNAT_S0001', label=u'AB1234C', id=u'XNAT_S0001', project=u'MyProject')
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication - label (str) – XNAT Subject label
- project (str) – XNAT Subject Project
Returns: Subject objects
Return type:
-
yaxil.experiments(auth, label=None, project=None, subject=None)¶ Retrieve Experiment tuples for experiments returned by this function.
- Example:
>>> import yaxil >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> yaxil.experiment(auth, 'AB1234C') Experiment(uri=u'/data/experiments/XNAT_E0001', label=u'AB1234C', id=u'XNAT_E0001', project=u'MyProject', subject_id=u'XNAT_S0001', subject_label='ABC')
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication - label (str) – XNAT Experiment label
- project (str) – XNAT Experiment Project
- subject (
yaxil.Subject) – YAXIL Subject
Returns: Experiment object
Return type:
-
yaxil.accession(*args)¶ Get the Accession ID for any Experiment label.
- Example:
>>> import yaxil >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> yaxil.accession(auth, 'AB1234C') u'XNAT_E00001'
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication - label (str) – XNAT Experiment label
- project (str) – XNAT Experiment Project
Returns: Accession ID
Return type: str
-
yaxil.extendedboldqc(auth, label, scan_ids=None, project=None, aid=None)¶ Get ExtendedBOLDQC data as a sequence of dictionaries.
- Example:
>>> import yaxil >>> import json >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> for eqc in yaxil.extendedboldqc2(auth, 'AB1234C') ... print(json.dumps(eqc, indent=2))
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication object - label (str) – XNAT MR Session label
- scan_ids (list) – Scan numbers to return
- project (str) – XNAT MR Session project
- aid (str) – XNAT Accession ID
Returns: Generator of scan data dictionaries
Return type: dict
-
yaxil.scans(auth, label=None, scan_ids=None, project=None, experiment=None)¶ Get scan information for a MR Session as a sequence of dictionaries.
- Example:
>>> import yaxil >>> import json >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> for scan in yaxil.scans2(auth, 'AB1234C'): ... print(json.dumps(scan, indent=2))
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication object - label (str) – XNAT MR Session label
- scan_ids (list) – Scan numbers to return
- project (str) – XNAT MR Session project
- experiment (
yaxil.Experiment) – YAXIL Experiment
Returns: Generator of scan data dictionaries
Return type: dict
-
yaxil.scansearch(auth, label, filt, project=None, aid=None)¶ Search for scans by supplying a set of SQL-based conditionals.
- Example:
>>> import yaxil >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> query = { ... 'eor1': "note LIKE %EOR1%", ... 'eor2': "note LIKE %EOR2%", ... 'mpr': "series_description='T1_MEMPRAGE RMS' OR note LIKE %ANAT%" ... } >>> yaxil.scansearch(auth, 'AB1234C', query) {"mpr": [4], "eor1": [13], "eor2": [14]}
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication object - label (str) – XNAT MR Session label
- filt (dict) – Scan search filter/query
- project (str) – XNAT MR Session project
- aid (str) – XNAT Accession ID
Returns: Same dictionary that was passed in, but values are now matching scans
Return type: dict
-
yaxil.download(auth, label, scan_ids=None, project=None, aid=None, out_dir='.', in_mem=True, progress=False, attempts=1)¶ Download scan data from XNAT.
- Example:
>>> import yaxil >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> yaxil.download(auth, 'AB1234C', ['1', '2'], out_dir='./data')
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication object - label (str) – XNAT MR Session label
- scan_ids (list) – Scan numbers to return; use None for all
- project (str) – XNAT MR Session project
- aid (str) – XNAT Accession ID
- out_dir (str) – Output directory
- in_mem (bool) – Keep download content in memory; faster but uses more memory
- progress (int) – Show download progress every N bytes
- attempts (int) – Number of download attempts
-
yaxil.has(auth, xsitype, project=None)¶ Test if a project contains any items of a particular xsi:type.
- Example:
>>> import yaxil >>> auth = yaxil.XnatAuth(url='...', username='...', password='...') >>> yaxil.has(auth, 'neuroinfo:extendedboldqc', project='MyProject')
Parameters: - auth (
yaxil.XnatAuth) – XNAT authentication - xsitype – XNAT xsi:type
- xsitype – str
- project (str) – XNAT Project
Returns: True or False
Return type: bool
Classes¶
-
class
yaxil.XnatAuth(url, username, password)¶ Container to hold XNAT authentication information. Fields include the
url,username, andpassword.
-
class
yaxil.Experiment(uri, label, id, project, subject_id, subject_label, archived_date)¶ Container to hold XNAT Experiment information. Fields include the Experiment URI (
uri), Accession ID (id), Project (project), Label (label), Subject Accession ID (subject_id), Subject label (subject_label), and archived date (archived_date).
-
class
yaxil.Subject(uri, label, id, project)¶ Container to hold XNAT Subject information. Fields include the Subject URI (
uri), Accession ID (id), Project (project), and Label (label).