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

Spatial reproject not working for cubes with different rest frequencies #874

Open
SpacialTree opened this issue Apr 4, 2023 · 1 comment

Comments

@SpacialTree
Copy link
Contributor

I am attempting to spatially reproject one cube to another.

# cube17.header['RESTFRQ] = 230538000000.0
# cube_29.header['RESTFRQ] = 220398684200.0

cube17.reproject(cube_29.header)

I am getting the following error:

ValueError                                Traceback (most recent call last)
/scratch/local/60838376/ipykernel_89087/2137793806.py in <module>
----> 1 reproj_cube17 = interp_cube17.reproject(cube_29.header)

/blue/adamginsburg/adamginsburg/repos/spectral-cube/spectral_cube/utils.py in wrapper(self, *args, **kwargs)
     47                           PossiblySlowWarning
     48                          )
---> 49         return function(self, *args, **kwargs)
     50     return wrapper
     51 

/blue/adamginsburg/adamginsburg/repos/spectral-cube/spectral_cube/spectral_cube.py in reproject(self, header, order, use_memmap, filled, **kwargs)
   2703                                                   **reproj_kwargs)
   2704         if np.all(np.isnan(newcube)):
-> 2705             raise ValueError("All values in reprojected cube are nan.  This can be caused"
   2706                              " by an error in which coordinates do not 'round-trip'.  Try "
   2707                              "setting ``roundtrip_coords=False``.  You might also check "

ValueError: All values in reprojected cube are nan.  This can be caused by an error in which coordinates do not 'round-trip'.  Try setting ``roundtrip_coords=False``.  You might also check whether the WCS transformation produces valid pixel->world and world->pixel coordinates in each axis.

The issue seems to be that reproject is trying to take the frequency space of the cubes into account when reprojecting, making the reprojected cube be full of NaNs.

A temporary fix is to make a copy of the target header and set its rest frequency to that of the cube you are trying to reproject.

tgthdr = cube_29.header
tgthdr['RESTFRQ'] = cube_17.header['RESTFRQ'], 'HACKHACKHACK'
reproj_cube17 = cube_17.reproject(tgthdr)
@keflavich
Copy link
Contributor

this appears to be a recent change in how spectral coordinate transforms are handled by astropy. I haven't found the origin of the issue.

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

No branches or pull requests

2 participants