python中接口的访问值

发布于 2025-02-11 10:53:58 字数 1385 浏览 1 评论 0原文

我在FMRI图像中阅读,其中我想计算一定的测量。

        initial_data = os.path.join(str(subject_path)+'/derivatives/participant/fmriprep/sub-'+str(subject_label)+'/ses-'+str(k)+'/func/sub-'+str(subject_label)+'_ses-'+str(k)+'_task-rest_run-3_space-MNI152NLin6Asym_desc-smoothAROMAnonaggr_bold.nii.gz')


            mean_img = MeanImage(in_file=initial_data,dimension="T",nan2zeros=False,out_file=out_file_mean)
            mean_img.run()
            sd_img = StdImage(in_file=initial_data,dimension="T",nan2zeros=False,out_file=out_file_sd)
            sd_img.run()
            division = BinaryMaths(in_file=out_file_mean,operand_file=out_file_sd,operation="div",nan2zeros=False,out_file=out_file_dv)
            division.run()
            tsnr_value_calc = ImageStats(in_file=out_file_dv,op_string="-M")
            tsnr_result = tsnr_value_calc.run()
            print(tsnr_result)

输出

220628-17:34:38,962 nipype.interface INFO:
     stdout 2022-06-28T17:34:38.962155:113.157831 

我想最终提取数字(113.157831),然后将其保存到数组中。我该怎么做?

将接口转换为使用str()的字符串不起作用。 打印接口导致:

print(tsnr_result)
<nipype.interfaces.base.support.InterfaceResult object at 0x7fd550078be0>

以下是vars和tsnr_results.outputs的输出。

vars(tsnr_results)

I read in a fMRI image where I want to calculate a certain measurement.

        initial_data = os.path.join(str(subject_path)+'/derivatives/participant/fmriprep/sub-'+str(subject_label)+'/ses-'+str(k)+'/func/sub-'+str(subject_label)+'_ses-'+str(k)+'_task-rest_run-3_space-MNI152NLin6Asym_desc-smoothAROMAnonaggr_bold.nii.gz')


            mean_img = MeanImage(in_file=initial_data,dimension="T",nan2zeros=False,out_file=out_file_mean)
            mean_img.run()
            sd_img = StdImage(in_file=initial_data,dimension="T",nan2zeros=False,out_file=out_file_sd)
            sd_img.run()
            division = BinaryMaths(in_file=out_file_mean,operand_file=out_file_sd,operation="div",nan2zeros=False,out_file=out_file_dv)
            division.run()
            tsnr_value_calc = ImageStats(in_file=out_file_dv,op_string="-M")
            tsnr_result = tsnr_value_calc.run()
            print(tsnr_result)

outputs

220628-17:34:38,962 nipype.interface INFO:
     stdout 2022-06-28T17:34:38.962155:113.157831 

I want to extract the number (113.157831) in the end and save that into an array. How would I do that?

Converting the interface to a string with str() does not work.
Printing the interface leads to:

print(tsnr_result)
<nipype.interfaces.base.support.InterfaceResult object at 0x7fd550078be0>

Here is the output of vars and tsnr_results.outputs would be the number I would need.

vars(tsnr_results)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月无声 2025-02-18 10:53:58

您可以在用分开的块中拆分字符串:并获取最后一个元素:

s = "220628-17:34:38,962 nipype.interface INFO: stdout 2022-06-28T17:34:38.962155:113.157831"

s = s.split(":")[-1]
print(s)

输出: 您可以使用float()

113.157831

You can split the string in chunks separated with : and get the last element:

s = "220628-17:34:38,962 nipype.interface INFO: stdout 2022-06-28T17:34:38.962155:113.157831"

s = s.split(":")[-1]
print(s)

Output: You can convert it to float with float()

113.157831
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文