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


Python dax.XnatUtils类代码示例

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


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

示例1: run

    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,代码行数:28,代码来源:Spider_Sample_GM_Segment_v1_0_0.py

示例2: has_inputs

    def has_inputs(self, csess):
        """Method overridden from base class.

        By definition:
            status = 0  -> NEED_INPUTS,
            status = 1  -> NEED_TO_RUN
            status = -1 -> NO_DATA
            qcstatus needs a value only when -1 or 0.
        You need to set qcstatus to a short string that explain
        why it's no ready to run. e.g: No NIFTI

        :param csess: object csess define in dax.XnatUtils
                      (see XnatUtils in dax for information)
        :return: status, qcstatus
        """
        gad_cscans = XnatUtils.get_good_cscans(csess, self.gad_type)
        if not gad_cscans:
            LOGGER.debug('Vessel Registration: No GAD scan found.')
            return -1, 'No GAD found'
        elif len(gad_cscans) > 1:
            LOGGER.debug('Vessel Registration: Too many GAD scans found.')
            return 0, 'Too many GAD found'

        vessels_cscans = XnatUtils.get_good_cscans(csess, self.vessels_type)
        if not vessels_cscans:
            LOGGER.debug('Vessel Registration: No Vessels scans found.')
            return -1, 'No Vessels found'

        return 1, None
开发者ID:byvernault,项目名称:ucl_processing,代码行数:29,代码来源:Processor_Vessels_Extraction_auto.py

示例3: run

    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,代码行数:31,代码来源:Spider_fMRIQA_v2.0.0.py

示例4: make_pdf

    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,代码行数:34,代码来源:Spider_Verdict_v1_0_0.py

示例5: run

    def run(self):
        """Method running the process for the spider on the inputs data."""
        output_dir = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
        osirix_dir = XnatUtils.makedir(os.path.join(self.jobdir, 'OsiriX'))
        self.time_writer('Dicom folder: %s' % os.path.dirname(self.inputs[0]))
        mat_lines = DEFAULT_ADC_TEMPLATE.format(
                matlab_code=self.matlab_code,
                input_path=os.path.dirname(self.inputs[0]),
                output=output_dir,
                pdf_name=self.pdf_final)
        matlab_script = os.path.join(output_dir, 'run_matlab_verdict.m')
        with open(matlab_script, "w") as f:
            f.writelines(mat_lines)
        self.run_matlab(matlab_script, verbose=True)

        # Zip outputs:
        # dcm_files = glob.glob(os.path.join(output_dir, '*', '*.dcm'))
        dcm_files = get_dicom_list(output_dir)
        for dicom in dcm_files:
            shutil.copy(dicom, osirix_dir)

        self.time_writer('Zipping OsiriX resource ...')
        # Zip the DICOMs output:
        initdir = os.getcwd()
        # Zip all the files in the directory
        zip_name = os.path.join(osirix_dir, 'osirix.zip')
        os.chdir(osirix_dir)
        os.system('zip -r %s * > /dev/null' % zip_name)
        # return to the initial directory:
        os.chdir(initdir)
开发者ID:byvernault,项目名称:ucl_processing,代码行数:30,代码来源:Spider_ADC_MAP_v1_0_0.py

示例6: get_cmds

    def get_cmds(self, assessor, jobdir):
        """Method to generate the spider command for cluster job.

        :param assessor: pyxnat assessor object
        :param jobdir: jobdir where the job's output will be generated
        :return: command to execute the spider in the job script
        """
        proj_label = assessor.parent().parent().parent().label()
        subj_label = assessor.parent().parent().label()
        sess_label = assessor.parent().label()
        assr_label = assessor.label()

        csess = XnatUtils.CachedImageSession(assessor._intf, proj_label,
                                             subj_label, sess_label)
        dti_cscans = XnatUtils.get_good_cscans(csess, self.dtitypes)
        dtis = ','.join([cscan.info()['ID'] for cscan in dti_cscans])
        gif_cassrs = XnatUtils.get_good_cassr(csess, self.giftypes)
        working_dir = os.path.join(self.working_dir, assr_label)

        cmd = SPIDER_FORMAT.format(spider=self.spider_path,
                                   proj=proj_label,
                                   subj=subj_label,
                                   sess=sess_label,
                                   dir=jobdir,
                                   suffix_proc=self.suffix_proc,
                                   dti=dtis,
                                   gif=gif_cassrs[0].info()['label'],
                                   exe=self.exe,
                                   gif_path=self.exe_args,
                                   number_core=self.ppn,
                                   working_dir=working_dir)

        return [cmd]
开发者ID:byvernault,项目名称:ucl_processing,代码行数:33,代码来源:Processor_Diffusion_Model_Fitting.py

示例7: finish

 def finish(self):
     """Method to copy the results in dax.RESULTS_DIR."""
     out_dir = os.path.join(self.jobdir, 'outputs')
     # Organise the outputs:
     ala_dir = XnatUtils.makedir(os.path.join(out_dir, 'REG_ALA'))
     aff_dir = XnatUtils.makedir(os.path.join(out_dir, 'AFF'))
     reg_dir = XnatUtils.makedir(os.path.join(out_dir, 'REG_F3D'))
     cpp_dir = XnatUtils.makedir(os.path.join(out_dir, 'CPP'))
     # Copy files:
     for scan_id, res_dict in self.sources.items():
         for folder in ['REG_ALA', 'REG_F3D', 'AFF', 'CPP']:
             old_path = glob.glob(os.path.join(out_dir, scan_id,
                                               folder, '*'))[0]
             new_path = os.path.join(out_dir, folder)
             shutil.copy(old_path, new_path)
     # Zipping all the dicoms in the OSIRIX folder and keep the zip
     zip_osirix = os.path.join(out_dir, 'OSIRIX', 'osirix.zip')
     results_dict = {'PDF': self.pdf_final,
                     'REG_ALA': ala_dir,
                     'AFF': aff_dir,
                     'REG_F3D': reg_dir,
                     'CPP': cpp_dir,
                     'OSIRIX': zip_osirix}
     # Upload data:
     self.upload_dict(results_dict)
     self.end()
开发者ID:byvernault,项目名称:ucl_processing,代码行数:26,代码来源:Spider_Registration_Prostate_v1_0_0.py

示例8: get_cmds

    def get_cmds(self, assessor, jobdir):
        """Method to generate the spider command for cluster job.

        :param assessor: pyxnat assessor object
        :param jobdir: jobdir where the job's output will be generated
        :return: command to execute the spider in the job script
        """
        proj_label = assessor.parent().parent().parent().label()
        subj_label = assessor.parent().parent().label()
        sess_label = assessor.parent().label()

        nb_acq = 1
        csess = XnatUtils.CachedImageSession(assessor._intf, proj_label,
                                             subj_label, sess_label)
        reg_verdict = ''
        for cassr in csess.assessors():
            if XnatUtils.is_cassessor_good_type(cassr, [self.proctype]):
                reg_verdict = cassr

        if XnatUtils.has_resource(reg_verdict, 'ACQ2'):
            nb_acq = 2

        cmd = SPIDER_FORMAT.format(spider=self.spider_path,
                                   proj=proj_label,
                                   subj=subj_label,
                                   sess=sess_label,
                                   dir=jobdir,
                                   nb_acq=nb_acq,
                                   proctype=self.proctype,
                                   mc=self.mc,
                                   camino=self.camino,
                                   scheme=self.scheme_file,
                                   suffix_proc=self.suffix_proc)

        return [cmd]
开发者ID:byvernault,项目名称:ucl_processing,代码行数:35,代码来源:Processor_Compute_ADC_Verdict.py

