def check_dicom(mse): dcm = "" dicom = glob("/working/henry_temp/PBR/dicoms/{}/E*/".format(mse)) if len(dicom) == 1: dicom = dicom[0] dicom2 = "" elif len(dicom) == 2: dicom = dicom[0] dicom2 = dicom[1] else: dicom = "" dicom2 = "" dicoms = [dicom, dicom2] for d in dicoms: try: cmd = ["dti_info", dicom] proc = Popen(cmd, stdout=PIPE) lines = [ description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:] ] if "C2_3_2Fl_seg_psir_TI_PSIR" in lines: dcm = True else: continue except: pass return dcm
def get_modality(mse): num = mse.split("mse")[-1] cmd = ["ms_dcm_exam_info", "-t", num] proc = Popen(cmd, stdout=PIPE) lines = [description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:]] print("******These are the sequence names coming from the dicom images*****") for items in lines: print(items) print("********************************************************************") sequences = ["T1", "T2", "FLAIR", "T1_Gad"] for sq in sequences: print("checking for...", sq) sequence_name = "" nii_type = sq if nii_type: try: sequence_name = filter_files(lines, nii_type, heuristic)[0] print(sequence_name, "This is the {0}".format(sq)) except: print(mse, "No {0} in dicom identified by the heuristic...Please check sequnces and heuristic".format(sq)) pass if len(sequence_name) > 1: print("checking for sequence names in nifti and align folders") check_for_sq_names(mse, sq, "/nii/", sequence_name) check_for_sq_names(mse, sq, "/alignment/", sequence_name) get_nifti(mse) get_align(mse)
def get_modality(mse, nii_type="T1"): output = pd.DataFrame() num = mse.split("mse")[-1] cmd = ["ms_dcm_exam_info", "-t", num] proc = Popen(cmd, stdout=PIPE) lines = [description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:]] files = filter_files(lines, "T1", heuristic) output["nii"] = files output["mse"] = mse return output
def get_modality(mse, nii_type="T1"): output = pd.DataFrame() num = mse.split("mse")[-1] cmd = ["ms_dcm_exam_info", "-t", num] proc = Popen(cmd, stdout=PIPE) lines = [description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:]] if nii_type: files = filter_files(lines, nii_type, heuristic) output["nii"] = files else: output["nii"] = lines output["mse"] = mse return output
def get_modality(mse, sequence): num = mse.split("mse")[-1] cmd = ["ms_dcm_exam_info", "-t", num] proc = Popen(cmd, stdout=PIPE) lines = [description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:]] sequence_name = "" nii_type = sequence if nii_type: try: sequence_name = filter_files(lines, nii_type, heuristic)[0] print(sequence_name, "This is the {0}".format(sequence)) except: pass return sequence_name
def check_pacman(mse): pacman = "" num = mse.split("mse")[-1] #print("ms_dcm_exam_info", "-t", num, "-D") cmd = ["ms_dcm_exam_info", "-t", num, "-D"] proc = Popen(cmd, stdout=PIPE) lines = [ description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:] ] if "C2_3_2Fl_seg_psir_TI_PSIR" in lines: pacman = True elif "C2-3_2Fl_seg_psir_TI_PSIR" in lines: pacman = True else: pacman = False return pacman
def get_modality(mse): num = mse.split("mse")[-1] cmd = ["ms_dcm_exam_info", "-t", num, "-D"] proc = Popen(cmd, stdout=PIPE) lines = [ description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:] ] sequences = ["T2_spine"] for sq in sequences: print("checking for...", sq) nii_type = sq if nii_type: series_name = filter_files(lines, nii_type, heuristic) if len(series_name) > 0: series_name = series_name[0] print(series_name, " is the {0}".format(sq)) else: print( mse, "No {0} in dicom identified by the heuristic...Please check sequnces and heuristic" .format(sq))
def get_modalityt1(mse, nii_type="FLAIR"): output = pd.DataFrame(index=None) num = mse.split("mse")[-1] cmd = ["ms_dcm_exam_info", "-t", num] proc = Popen(cmd, stdout=PIPE) #lines = [l.decode("utf-8").split() for l in proc.stdout.readlines()[8:]] lines = [ description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:] ] #print(lines, "lines") if nii_type: #print(nii_type) files = filter_files(lines, nii_type, heuristic) #print(mse, "t1 exists") output["nii"] = files else: output["nii"] = lines print(mse, "NO T1") output["mse"] = mse return output
def get_scanner_info(c, out): df = pd.read_csv("{}".format(c)) for idx in range(len(df)): msid = df.loc[idx, 'msid'] mse = df.loc[idx, 'mse'] print(msid, mse) if os.path.exists(get_align(mse)): with open(get_align(mse)) as data_file: data = json.load(data_file) if len(data["t1_files"]) > 0: t1_file = data["t1_files"][-1].split('/')[-1] df.loc[idx, "T1"] = t1_file if len(data["t2_files"]) > 0: t2_file = data["t2_files"][-1].split('/')[-1] df.loc[idx, "T2"] = t2_file if len(data["flair_files"]) > 0: flair_file = data["flair_files"][-1].split('/')[-1] df.loc[idx, "FLAIR"] = flair_file num = mse.split("mse")[-1] print("ms_dcm_exam_info", "-t", num, "-D") cmd = ["ms_dcm_exam_info", "-t", num, "-D"] proc = Popen(cmd, stdout=PIPE) lines = [ description_renamer(" ".join(l.decode("utf-8").split()[1:-1])) for l in proc.stdout.readlines()[8:] ] sequences = ["T1", "T2", "FLAIR", "T1_Gad"] for sq in sequences: nii_type = sq if nii_type: try: sequence_name = filter_files(lines, nii_type, heuristic)[-1] df.loc[idx, format(sq)] = sequence_name print(sequence_name, " is the {0}".format(sq)) except: pass try: dicom = glob( "/working/henry_temp/PBR/dicoms/{0}/E*/*/*.DCM".format(mse))[0] cmd = ["dcmdump", dicom] proc = Popen(cmd, stdout=PIPE) output = [ l.decode("utf-8").split() for l in proc.stdout.readlines()[:] ] x = [ "SoftwareVersions", "BodyPartExamined", "StationName", "TransmitCoilName", "ReceiveCoilName" ] for line in output: for flag in x: if flag in line: dicom_info = str( str(line[2:]).split(']')[0].split('[') [2:]).replace('[', "").replace(']', '').replace( '"', '').replace("'", "") print(flag, ":", dicom_info) if flag == "SoftwareVersions": df.loc[idx, "SoftwareVersions"] = dicom_info if flag == "BodyPartExamined": df.loc[idx, "BodyPartExamined"] = dicom_info if flag == "StationName": df.loc[idx, "StationName"] = dicom_info if flag == "TransmitCoilName": df.loc[idx, "TransmitCoilName"] = dicom_info if flag == "ReceiveCoilName": df.loc[idx, "ReceiveCoilName"] = dicom_info except: df.loc[idx, "dicom"] = "no dicom in working directory" pass df.to_csv("{0}".format(out))