def test_key_regex_filter(): filt = dcmstack.make_key_regex_filter(["test", "another"], ["2", "another test"]) ok_(filt("test", 1)) ok_(filt("test another", 1)) ok_(filt("another tes", 1)) ok_(not filt("test2", 1)) ok_(not filt("2 another", 1)) ok_(not filt("another test", 1))
def test_key_regex_filter(): filt = dcmstack.make_key_regex_filter(['test', 'another'], ['2', 'another test']) ok_(filt('test', 1)) ok_(filt('test another', 1)) ok_(filt('another tes', 1)) ok_(not filt('test2', 1)) ok_(not filt('2 another', 1)) ok_(not filt('another test', 1))
def test_key_regex_filter(): filt = dcmstack.make_key_regex_filter(['test', 'another'], ['2', 'another test']) ok_(filt('test', 1)) ok_(filt('test another', 1)) ok_(filt('another tes', 1)) ok_(not filt('test2', 1)) ok_(not filt('2 another', 1)) ok_(not filt('another test', 1))
def get_data_from_dicom(alldic, Ei): #Ei = Exam_info.Exam_info() mf = dcmstack.make_key_regex_filter(['nothingtoremove']) pg, dicom_file_size, n_ommited = Ei.get_group_stack_from_dic(alldic) all_stack = [] dicom_ok = True for v in pg.itervalues(): my_stack = dcmstack.DicomStack(meta_filter=mf, time_order='InstanceNumber') n_ommited = 0 n_repeat = 0 for vol in v: #vol[0] champs de pydicom vol[1] ordererd dict try: my_stack.add_dcm(vol[0], meta=vol[1]) except dcmstack.IncongruentImageError: n_ommited += 1 dicom_ok = False except dcmstack.ImageCollisionError: n_repeat += 1 dicom_ok = False except Exception as e: log.info("oups dic %s because expection" % (vol[2])) print e n_ommited += 1 dicom_ok = False # dicom_file_size += os.path.getsize(vol[2]) if n_repeat > 0: log.info("Found %d duplicate dicom file", n_repeat) if n_ommited > 0: log.info("Found %d stack incongruent dicom file", n_ommited) try: all_stack.append( my_stack.to_nifti(voxel_order='LAS', embed_meta=True)) except (dcmstack.InvalidStackError, dcmstack.IncongruentImageError) as detail: log.info("INVALIDE STACK because %s ", detail) dicom_ok = False except Exception: log.info("STACK error") dicom_ok = False alldata = [] for nii in all_stack: data = nii.get_data() alldata.append(data) return alldata, dicom_ok
def get_data_from_dicom(alldic,Ei): #Ei = Exam_info.Exam_info() mf =dcmstack.make_key_regex_filter(['nothingtoremove']) pg,dicom_file_size,n_ommited = Ei.get_group_stack_from_dic(alldic) all_stack=[] dicom_ok=True for v in pg.itervalues(): my_stack = dcmstack.DicomStack(meta_filter=mf,time_order='InstanceNumber') n_ommited=0 n_repeat=0 for vol in v: #vol[0] champs de pydicom vol[1] ordererd dict try: my_stack.add_dcm(vol[0],meta=vol[1]) except dcmstack.IncongruentImageError : n_ommited += 1 dicom_ok=False except dcmstack.ImageCollisionError: n_repeat += 1 dicom_ok=False except Exception as e: log.info("oups dic %s because expection"%(vol[2])) print e n_ommited +=1 dicom_ok=False # dicom_file_size += os.path.getsize(vol[2]) if n_repeat>0: log.info("Found %d duplicate dicom file",n_repeat) if n_ommited>0: log.info("Found %d stack incongruent dicom file",n_ommited) try: all_stack.append(my_stack.to_nifti(voxel_order='LAS', embed_meta=True)) except (dcmstack.InvalidStackError, dcmstack.IncongruentImageError) as detail: log.info( "INVALIDE STACK because %s ",detail) dicom_ok=False except Exception: log.info( "STACK error" ) dicom_ok=False alldata = [] for nii in all_stack: data=nii.get_data() alldata.append(data) return alldata,dicom_ok
def _run_interface(self, runtime): src_paths = self._get_filelist(self.inputs.dicom_files) include_regexes = dcmstack.default_key_incl_res if isdefined(self.inputs.include_regexes): include_regexes += self.inputs.include_regexes exclude_regexes = dcmstack.default_key_excl_res if isdefined(self.inputs.exclude_regexes): exclude_regexes += self.inputs.exclude_regexes meta_filter = dcmstack.make_key_regex_filter(exclude_regexes, include_regexes) stack = dcmstack.DicomStack(meta_filter=meta_filter) for src_path in src_paths: src_dcm = dicom.read_file(src_path, force=True) stack.add_dcm(src_dcm) nii = stack.to_nifti(embed_meta=True) nw = NiftiWrapper(nii) self.out_path = self._get_out_path(nw.meta_ext.get_class_dict(("global", "const"))) if not self.inputs.embed_meta: nw.remove_extension() nb.save(nii, self.out_path) return runtime
def _run_interface(self, runtime): src_paths = self._get_filelist(self.inputs.dicom_files) include_regexes = dcmstack.default_key_incl_res if isdefined(self.inputs.include_regexes): include_regexes += self.inputs.include_regexes exclude_regexes = dcmstack.default_key_excl_res if isdefined(self.inputs.exclude_regexes): exclude_regexes += self.inputs.exclude_regexes meta_filter = dcmstack.make_key_regex_filter(exclude_regexes, include_regexes) stack = dcmstack.DicomStack(meta_filter=meta_filter) for src_path in src_paths: src_dcm = dicom.read_file(src_path, force=True) stack.add_dcm(src_dcm) nii = stack.to_nifti(embed_meta=True) nw = NiftiWrapper(nii) self.out_path = \ self._get_out_path(nw.meta_ext.get_class_dict(('global', 'const'))) if not self.inputs.embed_meta: nw.remove_extension() nb.save(nii, self.out_path) return runtime