Example #1
0
    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
Example #2
0
    def add_preset(self, classname, name, idx=None):
        """
        Adds a new preset instance to the playlist.  Classname must be a currently loaded
        preset class.  Name must be unique.  If idx is specified, the preset will be inserted
        at the position idx, else it will be appended to the end of the playlist.
        """
        if classname not in list(self.available_pattern_classes.keys()):
            log.error("Tried to add nonexistent preset class %s" % classname)
            return False

        if self.preset_name_exists(name):
            log.error("Tried to add a preset that already exists: %s" % name)
            return False

        inst = self.available_pattern_classes[classname][1](self._app,
                                                            slugify(name))
        inst.set_name(name)
        inst.save()
        inst._reset()

        if idx is not None:
            self._playlist.insert(idx, inst)
        else:
            self._playlist.append(inst)

        if self.active_preset == self.next_preset:
            self.update_next_preset()

        self.changed()
        return True
Example #3
0
    def add_existing_preset(self, name):

        # TODO: Should we support multiple instances of the same preset on a playlist?
        for p in self._playlist:
            if p.name() == name:
                log.error("Cannot add a preset to the same playlist twice!")
                return False

        slug = slugify(name)
        preset_data = {}
        preset_path = os.path.join(os.getcwd(), "data", "presets",
                                   "".join([slug, ".json"]))

        try:
            with open(preset_path, "r") as f:
                preset_data = json.load(f)
        except:
            log.error("Could not load preset %s" % name)
            return False

        self._playlist.append(self.get_preset_from_json_data(
            preset_data, slug))
        if self.active_preset == self.next_preset:
            self.update_next_preset()

        self.changed()
        return True
Example #4
0
    def add_preset(self, classname, name, idx=None):
        """
        Adds a new preset instance to the playlist.  Classname must be a currently loaded
        preset class.  Name must be unique.  If idx is specified, the preset will be inserted
        at the position idx, else it will be appended to the end of the playlist.
        """
        if classname not in self.available_pattern_classes.keys():
            log.error("Tried to add nonexistent preset class %s" % classname)
            return False

        if self.preset_name_exists(name):
            log.error("Tried to add a preset that already exists: %s" % name)
            return False

        inst = self.available_pattern_classes[classname][1](self._app, slugify(name))
        inst.set_name(name)
        inst.save()
        inst._reset()

        if idx is not None:
            self._playlist.insert(idx, inst)
        else:
            self._playlist.append(inst)

        if self.active_preset == self.next_preset:
            self.update_next_preset()

        self.changed()
        return True
Example #5
0
    def add_existing_preset(self, name):

        # TODO: Should we support multiple instances of the same preset on a playlist?
        for p in self._playlist:
            if p.name() == name:
                log.error("Cannot add a preset to the same playlist twice!")
                return False

        slug = slugify(name)
        preset_data = {}
        preset_path = os.path.join(os.getcwd(), "data", "presets", "".join([slug, ".json"]))

        try:
            with open(preset_path, "r") as f:
                preset_data = json.load(f)
        except:
            log.error("Could not load preset %s" % name)
            return False

        self._playlist.append(self.get_preset_from_json_data(preset_data, slug))
        if self.active_preset == self.next_preset:
            self.update_next_preset()

        self.changed()
        return True
 def put(self):
     # auto-populate artist_slug
     self.artist_slug = slugify(self.artist)
     # Delete the cached artist, tag lists whenever created/updated
     memcache.delete('artist_list')
     memcache.delete('tag_list')
     key = super(Song, self).put()
     return key
Example #7
0
    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
Example #8
0
 def set_name(self, name):
     self._instance_name = name
     self._instance_slug = slugify(name)
     self.filename = os.path.join(os.getcwd(), "data", "presets",
                                  "".join([self._instance_slug, ".json"]))
     self.save()
Example #9
0
    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