-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matching two stand-alone catalogs (without images containing WCS) in tweakreg #77
Comments
Your question, unfortunately, can not be answered with just the information you include. The shift and scale specifically refer to some defined pixel size from an image or WCS. Therefore, without a WCS from an image associated with each catalog, you can not define an offset between the two in terms of scale or shift. With the WCS information associated with each catalog, then tweakreg functions can be called to perform the fit between the two catalogs, as that is basically what tweakreg does by default. |
Could one fake a pixel scale (say put it at 1 arseconds) and obtain an answer still? |
I agree with what @stsci-hack said. Without a coordinate system scale and shifts have no meaning. In addition, if you could align the two set of points on the celestial sphere directly using, let's say, Euler rotations, you would not be able to account for scale differences.
Yes, you can. A WCS is just a coordinate system - pixel scale does not matter at least from the point of view of aligning two catalogs. I think you could create an "artificial" WCS just using your catalog points. You will have to attach that WCS to a FITS image (=write it to a FITS header) because at present I am not aware of a way to attach a WCS to a catalog. |
@mgennaro I think you can do the following:
So, let me illustrate how this could be done in more details. Let's assume that you have two catalog files containing sky coordinates of sources arranged in columns. Let's say that the two files are called Let's say the
In order to create an artificial WCS we can do the following: import numpy as np
from astropy.wcs import WCS
from astropy.io import fits
from drizzlepac.tweakreg import TweakReg
# load first catalog
cat1 = np.loadtxt('sky_catalog1.txt')
# create an artificial WCS
w = WCS()
w.wcs.crval = np.mean(cat1, axis=0)
# w.wcs.cdelt = [None, None] # <-- optional
scale = 1.0 # alternatively: 1.0e-6 (or whatever you feel would be a good scale)
w.wcs.cd = scale * np.diag(np.ones(2))
w.wcs.ctype = ['RA---TAN', 'DEC--TAN']
# create an artificial image with this WCS:
img = w.to_fits()
img[0].data = np.zeros((10,10)) # or any other size
img.writeto('catalog1_wcs.fits', clobber=True)
# create image catalog:
imcat1 = w.wcs_world2pix(cat1, 0)
np.savetxt('catalog1.coo', imcat1)
# create "catfile":
with open('catfile.txt', 'w') as f:
f.writelines(['catalog1_wcs.fits catalog1.coo'])
# Run TweakReg:
TweakReg(files='catalog1_wcs.fits', catfile='catfile.txt', refcat='sky_catalog2.txt', updatehdr=True)
# Compute "aligned" coordinates of the first catalog sources:
h = fits.open('catalog1_wcs.fits')
wnew = WCS(h[0].header)
h.close()
newcoord = wnew.wcs_pix2world(imcat1, 0)
np.savetxt('sky_catalog1_aligned.txt', newcoord) |
That's an awesome idea @mcara thanks a lot! |
@mgennaro You are welcome! I hope this will do what you need and if it does - let us know here. |
@mgennaro In previous code I found a typo: TweakReg(files='catalog1_wcs.fits', catfile='catfile.txt', refcat='sky_catalog1.txt', updatehdr=True) should have been TweakReg(files='catalog1_wcs.fits', catfile='catfile.txt', refcat='sky_catalog2.txt', updatehdr=True)
# second catalog is the reference! I edited my original message to reflect this fix. |
@mgennaro Another typo: np.savetxt('catalog1.txt', imcat1) --> np.savetxt('catalog1.coo', imcat1) I will edit my original answer to reflect this correction. |
Due to inactivity, I think we can close this issue. |
say that I have 2 catalogs (no images, just lists of coordinates, ra, dec). Any idea of how to find shift, rot, scale to "astrometrize" cat2 onto cat1?
The text was updated successfully, but these errors were encountered: