I'm looking for a way to locate the pixel coordinates on my FITS image that correspond to ra and dec positions of an object in degrees, after oversampling. This would be simple if I wasn't oversampling, but I need to. Given an unaltered FITS image, I can do:
from astropy.wcs import WCS
ra, dec = (43.603, 31.029)
w = WCS('myimage.fits')
x, y = w.all_world2pix(ra, dec, 1) #this gives me the pixel coordinates of the object at (ra, dec) position
However, when I oversample it and THEN try to find the pixel coordinates, it obviously isn't accurate since the (ra, dec) is no longer accurate for the oversampled image. Since I'm oversampling 5x5, I tried simply multiplying my x, y
above by 5. But when I zoom in on this point in ds9, it shows the object off-center, so I don't think this is working. Below is my oversampling part of the code, since it may help to see that. Here, data
is just the 2D numpy array of the data contained in my original FITS image.
from astropy.nddata import Cutout2D
import numpy as np
from scipy import interpolate
def oversample(data_set, N):
size = 120 #pixel size of my box cutout
geom_ctr = (np.shape(data_set)[0]//2, np.shape(data_set)[1]//2)
cutout = Cutout2D(data_set, geom_ctr, size).data
Y, X = np.shape(cutout)
x = np.linspace(0, 0.5, X)
y = np.linspace(0, 0.5, Y)
f = interpolate.interp2d(x, y, cutout, kind='cubic')
Xnew = np.linspace(0, 0.5, X*N)
Ynew = np.linspace(0, 0.5, Y*N)
new_data = f(Xnew, Ynew)
return new_data
resampled_data = oversample(data, 5)
If anyone has any ideas on how I could recover the accurate pixel coordinates after oversampling, that would be great. Thank you!