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

Maintining ufunc compatibility #4

Open
msyriac opened this issue Feb 8, 2017 · 2 comments
Open

Maintining ufunc compatibility #4

msyriac opened this issue Feb 8, 2017 · 2 comments

Comments

@msyriac
Copy link
Contributor

msyriac commented Feb 8, 2017

I've started playing around with enlib and love how it inherits from numpy. But sometimes, the enlib-ness of a map gets stripped away when I pass it to a ufunc. For example:

>>> type(fAlpha)
<class 'enlib.enmap.ndmap'>
>>> retMap = np.fft.ifftshift(enmap.ifft(fAlpha).real)
>>> type(retMap)
<type 'numpy.ndarray'>

How can we prevent this? My workaround right now is to do something like:

retMap = np.fft.ifftshift(enmap.ifft(fAlpha).real)+fAlpha*0.

to allow it to retain its wcs.

@amaurea
Copy link
Owner

amaurea commented Feb 9, 2017

Yes, I agree that that would be nice. I have a function for giving back the wcs, but it's not very convenient:

retMap = enmap.samewcs(np.fft.ifftshift(enmap.ifft(fAlpha).real), fAlpha)

This isn't necessary for all functions. For example np.sum works fine and preserves the subclass. The problem is functions that clobber the subclass, for example by using np.asarray instead of np.asanyarray. I don't know of any way to make these functions behave, other than adding thousands of wrappers for them in enmap, and avoiding that was the main reason for making enmap a subclass in of ndarray in the first case.

If you have an idea for a better way of doing this, I'd love to hear it.

@msyriac
Copy link
Contributor Author

msyriac commented Feb 9, 2017

It's unfortunate that it is the ubiquitous np.asarray that causes this. I don't have a better way. I've raised the question here:
http://stackoverflow.com/questions/42126858/numpy-functions-clobber-my-inherited-dataype

Thanks for the samewcs tip.

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

2 participants