Skip to content

Instantly share code, notes, and snippets.

@karchie
Created July 29, 2014 05:47
Show Gist options
  • Save karchie/8ec1bec97a7c3d7b7c2a to your computer and use it in GitHub Desktop.
Save karchie/8ec1bec97a7c3d7b7c2a to your computer and use it in GitHub Desktop.
Python commands to use AWS EC2 to run Freesurfer analyses on XNAT data
# Get a connection to the XNAT server
import pyxnat
xnat = pyxnat.Interface('https://my-xnat.org','username','password')
# Request a list of all MR scans, keeping only those with RAGE in the scan type (e.g., MPRAGE, MP-RAGE)
import scans
mprage_sessions = scans.get_sessions(x, 'MYPROJECT', lambda t : 'RAGE' in t)
# Break the scans list into groups of 32
chunks32 = [g for g in scans.partition(32, mprage_sessions.iteritems())]
# Set up AWS EC2 client
import boto.ec2
aws = boto.ec2.connect_to_region('us-east-1',aws_access_key_id='access-key',aws_secret_access_key='secret-key')
# Request spot instances: 30 in us-east-1a, 30 in us-east-1d
# AMI includes Docker server with the Freesurfer application image; instance user data holds list of scans to analyze
reqsa = [scans.spot_docker(xnat, 'password', chunk, aws, price='6.0', image_id='ami-0badbeef', key_name='sshkey' instance_type='c3.8xlarge', security_groups=['docker-container-server'], az='a' for chunk in chunks32[0:30]]
reqsd = [scans.spot_docker(xnat, 'password', chunk, aws, price='6.0', image_id='ami-0badbeef', key_name='sshkey' instance_type='c3.8xlarge', security_groups=['docker-container-server'], az='d' for chunk in chunks32[30:60]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment