Exemplo n.º 1
0
    def __convertDwi(self, sequence, session, target):
        """ Convert a dwi dicomparser images into nifti

        the name of the resulting image will be:
            prefix_subjectName.nii.gz

        """
        dwi = util.buildName(self.__configParser, target,
                             sequence.getPrefix().getValue(),
                             session.getName(), 'nii.gz')
        bEnc = util.buildName(self.__configParser, target, dwi, None, "b")
        bvals = util.buildName(self.__configParser, target, dwi, None, "bvals")
        bvecs = util.buildName(self.__configParser, target, dwi, None, "bvecs")

        cmd = "mrconvert {} {} -force -export_grad_mrtrix {} -export_grad_fsl {} {}"\
            .format(sequence.getEscapedDirectory(), dwi, bEnc, bvecs, bvals)

        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3,4 "
        print cmd
        util.launchCommand(cmd)

        if not self.__arguments.noConfig:
            dicoms = glob.glob("{}/*.dcm".format(sequence.getDirectory()))
            if len(dicoms) > 0:
                toadinfo = Toadinfo(dicoms.pop())
                toadinfo.writeToadConfig(self.__configFilename)
Exemplo n.º 2
0
    def __convertDwi(self, sequence, session, target):
        """ Convert a dwi dicom images into nifti

        the name of the resulting image will be:
            prefix_subjectName.nii.gz

        """
        dwi = util.buildName(self.__configParser, target, sequence.getPrefix().getValue(), session.getName(),'nii.gz')
        bEnc = util.buildName(self.__configParser, target, dwi, None, "b")
        bvals = util.buildName(self.__configParser, target, dwi, None, "bvals")
        bvecs = util.buildName(self.__configParser, target, dwi, None, "bvecs")

        cmd = "mrconvert {} {} -force -export_grad_mrtrix {} -export_grad_fsl {} {}"\
            .format(sequence.getEscapedDirectory(), dwi, bEnc, bvecs, bvals)

        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3,4 "
        print cmd
        util.launchCommand(cmd)

        if not self.__arguments.noConfig:
            dicoms = glob.glob("{}/*.dcm".format(sequence.getDirectory()))
            if len(dicoms) > 0:
                toadinfo = Toadinfo(dicoms.pop())
                toadinfo.writeToadConfig( self.__configFilename)
                util.launchCommand(cmd)
Exemplo n.º 3
0
    def __convert(self, sequence, session, target):
        filename = util.buildName(self.__configParser, target, sequence.getPrefix().getValue(), session.getName(), 'nii.gz')

        cmd = "mrconvert {0} {1} -force ".format(sequence.getEscapedDirectory(), filename)
        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3 "

        if sequence.getPrefix().getName() == 'phase':
            cmd += " -datatype float32 "
        print cmd
        util.launchCommand(cmd)
Exemplo n.º 4
0
    def __convertMagnitude(self, sequence, session, target):
        """ Convert a magnitude fieldmap dicomparser images into nifti

        the name of the resulting image will be:
            prefix_subjectName.nii.gz


        """
        def __setMagnitudeFieldmapInConfigFiles(echo1, echo2):
            """ write magnitude image properties into a config file

            Args:
                configFile: a config file
                echo1: the echo time of the first magnitude map
                echo2: the echo time of the secong magnitude map
            """
            if os.path.exists(self.__configFilename):
                self.__configParser.read(self.__configFilename)
            if not self.__configParser.has_section("correction"):
                self.__configParser.add_section('correction')
            self.__configParser.set('correction', "echo_time_mag1", echo1)
            self.__configParser.set('correction', "echo_time_mag2", echo2)
            with open(self.__configFilename, 'w') as w:
                self.__configParser.write(w)

        values = []
        pattern = os.path.join(session.getDirectory(),
                               os.path.dirname(sequence.getName()), 'echo_*')
        for directory in glob.glob(pattern):
            values.append(
                (os.path.basename(directory).strip('echo_'), directory))
        try:
            echo1 = float(values[0][0])
            echo2 = float(values[1][0])

            if not self.__arguments.noConfig:
                if echo1 > echo2:
                    __setMagnitudeFieldmapInConfigFiles(echo2, echo1)
                else:
                    __setMagnitudeFieldmapInConfigFiles(echo1, echo2)

        except IndexError:
            return

        filename = util.buildName(self.__configParser, target,
                                  sequence.getPrefix().getValue(),
                                  session.getName(), 'nii.gz')
        cmd = "mrconvert {0} {1} -force ".format(
            sequence.getEscapedDirectory(), filename)
        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3 "
        print cmd
        util.launchCommand(cmd)
Exemplo n.º 5
0
    def __convertMagnitude(self, sequence, session, target):
        """ Convert a magnitude fieldmap dicom images into nifti

        the name of the resulting image will be:
            prefix_subjectName.nii.gz


        """
        def __setMagnitudeFieldmapInConfigFiles(echo1, echo2):
            """ write magnitude image properties into a config file

            Args:
                configFile: a config file
                echo1: the echo time of the first magnitude map
                echo2: the echo time of the secong magnitude map
            """
            if os.path.exists(self.__configFilename):
                self.__configParser.read(self.__configFilename)
            if not self.__configParser.has_section("correction"):
                self.__configParser.add_section('correction')
            self.__configParser.set('correction', "echo_time_mag1", echo1)
            self.__configParser.set('correction', "echo_time_mag2", echo2)
            with open(self.__configFilename,'w') as w:
                self.__configParser.write(w)

        values = []
        pattern = os.path.join(session.getDirectory(), os.path.dirname(sequence.getName()),'echo_*')
        for directory in glob.glob(pattern):
            values.append((os.path.basename(directory).strip('echo_'), directory))
        try:
            echo1 = float(values[0][0])
            echo2 = float(values[1][0])

            if not self.__arguments.noConfig:
                if echo1 > echo2:
                    __setMagnitudeFieldmapInConfigFiles(echo2, echo1)
                else:
                    __setMagnitudeFieldmapInConfigFiles(echo1, echo2)

        except IndexError:
            return

        filename = util.buildName(self.__configParser, target, sequence.getPrefix().getValue(), session.getName(), 'nii.gz')
        cmd = "mrconvert {0} {1} -force ".format(sequence.getEscapedDirectory(), filename)
        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3 "
        print cmd
        util.launchCommand(cmd)
Exemplo n.º 6
0
    def buildName(self, source, postfix, ext=None, absolute = True):
        """A simple utility function that return a file name that contain the postfix and the current working directory

        The filename is always into the current working  directory
        The extension name will be the same as source unless specify as argument

        Args:
            source: the input file name
            postfix: single element or array of elements which option item specified in config at the postfix section
            ext: the extension of the new target

        Returns:
            a file name that contain the postfix and the current working directory
        """
        absoluteBuildName = util.buildName(self.config, self.workingDir, source, postfix, ext, absolute)
        return os.path.basename(absoluteBuildName.replace("'",""))
Exemplo n.º 7
0
    def buildName(self, source, postfix, ext=None, absolute=True):
        """A simple utility function that return a file name that contain the postfix and the current working directory

        The path of the filename contain the current working  directory
        The extension name will be the same as source unless specify as argument

        Args:
            source: the input file name
            postfix: single element or array of elements which option item specified in config at the postfix section
            ext: the extension of the new target

        Returns:
            a file name that contain the postfix and the current working directory
        """
        return util.buildName(self.config, self.workingDir, source, postfix,
                              ext, absolute)
Exemplo n.º 8
0
    def __convert(self, sequence, session, target):
        filename = util.buildName(self.__configParser, target, sequence.getPrefix().getValue(), session.getName(), 'nii.gz')

        cmd = "mrconvert {0} {1} -force ".format(sequence.getEscapedDirectory(), filename)
        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3 "

        if sequence.getPrefix().getName() == 'phase':
            cmd += " -datatype float32 "
        print cmd
        util.launchCommand(cmd)

        if not self.__arguments.noConfig:
            dicoms = glob.glob("{}/*.dcm".format(sequence.getDirectory()))
            if len(dicoms) > 0:
                toadinfo = Toadinfo(dicoms.pop())
                toadinfo.writeToadConfig(self.__configFilename)
Exemplo n.º 9
0
    def __convert(self, sequence, session, target):
        filename = util.buildName(self.__configParser, target,
                                  sequence.getPrefix().getValue(),
                                  session.getName(), 'nii.gz')

        cmd = "mrconvert {0} {1} -force ".format(
            sequence.getEscapedDirectory(), filename)
        if not self.__arguments.noStride:
            cmd += " -stride 1,2,3 "

        if sequence.getPrefix().getName() == 'phase':
            cmd += " -datatype float32 "
        print cmd
        util.launchCommand(cmd)

        if not self.__arguments.noConfig:
            dicoms = glob.glob("{}/*.dcm".format(sequence.getDirectory()))
            if len(dicoms) > 0:
                toadinfo = Toadinfo(dicoms.pop())
                toadinfo.writeToadConfig(self.__configFilename)