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

memory copy issue when using sub on maps with more than 2 dims #42

Closed
xzackli opened this issue Feb 25, 2022 · 1 comment
Closed

memory copy issue when using sub on maps with more than 2 dims #42

xzackli opened this issue Feb 25, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@xzackli
Copy link
Collaborator

xzackli commented Feb 25, 2022

I think the sub function is affecting some memory references in the C struct, and does bad things to the WCSTransform.

This manifests in a strange way: the copy method is broken on such WCS.

Here's the MWE @guanyilun

using Pixell, WCS

shape, wcs = fullsky_geometry(WCSTransform, deg2rad(1))
shape = (shape..., 2)  # this is a map with shape (nx, ny, 2)
 
# read map to disk and then get it back
m = Enmap(randn(shape), wcs)
write_map("test.fits", m)
m2 = read_map("test.fits")  # add ; trim=false if PR #41 is merged
wcs = m2.wcs 

# check sky coordinates, then check sky coordinates of a *copy*
print(pix_to_world(wcs, [50., 50.]), " ", pix_to_world(copy(wcs), [50., 50.]))
[131.0, -41.0] [5.45352918278e-312, 0.0]

This is related to JuliaAstro/WCS.jl#43

@xzackli xzackli added the bug Something isn't working label Feb 25, 2022
@guanyilun guanyilun mentioned this issue Mar 1, 2022
@guanyilun
Copy link
Collaborator

guanyilun commented Mar 1, 2022

ok, I think I've figured out what is going on. When the image is loaded from disk, sub is called to trim the wcs to leave only the first two axes. I did it in a sloppy way by simply changing the naxis field. This works for all 1D fields such as crval, cdelt, etc., but it doesn't change naxis and the linear transformation matrix stored in the linprm struct in wcs.lin. For example, after the map has been read from disk (m2), wcs.naxis=2 but wcs.lin.naxis=3. This mismatch causes memory overflow when one tries to make a copy of it, resulting in the above error.

I fixed it in #47 by rewriting sub using wcslib.

@xzackli xzackli closed this as completed Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants