Cutout2D not updated wcs properly (?)

613 views
Skip to first unread message

Matt Stevans

unread,
Nov 19, 2015, 10:07:32 PM11/19/15
to astropy-dev
I'm using Cutout2D (from astropy.nddata.utils) to make a postage stamp cutout of an array from a FITS image. When I pass a wcs objects with the original wcs, Cutout2D should update it, but I don't think it is updating correctly because when I display the stamp in ds9 and match the stamp frame wcs to the wcs of the original image frame, the stamp appears with a huge zoom (i.e. the stamp is stretched such that the original image could fit inside the areas of a few stamp pixels) [see image below]. What's odd is that the coordinates shown in the ds9 display when moving the mouse over pixels in the stamp image appear to match the coordinates displayed in ds9 when moving the mouse over the identical pixels in the original image. So the pixels in both images seem to have the same coordinates, but the images don't align when matched by wcs and when running Source Extractor on the stamp images, sources get assigned nonsensical coordinates (e.g. RA: 98.95 Dec: -60.91 when it should be something like Ra: 21, Dec: -0.05).

I'm using Astropy v1.1.dev14093

Here's the code I use which follows the tutorial here: http://astropy.readthedocs.org/en/latest/nddata/utils.html#cutout-images


from astropy.io import fits 
from astropy import wcs
import numpy as np
from astropy.nddata import Cutout2D

f = fits.open(in_file)  #read in original FITS image with the input image path in in_file
scidata = f[0].data
header = f[0].header
w = wcs.WCS(f[0].header)

position = (header['CRPIX1'],  header['CRPIX2'])  #define the center pixel of the stamp
size = (2133,2133)  #define the dimensions of the stamp (which is ~15% of the image dimensions)
cutout = Cutout2D(scidata, position, size, wcs=w)

header_new = cutout.wcs.to_header()

hdu = fits.PrimaryHDU(cutout.data,header=header_new) #create new hdu
hdulist = fits.HDUList([hdu]) #create new hdulist
hdulist.writeto(out_file)



Below is a screen grab of the ds9 display with the original image on the right with its wcs matched to stamp image's wcs (on the left).


Below are the header files for the two images as displayed by ds9 (the original image's header is first):


Can anyone help me identify what's wrong here?



Adam Ginsburg

unread,
Nov 20, 2015, 1:40:53 AM11/20/15
to astro...@googlegroups.com
I recall seeing a bug like this sometime in the last year, but I'm not entirely sure what the fix was.  Some questions, though:
1. What version of ds9 are you using?
2. Could you send the whole headers as text rather than as screenshots?  I'm particularly interested in whether there are CDELT and/or PC keywords.  I think ds9 may have difficulty understanding headers with both CD and PC arrays defined.

--
You received this message because you are subscribed to the Google Groups "astropy-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to astropy-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Adam Ginsburg
Fellow, European Southern Observatory
http://www.adamgginsburg.com/

Matt Stevans

unread,
Nov 20, 2015, 10:38:10 AM11/20/15
to astropy-dev, adam.g....@gmail.com
Hi Adam,

I am using ds9 version 7.3.2.

Attached are the two header files in text.

-Matt
header_original.txt
header_stamp.txt

Adam Ginsburg

unread,
Nov 20, 2015, 11:43:04 AM11/20/15
to Matt Stevans, astropy-dev
So I think this is a ds9 bug, but I'd like to hear confirmation from others - maybe it's a WCS issue.  In the stamp, CDELT1 and CDELT2 are set to 1.0, and the pixel size is stored in PC1_1 and PC2_2.  A workaround is, in ds9, edit the WCS by going into the WCS menu: WCS parameters and change the CDELT values to be the PC values.  Or you can just edit the stamp's header moving the PCs into the CDELTs.

Matt Stevans

unread,
Nov 20, 2015, 12:11:59 PM11/20/15
to astropy-dev, ste...@astro.as.utexas.edu, adam.g....@gmail.com
Thanks for the work around Adam. I played around with different combination of cards and I liked moving the PC values to the CD values for the stamp because the original image uses the CD values. Do you know of any advantages or disadvantages to using a certain combination of cards over others (like using CDs over PCs or CDELTs?)?

-Matt
Reply all
Reply to author
Forward
0 new messages