当前位置: 首页>>代码示例>>Python>>正文


Python XnatUtils.run_matlab方法代码示例

本文整理汇总了Python中dax.XnatUtils.run_matlab方法的典型用法代码示例。如果您正苦于以下问题:Python XnatUtils.run_matlab方法的具体用法?Python XnatUtils.run_matlab怎么用?Python XnatUtils.run_matlab使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dax.XnatUtils的用法示例。


在下文中一共展示了XnatUtils.run_matlab方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
    def run(self):
        """Method running the process for the spider on the inputs data."""
        matlabdir = os.path.join(self.jobdir, 'MATLAB/')
        if not os.path.exists(matlabdir):
            os.makedirs(matlabdir)
        outputdir = os.path.join(self.jobdir, 'Outputs/')
        if not os.path.exists(outputdir):
            os.makedirs(outputdir)

        matlab_script = os.path.join(matlabdir, 'callfMRIQA_v2.m')
        f = open(matlab_script, "w")
        try:
            lines = ['% Matlab Script to call vufMRIQAGUI function\n',
                     'addpath(genpath(\''+str(self.fmatlab)+'\'));\n',
                     'outputdir = \''+str(outputdir)+'\';\n',
                     'imgfile=\''+str(self.inputs[0])+'\';\n',
                     'spm_path=\''+str(self.spm)+'\';\n',
                     'project=\''+str(self.xnat_project)+'\';\n',
                     'subject=\''+str(self.xnat_subject)+'\';\n',
                     'session=\''+str(self.xnat_session)+'\';\n',
                     'scan=\''+str(self.xnat_scan)+'\';\n',
                     'fMRIQA_Pipeline_v2(imgfile,outputdir,spm_path,project,\
subject,session,scan);\n'
                     ]
            f.writelines(lines)
        finally:
            f.close()

        # Running Matlab script:
        XnatUtils.run_matlab(matlab_script, True)
        print '============================================================\n'
开发者ID:byvernault,项目名称:scripts,代码行数:33,代码来源:Spider_fMRIQA_v2.0.0.py

示例2: run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
    def run(self):
        """Method running the process for the spider on the inputs data."""
        # Gzip files
        input_file = ''
        for filepath in self.inputs:
            if filepath.endswith('.nii.gz'):
                os.system("gzip -f -d %s" % (filepath))
                input_file = filepath[:-3]

        self.input_file = input_file
        folder = os.path.join(self.jobdir, 'Sample_GM_Segment')

        mat_lines = MAT_TEMPLATE.format(
            matlab_code=self.matlab_code,
            input_file=input_file,
            spm12=self.spm12
        )

        matlab_script = os.path.join(folder, 'run_sample_GM.m')
        with open(matlab_script, "w") as _fobj:
            _fobj.writelines(mat_lines)
        XnatUtils.run_matlab(matlab_script, verbose=True)

        # Make report:
        self.make_pdf()

        # Gzip nii:
        XnatUtils.gzip_nii(folder)
开发者ID:byvernault,项目名称:ucl_processing,代码行数:30,代码来源:Spider_Sample_GM_Segment_v1_0_0.py

示例3: make_pdf

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
    def make_pdf(self):
        """Method to make the PDF for the spider.

        :return: None
        """
        output_folder = os.path.join(self.jobdir, 'outputs')
        pdfs_dir = XnatUtils.makedir(os.path.join(output_folder, 'pdfs'))
        fpages = list()
        # Run matlab function
        for nb_acq in range(1, self.nb_acquisition + 1):
            pdf_page = os.path.join(output_folder, str(nb_acq),
                                    'VerdictMapAcq%d.pdf' % nb_acq)
            mat_lines = DEFAULT_PDF_MAKER.format(
                matlab_code=self.matlab_code,
                maps_folder=os.path.join(output_folder, str(nb_acq),
                                         'AMICO', self.model),
                subject=self.xnat_subject,
                output_folder=pdfs_dir,
                acq=nb_acq)
            matlab_script = os.path.join(output_folder,
                                         'run_pdf_page_%d.m' % nb_acq)
            with open(matlab_script, "w") as f:
                f.writelines(mat_lines)
            XnatUtils.run_matlab(matlab_script, verbose=True)
            # Get all PDFs:
            pdf_pages = XnatUtils.find_files(pdfs_dir, '.pdf')
            # Merge all pdfs into one:
            self.merge_pdf_pages(pdf_pages, pdf_page)
            fpages.append(pdf_page)

        if len(fpages) > 1:
            self.merge_pdf_pages(fpages, self.pdf_final)
        else:
            shutil.move(fpages[0], self.pdf_final)
开发者ID:byvernault,项目名称:ucl_processing,代码行数:36,代码来源:Spider_Verdict_v1_0_0.py

示例4: run_matlab

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
    def run_matlab(self, mat_template, filename):
        filepath = os.path.join(self.script_dir, filename)
        template = Template(mat_template)
        
        # Write the script
        with open(filepath, 'w') as f:
            f.write(template.substitute(self.run_inputs))

        # Run the script
        XnatUtils.run_matlab(filepath, verbose=True)
开发者ID:VUIIS,项目名称:VUIIS_DAX_SUPPORT,代码行数:12,代码来源:spiders.py

示例5: generate_4D_nifti

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
def generate_4D_nifti(folder_path):
    """
        Generate a 4D nifti from 3D nifti

        :param folder_path: folder containing the .nii files
    """
    nii_dict = organise_niftis(fpath)
    print "Converting 3D niftis into 4D nifti for folder %s ." % folder_path
    matlab_script = os.path.join(folder_path, 'convert3Din4D.m')
    f = open(matlab_script, "w")
    try:
        prefix_str = "{"
        for key in nii_dict.keys():
            prefix_str += "'%s'," % key
        prefix_str = prefix_str[:-1] + "}"
        lines = [ "% Matlab Script to call vufMRIQAGUI function\n",
                  "addpath(genpath('/Users/byvernault/home-local/masimatlab/trunk/xnatspiders/matlab/ext'));\n",
                  "addpath('/Users/byvernault/Documents/MATLAB');\n",
                  "folder_niis = '%s';\n" % folder_path,
                  "prefix = %s;\n" % prefix_str,
                  "dti = %s;\n" % (1 if ARGS.onedti else 0),
                  "untouch = %s;\n" % (1 if ARGS.untouch else 0),
                  "convert3Dto4DNII(folder_niis, prefix, dti, untouch);\n"]
        f.writelines(lines)
    finally:
        f.close()

    for key, nii_list in nii_dict.items():
        filename = os.path.join(folder_path, "%s_4D.nii.gz" % key)
        if os.path.isfile(filename):
            print"INFO: NIFTI already created. Skipping ... "
            return

    #Running Matlab script:
    XnatUtils.run_matlab(matlab_script, True)

    for key, nii_list in nii_dict.items():
        filename = os.path.join(folder_path, "%s_4D.nii" % key)
        if not os.path.isfile(filename):
            print"ERROR: NO NIFTI CREATED ... "
        else:
            # copying with fsl the header:
            print "Copying geometry from 3D nifti and gzipping the nifti for %s" % filename
            cmd = "fslcpgeom %s %s -d" % (nii_list[0], filename)
            os.system(cmd)
            os.system("gzip %s " % filename)
开发者ID:byvernault,项目名称:scripts,代码行数:48,代码来源:generate_4D_nii.py

示例6: verdict_dcm2nii

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
    def verdict_dcm2nii(self):
        """VERDICT dcm2nii conversion.

        :return: folder containing the dicom and the nifti(s) / bval / bvec
        """
        LOGGER.debug('convert dcm to nii using verdict...')
        for dicom in self.dicom_paths:
            nii_file = "%s.%s" % (os.path.splitext(dicom)[0], 'nii')
            mat_lines = DEFAULT_VERDICT_TEMPLATE.format(matlab_code=DEFAULT_MATLAB_CODE,
                                                        dcm_file=dicom,
                                                        nii_file=nii_file)
            matlab_script = os.path.join(os.path.dirname(dicom),
                                         'run_dcm2niiverdict.m')
            with open(matlab_script, "w") as f:
                f.writelines(mat_lines)
            XnatUtils.run_matlab(matlab_script)
        os.remove(matlab_script)  # remove matlab script
        matlab_log = '%s_outlog.log' % os.path.splitext(matlab_script)[0]
        os.remove(matlab_log)  # remove matlab log file
        return os.path.dirname(self.dicom_paths[0])
开发者ID:byvernault,项目名称:ucl_processing,代码行数:22,代码来源:Module_dcm2nii_VERDICT.py

示例7: run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import run_matlab [as 别名]
    def run(self):
        """Method running the process for the spider on the inputs data."""
        output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
        dcm_folder = XnatUtils.makedir(os.path.join(output_folder, 'OsiriX'))
        pdfs_dir = XnatUtils.makedir(os.path.join(output_folder, 'pdfs'))
        fpages = list()
        # Load dicom headers
        if not os.path.isfile(self.inputs['dcm']):
            err = "DICOM File %s not found."
            raise Exception(err % self.inputs['dcm'])

        for nb_acq in range(1, self.nb_acquisition+1):
            folder = os.path.join(output_folder, str(nb_acq))
            os.makedirs(folder)
            mat_lines = DEFAULT_VERDICT_TEMPLATE.format(
                    matlab_code=self.matlab_code,
                    input_path=os.path.dirname(self.inputs[nb_acq]),
                    subject=self.xnat_subject,
                    filename=os.path.basename(self.inputs[nb_acq]),
                    output=folder,
                    project=self.xnat_project,
                    camino=self.camino,
                    spams=self.spams,
                    scheme_filename=self.scheme_filename,
                    model=self.model,
                    dicom_file=self.inputs['dcm'],
                    out_dcm=dcm_folder,
                    acq=str(nb_acq),
                    suffix=PSUFFIX,
                    )
            matlab_script = os.path.join(output_folder,
                                         'run_verdict_map%d.m' % nb_acq)
            with open(matlab_script, "w") as f:
                f.writelines(mat_lines)
            self.run_matlab(matlab_script, verbose=True)

            mat_lines = PDF_TEMPLATE.format(
                    matlab_code=self.matlab_code,
                    subject=self.xnat_subject,
                    output=folder,
                    model=self.model,
                    out_pdf=pdfs_dir,
                    acq=str(nb_acq),
                    )
            matlab_script = os.path.join(output_folder,
                                         'run_pdf_%d.m' % nb_acq)
            with open(matlab_script, "w") as f:
                f.writelines(mat_lines)
            XnatUtils.run_matlab(matlab_script, verbose=True)

            pdf_pages = XnatUtils.find_files(pdfs_dir, '.pdf')
            # Merge all pdfs into one:
            pdf_page = os.path.join(output_folder, str(nb_acq),
                                    'VerdictMapAcq%d.pdf' % nb_acq)
            self.merge_pdf_pages(pdf_pages, pdf_page)
            fpages.append(pdf_page)

        # Merge PDFs:
        if len(fpages) > 1:
            self.merge_pdf_pages(fpages, self.pdf_final)
        else:
            shutil.move(fpages[0], self.pdf_final)

        # Zip the DICOMs output:
        initdir = os.getcwd()
        # Zip all the files in the directory
        zip_name = os.path.join(self.jobdir, 'outputs', 'OsiriX', 'osirix.zip')
        os.chdir(os.path.join(self.jobdir, 'outputs', 'OsiriX'))
        os.system('zip -r %s * > /dev/null' % zip_name)
        # return to the initial directory:
        os.chdir(initdir)

        # Gzip nii:
        XnatUtils.gzip_nii(os.path.join(output_folder, '1', 'AMICO',
                           self.model))
        if self.nb_acquisition == 2:
            XnatUtils.gzip_nii(os.path.join(output_folder, '2', 'AMICO',
                                            self.model))
开发者ID:byvernault,项目名称:ucl_processing,代码行数:80,代码来源:Spider_Verdict_v1_0_1.py


注:本文中的dax.XnatUtils.run_matlab方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。