0

I am looking for a solution to a problem I have, unfortunately searching the internet provided no answer. I have an array of data (20 x 100 points) with rectangular pixels, pixels in the x-direction have of size of 2 m and pixels in y-direction are 10 m. The total area of my array is 200 m x 200 m and the axes range from -100m to +100 m.

I want to reshape/reproject this data to a regular sized grid of (101 x 101 points) where the size of a pixel in x and y direction is 1 m. Points within the new array should be filled with the corresponding value of the old array

I have added a small piece of code to serve as an example below.

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,100,1)
arr = np.tile(x, (20,1))
x_size = 2
y_size = 10
plt.imshow(arr, aspect = 'auto', extent = [-100,100,-100, 100])
1
  • have you tried to use a min max scaler approach ? Commented Sep 28, 2017 at 13:02

1 Answer 1

2

I would do it with scipy.ndimage.zoom(), you just need to calculate the proper scaling factor.

import numpy as np
import scipy as sp
import scipy.ndimage

import scipy.ndimage

# generate dummy input
arr = np.arange(20 * 100).reshape((20, 100))

# resize
resized = sp.ndimage.zoom(arr, [101 / 20, 101 / 100])
print(resized.shape)
# prints: (101, 101) as expected

plt.imshow(resized)
plt.show()
Sign up to request clarification or add additional context in comments.

2 Comments

note that you may want to try out different interpolations other than the default, by playing around with the "order" argument.
This is exactly what I was looking for. Thanks!

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.