ncullen93 / mesh2nifti

Convert a .msh file in the simNIBS format to a .nii.gz file
4 stars 2 forks source link

Python error forming 3D struct #3

Open JoshBrownNeuro opened 7 years ago

JoshBrownNeuro commented 7 years ago

Hello, This looks to be very useful, though I ran into an error while running it on this mesh file: https://iu.box.com/s/2n7l0cx1p1mdgl2zlbbhlx0wr380a9sj

Here's the error below, with much appreciation for what is probably a simple fix. Thanks!


[cclab@torch simnibs_sim]$ msh2nifti -mesh almi5_001_tdcs_scalar_171009-194715_final.msh -t1 /data/hammer/space0/nidbs_pilot/simnibs/example/simnibs2.0_example/almi5_T1fs_conform.nii.gz -out /data/hammer/space0/nidbs_pilot/simnibs/example/simnibs2.0_example/test.nii.gz --verbose Mesh File: almi5_001_tdcs_scalar_171009-194715_final.msh T1 File: /data/hammer/space0/nidbs_pilot/simnibs/example/simnibs2.0_example/almi5_T1fs_conform.nii.gz View: 2 Field: normE Voxel Size: 1 mm^3 gmsh_numpy.py: Reading almi5_001_tdcs_scalar_171009-194715_final.msh in binary with 655656 nodes 0.181132078171 seconds to read $Nodes almi5_001_tdcs_scalar_171009-194715_final.msh reading triangle block of 895574 triangles reading triangle block of 3671308 tetrahedra 2.22894096375 seconds to read $EndElements almi5_001_tdcs_scalar_171009-194715_final.msh 6.48640298843 seconds to read almi5_001_tdcs_scalar_171009-194715_final.msh Found 858200 relevant elements Getting mesh data.. Applying inverse transform to Mesh coordinates.. min/max X coordinate: 61 195 min/max Y coordinate: 33 202 min/max Z coordinate: 65 183 Pre-mapping candidate elements for each voxel.. Voxelizing the Mesh at size 1mm^3 1%|? | 1/134 [00:01<03:24, 1.54s/it] Traceback (most recent call last): File "/usr/local/simnibs/fem_efield/msh2nifti", line 350, in output_file=args.out, verbose=args.verbose) File "/usr/local/simnibs/fem_efield/msh2nifti", line 291, in msh2nifti data[x:(x+vox),y:(y+vox),z:(z+vox)] = gray_vals[cand_idx] ValueError: could not broadcast input array from shape (3) into shape (1,1,1) [cclab@torch simnibs_sim]$

ncullen93 commented 7 years ago

weird.. maybe a simnibs update. any chance you can share the T1 as well, and I can fix it tonight. If you can't share the T1, please tell me the image size and the affine transform by running:

import nibabel as nib
t1 = nib.load(t1_file)
print(t1.shape)
print(t1.affine)
JoshBrownNeuro commented 7 years ago

Awesome- thanks! Here's the T1: https://iu.box.com/s/d4yvpw8sqfgus5c4zat1y2sj3ruea9jo

JoshBrownNeuro commented 7 years ago

FYI -- I was using the default 'normE' field when calling msh2nifti. It looks like the 'normE' and 'normJ' fields are vector fields (i.e. 3D). As a rule, 3D values can't be written as a scalar voxel value, which explains why it threw an error. So maybe the best option is to simply remove the option to write 'normE' or 'normJ' fields, or else require that a projection axis be specified so that the value written is the projection of the 3D vector fields on the given axis. Anyway if I use a more sensible scalar field like 'E', the script works fine.

zeynabre commented 6 years ago

Hello, I use 'E' field and got the same error. But when I change it to 'normE' the script worked. However, I need to use the sript for field E. How can I solve the problem?