def __initialized(self): try: header = read_file(self.__filename, defer_size=None, stop_before_pixels=True) except InvalidDicomError: self.__isDicom = False return try: #find the manufacturer self.__manufacturer = 'UNKNOWN' if 'Manufacturer' in header: for manufacturer in manufacturers: if manufacturer in header.Manufacturer: self.__manufacturer = manufacturer self.__patientName = util.slugify(header.PatientName) self.__seriesDescription = util.slugify(header.SeriesDescription) self.__seriesNumber = header.SeriesNumber self.__instanceNumber = header.InstanceNumber self.__echoTime = header.EchoTime self.__isDicom = True except AttributeError as a: if "EchoTime" in a.message: try: self.__echoTime = header[Tag((0x2001, 0x1025))].value self.__isDicom = True except KeyError as k: self.__isDicom = False else: self.__isDicom = False if self.isSiemens(): #inherith Siemens ascconv properties Ascconv.__init__(self, self.__filename) bandwidthPerPixelPhaseEncodeTag = Tag((0x0019, 0x1028)) try: if header.has_key(bandwidthPerPixelPhaseEncodeTag): val = header[bandwidthPerPixelPhaseEncodeTag].value try: self.__bandwidthPerPixelPhaseEncode = float(val) except ValueError: # some data have wrong VR in dicom, try to unpack self.__bandwidthPerPixelPhaseEncode = struct.unpack('d', val)[0] self.__echoSpacing = 1/(self.__bandwidthPerPixelPhaseEncode* self.getEpiFactor()) *1000.0 * \ self.getPatFactor() * self.getPhaseResolution() * \ self.getPhaseOversampling() except (KeyError, IndexError, TypeError, ValueError): self.__echoSpacing = None
def __initialized(self): try: header = read_file(self.__filename, defer_size=None, stop_before_pixels=True, force=True) except InvalidDicomError: self.__isDicom = False return try: # find the manufacturer self.__manufacturer = 'UNKNOWN' if 'Manufacturer' in header: for manufacturer in manufacturers: if manufacturer in header.Manufacturer: self.__manufacturer = manufacturer self.__patientName = util.slugify(header.PatientName) self.__seriesDescription = util.slugify(header.SeriesDescription) self.__seriesNumber = header.SeriesNumber self.__instanceNumber = header.InstanceNumber self.__mrModel = header.ManufacturerModelName self.__magneticFieldStrength = header.MagneticFieldStrength self.__studyUID = header.StudyInstanceUID self.__tr = float(header.RepetitionTime) # TR Repetition Time self.__te = float(header.EchoTime) # TE Echo Time self.__flipAngle = float(header.FlipAngle) # Flip Angle self.__matrixSize = [value for value in header.AcquisitionMatrix if value != 0] # Matrix Size self.__voxelSize = map(float, [header.PixelSpacing[0], # Voxel size header.PixelSpacing[1], header.SliceThickness]) self.__fov = self.__matrixSize[0] * self.__voxelSize[0] # Compute FOV self.__isDicom = True except AttributeError as a: if "EchoTime" in a.message: try: self.__te = header[Tag((0x2001, 0x1025))].value self.__isDicom = True except KeyError as k: self.__isDicom = False else: self.__isDicom = False if self.isSiemens(): if 'DIFFUSION' and 'MOSAIC' in header.ImageType: # If Diffusion Acquistion self.__SequenceName = 'Diffusion' elif 'DIFFUSION' in header.ImageType: # If b0 Acquistion self.__SequenceName = 'b0' elif 'M' and 'NORM' in header.ImageType: # If T1 Acquisition self.__SequenceName = 'Structural T1' self.__ti = float(header.InversionTime) elif 'P' in header.ImageType: # If Phase acquisition self.__SequenceName = 'Phase' else: # If Magnitude acquisition self.__SequenceName = 'Magnitude' # inherith Siemens ascconv properties Ascconv.__init__(self, self.__filename) bandwidthPerPixelPhaseEncodeTag = Tag((0x0019, 0x1028)) try: if header.has_key(bandwidthPerPixelPhaseEncodeTag): val = header[bandwidthPerPixelPhaseEncodeTag].value try: self.__bandwidthPerPixelPhaseEncode = float(val) except ValueError: # some data have wrong VR in dicomparser, try to unpack self.__bandwidthPerPixelPhaseEncode = struct.unpack('d', val)[0] self.__echoSpacing = 1 / (self.__bandwidthPerPixelPhaseEncode * self.getEpiFactor()) * 1000.0 * \ self.getPatFactor() * self.getPhaseResolution() * \ self.getPhaseOversampling() except (KeyError, IndexError, TypeError, ValueError): self.__echoSpacing = None
def __initialized(self): try: header = read_file(self.__filename, defer_size=None, stop_before_pixels=True, force=True) except InvalidDicomError: self.__isDicom = False return try: # find the manufacturer self.__manufacturer = 'UNKNOWN' if 'Manufacturer' in header: for manufacturer in manufacturers: if manufacturer in header.Manufacturer: self.__manufacturer = manufacturer self.__patientName = util.slugify(header.PatientName) self.__seriesDescription = util.slugify(header.SeriesDescription) self.__seriesNumber = header.SeriesNumber self.__instanceNumber = header.InstanceNumber self.__mrModel = header.ManufacturerModelName self.__magneticFieldStrength = header.MagneticFieldStrength self.__studyUID = header.StudyInstanceUID self.__tr = float(header.RepetitionTime) # TR Repetition Time self.__te = float(header.EchoTime) # TE Echo Time self.__flipAngle = float(header.FlipAngle) # Flip Angle self.__matrixSize = [ value for value in header.AcquisitionMatrix if value != 0 ] # Matrix Size self.__voxelSize = map( float, [ header.PixelSpacing[0], # Voxel size header.PixelSpacing[1], header.SliceThickness ]) self.__fov = self.__matrixSize[0] * self.__voxelSize[ 0] # Compute FOV self.__isDicom = True except AttributeError as a: if "EchoTime" in a.message: try: self.__te = header[Tag((0x2001, 0x1025))].value self.__isDicom = True except KeyError as k: self.__isDicom = False else: self.__isDicom = False if self.isSiemens(): if 'DIFFUSION' and 'MOSAIC' in header.ImageType: # If Diffusion Acquistion self.__SequenceName = 'Diffusion' elif 'DIFFUSION' in header.ImageType: # If b0 Acquistion self.__SequenceName = 'b0' elif 'M' and 'NORM' in header.ImageType: # If T1 Acquisition self.__SequenceName = 'Structural T1' self.__ti = float(header.InversionTime) elif 'P' in header.ImageType: # If Phase acquisition self.__SequenceName = 'Phase' else: # If Magnitude acquisition self.__SequenceName = 'Magnitude' # inherith Siemens ascconv properties Ascconv.__init__(self, self.__filename) bandwidthPerPixelPhaseEncodeTag = Tag((0x0019, 0x1028)) try: if header.has_key(bandwidthPerPixelPhaseEncodeTag): val = header[bandwidthPerPixelPhaseEncodeTag].value try: self.__bandwidthPerPixelPhaseEncode = float(val) except ValueError: # some data have wrong VR in dicomparser, try to unpack self.__bandwidthPerPixelPhaseEncode = struct.unpack( 'd', val)[0] self.__echoSpacing = 1 / (self.__bandwidthPerPixelPhaseEncode * self.getEpiFactor()) * 1000.0 * \ self.getPatFactor() * self.getPhaseResolution() * \ self.getPhaseOversampling() except (KeyError, IndexError, TypeError, ValueError): self.__echoSpacing = None