Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testLatin1(self):
"""charset: can read and decode latin_1 file........................"""
ds = dicomio.read_file(latin1_file)
ds.decode()
# Make sure don't get unicode encode error on converting to string
expected = u'Buc^J\xe9r\xf4me'
got = ds.PatientName
self.assertEqual(expected, got,
"Expected %r, got %r" % (expected, got))
def testExplicitISO2022_IR6(self):
"""charset: can decode file with multi-valued data elements........."""
ds = dicomio.read_file(explicit_ir6_file)
ds.decode()
def testEqualityFileMeta(self):
"""Dataset: equality returns correct value if with metadata"""
d = read_file(self.test_file)
e = read_file(self.test_file)
self.assertTrue(d == e)
e.is_implicit_VR = not e.is_implicit_VR
self.assertFalse(d == e)
e.is_implicit_VR = not e.is_implicit_VR
self.assertTrue(d == e)
e.is_little_endian = not e.is_little_endian
self.assertFalse(d == e)
e.is_little_endian = not e.is_little_endian
self.assertTrue(d == e)
e.filename = 'test_filename.dcm'
self.assertFalse(d == e)
def testSaveLoadPlane(self):
self.plugin.saveObject(self.plane,self.tempdir)
firstfile=first(glob.glob(self.tempdir+'/*'))
read_file(firstfile)
eidolon.printFlush(self.planearr)
def loadDicomVolume(self,filename,name=None,interval=1.0,toffset=0.0,position=vec3(),rot=rotator(),task=None):
'''Load a single DICOM file containing a 3D or 4D image volume (ie. ultrasound) using nonstandard tags.'''
dcm=read_file(filename)
name=name or eidolon.splitPathExt(filename)[1]
NT=NonstandardTags
spacing=vec3(dcm[NT.USpixdimx].value,dcm[NT.USpixdimy].value,dcm[NT.USpixdimz].value)*10
dimsize=(dcm[NT.USnumframes].value,dcm[NT.USdepth].value,dcm[NT.USheight].value,dcm[NT.USwidth].value)
pixeldata=dcm[NT.USpixeldata].value
assert len(pixeldata)==eidolon.prod(dimsize), 'Pixel data dimension is %i, should be %i'%(len(pixeldata),eidolon.prod(dimsize))
dat=np.ndarray(dimsize,dtype=np.uint8,buffer=pixeldata,order='C')
dat=np.transpose(dat,(3,2,1,0))
obj=self.createObjectFromArray(name,dat,interval,toffset,position,rot*rotator(eidolon.halfpi,0,0),spacing,task=task)
obj.source=convertToDict(dcm)
return obj
def load_dicom(filename):
try:
name = osp.splitext(osp.basename(filename))[0]
try:
data = dicomio.read_file(filename, force=True)
except TypeError:
data = dicomio.read_file(filename)
arr = data.pixel_array
return {name: arr}, None
except Exception as error:
return None, str(error)
except ImportError:
def getTagObject(self,index):
'''Get the object storing tag information from Dicom file at the given index.'''
if index not in self.tagcache:
dcm=dicomio.read_file(self.filenames[index],stop_before_pixels=True)
self.tagcache[index]=dcm
return self.tagcache[index]
def getTagObject(self, index):
"""Get the object storing tag information from Dicom file at the given index."""
if index not in self.tagcache:
dcm = dicomio.read_file(self.filenames[index], stop_before_pixels=True)
self.tagcache[index] = dcm
return self.tagcache[index]
def loadDicomZipFile(filename, includeTags=False):
dds=DicomDataset(filename)
with zipfile.ZipFile(filename) as z:
for n in z.namelist():
s=BytesIO(z.read(n))
try:
ds=read_file(s)
except:
pass # ignore files which aren't Dicom files
else:
dsi=DicomSharedImage(n,dcm=ds,includeTags=includeTags)
series=dds.getSeries(ds.SeriesInstanceUID,True)
series.addFile(n)
series.addSharedImages([dsi])
series.desc=series.desc or str(ds.get('SeriesDescription',series.desc)).strip()
series.seriesNum=series.seriesNum or int(ds.get('SeriesNumber',series.seriesNum))
return dds
def loadDicomFile(self,index):
return read_file(os.path.join(self.parent.rootdir,self.filenames[index]))