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

Resample to structured grid and convert to numpy array #445

Open
alexjarosch opened this issue Jun 18, 2021 · 0 comments
Open

Resample to structured grid and convert to numpy array #445

alexjarosch opened this issue Jun 18, 2021 · 0 comments

Comments

@alexjarosch
Copy link

Hi all,

I struggle with resampling a unstructured dataset to a structured grid and then convert the point dataset back to an numpy array on which I could do some math.
Here is a basic example utilizing the embryo dataset:

import pyvista as pv
from pyvista import examples
import matplotlib.pyplot as plt

# get a sample dataset
data_to_probe = examples.download_embryo()

# create a grid to resample
mesh = pv.create_grid(data_to_probe, dimensions=(70, 72, 74))

# resample the data
result = mesh.sample(data_to_probe)

# convert the resampled data to an numpy array
SLCImage = pv.point_array(result, 'SLCImage')

# attempt to reshape
SLCImage_shape = SLCImage.reshape((70, 72, 74))

# this should show a slice in the xy plane at the middel of z
plt.imshow(SLCImage_shape[:, :, 46])
plt.show()

I get the dataset and create a grid (which is structured) on a lower resolution. Then I utilize the point_array feature the extract the values from the point dataset 'SLCImage'. However in the last step when I attempt to reshape the numpy array values into a 3D array with the same dimensions as the resample grid, I fail. To prove my point I plot a slice through the extracted numpy array, which shows that the ordering of the numpy array is wrong.

Does anybody know how to reshape the point_array correctly? Any help would be highly appreciated.

Best wishes,
Alex

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

1 participant