0

The data that I have is the frequency (f) and theta *(th) *which are coordinates that correspond to a 2d object beam (b). i.e: (f_i, th_i) == b_ii.

I set up the 2d interpolation using scipy.interpolate.interp2d. Works well, until I use new input data in descending order or with masked arrays (the mask values become 0) which re-orders the data such that zero values are first.

If I re-apply the mask it will appear in the incorrect place due to the ordering of the data. Does anyone have a simple workaround?

Note: New input values are within the bounds of the original grid setup.

Red
  • 26,798
  • 7
  • 36
  • 58
B.Eng
  • 23
  • 4

1 Answers1

0

Solution from Scipy-interp2d returned function sorts input argument automatically and undesirably

Based on the submitted at link above

from scipy.interpolate import interp2d
import numpy as np

class unsorted_interp2d(interp2d):
    def __call__(self, x, y, dx=0, dy=0):
        unsorted_idxs = np.argsort(np.argsort(x))
        return interp2d.__call__(self, x, y, dx=dx, dy=dy)[:,unsorted_idxs]

Just changed [unsorted_idxs] to [:,unsorted_idxs] to work for all x values in the 2d object

B.Eng
  • 23
  • 4