mcvaneede/pyminc — pull request #5 by carlohamalainen (2013-10-12 17:22:25+00:00)
Title: Fix for the definition of miget_dimension_sizes.

The full definition from MINC-2.2.00 is:

extern int miget_dimension_sizes(const midimhandle_t dimensions[], int array_length,
unsigned int sizes[]);

The definition in libpyminc2.py has int_sizes (C's unsigned long long)
for the last parameter, but it should be uint_sizes.

Test script:

from pyminc.volumes.factory import *
import numpy as np
import os

tmp = '/tmp/test.mnc'

try:
os.remove(tmp)
except OSError:
pass

shape = (10, 20)

vol = volumeFromDescription(tmp, ['yspace', 'xspace'], shape, [-5, -5], [0.2, 0.2])
vol.data = np.random.random(shape)
print vol.data.shape # should say (10, 20)
vol.writeFile()
vol.closeVolume()

Result:

$ python test_creation.py
Traceback (most recent call last):
File "test_creation.py", line 15, in
vol.data = np.random.random(shape)
File "/usr/local/lib/python2.7/dist-packages/pyminc/volumes/volumes.py", line 63, in setdata
raise IncorrectDimsException
pyminc.volumes.volumes.IncorrectDimsException

After the fix:

$ python test_creation.py
(10, 20)

I tested scripts/pyminc_test2.py and it seemed to run successfully:

$ ./pyminc_test2.py /tmp/test.mnc numpy /tmp/test_out.mnc
4
Opening volume took 0.01000 seconds
Voxel: 0.000000
sizes: 110 217 181
0
Getting hyperslab took 0.15000 seconds
55
0
(4320470,)
(110, 217, 181)
0
computing ten neighbourhood averages using numpy method
Iterations 0 took 0.260 seconds
Iterations 1 took 0.230 seconds
Iterations 2 took 0.220 seconds
Iterations 3 took 0.230 seconds
Iterations 4 took 0.230 seconds
Iterations 5 took 0.220 seconds
Iterations 6 took 0.230 seconds
Iterations 7 took 0.230 seconds
Iterations 8 took 0.220 seconds
Iterations 9 took 0.230 seconds
done averaging. Took a total of 2.300 seconds, averaging 0.230 seconds
before volume
after volume
max and min 87 0
(110, 217, 181)
Creating new volume took 0.36000 seconds
before setting hyperslab
0
0.0
0 255 0 63.2519589304
int32 uint8
[[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

...,
[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]

[[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
...,
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]
[0 0 0 ..., 0 0 0]]]
Setting hyperslab took 0.09000 seconds

$ mincstats /tmp/test.mnc
File: /tmp/test.mnc
Mask file: (null)
Total voxels: 4320470
# voxels: 4320470
% of total: 100
Volume (mm3): 4320470
Min: 0
Max: 102.5024482
Sum: 102940629.4
Sum^2: 5570867979
Mean: 23.82625718
Variance: 721.7221255
Stddev: 26.86488648
CoM_voxel(z,y,x): 42.81716948 105.8562036 90.67176645
CoM_real(x,y,z): 0.6717664491 -20.14379639 30.81716948

Histogram: (null)
Total voxels: 4320470
# voxels: 4320470
% of total: 100
Median: 0.03855289613
Majority: 0.02562561259
BiModalT: 28.26505089
PctT [ 0%]: 0.02562561259
Entropy : 5.90236189

$ mincstats /tmp/test_out.mnc
File: /tmp/test_out.mnc
Mask file: (null)
Total voxels: 4320470
# voxels: 4320470
% of total: 100
Volume (mm3): 4320470
Min: 0
Max: 87
Sum: 93236088.69
Sum^2: 4408692362
Mean: 21.58008011
Variance: 554.7198926
Stddev: 23.55249228
CoM_voxel(z,y,x): 42.56045625 105.8436785 90.68415457
CoM_real(x,y,z): 0.6841545723 -20.15632149 30.56045625

Histogram: (null)
Total voxels: 4320470
# voxels: 4320470
% of total: 100
Median: 8.808750357
Majority: 0.02174999937
BiModalT: 24.90374947
PctT [ 0%]: 0.02174999937
Entropy : 3.946002744

Note: all testing was done on Debian Wheezy 64bit; I got segfaults
on Debian Wheezy 32bit with the latest commit and also my patches.
Is pyminc compatible with 32bit systems?