[AstroPy] Cutout2D with weird formatting

Adam Ginsburg adam.g.ginsburg at gmail.com
Mon Mar 29 21:41:00 EDT 2021


There is also a convenience function built into astropy.wcs for this
purpose:

wcs = WCS(the_header).celestial

will take the subset of the WCS that corresponds to celestial coordinates
using the wcs.sub functionality provided by wcstools internally.

On Mon, Mar 29, 2021 at 9:32 PM Eric Jensen <ejensen1 at swarthmore.edu> wrote:

> Hi Dominik,
>
> You should be able to do this by modifying the FITS header to remove the
> references to the third and fourth dimensions.
>
> Adding these lines to your code should do the trick, before you create the
> WCS from the header:
>
> # Remove length-1 dimensions:
> the_map = np.squeeze(hdul[0].data)
>
> # Get rid of references to third and fourth
> # dimensions in the FITS header:
> the_header['NAXIS'] = 2
> for f in (['CTYPE', 'CRVAL', 'CDELT',
>            'CRPIX', 'CUNIT', 'NAXIS']):
>     for i in ['3', '4']:
>         del(the_header[f + i])
> wcs = WCS(header=the_header)
>
>
> Eric
>
>
> > On Mar 25, 2021, at 11:44 AM, Dominik Rhiem <hg.dude.hg at gmail.com>
> wrote:
> >
> > Dear all,
> >
> > I am using FITS maps produced by a program called PyBDSF used for source
> detection and removal, and I want to make cutouts from these maps. However,
> the formatting of these maps is a bit weird and I am having trouble with
> making Cutout2D work with it. I have attached the fits file. Some sample
> code:
> > hdul = fits.open('test.fits')
> > the_map = hdul[0].data
> > the_header = hdul[0].header
> > position = (the_header['CRPIX1'], the_header['CRPIX2']) #I want the
> cutout to be centred on the map
> > size = 400 * u.arcsec #the cutout should have a total extent of 400
> arcsec in x and y direction
> > wcs = WCS(header=the_header)
> > cutout = Cutout2D(the_map, position, size, wcs)
> >
> > Which results in:
> > ValueError: "large_array_shape" and "small_array_shape" must have the
> same number of dimensions.
> > Importantly, the array has a shape of (1, 1, 600, 600), i.e. the actual
> 2D data array is found via:
> > the_map = the_map[0][0]
> > which is reflected in the wcs. If I try to use that definition of the
> array for the cutout, I get this error:
> > ValueError: operands could not be broadcast together with shapes (4,)
> (2,) (4,)
> >
> > How can I solve either of these issues?
> >
> > Sincerely,
> > Dominik
> >
> > <test.fits>_______________________________________________
> > AstroPy mailing list
> > AstroPy at python.org
> > https://mail.python.org/mailman/listinfo/astropy
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>


-- 
Adam Ginsburg
Assistant Professor, Department of Astronomy
University of Florida, Gainesville
http://www.adamgginsburg.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20210329/297d550b/attachment.html>


More information about the AstroPy mailing list