copyxnat.xnat_backend.simple_xnat module

SimpleXnat wrappers for the XNAT REST API

class copyxnat.xnat_backend.simple_xnat.SimpleXnatAssessor(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithInOutResources

Wrapper around a pyxnat assessor interface

label_keys = ['label']
optional = True
parent_container_list = 'assessor_list'
rest_id_keys = ['ID']
rest_type = 'assessors'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatBase[source]

Bases: object

Base class for an item in the XNAT REST hierarchy

abstract read_uri()[source]

Return URI of this XNAT item relative to the XNAT REST interface as used for read operations

abstract write_uri()[source]

Return URI of this XNAT item relative to the XNAT REST interface as used for write operations

class copyxnat.xnat_backend.simple_xnat.SimpleXnatExperiment(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithResources

Wrapper around an XNAT experiment interface

assessors()[source]

Return array of SimpleXnatAssessors for this experiment

label_keys = ['label']
optional = False
parent_container_list = 'experiment_list'
reconstructions()[source]

Return array of SimpleXnatReconstructions for this experiment

rest_id_keys = ['ID']
rest_type = 'experiments'
scans()[source]

Return array of SimpleXnatScans for this experiment

class copyxnat.xnat_backend.simple_xnat.SimpleXnatFile(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItem

Wrapper around an XNAT file interface

create_on_server(local_file, create_params, overwrite, reporter)[source]

Create this item on the XNAT server if it does not already exist

download_file(save_dir, label)[source]

Get file from server and save to disk

file_attributes()[source]

Get file from server and save to disk

label_keys = ['Name']
optional = False
parent_container_list = 'file_list'
rest_id_keys = ['Name']
rest_type = 'files'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatInResource(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatResourceBase

Wrapper around an XNAT in-resource

optional = False
parent_container_list = 'in_resource_list'
rest_type = 'in/resources'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatItem(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatBase

Abstraction of wrappers around XNAT REST API interfaces

add_to_parent()[source]

Update parent’s metadata to show existance of new item

classmethod create(parent, label)[source]

Create a new child item of this class type from given parent

create_on_server(local_file, create_params, overwrite, reporter)[source]

Create this item on the XNAT server if it does not already exist

datatype()[source]

Return the XNAT datatype of this item. This will be cached if not empty

exists()[source]

Return True if the item already exists on the server

classmethod find_label(metadata)[source]

Find a valid label from the given metadata dictionary

get_attribute(name)[source]

Return the specified attribute from this item

classmethod get_existing(parent, label, metadata)[source]

Create a new child item of this class type from given parent

get_id()[source]

Return the XNAT ID of this item

get_label()[source]

Return the XNAT label of this item

get_metadata()[source]

Return XNAT metadata for this item

get_xml_string()[source]

Return XML representation of this XNAT item

label()[source]

Return the XNAT label of this item

abstract property label_keys

Name of the dictionary key in the item’s metadata dict which will be used to match items between servers. In most cases label is appropriate if it exists for this item’s metadata

abstract property optional

True if this type is not guaranteed to exist in its parent’s schema. For example, some experiment types might not include scans, so querying for scans might return a 404 error. If this property is set to True, then a 404 error will be returned as en empty array.

For example, experiments derive from type subjectAssessorData. This does not itself have scans, but many experiments derive from the subtype imageSessionData which does include scans. But another experiment type derived from subjectAssessorData might not have scans. This flag allows us to process experiments with and without scans without having to parse the schema.

abstract property parent_container_list

Name of the parent property which contains the LazyList object which can be queried to get the metadata for this item.

read_uri()[source]

Return URI of this XNAT item relative to the XNAT REST interface as used for read operations

abstract property rest_id_keys

List of the dictionary keys in the item’s metadata dict which can be used to as part of the REST URI to fetch a resource or metadata. The first key in the list which has a non-empty value in the dict will be used. In most cases ID is appropriate, but does not exist for all items. label can often be used if it exists but may be empty for some types of resource collections.

abstract property rest_type

Return the type specifier used in the REST URL

write_uri()[source]

Return URI of this XNAT item relative to the XNAT REST interface as used for write operations

class copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithInOutResources(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItem

Wrapper around an XNAT interface that can contain resources

in_resources()[source]

Return array of SimpleXnatInResources for this item

out_resources()[source]

Return array of SimpleXnatOutResources for this item

class copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithResources(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItem

Wrapper around a XNAT REST API interface that can contain resources

resources()[source]

Return item’s resources as an array of SimpleXnatResources

class copyxnat.xnat_backend.simple_xnat.SimpleXnatOutResource(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatResourceBase

Wrapper around an XNAT out-resource

optional = False
parent_container_list = 'out_resource_list'
rest_type = 'out/resources'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatProject(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithResources

Wrapper around an XNAT project interface

label_keys = ['ID']
optional = False
parent_container_list = 'cached_project_list'
rest_id_keys = ['ID']
rest_type = 'projects'
subjects()[source]

Return array of SimpleXnatSubjects for this project

class copyxnat.xnat_backend.simple_xnat.SimpleXnatReconstruction(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithInOutResources

Wrapper around an XNAT reconstruction

label_keys = ['ID']
optional = True
parent_container_list = 'reconstruction_list'
rest_id_keys = ['ID']
rest_type = 'reconstructions'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatResource(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatResourceBase

Wrapper around an XNAT resource interface

optional = False
parent_container_list = 'resource_list'
rest_type = 'resources'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatResourceBase(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItem

Wrapper around an XNAT resource interface

create_on_server(local_file, create_params, overwrite, reporter)[source]

Create this item on the XNAT server if it does not already exist

download_zip_file(save_dir)[source]

Get zip file from server and save to disk

files()[source]

Return array of SimpleXnatFiles for this resource container

label_keys = ['label', 'xnat_abstractresource_id']
resource_attributes()[source]

Get dict or resource attributes

rest_id_keys = ['label', 'xnat_abstractresource_id']
class copyxnat.xnat_backend.simple_xnat.SimpleXnatScan(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithResources

Wrapper around an XNAT interface for items which can contain resources

label_keys = ['ID']
optional = True
parent_container_list = 'scan_list'
rest_id_keys = ['ID']
rest_type = 'scans'
class copyxnat.xnat_backend.simple_xnat.SimpleXnatServer(params, read_only)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatBase

Interface to XNAT REST API

datatypes()[source]

Return datatypes on this server

experiment_list(project)[source]

Return list of experiments in this project

logout()[source]

Disconnect from server

num_experiments(project)[source]

Return number of experiments in this project

project(label)[source]

Return SimpleXnatProject project

project_list()[source]

Return array of project ids

project_name_metadata()[source]

Return list of dictionaries containing project name metadata

projects()[source]

Return item’s projects as an array of SimpleXnatProjects

read_uri()[source]

Return URI of this XNAT item relative to the XNAT REST interface as used for read operations

request(uri, method)[source]

Execute a REST call on the server

request_json_property(uri)[source]

Execute a REST call on the server and return JSON response

request_string(uri)[source]

Execute a REST call on the server and return string

write_uri()[source]

Return URI of this XNAT item relative to the XNAT REST interface as used for write operations

class copyxnat.xnat_backend.simple_xnat.SimpleXnatSubject(parent, label, metadata)[source]

Bases: copyxnat.xnat_backend.simple_xnat.SimpleXnatItemWithResources

Wrapper around an XNAT subject interface

experiments()[source]

Return array of SimpleXnatExperiments for this subject

label_keys = ['label']
optional = False
parent_container_list = 'subject_list'
rest_id_keys = ['ID']
rest_type = 'subjects'