Skip to content
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

Closed
pllim opened this issue Aug 1, 2017 · 10 comments
Closed
Assignees
Labels

Comments

@pllim
Copy link
Contributor

pllim commented Aug 1, 2017

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?

@stsci-hack
Copy link
Contributor

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.

@mgennaro
Copy link

mgennaro commented Aug 1, 2017

Could one fake a pixel scale (say put it at 1 arseconds) and obtain an answer still?

@mcara
Copy link
Member

mcara commented Aug 1, 2017

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.

Could one fake a pixel scale (say put it at 1 arseconds) and obtain an answer still?

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.

@mcara
Copy link
Member

mcara commented Aug 1, 2017

@mgennaro I think you can do the following:

  1. Create an artificial WCS for one of the catalogs; Save the WCS as a FITS image (i.e., 'catalog1_wcs.fits';
  2. Convert RA & DEC of that catalog to "image" coordinates (x and y pixel coordinates) and save these coordinates as 'catalog1.coo'; Create a "catfile" - see Table 4.21 in TweakReg documentation
  3. Run tweakreg by passing the name of the FITS file containing the WCS, "catfile", and use second catalog as the reference catalog.

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 "sky_catalog1.txt" and "sky_catalog2.txt". We will use "sky_catalog2.txt" as a "reference" catalog when running tweakreg. Therefore we need to create a WCS for "sky_catalog1.txt" and convert that catalog from "sky" coordinates to "image" coordinates.

Let's say the "sky_catalog1.txt" catalog looks like this:

$ more sky_catalog1.txt
# RA: DEC:
59.6 72.23
59.55 72.236
59.32 72.235

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)

@mcara mcara self-assigned this Aug 1, 2017
@mcara mcara added the question label Aug 1, 2017
@mgennaro
Copy link

mgennaro commented Aug 1, 2017

That's an awesome idea @mcara thanks a lot!

@mcara
Copy link
Member

mcara commented Aug 1, 2017

@mgennaro You are welcome! I hope this will do what you need and if it does - let us know here.

@mcara mcara changed the title Matching two catalogs in tweakreg Matching two stand-alone catalogs (without images containing WCS) in tweakreg Aug 1, 2017
@mcara
Copy link
Member

mcara commented Aug 1, 2017

@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
Copy link

mgennaro commented Aug 1, 2017

@linandr @hover2pi might both be interested in following this thread in case there are further modifications (they are those that will actually need @mcara example above, I was the one trying to find out how to tweak tweakreg to help them implement something for a common project)

@mcara
Copy link
Member

mcara commented Aug 1, 2017

@mgennaro Another typo:

np.savetxt('catalog1.txt', imcat1) --> np.savetxt('catalog1.coo', imcat1)

I will edit my original answer to reflect this correction.

@mcara
Copy link
Member

mcara commented Aug 8, 2017

Due to inactivity, I think we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants