Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voxel-wise math returns hyperslabs instead of scalar values #15

Open
gdevenyi opened this issue Feb 9, 2016 · 7 comments
Open

Voxel-wise math returns hyperslabs instead of scalar values #15

gdevenyi opened this issue Feb 9, 2016 · 7 comments

Comments

@gdevenyi
Copy link
Contributor

gdevenyi commented Feb 9, 2016

Rather than trying to manipulate minc volumes, I'm trying to do some math with the voxels.

I would've expected numpy array operations to work as expected, however they still seem to return hyperslabs, even if they would've returned a scalar without minc stuff.

Example

> infile = volumeFromFile("/home/cic/devgab/projects/OASIS/input/OAS1_0001_MR1_mpr_n4_anon_sbj_111.mnc")
> np.sum(infile.data)
        array(data=
              3188845312.0,
        start=[0 0 0], count=[160 256 256],
        separations=[-1.0, 1.0, 1.0], dimnames=[]

I would've expected just a value.

Because it's a hyperslab, I can't do further math with that value.

@jasonlerch
Copy link
Contributor

Hrm - you’re right. Not the obvious way to handle your scenario.

Quick workaround: wrap in float, i.e. float(np.sum(infile.data))

On Feb 9, 2016, at 12:59 PM, Gabriel A. Devenyi [email protected] wrote:

Rather than trying to manipulate minc volumes, I'm trying to do some math with the voxels.

I would've expected numpy array operations to work as expected, however they still seem to return hyperslabs, even if they would've returned a scalar without minc stuff.

Example

infile = volumeFromFile("/home/cic/devgab/projects/OASIS/input/OAS1_0001_MR1_mpr_n4_anon_sbj_111.mnc")
np.sum(infile.data)
array(data=
3188845312.0,
start=[0 0 0], count=[160 256 256],
separations=[-1.0, 1.0, 1.0], dimnames=[]
I would've expected just a value.

Because it's a hyperslab, I can't do further math with that value.


Reply to this email directly or view it on GitHub #15.

@gdevenyi
Copy link
Contributor Author

gdevenyi commented Feb 9, 2016

Workaround worked! Thanks.

@gdevenyi gdevenyi changed the title Docs for doing math with minc volumes? Voxel-wise math returns hyperslabs instead of scalar values Feb 9, 2016
@mcvaneede
Copy link
Member

I guess the question is how do we want to store data in a mincVolume? We can quite easily fix this issue by storing the .data part as a numpy array and storing the metadata about the hyperslab (start, count, separations and dimnames) somewhere else. That does seem like a better way to handle the data in my opinion, because it will allow you to do what Gabe was trying here more intuitively. Without the need for any casting.

Thoughts? Objections to me adding in changes to reflect this?

@gdevenyi
Copy link
Contributor Author

That seems okay to me, does that mean extra attributes that are ignored by numpy but minc operators may handle?

@mcvaneede
Copy link
Member

I've talked with Ben about this, and the real issue seems to be with subclassing in python. The HyperSlab class is a subclass of numpy's ndarray, but it doesn't fully behave as you'd expect. In that sum(), min() and max() for instance return the subclass, and not what an ndarray would return. We'll pose this question to the python/numpy world and see if they have a solution for it.

@bcdarwin
Copy link
Member

I've posted an issue on the numpy docs here; let's see what they say ...

@bcdarwin bcdarwin added bug and removed bug labels Jun 23, 2016
@bcdarwin
Copy link
Member

bcdarwin commented Jun 24, 2016

A couple people have recently replied, but there doesn't seem to be a clear fix (the suggestion we override many methods doesn't seem right) ... perhaps going with Matthijs's original suggestion would be OK, or we could leave as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants