예제 #1
0
        print pixel_array2.min()

    ds.PixelData = pixel_array2.tostring()
    # Save the image
    ds.save_as(filename)

if __name__ == '__main__':
    args = parse_args()

    # Scans on XNAT:
    try:
        xnat = XnatUtils.get_interface()
        li_scans = XnatUtils.list_project_scans(xnat, args.project)
        # Filter:
        if args.sessions:
            li_scans = XnatUtils.filter_list_dicts_regex(
                           li_scans, 'session_label', args.sessions.split(','))
        if args.subjects:
            li_scans = XnatUtils.filter_list_dicts_regex(
                           li_scans, 'subject_label', args.subjects.split(','))
        li_scans = sorted(li_scans, key=lambda k: k['session_label'])
        for scan_d in li_scans:
            if scan_d['ID'] == 'n004':
                print (' -> converting session: %s /scan: %s'
                       % (scan_d['session_label'], scan_d['ID']))
                if 'IMG' in scan_d['resources']:
                    if 'NIFTI' not in scan_d['resources'] or args.force:
                        tmp_dir = os.path.join(args.directory,
                                               scan_d['session_label'],
                                               scan_d['ID'])
                        if not os.path.isdir(tmp_dir):
                            os.makedirs(tmp_dir)
예제 #2
0
from dax import XnatUtils
import os


if __name__ == "__main__":
    # Variables:
    project = 'DIAN'
    types = {'': 'PhoenixZIPReport'}

    with XnatUtils.get_interface(host=os.environ['DPUK']) as xnat:
        scans = XnatUtils.list_project_scans(xnat, project)
        scans = XnatUtils.filter_list_dicts_regex(scans, 'type', types.keys())
        for scan in sorted(scans, key=lambda k: k['session_label']):
            print "%s - %s - %s - %s" % (scan["session_label"],
                                         scan["ID"],
                                         scan["type"],
                                         scan["series_description"])
            scan_obj = XnatUtils.get_full_object(xnat, scan)
            scan_obj.attrs.set('type', types[scan['type']])
            print('   new type: {}'.format(types[scan['type']]))
예제 #3
0
            HOST = os.environ['XNAT_HOST']
        if ARGS.username:
            MSG = ("Please provide the password for user <%s> on xnat(%s):"
                   % (ARGS.username, HOST))
            PWD = getpass.getpass(prompt=MSG)
        else:
            PWD = None

        if not os.path.isdir(ARGS.tmpdir):
            os.makedirs(ARGS.tmpdir)
        print 'INFO: connection to xnat <%s>:' % (HOST)
        XNAT = XnatUtils.get_interface(host=ARGS.host, user=ARGS.username,
                                       pwd=PWD)
        li_assessors = XnatUtils.list_project_assessors(XNAT, ARGS.project)
        li_assessors = XnatUtils.filter_list_dicts_regex(
                                li_assessors, 'proctype',
                                ['GIF_Parcellation_v2'])
        li_assessors = XnatUtils.filter_list_dicts_regex(
                                li_assessors, 'procstatus',
                                ['COMPLETE'])
        li_assessors = filter(lambda x: 'WHOLEBRAIN' not in x['resources'],
                              li_assessors)
        li_assessors = sorted(li_assessors, key=lambda k: k['session_label'])
        start = False
        for assessor in li_assessors:
            if ARGS.session:
                if assessor['session_label'] == ARGS.session:
                    start = True
            else:
                start = True
            if start:
예제 #4
0
def get_sessions_list():
    """Extract sessions list from XNAT to be deleted."""
    li_sessions = XnatUtils.list_sessions(XNAT, OPTIONS.project)
    li_sessions = XnatUtils.filter_list_dicts_regex(
                    li_sessions, 'session_label', OPTIONS.sessions.split(','))
    return li_sessions
예제 #5
0
        if ARGS.host:
            HOST = ARGS.host
        else:
            HOST = os.environ['XNAT_HOST']
        if ARGS.username:
            MSG = ("Please provide the password for user <%s> on xnat(%s):"
                   % (ARGS.username, HOST))
            PWD = getpass.getpass(prompt=MSG)
        else:
            PWD = None

        print 'INFO: connection to xnat <%s>:' % (HOST)
        XNAT = XnatUtils.get_interface(host=ARGS.host, user=ARGS.username,
                                       pwd=PWD)
        li_assessors = XnatUtils.list_project_assessors(XNAT, ARGS.project)
        li_assessors = XnatUtils.filter_list_dicts_regex(
                                li_assessors, 'proctype',
                                ARGS.proctype.split(','))
        li_assessors = XnatUtils.filter_list_dicts_regex(
                                li_assessors, 'procstatus',
                                ['COMPLETE'])
        li_assessors = sorted(li_assessors, key=lambda k: k['session_label'])
        for assessor in li_assessors:
            assessor_obj = XnatUtils.get_full_object(XNAT, assessor)
            if not assessor_obj.resource('PBS').exists():
                assessor_obj.resource('PBS').create()
                print 'Resource PBS added to %s.' % assessor['label']

    finally:
        XNAT.disconnect()
예제 #6
0
import sys
from dax import XnatUtils


SCAN = 'T2 Axial'
HOST = 'https://prostate-xnat.cs.ucl.ac.uk'
PROJECT = 'PICTURE'
RESOURCE = 'OsiriX'
OLD_FILE = 'mantonelli_Unnamed.rois_series'
NEW_FILE = 'Mrishta_Unnamed.rois_series'
TMP_DIR = '/Users/byvernault/data/temp_roi_upgrade/'

with XnatUtils.get_interface(host=HOST) as xnat:

    li_scans = XnatUtils.list_project_scans(xnat, PROJECT)
    li_scans = XnatUtils.filter_list_dicts_regex(li_scans, 'type', SCAN)
    li_scans = filter(lambda x: RESOURCE in x['resources'], li_scans)
    sys.stdout.write('Renaming file %s to %s for scan type %s\n'
                     % (OLD_FILE, NEW_FILE, SCAN))

    for scan in li_scans:
        sys.stdout.write(' - scan: %s / %s ...\n'
                         % (scan['session_label'], scan['ID']))
        scan_obj = XnatUtils.get_full_object(xnat, scan)
        res_obj = scan_obj.resource(RESOURCE)
        files = None
        if res_obj.exists() and OLD_FILE in res_obj.files().get()[:]:

            # fpath = XnatUtils.download_file_from_obj(TMP_DIR, res_obj,
            #                                          fname=OLD_FILE)
            # if fpath: