Permalink
Browse files

Updated central example to work with anonymous access, pickle of inte…

…rface object works with anonymous login now
  • Loading branch information...
1 parent 139f0b4 commit 0374f585ffe627c69c21c603957438b82013611a @schwarty schwarty committed Feb 13, 2012
Showing with 24 additions and 30 deletions.
  1. +1 −1 pyxnat/__init__.py
  2. +5 −1 pyxnat/core/interfaces.py
  3. +18 −28 pyxnat/examples/central_example.py
View
@@ -1,4 +1,4 @@
-__version__ = '0.9.1'
+__version__ = '0.9.2'
from .core import Interface
from .core import SearchManager
@@ -205,11 +205,15 @@ def __getstate__(self):
'_user': self._user,
'_pwd': self._pwd,
'_cachedir': os.path.split(self._cachedir)[0],
+ '_anonymous': self._anonymous,
}
def __setstate__(self, dict):
self.__dict__ = dict
- self.__init__(self._server, self._user, self._pwd, self._cachedir)
+ if self._anonymous:
+ self.__init__(self._server, anonymous=True)
+ else:
+ self.__init__(self._server, self._user, self._pwd, self._cachedir)
def _get_entry_point(self):
if self._entry is None:
@@ -4,52 +4,42 @@
import pyxnat
+URL = 'https://central.xnat.org' # central URL
+BET = 'fsl4.1-bet2' # BET executable path
-URL = 'https://central.xnat.org'
-BET = 'fsl4.1-bet2'
-
-central = pyxnat.Interface(URL)
-
-def bet(in_img, in_hdr):
- in_image = in_img.get()
- in_hdr.get()
+central = pyxnat.Interface(URL, anonymous=True) # connection object
+def bet(in_img, in_hdr): # Python wrapper on FSL BET, essentially a system call
+ in_image = in_img.get() # download .img
+ in_hdr.get() # download .hdr
path, name = os.path.split(in_image)
in_image = os.path.join(path, name.rsplit('.')[0])
out_image = os.path.join(path, name.rsplit('.')[0] + '_brain')
-
print '==> %s' % in_image[-120:]
-
Popen('%s %s %s' % (BET, in_image, out_image),
shell=True).communicate()
-
return out_image
-def notify(message):
+def notify(message): # message to notify the end of a BET process
print '<== %s' % message[-120:]
-pool = mp.Pool(processes=mp.cpu_count() * 2)
-
-_query = ('/projects/CENTRAL_OASIS_CS/subjects/*'
- '/experiments/*_MR1/scans/mpr-1*/resources/*/files/*')
-
-_filter = [('xnat:mrSessionData/AGE', '>', '80'), 'AND']
-
+pool = mp.Pool(processes=mp.cpu_count() * 2) # pool of concurrent workers
images = {}
+query = ('/projects/CENTRAL_OASIS_CS/subjects/*'
+ '/experiments/*_MR1/scans/mpr-1*/resources/*/files/*')
+filter_ = [('xnat:mrSessionData/AGE', '>', '80'), 'AND']
-for f in central.select(_query).where(_filter):
+for f in central.select(query).where(filter_):
label = f.label()
-
+ # images are stored in pairs of files (.img, .hdr) in this project
if label.endswith('.img'):
images.setdefault(label.split('.')[0], []).append(f)
-
if f.label().endswith('.hdr'):
images.setdefault(label.split('.')[0], []).append(f)
-
- for name in images.keys():
- if len(images[name]) == 2:
- img, hdr = images.pop(name)
- pool.apply_async(bet, (img, hdr), callback=notify)
-
+ # download and process both occur in parallel within the workers
+ for name in images.keys():
+ if len(images[name]) == 2: # if .img and .hdr XNAT references are ready
+ img, hdr = images.pop(name) # get references
+ pool.apply_async(bet, (img, hdr), callback=notify) # start worker
pool.close()
pool.join()

0 comments on commit 0374f58

Please sign in to comment.