Ejemplo n.º 1
0
def move_replace(source, dest):
    for root, dir, files in os.walk(source, topdown=False):
        for name in files:
            newdir = root.replace(source, dest)
            if not os.path.isdir(newdir):
                os.makedirs(newdir, 0775)
            copy2(join(root, name), join(newdir, name))
    rmtree(source)
    misc.set_permissions(dest)
Ejemplo n.º 2
0
def recon_visit(visit, databin, shallow_recon=False):
    'shallow_recon will NOT check the individual files to see if they exist. Shallow Recon will stop if the top level folder exists'
    dcm2nii_object = dcm2nii(args_list=[
        '-a', 'N', '-d', 'N', '-e', 'N', '-g', 'N', '-i', 'N', '-n', 'Y', '-p',
        'N', '-m', 'N', '-r', 'N', '-v', 'Y', '-x', 'N'
    ])
    could_not_recon_list = []
    #remove garbage in quarantine
    for dicom in visit.dicomlist:
        dicom.series_folder_list.sort(key=lambda x: x.SeriesNumber
                                      )  # to ensure that 0 entry removed first
        folders_to_check = [
            x for x in dicom.series_folder_list
            if x.bad == False and x.manual_recon == False
        ]
        num_folders_to_check = len(folders_to_check)
        skip_check = False
        for series_folder in folders_to_check:
            series_info = databin.dicom_series_read.merged_series[
                visit.subject.subid][visit.visid][
                    series_folder.SeriesInstanceUID]
            dicom_series_type = series_info.DICOMseries_types.itervalues(
            ).next()
            folder_name = dicom_series_type.folder  #folder inside visit dir
            expected_image_quantity = dicom_series_type.expected_image_quantity  #number of niftis we expect
            if series_info.series == 'DTI_1' or series_info.series == 'DTI_2':
                folder_name = series_info.series
            if shallow_recon and folder_name in visit.niftis:  #i
                print "SHALLOW SKIPPING"
                continue
            if num_folders_to_check == 1:
                skip_check = True
            if databin.dicom_series_read.merged_series[visit.subject.subid][
                    visit.visid][
                        series_folder.
                        SeriesInstanceUID].Modality == 'PR':  #skip PR visits
                num_folders_to_check = num_folders_to_check - 1
                continue
            elif skip_check:
                check_recon_dicom_folder(series_folder, dcm2nii_object,
                                         folder_name, expected_image_quantity)

            if expected_image_quantity >= 0:  #not -1, the default
                generated_nifti_paths = gen_nifti_basename_fullpaths(
                    series_folder, folder_name, expected_image_quantity)
                if all([nifti_exists(x) for x in generated_nifti_paths]):
                    break
                else:
                    could_not_recon_list.append(
                        "subid:{0.visit.subject.subid} visid: {0.visit.visid} series: {0.series}"
                        .format(dicom))

    misc.set_permissions(visit.path)
    return could_not_recon_list
Ejemplo n.º 3
0
def recon_visit(visit, databin, shallow_recon=False):
    'shallow_recon will NOT check the individual files to see if they exist. Shallow Recon will stop if the top level folder exists'
    dcm2nii_object = dcm2nii(args_list=['-a', 'N', '-d', 'N', '-e', 'N', '-g', 'N', '-i', 'N', '-n', 'Y', '-p', 'N', '-m', 'N', '-r', 'N', '-v', 'Y', '-x', 'N'])
    could_not_recon_list = []
    #remove garbage in quarantine
    for dicom in visit.dicomlist:
        dicom.series_folder_list.sort(key=lambda x: x.SeriesNumber) # to ensure that 0 entry removed first
        folders_to_check = [x for x in dicom.series_folder_list if x.bad == False and x.manual_recon == False]
        num_folders_to_check = len(folders_to_check)
        skip_check = False
        for series_folder in folders_to_check:
            series_info = databin.dicom_series_read.merged_series[visit.subject.subid][visit.visid][series_folder.SeriesInstanceUID]
            dicom_series_type = series_info.DICOMseries_types.itervalues().next()
            folder_name = dicom_series_type.folder #folder inside visit dir
            expected_image_quantity = dicom_series_type.expected_image_quantity #number of niftis we expect
            if series_info.series == 'DTI_1' or series_info.series == 'DTI_2':
                folder_name = series_info.series
            if shallow_recon and folder_name in visit.niftis:  #i
                print "SHALLOW SKIPPING"
                continue
            if num_folders_to_check == 1:
                skip_check = True
            if databin.dicom_series_read.merged_series[visit.subject.subid][visit.visid][series_folder.SeriesInstanceUID].Modality == 'PR': #skip PR visits
                num_folders_to_check = num_folders_to_check - 1
                continue
            elif skip_check:
                check_recon_dicom_folder(series_folder, dcm2nii_object, folder_name, expected_image_quantity)
            
            if expected_image_quantity >= 0: #not -1, the default
                generated_nifti_paths = gen_nifti_basename_fullpaths(series_folder, folder_name, expected_image_quantity)
                if all([nifti_exists(x) for x in generated_nifti_paths]):
                    break
                else:
                    could_not_recon_list.append("subid:{0.visit.subject.subid} visid: {0.visit.visid} series: {0.series}".format(dicom))
    
    misc.set_permissions(visit.path)
    return could_not_recon_list