# Interpolation of a large 2d masked matrix

I have a matrix with a mask. And I wanted to do interpolation in masked regions. I tried RectBivariateSpline but it didn't recognize the masked areas as masked and used those points for interpolation. I also tried bisplrep after generating X, Y, Z 1d vectors. They were 45,900 long. It took a long time to figure out the Bsplines. And finally, with a segmentation fault when running bisplev. 2d matrix has a size of 270x170.

Is there a way to make the RectBivariateSpline not include masked areas in interpolation? Or is there another method? bisplrep was too slow.

Thanking you indiajoe

**UPDATE:**
When the grid is small, scipy.interpolate.Rbf with a "linear" function does a reasonable job. But it gives error when the array is large.

Is there any other function that will allow me to interpolate and flatten my matrix?

I also concluded the following. Correct me if I am wrong.

1) RectBivariateSpline requires a perfectly filled matrix and therefore masked matrices cannot be used.

source to share

Very late, but ...

I have a problem similar to yours and I am getting a segmentation error with bisplines as well as a memory error with rbf (in which the "thin_plate" function works fine for me.

Since my data is unstructured, but generated in a structured manner, I am using downsampling to half or one third of the data point density so that I can use Rbf. I advise you to do (very inefficient, but still better than not doing at all) to split the matrix in many overlapping regions, then create rbf interpolators for each region, and then when you interpolate one point, you choose the appropriate interpolator.

~~Also, if you have a masked array, you can still interpolate on the unmasked array and then apply the mask to the result. ~~(well not really, see comments)

Hope this helps someone.

source to share