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

Adam Ginsburg adam.g.ginsburg at gmail.com
Wed Aug 5 17:12:06 EDT 2020


Oops.  Yeah, I guess we partly implemented that - if you have a WCS that's
aligned with the celestial axes, i.e., it has CDELT specified but no CROTA
and only an identity matrix for CD, then it will work.  For other cases,
it's less straightforward.  It looks like I'm to blame for the
partially-implemented state of this:
https://github.com/astropy/astropy/blame/master/astropy/wcs/wcs.py#L3010

It might be possible, but not trivial, to generalize this to the CD case.

On Wed, Aug 5, 2020 at 4:59 PM Bernstein, Gary M <garyb at physics.upenn.edu>
wrote:

> 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
> >
>
> _______________________________________________
> 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: <http://mail.python.org/pipermail/astropy/attachments/20200805/21bfc068/attachment.html>


More information about the AstroPy mailing list