Main entry point to access a XNAT server.
>>> central = Interface(server='http://central.xnat.org:8080',
user='login',
password='pwd',
cachedir='/tmp'
)
Attributes: | _mode: online | offline :
_memlifespan: float :
|
---|
Defines a callback to execute when collections of resources are accessed.
Parameters: | func: callable :
|
---|
Examples
>>> def notify(cobj, eobj):
>>> print eobj._uri
>>> interface.global_callback(notify)
Data selection interface. Callable object that indicates the data to be returned to the user.
Examples
>>> interface.select('/projects/myproj/subjects').get()
>>> interface.select('xnat:subjectData', ['xnat:subjectData/PROJECT', 'xnat:subjectData/SUBJECT_ID']
).where([('xnat:subjectData/SUBJECT_ID', 'LIKE', '*'), 'AND'])
Select clause to specify what type of data is to be returned.
Parameters: | datatype_or_path: string :
columns: list :
|
---|
Access a particular project.
Parameters: | ID: string :
|
---|
Returns the list of all visible projects for the server.
Parameters: | id_filter: string :
|
---|
Search interface. Handles operations to save and get back searches on the server.
Examples
>>> interface.search.save(name='mysearch',
row='xnat:subjectData',
columns=['xnat:subjectData/PROJECT','xnat:subjectData/SUBJECT_ID'],
constraints=[('xnat:subjectData/SUBJECT_ID', 'LIKE', '*'), 'AND'],
sharing='public'
)
Saves a query on the XNAT server.
Parameters: | name: string :
row: string :
columns: list :
constraints: list :
sharing: string | list :
|
---|
See also
Search.where
Define constraints to make a complex search on the database.
>>> interface.select(DATA_SELECTION).where(QUERY)
>>> interface.search.save('name', TABLE_DEFINITION, QUERY)
Examples
>>> query = [('xnat:subjectData/SUBJECT_ID', 'LIKE', '%'),
('xnat:projectData/ID', '=', 'my_project'),
[('xnat:subjectData/AGE', '>', '14'),
'AND'
],
'OR'
]
Triggers the search.
Parameters: | contraints: list :
|
---|---|
Returns: | results: JsonTable object :
|
Generic Object for an element URI.
Returns an absolute URL of the element resource, including the server address and the user login and password.
Note
Not used at the moment.
Returns the children levels of this element.
Examples
>>> subject_object.children()
['experiments', 'resources']
Creates the element if it does not exists. Any non-existing ancestor will be created as well.
Warning
An element resource both have an ID and a label that can be used to access it. At the moment, XNAT REST API defines the label when creating an element, but not the ID, which is generated. It means that the name given to a resource may not appear when listing the resources because the IDs will appear, not the labels.
Parameters: | datatypes: keywords or dict :
|
---|
See also
EObject.id, EObject.label, EObject.datatype, Interface.inspect.naming_conventions
Examples
>>> interface.select('/project/PROJECT/subject/SUBJECT/experiment/EXP/scan/SCAN'
).create(experiments='xnat:mrSessionData', scans='xnat:mrScanData')
Returns the type defined in the XNAT schema for this element resource.
EObject | possible xsi types |
---|---|
Project | xnat:projectData |
Subject | xnat:subjectData |
Experiment | xnat:mrSessionData xnat:petSessionData |
Deletes an element resource.
Parameters: | delete_files: True | False :
|
---|
Generic Object for a collection resource.
A collection resource is a list of element resources. There is however several ways to obtain such a list:
- a collection URI e.g. /REST/projects
- a list of element URIs
- a list of collections e.g. /REST/projects/ONE/subjects and /REST/projects/TWO/subjects
- a list of element objects
- a list a collection objects
Examples
>>> interface.select.projects()
<Collection Object> 173667084
>>> for project in interface.select.projects():
>>> print project
>>> for subject in interface.select.projects().subjects():
>>> print subject
Returns every element.
Warning
If a collection needs to issue thousands of queries it may be better to access the resources within a for-loop.
Parameters: | args: ID, label, obj :
|
---|
Only the element objects whose subject that are matching the constraints will be returned. It means that it is not possible to use this method on an element that is not linked to a subject, such as a project.
See also
Examples
>>> for experiment in interface.select('//experiments'
>>> ).where([('atest/FIELD', '=', 'value'), 'AND']):
>>> print experiment
>>> for experiment in interface.select('//experiments'):
>>> for assessor in experiment.assessors(
>>> ).where([('atest/FIELD', '=', 'value'), 'AND']):
>>> print assessor
>>> for project in interface.select('//projects'
>>> ).where([('atest/FIELD', '=', 'value'), 'AND']):
>>> print project
Adds a user to the project. The user must already exist on the server.
Parameters: | login: string :
role: owner | member | collaborator :
|
---|
Removes a user from the project.
Parameters: | login: string :
|
---|
Sets project accessibility.
Parameters: | accessibility: public | protected | private :
|
---|
Sets project prearchive code.
Parameters: | code: 0 to 4 : |
---|
Sets project quarantine code.
Parameters: | code: 0 to 1 : |
---|
Gets the user level of the user for this project.
Parameters: | login: string :
|
---|---|
Returns: | owner | member | collaborator : |
EObject for files stored in XNAT.
Returns: | A dictionnary with the file attributes. : |
---|
Downloads the file to the cache directory.
Note
The path is computed like this: path_to_cache/urichecksum_filename
Returns: | The location of the file in the cache directory . : |
---|
Downloads the file to the cache directory but creates a copy at the specified location.
Parameters: | dest: string | None :
|
---|---|
Returns: | The location of the copy. : |
Uploads a file to XNAT.
Parameters: | src: string :
format: string :
content: string :
tags: string :
|
---|
Database user management interface. It is used to retrieve information on users registered on a server.
Note
At the moment user creation and deletion is not supported through the REST API but it will be at some point.
See also
Project.users, Project.add_user, Project.remove_user
Examples
>>> interface.users()
['list_of_users']
>>> interface.firstname('nosetests')
'nose'