示例#1
0
文件: localizer.py 项目: imclab/gild
def import_maps(data_dir, dtype='c'):
    """Import c/t maps"""
    info = json.load(open('%s/subject.json' % data_dir))
    base_path = os.path.join(data_dir, '%s_maps' % dtype)
    for img_path in glob.iglob(os.path.join(base_path, '*.nii.gz')):
        scan_data, mri_data = {}, {}
        scan_data['identifier'] = u'%s_%s_map' % (info['exam'], dtype)
        scan_data['label'] = unicode(os.path.split(img_path)[1].split(
            '.nii.gz')[0].replace('_', ' '))
        scan_data['format'] = u'nii.gz'
        scan_data['type'] = u'%s map' % dtype
        scan_data['filepath'] = img_path
        scan_data['timepoint'] = info['date']
        scan_data['completed'] = True
        scan_data['valid'] = True
        # Mri data
        mri_data['sequence'] = None
        mri_data.update(get_image_info(scan_data['filepath'], get_tr=False))
        name = os.path.split(img_path)[1].split('.nii.gz')[0]
        ext_resource = {}
        ext_resource['name'] = u'contrast definition'
        ext_resource['filepath'] = unicode(os.path.join(data_dir,
                                                        'contrasts',
                                                        '%s.json' % name))
        yield scan_data, mri_data, ext_resource
示例#2
0
文件: localizer.py 项目: imclab/gild
def import_mask(data_dir):
    """Import a mask"""
    scan_data, mri_data = {}, {}
    info = json.load(open('%s/subject.json' % data_dir))
    scan_data['identifier'] = u'%s_mask' % info['exam']
    scan_data['label'] = u'mask'
    scan_data['format'] = u'nii.gz'
    scan_data['type'] = u'boolean mask'
    scan_data['filepath'] = unicode(os.path.join(data_dir, 'mask.nii.gz'))
    scan_data['timepoint'] = info['date']
    scan_data['completed'] = True
    scan_data['valid'] = True
    mri_data['sequence'] = None
    mri_data.update(get_image_info(scan_data['filepath']))
    return scan_data, mri_data
示例#3
0
文件: localizer.py 项目: imclab/gild
def import_neuroimaging(data_dir, dtype='anat', norm_prep=False):
    """Import a neuorimaging scan"""
    scan_data, mri_data = {}, {}
    info = json.load(open('%s/subject.json' % data_dir))
    # Label and id
    if dtype == 'anat':
        mri_data['sequence'] = u'T1'
        scan_data['identifier'] = u'%s_anat' % info['exam']
        scan_data['label'] = u'anatomy' if normalized else u'raw anatomy'
        scan_data['type'] = u'normalized T1' if norm_prep else u'raw T1'
        if norm_prep:
            scan_data['filepath'] = os.path.join(data_dir, 'anat', 'anat_defaced.nii.gz')
        else:
            scan_data['filepath'] = os.path.join(data_dir, 'anat', 'raw_anat_defaced.nii.gz')
    else:
        mri_data['sequence'] = u'EPI'
        scan_data['identifier'] = u'%s_fmri' % info['exam'] if norm_prep  \
                                  else u'%s_raw_fmri' % info['exam']
        scan_data['label'] = u'bold' if norm_prep else u'raw bold'
        scan_data['type'] = u'preprocessed fMRI' if norm_prep else u'raw fMRI'
        if norm_prep:
            scan_data['filepath'] = os.path.join(data_dir, 'fmri', 'bold.nii.gz')
        else:
            scan_data['filepath'] = os.path.join(data_dir, 'fmri', 'raw_bold.nii.gz')
    # Data properties
    scan_data['format'] = u'nii.gz'
    scan_data['timepoint'] = info['date']
    scan_data['completed'] = True
    scan_data['valid'] = True
    # Description
    if dtype == 'anat':
        scan_data['description'] = info['anatomy']
    else:
        scan_data['description'] = (
            u'epi_problem=%(epi_problem)s '
            'sound_problem=%(sound_problem)s '
            'video_problem=%(video_problem)s '
            'motor_error=%(motor_error)s' % info)
        for seq_type in SEQ_TYPES:
            if info[seq_type]:
                scan_data['description'] += u' %s' % seq_type
    # Update mri data
    mri_data.update(get_image_info(scan_data['filepath']))
    return scan_data, mri_data
示例#4
0
文件: mindboogle.py 项目: imclab/gild
            store.relate(subject.eid, 'related_studies', study.eid)
            store.relate(subject.eid, 'related_studies', global_study.eid)
            assessment = store.create_entity('Assessment',identifier=u'label',
                                             related_study=study.eid,
                                             protocol=u'mindboggle-label')
            store.relate(subject.eid, 'concerned_by', assessment.eid)
            for image in glob.iglob(osp.join(full_study_path, subject_path, '*.nii.gz')):
                image_id = image.split('/')[-1].split('.')[0]
                anat = {'identifier': u'%s_%s' % (subject_id, image_id),
                        'label': u'labels' if 'labels' in image_id else u'anatomy',
                        'format': u'nii.gz',
                        'type': u'normalized T1',
                        'related_study': study.eid,
                        'filepath': unicode(osp.relpath(image, start=full_study_path)),
                        'valid': True, 'completed': True, 'description': 'Image from Mindboggle'}
                mri_data = store.create_entity('MRIData', sequence=u'T1')
                # MRI data
                mri_data = {'sequence': u'T1'}
                mri_data.update(get_image_info(image))
                mri_data = store.create_entity('MRIData', **mri_data)
                anat['has_data'] = mri_data.eid
                anat['related_study'] = study.eid
                anat = store.create_entity('Scan', **anat)
                store.relate(anat.eid, 'concerns', subject.eid, subjtype='Scan')
                store.relate(assessment.eid, 'generates', anat.eid, subjtype='Assessment')
            count_subject += 1
        # Flush
        store.flush()
        store.commit()
        print '-------> %s subjects imported for %s' % (count_subject, study_path)