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

Eric Jensen ejensen1 at swarthmore.edu
Tue Aug 4 16:55:40 EDT 2020

Ah, excellent!  This is the kind of thing I was hoping for. 

I’ll play around with Larry’s suggestion of block_reduce combined with Adam’s idea of WCS resampling and see if I can come up with a compact solution.   It may be a little bit before I get to test it fully, but I’ll definitely post back here to share the final product. 

Thanks to all for the help!


> On Aug 4, 2020, at 2:46 PM, Larry Bradley <larry.bradley at gmail.com> wrote:
> The astropy function to downsample an array by applying a user-supplied function (e.g., np.mean, np.sum) to local blocks is block_reduce (https://docs.astropy.org/en/latest/api/astropy.nddata.block_reduce.html <https://docs.astropy.org/en/latest/api/astropy.nddata.block_reduce.html>).  It does not handle the WCS.
> On Tue, Aug 4, 2020 at 2:41 PM Adam Ginsburg <adam.g.ginsburg at gmail.com <mailto: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 <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. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20200804/fd44f1a2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3946 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20200804/fd44f1a2/attachment.bin>

More information about the AstroPy mailing list