Skip to content

Commit

Permalink
replace interp2d in utils_findsat_mrt (spacetelescope#210)
Browse files Browse the repository at this point in the history
* replace interp2d with RegularGridInterpolator

* pep8 and flake8 formatting fixes
  • Loading branch information
dvstark authored Aug 27, 2024
1 parent 29974b0 commit 26ab8be
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions acstools/utils_findsat_mrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,16 +1432,24 @@ def create_mrt_line_kernel(width, sigma, outfile=None, shape=(1024, 2048),
LOG.info('Inteprolating onto new grid to center kernel')
theta_arr = np.arange(cutout.shape[1])
rho_arr = np.arange(cutout.shape[0])
theta_grid, rho_grid = np.meshgrid(theta_arr, rho_arr)

new_theta_arr = theta_arr + theta_shift
new_rho_arr = rho_arr + rho_shift
new_theta_grid, new_rho_grid = np.meshgrid(new_theta_arr, new_rho_arr)

# inteprolate onto new grid
f = interpolate.interp2d(theta_grid, rho_grid, cutout.data,
kind='cubic')
cutout = f(new_theta_arr, new_rho_arr) # overwrite old cutout
f = interpolate.RegularGridInterpolator((rho_arr, theta_arr),
cutout.data,
bounds_error=False,
fill_value=0,
method='cubic')

# unable to provide 2D grid of points for interpolation. Switching to
# 1D, and then will switch back
points = [[r, t] for r, t in zip(np.ravel(new_rho_grid),
np.ravel(new_theta_grid))]

# return to original shape and replace the old cutout
cutout = np.reshape(f(points), cutout.data.shape)

if ax:
fig4, ax4 = plt.subplots()
Expand Down

0 comments on commit 26ab8be

Please sign in to comment.