2

I have a 4D dataset (time, z, y, x) and I would like to interpolate the data to get a higher resolution, this is a simple example code:

import numpy as np
from scipy.interpolate import griddata

x_0 = 10
cut_index = 10

res = 200j
x_index = x_0
y_index = np.linspace(0, 100, 50).astype(int)
z_index = np.linspace(0, 50, 25).astype(int)

#Time, zyx-coordinate
u = np.random.randn(20, 110, 110, 110)

z_index, y_index = np.meshgrid(z_index, y_index)
data = u[cut_index, z_index, y_index, x_index]


res = 200j
y_f = np.mgrid[0:100:res]
z_f = np.mgrid[0:50:res]
z_f, y_f = np.meshgrid(z_f, y_f)

data = griddata((z_index, y_index), data, (z_f, y_f))

I am getting the ValueError: invalid shape for input data points error. What kind of input is expected by the griddata function?

0

1 Answer 1

2

Your data parameter has to be a 1D array. Try flattening the arrays:

data = griddata((z_index.flatten(), y_index.flatten()), data.flatten(), (z_f, y_f))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.