python - 脚本使用 .nrrd 文件但保存了 .npy
问题描述
我解释我的问题:
背景:我使用该文件find_borders.py
来纠正这样的小脑图像的特定部分。
从这种情况:
文件find_borders.py帮助我使用 GUI 更正保存的文件,如annotation_corrected5.npy
下一步将使用使用此工具创建的everyslice 来构建这样的 3D 结构(这是另一个区域,而不是主题区域):
现在:原始文件是一个名为 .nrrd 的文件annotations.nrrd
。但我修改的最后一次保存将始终是.npy
文件。
我只是尝试从以下位置调用 .npy 文件:
ann, h = nrrd.read(data_path+"data/annotations.nrrd")
至:
ann, h = np.load(data_path+"data/annotation_corrected5.npy")
但它返回:
Traceback (most recent call last):
File "/Users/*****/github/full_mouse_cerebellum/compute_results.py", line 29, in <module>
ann, h = np.load(data_path+"data/annotation_corrected5.npy")
ValueError: too many values to unpack (expected 2)
所以我尝试纠正:
ann = np.load(data_path+"data/annotation_corrected5.npy")
h = np.load(data_path+"data/annotation_corrected5.npy")
并且代码运行。
问题将出在带有“RuntimeWarning”的错误行上:
dens cell (528, 320, 456)
orientation: (3, 528, 320, 456)
(528, 320, 456)
[10677, 10676, 10675]
10677
molecular layer
Purkinje layer
/Users/*******/github/full_mouse_cerebellum/compute_results.py:91: RuntimeWarning: invalid value encountered in double_scalars
cell_densities.append(number_cells[-1]/volumes[-1])
/Users/*******/github/full_mouse_cerebellum/compute_results.py:92: RuntimeWarning: invalid value encountered in double_scalars
neuron_densities.append(number_neurons[-1]/volumes[-1])
granular layer
['Crus 1, molecular layer', 'Crus 1, Purkinje layer', 'Crus 1, granular layer', 'Crus 1']
i_molecular: 0
Volume molecular layer: 3.246390625
Volume purkinje layer: 0.0
Volume granular layer: 2.9016875
2937.5
0.0
[12.5 12.5 12.5 ... 62.5 62.5 62.5]
Mean down layer: 0.0
Mean up layer: 0.0
/Users/*******/github/full_mouse_cerebellum/compute_results.py:145: RuntimeWarning: invalid value encountered in true_divide
+ down_layer_distance)
Volume Stellate layer: 0.0
Volume Basket layer: 3.246390625
Total volume: 6.148078125
Voxels Granular layer: 185708
Voxels Purkinje layer: 0
Voxels Stellate layer: 0
Voxels Basket layer: 207769
Traceback (most recent call last):
File "/Users/*******/github/full_mouse_cerebellum/compute_results.py", line 173, in <module>
print("Density stellate cells - max: ", np.amax(density_stellate_all),", min: ", np.amin(density_stellate_all))
File "<__array_function__ internals>", line 6, in amax
File "/Users/*******/opt/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 2706, in amax
keepdims=keepdims, initial=initial, where=where)
File "/Users/*******/opt/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 87, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity
第一部分是正确的(显然),但我无法解决这个问题。
我想转换.npy
为.nrrd
直接绕过这个问题。
可能是个好主意吗?
如果是:有人可以帮助我进行转换吗?
非常感谢您的耐心。
解决方案
解决了:
在最后一行代码中,我写了这个:
nrrd.write(join(DATA_FOLDER, "annotation_corrected5.nrrd"), ann)
print(ann.shape)
因此,文件 .npy 将保存在 .nrrd 文件中。
推荐阅读
- eclipse - 如何在 Eclipse 4.16 中制作功能插件或扩展。请帮助我
- python - 将重复项转换为 nan 仅保留最后一次出现
- google-cloud-platform - 谷歌云sql数据读取审计日志
- c - GCC 可以警告库中未定义的函数吗?
- c++ - 为什么这些介于 0 和 1 之间的双精度数总是打印 0?
- html - 没有填充或边距:是什么让我的表格无法获得 100% 的宽度?& 为什么当鼠标悬停在可滚动的 el 上时滚动条不随滚轮滚动?
- regex - LoadError:PCRE 编译错误:lookbehind 断言不是固定长度
- reactjs - 将 Redux 选择器值传递给响应状态而不在 useEffect 中重新渲染
- c++ - 为什么 C++20 std::condition_variable 不支持 std::stop_token?
- c++ - 如何在 C++ 控制台中禁用输入法?