Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Add axis reduction function #6

Open
cdeil opened this issue Jul 28, 2014 · 4 comments
Open

Add axis reduction function #6

cdeil opened this issue Jul 28, 2014 · 4 comments

Comments

@cdeil
Copy link
Member

cdeil commented Jul 28, 2014

We should add a function or functions to reduce the number of axes by slicing one plane or performing some reduction operation over some axis like sum or mean.

Just to illustrate what I mean, in Gammapy we have cube_to_image.
@keflavich Do you have an existing function or suggestion how to implement this in a generic way?

@keflavich
Copy link

Yes - and I think this probably does not belong in imageutils. https://github.com/radio-astro-tools/spectral-cube is the place for this, though perhaps we can factor out the spectral part. See in particular https://github.com/radio-astro-tools/spectral-cube/blob/master/spectral_cube/spectral_cube.py#L223

@cdeil
Copy link
Member Author

cdeil commented Jul 28, 2014

I'd prefer if we put this somewhere in the Astropy core ... IMO this is general enough. (It has been (partly) re-implemented in an affiliated package for radio- and one for gamma-astronomy and none want to have the other as a dependency, right?)

I think it could go in astropy.image or astropy.wcs or astropy.nddata, not sure which is best!?

@keflavich
Copy link

OK, the very simple example you illustrated in cube_to_image is basically already in astropy; e.g. https://github.com/astropy/astropy/pull/2326/files#diff-d4c5b9e74c6c26000684075497033504R1879

slice = cube[:,:,0]
slicewcs = cubewcs.dropaxis(2)
projection = cube.sum(axis=0)
projwcs = cubewcs.dropaxis(0)

@keflavich
Copy link

For more sophisticated reductions across axes, I think nddata is the right place. But for now, since it's a 2-liner to get the WCS right for these simple operations, I'd say additional wrappers are probably not necessary.

p.s. wcs.sub also does this. I only learned about it 2 months ago, but it is awesome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants