0

I’m searching for a way to interpolate a portion of a 2d array, likely with a power law approach though perhaps more knowledgeable users have other suggestions more suited to the data. In truth, I'm at a loss for how to even implement a power law approach, but my (poor) intuition is that it might do the trick.

I have an array which has a roughly circular region of masked data, similar to the example provided. I would like to interpolate across this area using the surrounding data to get an estimate for the empty region. The complication however is that on one edge (right side here) there is an additional component to the surrounding data which I know has fairly sharp borders, likely fit with a power law. So far I have tried both linear and bicubic interpolation methods however these approaches fail because they over-estimate the contribution from the region of excess on the right.

 annulus= np.array([[0.0,   0.0,    0.0,    0.0,    0.0,    0.0,    16.0,   16.0,   17.0,   18.0,   0.0,    0.0,    0.0,    0.0,    0.0],
[0.0,   0.0,    0.0,    15.0,   15.0,   16.0,   16.0,   17.0,   18.0,   19.0,   19.0,   0.0,    0.0,    0.0,    0.0],
[0.0,   0.0,    15.0,   15.0,   15.0,   16.0,   17.0,   17.0,   18.0,   19.0,   20.0,   21.0,   0.0,    0.0,    0.0],
[0.0,   0.0,    15.0,   15.0,   16.0,   16.0,   0.0,    0.0,    0.0,    20.0,   21.0,   22.0,   23.0,   0.0,    0.0],
[14.0,  14.0,   15.0,   15.0,   0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    22.0,   23.0,   25.0,   26.0,   0.0],
[14.0,  14.0,   15.0,   0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    24.0,   26.0,   28.0,   30.0],
[13.0,  14.0,   14.0,   0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    26.0,   28.0,   30.0,   33.0],
[13.0,  14.0,   14.0,   0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    25.0,   28.0,   30.0,   33.0,   0.0],
[13.0,  13.0,   14.0,   0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    24.0,   27.0,   30.0,   33.0,   0.0,    0.0],
[13.0,  13.0,   14.0,   0.0,    0.0,    0.0,    0.0,    0.0,    0.0,    26.0,   28.0,   32.0,   35.0,   0.0,    0.0],
[12.0,  13.0,   14.0,   15.0,   0.0,    0.0,    0.0,    0.0,    24.0,   27.0,   30.0,   34.0,   0.0,    0.0,    0.0],
[0.0,   13.0,   14.0,   15.0,   16.0,   0.0,    0.0,    22.0,   24.0,   27.0,   31.0,   0.0,    0.0,    0.0,    0.0],
[0.0,   0.0,    0.0,    15.0,   16.0,   18.0,   19.0,   22.0,   25.0,   28.0,   32.0,   0.0,    0.0,    0.0,    0.0],
[0.0,   0.0,    0.0,    14.0,   16.0,   18.0,   20.0,   22.0,   25.0,   29.0,   33.0,   0.0,    0.0,    0.0,    0.0],
[0.0,   0.0,    0.0,    14.0,   16.0,   18.0,   20.0,   22.0,   26.0,   29.0,   34.0,   0.0,    0.0,    0.0,    0.0]])




 #change 0 to nan
 annulus[annulus==0]='nan'

 x=np.arange(0,annulus.shape[1])
 y=np.arange(0,annulus.shape[0])

 #mask
 annulus=np.ma.masked_invalid(annulus)
 xx,yy=np.meshgrid(x,y)

 x1=xx[~annulus.mask]
 y1=yy[~annulus.mask]
 newarr=annulus[~annulus.mask]

 #for method below, "linear" instead of "cubic" applies linear interpolation.
 result=interpolate.griddata((x1,y1),newarr.ravel(),
                             (xx,yy),
                                 method='cubic')

The result is an interpolation which looks like: enter image description here.

I would like instead to find an approach which leaves lower values in the interpolated central region, taking into account the fact that the data on the right has a sharp decrease in signal strength beyond its border which lies on the edge of the interpolated zone.

norok2
  • 25,683
  • 4
  • 73
  • 99
Harry B
  • 351
  • 1
  • 5
  • 17
  • 2
    interpolating is not the right choice here in my opinion. You should instead fit your data with a 2D power law. See [here](https://scipy-cookbook.readthedocs.io/items/FittingData.html#Fitting-a-2D-gaussian) for details about 2D fitting. – gehbiszumeis Sep 18 '18 at 06:56
  • What you are really looking for is an extrapolation technique. Most of the interpolation techniques you can find around are good at extrapolation in a limited set of cases, and yours does not seem to be one of those. Since you mentioned that you already have some idea on what your data may look like, the fitting solution proposed by @gehbiszumeis seems to be a better alternative. – norok2 Sep 18 '18 at 09:03
  • Thanks @gehbiszumeis, I took a look at the link you sent and it's one I've come across before when researching the bilinear/ linear approaches. I'm curious though how to implement the power law in 2D? I'm not sure how this would change approach/ validity of the method described there for the 1D power law. – Harry B Sep 19 '18 at 01:30

0 Answers0