Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly handle WCS when slicing Enmap #12

Merged
merged 8 commits into from
Jan 26, 2022
Merged

properly handle WCS when slicing Enmap #12

merged 8 commits into from
Jan 26, 2022

Conversation

xzackli
Copy link
Collaborator

@xzackli xzackli commented Jan 26, 2022

This PR implements the proper WCS modifications one must make when slicing an enmap. This mostly involves modifying the CRPIX entry of the WCS structure. For example,

using Pixell

shape, wcs = fullsky_geometry(deg2rad(1); dims=(3,) )
m = Enmap(rand(shape...), wcs)
print(m.wcs.crpix, "\n", m[3:20, 50:70, 1].wcs.crpix)
[180.5, 91.0]
[178.5, 42.0]

If the stride is not 1, then CDELT can also change.

shape, wcs = fullsky_geometry(deg2rad(1))
m = Enmap(rand(shape...), wcs)
print(m.wcs.cdelt, "\n", m[3:5:24, 39:-3:2].wcs.cdelt)
[-1.0, 1.0]
[-5.0, -3.0]

In Julia, there is a syntactical distinction between slicing as copy and slicing as view. The usual array slice always copies! To avoid copies, you have to use @view or the view(...) function. This PR also provides the appropriate WCS manipulations when a view is made of an Enmap.

m = Enmap(rand(shape...), wcs)
m_view = @view m[3:24, 80:100]
print(m.wcs.crpix, "\n", m_view.wcs.crpix)
[180.5, 91.0]
[178.5, 12.0]

@xzackli xzackli merged commit 0e0edc6 into main Jan 26, 2022
@xzackli xzackli deleted the slice_geometry branch February 15, 2022 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant