[AstroPy] Rebin FITS images and preserve or recalculate WCS?

Bernstein, Gary M garyb at PHYSICS.UPENN.EDU
Wed Aug 5 16:59:00 EDT 2020


Thanks Adam, this idea of slicing WCS objects is really clever and useful, I didn’t know about it.  I tried it out:

w1 = WCS(header=pf.getheader(’someimage.fits’))
w2 = w1[::2,::2]

and I find that the CRPIXn values have been properly changed but the CDp_q values were not changed; and w1.pixel_to_world(100.5,100.5) is quite different from w2.pixel_to_world(50.5,50.5).  So maybe it’s not fully implemented?  The docs for the `slice` method of WCS at https://docs.astropy.org/en/stable/api/astropy.wcs.WCS.html#astropy.wcs.WCS.slice suggest this is the case: "The step method, the third argument to a slice, is not presently supported.” 

I didn’t see any open issues about this on Astropy but I’m not experienced in looking through them.

Gary

> On Aug 4, 2020, at 2:41 PM, Adam Ginsburg <adam.g.ginsburg at gmail.com> wrote:
> 
> I'm a bit late to this, but I think astropy handles a lot of this really well internally with the wcs object.  You can resample any WCS object with:
> wcs[::2, ::2]
> for example, and it will do something at least close to correct (in other words, check that it looks right!)
> 
> I had written downsampling code years ago in this standalone package, but I'm sure it's outdated - I just can't find the astropy-specific tool that supplanted it
> https://fits-tools.readthedocs.io/en/latest/_modules/FITS_tools/downsample.html  
> I think the code I link there is just a more complicated version of Gary's suggestion:
> >> m,n = img.shape
> >> img = np.sum( img.reshape(m//s,s,n), axis=1)  # Contract along y
> >> Img = np.sum( img.reshape(m//s,n//s,s),axis=2). # Contract along x 
> but if you piece Gary's suggestion together with `wcs[::s, ::s]`, you should be able to do this all with vetted tools. 
> 
> On Tue, Aug 4, 2020 at 2:20 PM Kelle Cruz <kellecruz at gmail.com> wrote:
> Link to FB discussion: https://www.facebook.com/groups/astropython/permalink/2702447229999950/
> 
> and link to a printout of the discussion: 
> https://www.dropbox.com/s/zyy67kfemo03w66/%282%29%20Python%20users%20in%20Astronomy.pdf?dl=0
> 
> Kelle
> 
> --
> Kelle Cruz, PhD (she/her, they/them)
> Assoc. Professor, Physics and Astronomy, Hunter College
> CEO, ScienceBetter Consulting, LLC
> CFO, Startorialist, Inc.
> Editor-in-Chief, AstroBetter Blog and Wiki
> Director, McNulty Scholars Program, Hunter College
> Research Associate, American Museum of Natural History
> Visiting Scholar, Center for Computational Astrophysics
> 



More information about the AstroPy mailing list