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


Python XnatUtils.download_file_from_obj方法代码示例

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


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

示例1: pre_run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import download_file_from_obj [as 别名]
    def pre_run(self):
        """Method to download data from XNAT.

        :param argument_parse: argument parser object return by parse_args()
        """
        resource = 'ACQ'  # resource to download from the scan on XNAT
        folder = os.path.join(self.jobdir, 'inputs')
        os.makedirs(folder)
        assessor_label = '-x-'.join([self.xnat_project,
                                     self.xnat_subject,
                                     self.xnat_session,
                                     self.proctype])

        xnat = XnatUtils.get_interface()
        a = xnat.select('/projects/%s/subjects/%s/experiments/%s/assessors/%s'
                        % (self.xnat_project, self.xnat_subject,
                           self.xnat_session, assessor_label))

        for nb_acq in range(1, self.nb_acquisition+1):
            res_name = '%s%d' % (resource, nb_acq)
            self.time_writer('Download resource: %s' % res_name)
            file_gzip = XnatUtils.download_file_from_obj(
                                  folder, a.out_resource(res_name))
            self.time_writer('Unzip file: %s' % file_gzip)
            XnatUtils.gunzip_file(file_gzip)
            self.inputs[nb_acq] = file_gzip[:-3]

        sc = XnatUtils.get_good_scans(a.parent(), DICOM_SCAN_TYPE)[0]
        dcm_file = XnatUtils.download_file_from_obj(
                              folder, sc.resource('DICOM'))
        self.inputs['dcm'] = dcm_file
        xnat.disconnect()
开发者ID:byvernault,项目名称:ucl_processing,代码行数:34,代码来源:Spider_Verdict_v1_0_1.py

示例2: pre_run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import download_file_from_obj [as 别名]
    def pre_run(self):
        """Method to download data from XNAT.

        :param argument_parse: argument parser object return by parse_args()
        """
        # Make directory
        input_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'inputs'),
                                         subdir=False)

        # Download scans:
        self.time_writer('Connection to XNAT')
        xnat = XnatUtils.get_interface(host=self.host,
                                       user=self.user,
                                       pwd=self.pwd)

        # Download NIFTIs
        index = 1
        for scan_id in self.scans_id:
            scan_info = {}
            scan_dir = XnatUtils.makedir(os.path.join(input_folder, scan_id),
                                         subdir=False)

            self.time_writer('Downloading scan ID %s ...' % scan_id)
            scan = XnatUtils.select_obj(xnat,
                                        self.xnat_project,
                                        self.xnat_subject,
                                        self.xnat_session,
                                        scan_id)
            snii_obj = scan.resource('NIFTI')
            scan_info['4D'] = XnatUtils.download_file_from_obj(scan_dir,
                                                               snii_obj)
            # Download DICOMs
            sdcm_obj = scan.resource('DICOM')
            self.time_writer('Downloading DICOM for scan ID %s ...'
                             % scan_id)

            scan_info['dicom'] = XnatUtils.download_file_from_obj(scan_dir,
                                                                  sdcm_obj)
            scan_info['type'] = scan.attrs.get('type')
            scan_info['ID'] = scan_id
            if 'b3000' in scan_info['type'].lower() and \
               len([o for o in self.acquisitions.get(index, list())
                    if 'b3000' in o['type'].lower()]) > 0:
                index += 1

            if index in self.acquisitions:
                self.acquisitions[index].append(scan_info)
            else:
                self.acquisitions[index] = [scan_info]
        xnat.disconnect()
        self.time_writer('Disconnection of XNAT')
开发者ID:byvernault,项目名称:ucl_processing,代码行数:53,代码来源:Spider_Registration_Verdict_v1_0_0.py

示例3: sorted

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import download_file_from_obj [as 别名]
        if args.sessions:
            li_scans = XnatUtils.filter_list_dicts_regex(
                li_scans, 'session_label', args.sessions.split(','))
        li_scans = sorted(li_scans, key=lambda k: k['session_label'])
        for scan_d in li_scans:
            # If type is unknown or empty, run:
            if scan_d['type'] == 'unknown' or not scan_d['type']:
                if 'DICOM' in scan_d['resources']:
                    print (" - setting type for %s/%s"
                           % (scan_d['session_label'], scan_d['ID']))
                    tmp_dir = os.path.join(directory, scan_d['session_label'],
                                           scan_d['ID'])
                    if not os.path.isdir(tmp_dir):
                        os.makedirs(tmp_dir)
                    # Download the dicom and read the header:
                    scan_obj = XnatUtils.get_full_object(xnat, scan_d)
                    dicom_file = XnatUtils.download_file_from_obj(
                        tmp_dir, scan_obj.resource('DICOM'))
                    # for dicom_path in dicom_files:
                    print "   file: %s " % dicom_file
                    dcm = dicom.read_file(dicom_file)
                    # Get the protocol name
                    protocol = dcm.ProtocolName
                    if protocol is not None:
                        # Set it to the scan
                        scan_obj.attrs.mset({'type': protocol,
                                             'series_description': protocol})

    finally:
        xnat.disconnect()
开发者ID:byvernault,项目名称:scripts,代码行数:32,代码来源:set_types_from_dicom.py

示例4: pre_run

# 需要导入模块: from dax import XnatUtils [as 别名]
# 或者: from dax.XnatUtils import download_file_from_obj [as 别名]
    def pre_run(self):
        """Method to download data from XNAT.

        :param argument_parse: argument parser object return by parse_args()
        """
        # Make directory
        input_folder = XnatUtils.makedir(os.path.join(self.jobdir, 'inputs'),
                                         subdir=False)

        # Target
        target_folder = XnatUtils.makedir(os.path.join(input_folder,
                                                       ARGS.target_id),
                                          subdir=False)
        target_dcm = XnatUtils.makedir(os.path.join(target_folder, 'DICOM'),
                                       subdir=False)
        self.time_writer('Connection to XNAT')
        xnat = XnatUtils.get_interface(host=self.host,
                                       user=self.user,
                                       pwd=self.pwd)
        self.time_writer('Downloading target %s ...' % ARGS.target_id)
        target_scan = XnatUtils.select_obj(xnat,
                                           ARGS.proj_label,
                                           ARGS.subj_label,
                                           ARGS.sess_label,
                                           ARGS.target_id)
        tnii_obj = target_scan.resource('NIFTI')
        self.target['nii'] = XnatUtils.download_file_from_obj(target_folder,
                                                              tnii_obj)
        tdcm_obj = target_scan.resource('DICOM')
        self.target['dcm'] = XnatUtils.download_files_from_obj(target_dcm,
                                                               tdcm_obj)
        self.target['type'] = target_scan.attrs.get('type')
        self.target['ID'] = ARGS.target_id

        # Sources
        sources_list = XnatUtils.get_input_list(ARGS.sources_id, list())
        self.time_writer('Downloading sources %s ...' % sources_list)
        for scan_id in sources_list:
            # Make directories
            spath = os.path.join(input_folder, scan_id)
            source_folder = XnatUtils.makedir(spath, subdir=False)
            dpath = os.path.join(source_folder, 'DICOM')
            source_dcm = XnatUtils.makedir(dpath, subdir=False)
            source_scan = XnatUtils.select_obj(xnat,
                                               ARGS.proj_label,
                                               ARGS.subj_label,
                                               ARGS.sess_label,
                                               scan_id)
            snii_obj = source_scan.resource('NIFTI')
            nii_list = XnatUtils.download_file_from_obj(source_folder,
                                                        snii_obj)
            sdcm_obj = source_scan.resource('DICOM')
            dcm_list = XnatUtils.download_file_from_obj(source_dcm, sdcm_obj)
            self.sources[scan_id] = dict()
            self.sources[scan_id]['nii'] = nii_list
            self.sources[scan_id]['dcm'] = dcm_list
            self.sources[scan_id]['type'] = source_scan.attrs.get('type')
            self.sources[scan_id]['ID'] = scan_id

        xnat.disconnect()
        self.time_writer('Disconnection of XNAT')
开发者ID:byvernault,项目名称:ucl_processing,代码行数:63,代码来源:Spider_Registration_Prostate_v1_0_0.py


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