Example #1
0
def initialize(cfg, args):
    """ purpose: load information and add to config """

    if cfg.sessionId in (None, '') or cfg.useSessionTimestamp is True:
        cfg.useSessionTimestamp = True
        cfg.sessionId = utils.dateStr30(time.localtime())
    else:
        cfg.useSessionTimestamp = False
    # MERGE WITH PARAMS
    if args.runs != '' and args.scans != '':
        # use the run and scan numbers passed in as parameters
        cfg.runNum = [int(x) for x in args.runs.split(',')]
        cfg.scanNum = [int(x) for x in args.scans.split(',')]
    else: # when you're not specifying on the command line it's already in a list
        cfg.runNum = [int(x) for x in cfg.runNum]
        cfg.scanNum = [int(x) for x in cfg.scanNum]
    
    # GET DICOM DIRECTORY
    if cfg.buildImgPath:
        imgDirDate = datetime.now()
        dateStr = cfg.date.lower()
        if dateStr != 'now' and dateStr != 'today':
            try:
                imgDirDate = parser.parse(cfg.date)
            except ValueError as err:
                raise RequestError('Unable to parse date string {} {}'.format(cfg.date, err))
        datestr = imgDirDate.strftime("%Y%m%d")
        imgDirName = "{}.{}.{}".format(datestr, cfg.subjectName, cfg.subjectName)
        cfg.dicomDir = os.path.join(cfg.local.dicomDir,imgDirName)
    else:
        cfg.dicomDir = cfg.local.dicomDir # then the whole path was supplied
    ########
    cfg.bids_id = 'sub-{0:03d}'.format(cfg.subjectNum)
    cfg.ses_id = 'ses-{0:02d}'.format(cfg.subjectDay)
    
    # specify local directories
    cfg.local.codeDir = os.path.join(cfg.local.rtcloudDir, 'projects', cfg.projectName)
    cfg.local.dataDir = os.path.join(cfg.local.codeDir, 'data') 
    cfg.local.subject_full_day_path = os.path.join(cfg.local.dataDir, cfg.bids_id, cfg.ses_id)
    cfg.local.subject_reg_dir = os.path.join(cfg.local.subject_full_day_path, 'registration_outputs')
    cfg.local.wf_dir = os.path.join(cfg.local.dataDir, cfg.bids_id, 'ses-01', 'registration')
    cfg.local.maskDir = os.path.join(cfg.local.codeDir, 'ROI')
    cfg.subject_reg_dir = cfg.local.subject_reg_dir
    cfg.wf_dir = cfg.local.wf_dir
    cfg.n_masks = len(cfg.MASK)

    if args.filesremote: # here we will need to specify separate paths for processing
        cfg.server.codeDir = os.path.join(cfg.server.rtcloudDir, 'projects', cfg.projectName)
        cfg.server.dataDir = os.path.join(cfg.server.codeDir, cfg.server.serverDataDir)
        cfg.server.subject_full_day_path = os.path.join(cfg.server.dataDir, cfg.bids_id, cfg.ses_id)
        cfg.server.subject_reg_dir = os.path.join(cfg.server.subject_full_day_path, 'registration_outputs')
        cfg.server.wf_dir = os.path.join(cfg.server.dataDir, cfg.bids_id, 'ses-01', 'registration')
        cfg.server.maskDir = os.path.join(cfg.server.codeDir, 'ROI')
        cfg.subject_reg_dir = cfg.server.subject_reg_dir
        cfg.wf_dir = cfg.server.wf_dir
    cfg.ref_BOLD = os.path.join(cfg.wf_dir,'ref_image.nii.gz')
    cfg.MNI_ref_filename = os.path.join(cfg.wf_dir, cfg.MNI_ref_BOLD) 
    cfg.T1_to_BOLD = os.path.join(cfg.wf_dir, 'affine.txt')
    cfg.MNI_to_T1 = os.path.join(cfg.wf_dir, 'ants_t1_to_mniInverseComposite.h5')
    cfg.MASK_transformed = [''] * cfg.n_masks
    cfg.local_MASK_transformed = [''] * cfg.n_masks
    for m in np.arange(cfg.n_masks):
        mask_name = cfg.MASK[m].split('.')[0] + '_space-native.nii.gz'
        cfg.MASK_transformed[m] = os.path.join(cfg.subject_reg_dir, mask_name)
        cfg.local_MASK_transformed[m] = os.path.join(cfg.local.subject_reg_dir, mask_name)
    # get conversion to flip dicom to nifti files
    cfg.axesTransform = getTransform(('L', 'A', 'S'),('P', 'L', 'S'))
    return cfg
Example #2
0
def initializeGreenEyes(configFile,args):
    # load subject information
    # create directories for new niftis
    # randomize which category they'll be attending to and save that
    # purpose: load information and add to configuration things that you won't want to do each time a new file comes in
    # TO RUN AT THE START OF EACH RUN

    cfg = loadConfigFile(configFile)
    if cfg.sessionId in (None, '') or cfg.useSessionTimestamp is True:
        cfg.useSessionTimestamp = True
        cfg.sessionId = dateStr30(time.localtime())
    else:
        cfg.useSessionTimestamp = False
    # MERGE WITH PARAMS
    if args.runs != '' and args.scans != '':
        # use the run and scan numbers passed in as parameters
        cfg.runNum = [int(x) for x in args.runs.split(',')]
        cfg.scanNum = [int(x) for x in args.scans.split(',')]
    else: # when you're not specifying on the command line it's already in a list
        cfg.runNum = [int(x) for x in cfg.runNum]
        cfg.scanNum = [int(x) for x in cfg.scanNum]
    # GET DICOM DIRECTORY
    if cfg.mode != 'debug':
        if cfg.buildImgPath:
            imgDirDate = datetime.datetime.now()
            dateStr = cfg.date.lower()
            if dateStr != 'now' and dateStr != 'today':
                try:
                    imgDirDate = parser.parse(cfg.date)
                except ValueError as err:
                    raise RequestError('Unable to parse date string {} {}'.format(cfg.date, err))
            datestr = imgDirDate.strftime("%Y%m%d")
            imgDirName = "{}.{}.{}".format(datestr, cfg.subjectName, cfg.subjectName)
            cfg.dicomDir = os.path.join(cfg.intelrt.imgDir, imgDirName)
        else:
            cfg.dicomDir = cfg.intelrt.imgDir # then the whole path was supplied
        cfg.dicomNamePattern = cfg.intelrt.dicomNamePattern
    else:
        cfg.dicomDir = glob.glob(cfg.cluster.imgDir.format(cfg.subjectName))[0]
        cfg.dicomNamePattern = cfg.cluster.dicomNamePattern
    #cfg.commPipe = args.commPipe
    #cfg.webfilesremote = args.filesremote # FLAG FOR REMOTE OR LOCAL
	########
    cfg.bids_id = 'sub-{0:03d}'.format(cfg.subjectNum)
    cfg.ses_id = 'ses-{0:02d}'.format(cfg.subjectDay)
    if cfg.mode == 'local':
        # then all processing is happening on linux too
        cfg.dataDir = cfg.intelrt.codeDir + 'data'
        cfg.classifierDir = cfg.intelrt.classifierDir
        cfg.mask_filename = os.path.join(cfg.intelrt.maskDir, cfg.MASK)
        cfg.MNI_ref_filename = os.path.join(cfg.intelrt.maskDir, cfg.MNI_ref_BOLD)
    elif cfg.mode == 'cloud':
        cfg.dataDir = cfg.cloud.codeDir + 'data'
        cfg.classifierDir = cfg.cloud.classifierDir
        cfg.mask_filename = os.path.join(cfg.cloud.maskDir, cfg.MASK)
        cfg.MNI_ref_filename = os.path.join(cfg.cloud.maskDir, cfg.MNI_ref_BOLD)
        cfg.intelrt.subject_full_day_path = '{0}/data/{1}/{2}'.format(cfg.intelrt.codeDir,cfg.bids_id,cfg.ses_id)
    elif cfg.mode == 'debug':
        cfg.dataDir = cfg.cluster.codeDir + 'data'
        cfg.classifierDir = cfg.cluster.classifierDir
        cfg.mask_filename = cfg.cluster.maskDir + cfg.MASK
        cfg.MNI_ref_filename = cfg.cluster.maskDir + cfg.MNI_ref_BOLD
    cfg.station_stats = cfg.classifierDir + 'station_stats.npz'
    cfg.subject_full_day_path = '{0}/{1}/{2}'.format(cfg.dataDir,cfg.bids_id,cfg.ses_id)
    cfg.temp_nifti_dir = '{0}/converted_niftis/'.format(cfg.subject_full_day_path)
    cfg.subject_reg_dir = '{0}/registration_outputs/'.format(cfg.subject_full_day_path)
    cfg.nStations, cfg.stationsDict, cfg.last_tr_in_station, cfg.all_station_TRs = getStationInformation(cfg)

	# REGISTRATION THINGS
    cfg.wf_dir = '{0}/{1}/ses-{2:02d}/registration/'.format(cfg.dataDir,cfg.bids_id,1)
    cfg.BOLD_to_T1= cfg.wf_dir + 'affine.txt'
    cfg.T1_to_MNI= cfg.wf_dir + 'ants_t1_to_mniComposite.h5'
    cfg.ref_BOLD=cfg.wf_dir + 'ref_image.nii.gz'

    # GET CONVERSION FOR HOW TO FLIP MATRICES
    cfg.axesTransform = getTransform()
    ###### BUILD SUBJECT FOLDERS #######
    return cfg
Example #3
0
def initializeFaceMatching(configFile, args):
    # load subject information
    # create directories for new niftis
    # purpose: load information and add to configuration things that you won't want to do each time a new file comes in
    # TO RUN AT THE START OF EACH RUN

    cfg = loadConfigFile(configFile)
    if cfg.sessionId in (None, '') or cfg.useSessionTimestamp is True:
        cfg.useSessionTimestamp = True
        cfg.sessionId = dateStr30(time.localtime())
    else:
        cfg.useSessionTimestamp = False
    # MERGE WITH PARAMS
    if args.runs != '' and args.scans != '':
        # use the run and scan numbers passed in as parameters
        cfg.runNum = [int(x) for x in args.runs.split(',')]
        cfg.scanNum = [int(x) for x in args.scans.split(',')]
    else:  # when you're not specifying on the command line it's already in a list
        cfg.runNum = [int(x) for x in cfg.runNum]
        cfg.scanNum = [int(x) for x in cfg.scanNum]
    # GET DICOM DIRECTORY

    if cfg.buildImgPath:
        imgDirDate = datetime.datetime.now()
        dateStr = cfg.date.lower()
        if dateStr != 'now' and dateStr != 'today':
            try:
                imgDirDate = parser.parse(cfg.date)
            except ValueError as err:
                raise RequestError('Unable to parse date string {} {}'.format(
                    cfg.date, err))
        datestr = imgDirDate.strftime("%Y%m%d")
        imgDirName = "{}.{}.{}".format(datestr, cfg.subjectName,
                                       cfg.subjectName)
        if cfg.mode != 'debug':
            cfg.dicomDir = os.path.join(cfg.intelrt.imgDir, imgDirName)
            cfg.dicomNamePattern = cfg.intelrt.dicomNamePattern
        else:
            cfg.dicomDir = os.path.join(cfg.cluster.imgDir, imgDirName)
            cfg.dicomNamePattern = cfg.cluster.dicomNamePattern
    else:  # if you're naming the full folder directly
        if cfg.mode != 'debug':
            cfg.dicomDir = cfg.intelrt.imgDir  # then the whole path was supplied
            cfg.dicomNamePattern = cfg.intelrt.dicomNamePattern
        else:
            cfg.dicomDir = cfg.cluster.imgDir
            cfg.dicomNamePattern = cfg.cluster.dicomNamePattern

########
    cfg.bids_id = 'sub-{0:03d}'.format(cfg.subjectNum)
    cfg.ses_id = 'ses-{0:02d}'.format(cfg.subjectDay)
    if cfg.mode == 'local':
        # then all processing is happening on linux too
        cfg.dataDir = cfg.intelrt.codeDir + 'data'
        cfg.mask_filename = os.path.join(cfg.intelrt.maskDir, cfg.MASK)
        cfg.MNI_ref_filename = os.path.join(cfg.intelrt.maskDir,
                                            cfg.MNI_ref_BOLD)
    elif cfg.mode == 'cloud':
        cfg.dataDir = cfg.cloud.codeDir + 'data'
        cfg.mask_filename = os.path.join(cfg.cloud.maskDir, cfg.MASK)
        cfg.MNI_ref_filename = os.path.join(cfg.cloud.maskDir,
                                            cfg.MNI_ref_BOLD)
        cfg.intelrt.subject_full_day_path = '{0}/data/{1}/{2}'.format(
            cfg.intelrt.codeDir, cfg.bids_id, cfg.ses_id)
    elif cfg.mode == 'debug':
        cfg.dataDir = cfg.cluster.codeDir + '/data'
        cfg.mask_filename = os.path.join(cfg.cluster.maskDir, cfg.MASK)
        cfg.MNI_ref_filename = os.path.join(cfg.cluster.maskDir,
                                            cfg.MNI_ref_BOLD)

    cfg.subject_full_day_path = '{0}/{1}/{2}'.format(cfg.dataDir, cfg.bids_id,
                                                     cfg.ses_id)
    cfg.subject_reg_dir = '{0}/registration_outputs/'.format(
        cfg.subject_full_day_path)
    # check that this directory exists
    if not os.path.exists(cfg.subject_reg_dir):
        os.mkdir(cfg.subject_reg_dir)
        print('CREATING REGISTRATION DIRECTORY %s' % cfg.subject_reg_dir)

# REGISTRATION THINGS
    cfg.wf_dir = '{0}/{1}/ses-{2:02d}/registration/'.format(
        cfg.dataDir, cfg.bids_id, 1)
    cfg.BOLD_to_T1 = cfg.wf_dir + 'affine.txt'
    cfg.T1_to_MNI = cfg.wf_dir + 'ants_t1_to_mniComposite.h5'
    cfg.ref_BOLD = cfg.wf_dir + 'ref_image.nii.gz'

    # GET CONVERSION FOR HOW TO FLIP MATRICES
    cfg.axesTransform = getTransform()
    ###### BUILD SUBJECT FOLDERS #######
    return cfg