@@ -555,6 +555,8 @@ class Nifti1DicomExtension(Nifti1Extension[DicomDataset]):
555
555
"""
556
556
557
557
code = 2
558
+ _is_implict_VR : bool = False
559
+ _is_little_endian : bool = True
558
560
559
561
def __init__ (
560
562
self ,
@@ -586,27 +588,25 @@ def __init__(
586
588
code should always be 2 for DICOM.
587
589
"""
588
590
589
- self ._is_little_endian = parent_hdr is None or parent_hdr .endianness == '<'
591
+ if code != 2 :
592
+ raise ValueError (f'code must be 2 for DICOM. Got { code } .' )
593
+
594
+ if content is None :
595
+ content = pdcm .Dataset ()
596
+
597
+ if parent_hdr is not None :
598
+ self ._is_little_endian = parent_hdr .endianness == '<'
590
599
591
- bytes_content : bytes
592
600
if isinstance (content , pdcm .dataset .Dataset ):
593
- self ._is_implicit_VR = False
594
- self ._object = content
595
- bytes_content = self ._mangle (content )
601
+ super ().__init__ (code , object = content )
596
602
elif isinstance (content , bytes ): # Got a byte string - unmangle it
597
603
self ._is_implicit_VR = self ._guess_implicit_VR (content )
598
- self ._object = self ._unmangle (content )
599
- bytes_content = content
600
- elif content is None : # initialize a new dicom dataset
601
- self ._is_implicit_VR = False
602
- self ._object = pdcm .dataset .Dataset ()
603
- bytes_content = self ._mangle (self ._object )
604
+ super ().__init__ (code , content = content )
604
605
else :
605
606
raise TypeError (
606
607
f'content must be either a bytestring or a pydicom Dataset. '
607
608
f'Got { content .__class__ } '
608
609
)
609
- super ().__init__ (code , bytes_content )
610
610
611
611
@staticmethod
612
612
def _guess_implicit_VR (content ) -> bool :
0 commit comments