Search code examples
pythonscipyndimage

ndimage map_coordinates with masked arrays


I am using ndimage to interpolate as follows:

ndimage.map_coordinates(input_data, coords, output, 2, prefilter=False)

Now, the problem is that I do not have valid measurements over my whole input data. So, I have a masked array which tells me which data points are valid. So, when doing the interpolation, I would like to only use pixels which are valid and also adjust the weightings accordingly (to ensure that the weights sum to 1).

However, I see that there is no easy way to do this. I was wondering if someone knows of a good way to do this or can point me to some library or code that I can use. I am coming from a C++ background, so still finding my way around python.


Solution

  • It sounds like you need to focus on the interpolation of data and then extract values from desired coordinates. For 1D splrep and 2D bisplrep are the interpolation functions you need to check out (A good overview). Both of these functions can be weighted and provide fine tune control over the spline function you interpolate with.

    Once you have filtered the data with the desired weights you can then determine the value at specified coordinates using.

    ndimage.map_coordinates(input_data, coords, output, prefilter=True)
    

    note the prefilter key word argument is not needed as that is the default value