meierlab.cirxnat.Cirxnat: CIRXNAT Server#

XNAT base for python3 using requests.

class meierlab.cirxnat.Cirxnat(address, project, user, password)[source]#

An instance of XNAT.

get_user()[source]#

Get XNAT user.

Returns:
str

CIRXNAT user associated with current server.

get_project()[source]#

Get XNAT project.

Returns:
str

CIRXNAT project associated with current server.

get_address()[source]#

Get XNAT server address.

Returns:
str

CIRXNAT address associated with current server.

get_subjects(mformat='csv')[source]#

Get subjects associated with project.

Parameters:
mformatstr

Output format. Default: ‘csv’.

Returns:
str

Text string request result.

get_subjects_json()[source]#

Get the subject list JSON and split it up into individual subjects.

Returns:
list

List of JSON dictionaries with subjects.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> subjects = server.get_subjects_json()
>>> print(subjects[0])
{'insert_date': '2016-07-20 12:51:48.678',
'project': 'UWARC',
'ID': 'XNAT_S00071',
'label': '4_ASN_test_3D_TOF',
'insert_user': 'admin',
'URI': '/data/subjects/XNAT_S00071'}
get_experiments(subject_id, mformat='csv')[source]#

Get experiments associated with a subject.

Parameters:
subject_idstr

Subject label from XNAT.

mformatstr

Output format. Default: ‘csv’.

Returns:
str

Text string request result.

get_experiments_json(subject_id)[source]#

Get the experiments JSON and split them up.

Parameters:
subject_idstr

Subject label from XNAT.

Returns:
list

List of JSON dictionaries with subject’s experiments.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> experiments = server.get_experiments_json('4_ASN_test_3D_TOF')
>>> print(experiments[0])
{'date': '2014-10-28',
'xsiType': 'xnat:mrSessionData',
'xnat:subjectassessordata/id': 'XNAT_E00130',
'insert_date': '2016-07-20 13:07:19.808',
'project': 'UWARC',
'ID': 'XNAT_E00130',
'label': '4_ASN_test_3D_TOF_28_10_2014_1',
'URI': '/data/experiments/XNAT_E00130'}
get_experiment_note_json(subject_id, experiment_id)[source]#

Get overall QA/scan note for experiment.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

Returns:
str

JSON string with note from XNAT.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> note = server.get_experiment_note_json(
    '4_QA_HUMAN','4_QA_HUMAN_11_11_2015_1')
>>> print(note['note'])
'Note:  There is nose wrap on all Sagittal Sequences.'
get_scans(subject_id, experiment_id, mformat='csv')[source]#

Get scans associated with a subject’s experiment.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

mformatstr

Output format. Default: ‘csv’.

Returns:
str

Text string request result.

get_scans_json(subject_id, experiment_id)[source]#

Get a subject’s experiment’s scans in JSON format.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

Returns:
list

List of scans from experiment.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> scans = server.get_scans_json(
'4_QA_HUMAN','4_QA_HUMAN_11_11_2015_1')
>>> print(scans[0])
{'xsiType': 'xnat:mrScanData',
'xnat_imagescandata_id': '1423',
'note': '',
'series_description': '3Plane Loc SSFSE',
'ID': '1',
'type': '3Plane Loc SSFSE',
'URI': '/data/experiments/XNAT_E00131/scans/1',
'quality': 'usable'}
get_scans_dictionary(subject_id, experiment_id)[source]#

Get a dictionary of scan IDs and their descriptions from an experiment.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

Returns:
dict

Dictionary of scan ID: series_description.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> scans = server.get_scans_dictionary(
    '4_QA_HUMAN','4_QA_HUMAN_11_11_2015_1')
>>> print(scans)
{'1': '3Plane Loc SSFSE',
'2': '3Plane Loc SSFSE',
...,
}
print_all_experiments()[source]#

Get a list of experiment dictionaries with experiment data.

Returns:
list

List of experiment dictionaries with labels, IDs, upload date, XNAT URI.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> all_experiments = server.print_all_experiments()
>>> print(len(all_experiments))
595
get_dicom_header(experiment_id, scan_num)[source]#

Get a JSON formatted subject experiment scan DICOM header.

Parameters:
experiment_idstr

Experiment label from XNAT.

scan_numint

Scan number from XNAT.

Returns:
list

JSON dictionary containing scan header information.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> hdr = server.get_dicom_header('4_ASN_test_3D_TOF_28_10_2014_1','1')
>>> print(hdr[0])
{'tag1': '(0002,0001)',
'vr': 'OB',
'value': '00\\01',
'tag2': '',
'desc': 'File Meta Information Version'}
get_dicom_tag(subject_id, experiment_id, scan_num, tag_id)[source]#

Get DICOM tag value from id an 8 digit/text string.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

scan_numint

Scan number from XNAT.

tag_idstr

DICOM tag.

Returns:
str

JSON string with tag information.

get_dicom_tags(experiment, scans_list, extra_tags={})[source]#

Get common dicom tag info.

Defaults include:

“(0008,0008)”: “image_type”, “(0008,0070)”: “manufacturer”, “(0008,1090)”: “scanner”, “(0018,0050)”: “slice_thickness”, “(0018,0080)”: “repetition_time”, “(0018,0081)”: “echo_time”, “(0018,0082)”: “inversion_time”, “(0018,0083)”: “num_avgs”, “(0018,0087)”: “field_strength”, “(0018,0091)”: “echo_train_len”, “(0018,0093)”: “percent_sampling”, “(0018,0094)”: “percent_phase_fov”, “(0018,0095)”: “pixel_bandwidth”, “(0018,1020)”: “software_version”, “(0018,1250)”: “coil”, “(0018,1310)”: “acq_matrix”, “(0018,1314)”: “flip_angle”, “(0018,1316)”: “sar”, “(0028,0010)”: “rows”, “(0028,0011)”: “cols”, “(0028,0030)”: “pixel_spacing”, “(0029,1020)”: “channels”,

Parameters:
experimentstr

Experiment label from XNAT.

scans_listlist

List of scans to get data from.

extra_tagsdict, optional

Dictionary of tag (str) : label (str) to add to defaults.

Returns:
dict

Dictionary of scans DICOM tags: values.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> tags = server.get_dicom_tags('4_ASN_test_3D_TOF_28_10_2014_1',[1])
>>> print(tags[1]['echo_time'])
'1.448'
get_scans_usability(subject_id, experiment_id, scan_list=[])[source]#

Get a dictionary of subject scans and their usability.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

scan_listlist, optional

List of scan descriptions to use.

Returns:
dict

Scan usability dictionary with ID, series_description, and QA note.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> usability = server.get_scans_usability(
    '4_ASN_test_3D_TOF','4_ASN_test_3D_TOF_28_10_2014_1',['2'])
>>> print(usability)
{'1': ['desc':'3Plane Loc  32ch', 'quality':'usable','note': '']}
zip_scans_to_file(subject_id, experiment_id, out_file, scan_list='ALL')[source]#

Return a zip file with all of the resource files.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAT.

out_filestr

Path to output file

scan_listlist, optional

List of scans to download. Default: ‘ALL’

zip_scan_descriptions_to_file(subject_id, experiment_id, descriptions, out_file)[source]#

Zip scans by series description.

Parameters:
subject_idstr

Subject label from XNAT.

experiment_idstr

Experiment label from XNAt.

descriptionslist

List of scan_description strings.

out_filestr

Path to output file.

Returns:
int

0 if files downloaded successfully, 1 if no matching scans were found.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> err = server.zip_scans_descriptions_to_file(
    '4_ASN_test_3D_TOF','4_ASN_test_3D_TOF_28_10_2014_1',['BRAVO'])
get_project_dcm_params(scan_list=[], extra_tags={})[source]#

Get DICOM parameter information for all experiments in a project.

Parameters:
scan_listlist, optional

List of scan descriptions to get DICOM information for. Default: all scans.

Returns:
DataFrame

DataFrame containing DICOM parameter information.

Examples

>>> import os
>>> from meierlab import cirxnat
>>> cir1_pass = os.getenv('CIR1')
>>> cir1_addr = os.getenv('CIR1ADDR')
>>> server = cirxnat.Cirxnat(address=cir1_addr,
project='UWARC',user='lespana',password=cir1_pass)
>>> dcm_params = server.get_project_dcm_params(scan_list=['BRAVO'])
>>> dcm_params.head()
Ax FSPGR BRAVO_channels ... SB DTI MCW Axial R/L_note
4_ASN_test_3D_TOF_28_10_2014_1 ... NaN
4_QA_HUMAN_11_11_2015_1 NaN ... NaN
WISC_IH_1746_20_11_2015_3 NaN ... NaN
4_WISC_IH_1746_03_05_2016_4 NaN ... NaN
4_WISC_IH_1556_24_11_2015_1 NaN ... NaN
[5 rows x 79 columns]