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


Python XnatUtils.find_files方法代码示例

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


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

示例1: make_pdf

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import find_files [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

示例2: run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import find_files [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.find_files方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。