-
Notifications
You must be signed in to change notification settings - Fork 441
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
UniformGrid.points setter not stable - need to deprecate #713
Comments
Hi and welcome! Thanks for posting your first issue in the PyVista project! Someone from @pyvista/developers will chime in before too long. If your question is support related, it may be automatically transferred to https://github.com/pyvista/pyvista-support |
Thanks for reporting @lifehappenstoyou ! I'll try to reproduce. |
As expected, I encounter the same fate:
If you know those informations, there is still the option to set dimensions, spacing and origin instead of setting the points directly (as a workaround). |
Using a version of def _unique(x):
def eclose(a,b,rtol=1.0000000000000001e-05, atol=1e-08):
return np.abs(a - b) <= (atol + rtol * np.abs(b))
y = x.flat.copy()
y.sort()
ci = 0
U = np.empty((0,),dtype=y.dtype)
while ci < y.size:
ii = eclose(y[ci],y)
mi = np.max(ii.nonzero())
U = np.concatenate((U,[y[mi]]))
ci = mi + 1
return U Also, in your code snippet, you use: signal = np.ones(pixel_centers.size) I think you mean: signal = np.ones(len(pixel_centers))
|
Hi Guillaume, yes, I think introducing a tolerance in unique might be a way to solve the issue. I will for now try to build the UniformGrid from dimensions and spacings. For my immediate use there should be no problem. And propably doing it this way anyways might be best and safest for a UniformGrid. The question would be if this constructor is needed then in the first place for a UniformGrid? I originally tried a StructuredGrid which is a different story then. There are slight floating point differences do not matter when setting it up as you have to specify all points anyways. Thanks for pointing out my mistake with pixel_centers.size, you are right, it must be len(pixel_centers) instead. Since the bug appeared before I did not care to much in the minimum example. best Daniel |
What is your opinion on this @banesullivan ? |
IMO (as the person who originally implemented all of this code for
If you want to be able to explicitly set the points of a grid mesh, then you should use the Also, having the points setter is misleading: you cannot dynamically adjust the points of a |
SO my recommendation to you, @lifehappenstoyou (great username!), is to switch to using the |
Thanks for your input on this, @banesullivan. After discussing it above, not providing a point setter method for this case at all seemed to me a reasonable conclusion as well. Setting the points explicitely does not really make sense. I just ran into this problem, because I had the point coordinates at hand anyways, so I thought, why not use it? But personally I can work around this, so no real issue for me and there should not be any issue for anybody else for the reasons you pointed out once this method is taken out. Thanks to all contributors for developing pyvista. I just started using it for my project and it really saved me from digging through all the rather clumsy vtk code in most cases! Awesome work! |
I'm going to keep this open as a ticket to deprecate that setter and try to do it this weekend.
That's exactly the logic I had when implementing as I was using UniformGirds on a weird little project and just threw this feature into PyVista when implementing the Otherwise, it's awesome to hear you are enjoying and benefiting from PyVista in your work! |
Hi everyone,
I ran into an issue with the UniformGrid's points.setter method giving me the error:
I use spacings in my point grid that are float and not integer since I need to have my grid in mm coordinates. It seems that the way the spacings are determined from the point data is not stable in this case. In this case the np.unique call that is supposed to pick one of the spacings determined from the dataset return an array, which then causes the above error.
Interestingly there is a remark in the code:
TODO: this needs to be tested (unique might return a tuple)
Well, I DID the testing now, is DOES return a tuple :-). In general it does not seem so easy to deal with. I suspect that this is caused by floating point issues. The idea to take the points, reconstruct the grid parameters they have been created with and then recreate the grid seems prone to errors in itself. But I do not have good solution for this. Anyone a good idea?
To Reproduce
System Information:
The text was updated successfully, but these errors were encountered: