Skip to content

Instantly share code, notes, and snippets.

@bud42
Last active December 14, 2015 13:29
Show Gist options
  • Save bud42/5094054 to your computer and use it in GitHub Desktop.
Save bud42/5094054 to your computer and use it in GitHub Desktop.
XNAT Processing Assessors Tutorial
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "XNAT_Processing_Assessors"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": "XNAT Processing Assessors Tutorial"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "The code snippets below can be run in sequence to create an assessor, set attributes, load preview thumbnails, and load a PDF"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "**Initiate a pyxnat session**"
},
{
"cell_type": "code",
"collapsed": false,
"input": "import os\nfrom pyxnat import Interface\n\nXNAT_USER = os.environ['XNAT_USER']\nXNAT_PWD = os.environ['XNAT_PASS']\nXNAT_HOST = os.environ['XNAT_HOST']\n\nxnat = Interface(server=XNAT_HOST,user=XNAT_USER,password=XNAT_PWD)",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": " **Create an assessor** \nDon't forget **assessors=proc:genProcData** or the DB will go haywire. The data type of our generic processing assessor is \"proc:genProcData\". Unlike the other objects (e.g. scans), we need to specify the type when using create(). XNAT doesn't provide any instantiable assessor types by default. Currently, the only types we've added to the database are the generic assessor and a Freesurfer-specific assessor (fs:fsData). We can add more as needed. "
},
{
"cell_type": "code",
"collapsed": false,
"input": "e = xnat.select('/project/prj001/subject/prj001_sub001/experiment/prj001_subj001_exp001')\na = e.assessor('exp001__dtiQA_601')\na.create(assessors='proc:genProcData')",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": "**Set some attributes** \nSince **proc:genProcData** is a subclass of **xnat:experimentData** it inherits these attributes: \nxnat:experimentdata/visit_id \nxnat:experimentdata/date \nxnat:experimentdata/time \nxnat:experimentdata/note \nxnat:experimentdata/investigator/firstname \nxnat:experimentdata/investigator/lastname \nxnat:experimentdata/validation/method \nxnat:experimentdata/validation/status \nxnat:experimentdata/validation/date \nxnat:experimentdata/validation/notes \n\nAnd the attributes specific to the **genProcData** type are: \nproc:genProcData/proctype \nproc:genProcData/procstatus \n"
},
{
"cell_type": "code",
"collapsed": false,
"input": "a.attrs.set('proc:genProcData/date', '2013-02-10')\na.attrs.set('proc:genProcData/proctype','dtiQA')\na.attrs.set('proc:genProcData/procstatus','Complete')",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": "**Upload Snaphots** \nUnlike a scan which has only **resource**, an assessor has **in_resource** and **out_resource** \nWhen uploading a file, we specfy the destination file name. We can use the same name as the source or use a different name and effectively rename the file during upload. \nHere we are naming the destination files t.png and o.png\n\nIn order for the preview snapshots to be displayed properly, we must specify the content type of the thumbnail image as \"THUMBNAIL\" and the full size image as \"ORIGINAL\". There are no requirements for the file name or file type."
},
{
"cell_type": "code",
"collapsed": false,
"input": "r = a.out_resource('SNAPSHOTS')\nr.file('t.png').put('/Users/boydb1/Desktop/test2.png','PNG','THUMBNAIL')\nr.file('o.png').put('/Users/boydb1/Desktop/test1.png','PNG','ORIGINAL')",
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": "**Upload PDF**"
},
{
"cell_type": "code",
"collapsed": false,
"input": "r = a.out_resource('PDF')\nr.file('exp001__dtiQA_601.pdf').put('/Users/boydb1/Desktop/test.pdf')",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment