-
Notifications
You must be signed in to change notification settings - Fork 107
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
Image array throws error about having no setter but still performs operation #1272
Comments
Here's my understanding—do feel free to correct me. I think this is because If the intention was for |
Honestly, I think this is a Python bug. Python thinks that something using /= requires a setter, but numpy has overridden that to work in place. You can check that the id of the array before and after is the same, so you didn't assign a new object to psf_image.array. Rather, numpy modified the elements in place. And obviously, the intent is very much NOT to have the array to be read-only. We modify Image arrays all the time. In fact that's basically the whole point of most of GalSim's functionality. I'm not sure if there is a strong need to fix this. The current workarounds are pretty easy.
Both do the same thing and avoid the exception. |
Yes, I agree it is easy to avoid this problem. I mostly raised this issue because I ran into a situation where I forgot to make the view of the array and received the error (e.g., Here's a quick mockup that seems to alleviate this behavior:
|
Pull request welcome. ;-) |
While testing, I've also found that
also works fine. Will still submit a pull request to prevent the unnecessary error from popping up when modifying |
|
Surprising in the sense that I don't recall having seen it documented. I always assumed that operations of the array values of an image had to happen on the underlying array and were not possible on the image itself (especially because most numpy operations don't work on the image object but do on the array). For example,
|
Calling numpy functions on images directly doesn't seem like an appropriate API. But arithmetic seems quite intuitive to me. YMMV. |
I guess this only works in an interactive session / debug shell, but modifying the underlying numpy array of an image can be done despite an AttributeError being thrown. For example, the following throws an
AttributeError
but the operation still has taken place. This is somewhat confusing behaviorThe text was updated successfully, but these errors were encountered: