Skip to content

Instantly share code, notes, and snippets.

@mattsouth
mattsouth / download.py
Created July 9, 2019 15:52
A python 2.7 / pyxnat script for downloading the resources from an xnat project
import pyxnat
import os
import time
# A python 2.7 / pyxnat script for downloading the resources from an xnat project
# gather source xnat details
print '** DOWNLOAD XNAT PROJECT RESOURCES **'
xnat_url=raw_input("Enter the xnat url: ")
project_name=raw_input("Enter the xnat project id: ")
@mattsouth
mattsouth / spiderdel.sh
Created October 31, 2018 14:28
bash script to remove unwanted files in xnat using the XnatDataClient
#!/bin/bash
# bash script to remove unwanted files in xnat using the XnatDataClient
# iterates through all sessions looking for particular scan types with particular file types and file name patterns
# CLI parameters:
# 1. url - xnat url
# 2. username - xnat username
# 3. project - xnat project
# 4. scan type - e.g. "STRUCTURAL", "FLAIR"
@mattsouth
mattsouth / createexperiment.sh
Created November 9, 2017 16:22
A bash script for creating a subject / experiment in xnat
#!/bin/bash
# creates subject / experiment ids if they dont already exist
# 1. url - xnat url
# 2. session - tomcat session_id (instead of username / password)
# 3. project - project id
# 4. subject - subject_id
# 5. experiment - experiment id
# 6. date - experiment_date
# 7. verbosity - 0 = surpress, 1 = log (default), 2 = debug
@mattsouth
mattsouth / ticker.coffee
Last active August 17, 2017 15:40
In your REPL of choice you can create a ticker and then start and stop it at will.
class exports.Ticker
constructor: (timeout) ->
@timeout = timeout || 1000
_nextTick: =>
@tick = setTimeout(@_nextTick, @timeout)
console.log 'tick'
start: ->
@_nextTick()
@mattsouth
mattsouth / anonymizeall.py
Created August 11, 2017 08:48
A python script that re-runs an updated anonymisation script on all MR sessions in an XNAT project
# Renames every MR experiment, thus kicking off the anonymisation script.
# see https://groups.google.com/d/msg/xnat_discussion/vvLyLvyo2uQ/yMPHgkrOEwAJ
# used in XNAT 1.6.5
# also see https://groups.google.com/d/msg/xnat_discussion/fBI33j36D3Y/VEwh-HWez70J for discussion about changing experiment label
import xnat # see https://xnat.readthedocs.io/en/latest/
url = raw_input("Enter XNAT url: ")
user = raw_input("Enter username: ")
with xnat.connect(url, user=user) as session:
name = raw_input("Enter project: ")
@mattsouth
mattsouth / summary.py
Created July 13, 2017 12:19
Output a summary of an xnat project
# outputs a summary of the data in an xnat project, e.g.:
# 55 subjects, 65 scans, 400 sequences (SNAPSHOTS: 400, DICOM: 400, NIFTI: 200)
# Note that in our lab we talk about "scans" and "sequences" which correspond
# to xnat's "MR Sessions" and "Scans" respectively.
# Parameters:
# 1. url - xnat url
# 2. username - xnat username
@mattsouth
mattsouth / missingsnapshot.py
Last active May 16, 2017 15:10
Prints the subject_id and experiment_id of XNAT experiments where a scan is missing a snapshot
# prints the subject_id and experiment_id of XNAT experiments where a scan is missing a snapshot
# used against XNAT 1.6.5 by python 2.7
import xnat # see https://xnat.readthedocs.io/en/latest/
url = raw_input("Enter XNAT url: ")
user = raw_input("Enter username: ")
session = xnat.connect(url, user=user)
name = raw_input("Enter project: ")
project = session.projects[name]
@mattsouth
mattsouth / nosnapshots.py
Last active May 16, 2017 15:09
Prints the subject_id and experiment_id of XNAT experiments whose scans are all missing snapshots
# prints the subject_id and experiment_id of XNAT experiments whose scans are all missing snapshots
# used against XNAT 1.6.5 by python 2.7
import xnat # see https://xnat.readthedocs.io/en/latest/
url = raw_input("Enter XNAT url: ")
user = raw_input("Enter username: ")
session = xnat.connect(url, user=user)
name = raw_input("Enter project: ")
project = session.projects[name]
#!/bin/bash
# upload pre-processed niftii images to xnat 1.6.5
# 1. xnat - xnat url, e.g. https://central.xnat.org
# 2. username - xnat username
# 3. password - xnat password
# 4. project - project id
# 5. subject - subject id
# 6. session - session id
# 7. scan - scan id
# 8. nifti - filepath of nifti image
import pyxnat
import os
import shutil
import requests
import zipfile
import requests
import time
# A python 2.7 / pyxnat script for copying an xnat project which consists of
# subjects with multiple MRSession experiments