示例9: generate_big_nifti

    def generate_big_nifti(self):
        """Generate big nifti with all VERDICT acquisition files."""
        for i in range(1, len(self.acquisitions.keys()) + 1):
            f_img = nib.load(self.acquisitions[i][0]['4D'])
            f_img_data = f_img.get_data()
            data = np.zeros(
                    shape=(f_img_data.shape[0],
                           f_img_data.shape[1],
                           f_img_data.shape[2],
                           f_img_data.shape[3]*len(self.acquisitions[i])))

            sorted_list = sorted(self.acquisitions[i],
                                 key=lambda k: int(k['ID']))
            for index, scan_info in enumerate(sorted_list):
                # Open niftis with nibabel
                f_img = nib.load(scan_info['reg'])
                f_img_data = f_img.get_data()

                for vol in range(0, f_img_data.shape[3]):
                    # Draw
                    vol_index = index*f_img_data.shape[3] + vol
                    data[:, :, :, vol_index] = f_img_data[:, :, :, vol]

            nii_5d = nib.Nifti1Image(data, affine=f_img.affine)
            acq_dir = XnatUtils.makedir(os.path.join(self.jobdir,
                                                     'outputs',
                                                     'ACQ%d' % i))
            filename = '%s_acquisition%d.nii' % (self.xnat_session, i)
            nii_file = os.path.join(acq_dir, filename)
            nib.save(nii_5d, nii_file)
            # gzip the nifti:
            XnatUtils.gzip_file(nii_file)
开发者ID:byvernault,项目名称:ucl_processing,代码行数:32,代码来源:Spider_Registration_Verdict_v1_0_0.py

示例10: get_cmds

    def get_cmds(self, assessor, jobdir):
        """Method to generate the spider command for cluster job.

        :param assessor: pyxnat assessor object
        :param jobdir: jobdir where the job's output will be generated
        :return: command to execute the spider in the job script
        """
        proj_label = assessor.parent().parent().parent().label()
        subj_label = assessor.parent().parent().label()
        sess_label = assessor.parent().label()

        csess = XnatUtils.CachedImageSession(assessor._intf, proj_label,
                                             subj_label, sess_label)
        target_cscans = XnatUtils.get_good_cscans(csess, self.target_type)
        target_id = target_cscans[0].info()['ID']
        source_cscans = XnatUtils.get_good_cscans(csess, self.sources_type)
        sources_id = ','.join([sc.info()['ID'] for sc in source_cscans])

        cmd = SPIDER_FORMAT.format(spider=self.spider_path,
                                   proj=proj_label,
                                   subj=subj_label,
                                   sess=sess_label,
                                   dir=jobdir,
                                   target=target_id,
                                   sources=sources_id,
                                   regaladin=self.regaladin,
                                   number_core=self.ppn,
                                   suffix_proc=self.suffix_proc)

        return [cmd]
开发者ID:byvernault,项目名称:ucl_processing,代码行数:30,代码来源:Processor_Registration2Ref.py

示例11: has_inputs

    def has_inputs(self, csess):
        """Method overridden from base class.

        By definition:
            status = 0  -> NEED_INPUTS,
            status = 1  -> NEED_TO_RUN
            status = -1 -> NO_DATA
            qcstatus needs a value only when -1 or 0.
        You need to set qcstatus to a short string that explain
        why it's no ready to run. e.g: No NIFTI

        :param csess: object csess define in dax.XnatUtils
                      (see XnatUtils in dax for information)
        :return: status, qcstatus
        """
        # Check that there is only one scan usable with the reference type and
        # that the reference file as a NIFTI
        verdict_cscans = XnatUtils.get_good_cscans(csess, self.modalities)
        if not verdict_cscans:
            LOGGER.debug('Processor_Registration_Verdict: \
        cannot run at all, no VERDICT image found')
            return -1, 'VERDICT not found'
        for cscan in verdict_cscans:
            if not XnatUtils.has_resource(cscan, 'NIFTI'):
                LOGGER.debug('Processor_Registration_Verdict: \
        cannot run, no NIFTI found for %s scan', cscan.info()['ID'])
                return 0, "Missing NIFTI"

        return 1, None
开发者ID:byvernault,项目名称:ucl_processing,代码行数:29,代码来源:Processor_Registration_Verdict.py

示例12: get_cmds

    def get_cmds(self, assessor, jobdir):
        """Method to generate the spider command for cluster job.

        :param assessor: pyxnat assessor object
        :param jobdir: jobdir where the job's output will be generated
        :return: command to execute the spider in the job script
        """
        assessor_label = assessor.label()
        proj_label = assessor.parent().parent().parent().label()
        subj_label = assessor.parent().parent().label()
        sess_label = assessor.parent().label()

        csess = XnatUtils.CachedImageSession(assessor._intf, proj_label,
                                             subj_label, sess_label)

        gad_cscans = XnatUtils.get_good_cscans(csess, self.gad_type)
        gad = self.get_file_path(gad_cscans[0], SCAN_RESOURCE)

        vessels_cscans = XnatUtils.get_good_cscans(csess, self.vessels_type)
        vessels = self.get_file_path(vessels_cscans, SCAN_RESOURCE)
        vessel_ids = [ves.info()['ID'] for ves in vessels_cscans]

        cmd = SPIDER_FORMAT.format(spider=self.spider_path,
                                   assr=assessor_label,
                                   dir=jobdir,
                                   exe=self.exe,
                                   gad=','.join(gad),
                                   vessels=','.join(vessels),
                                   vesselsids=','.join(vessel_ids),
                                   number_core=self.ppn,
                                   working_dir=self.working_dir)

        return [cmd]
开发者ID:byvernault,项目名称:ucl_processing,代码行数:33,代码来源:Processor_Vessels_Extraction_auto.py

示例13: run

    def run(self):
        """Method running the process for the spider on the inputs data."""
        output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
        osirix_folder = XnatUtils.makedir(os.path.join(output_folder,
                                                       'OsiriX'))
        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)
            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)

            # Generate Dicom for OsiriX
            outdir = os.path.join(output_folder, str(nb_acq), 'AMICO',
                                  self.model)
            # Load dicom headers
            if not os.path.isfile(self.inputs['dcm']):
                err = "DICOM File %s not found."
                raise Exception(err % self.inputs['dcm'])
            sour_obj = dicom.read_file(self.inputs['dcm'])

            # Convert all niftis to dicoms
            convert_niftis_2_dicoms(
                outdir,
                sour_obj,
                osirix_folder,
                nb_acq)

            # Subtract the Cobj to the maps:
            subtract_obj_to_map(outdir, sour_obj, osirix_folder, nb_acq)

        # Make pdf:
        self.make_pdf()

        # 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(outdir)
开发者ID:byvernault,项目名称:ucl_processing,代码行数:58,代码来源:Spider_Verdict_v1_0_0.py

示例14: run

    def run(self):
        """Method running the process for the spider on the inputs data."""
        output_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'outputs'))
        osirix_folder = XnatUtils.makedir(os.path.join(output_folder,
                                                       'OsiriX'))
        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=self.inputs[nb_acq],
                    output=folder,
                    scheme_filename=self.scheme_filename,
                    camino=self.camino)
            matlab_script = os.path.join(output_folder,
                                         'run_matlab_adc_%d.m' % nb_acq)
            with open(matlab_script, "w") as f:
                f.writelines(mat_lines)
            self.run_matlab(matlab_script, verbose=True)

            # Generate Dicom for OsiriX
            res_nii = os.path.join(folder, 'FIT_ADC.nii')
            out_nii = os.path.join(folder,
                                   '%s_FIT_ADC_%d.nii' % (self.xnat_session,
                                                          nb_acq))
            shutil.move(res_nii, out_nii)

            # Load dicom headers
            if not os.path.isfile(self.inputs['dcm']):
                err = "DICOM File %s not found."
                raise Exception(err % self.inputs['dcm'])
            sour_obj = dicom.read_file(self.inputs['dcm'])

            # Convert all niftis to dicoms
            convert_nifti_2_dicoms(
                out_nii,
                sour_obj,
                osirix_folder,
                nb_acq,
                self.xnat_project,
                self.xnat_subject,
                self.xnat_session)

            # Gzip nii:
            XnatUtils.gzip_nii(folder)

        # Make pdf:
        self.make_pdf()

        # 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)
开发者ID:byvernault,项目名称:ucl_processing,代码行数:57,代码来源:Spider_Compute_ADC_Verdict_v1_0_0.py

示例15: run_matlab

    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,代码行数:10,代码来源:spiders.py


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