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

Nans appearing in reproject_to_healpix #284

Open
runburg opened this issue Mar 30, 2022 · 3 comments
Open

Nans appearing in reproject_to_healpix #284

runburg opened this issue Mar 30, 2022 · 3 comments

Comments

@runburg
Copy link

runburg commented Mar 30, 2022

I might be misunderstanding something, but I find that when using reproject_to_healpix, the returned healpy map has exactly nside number of NaN pixels. I'm trying to reproject the Fermi galactic background map and I persistently get NaN pixels in the reprojection where there are none before the projection.

I can add an MWE and a sample file if needed.

@astrofrog
Copy link
Member

A MWE would be helpful, thanks!

@runburg
Copy link
Author

runburg commented Mar 31, 2022

The Fermi background file is here: https://fermi.gsfc.nasa.gov/ssc/data/access/lat/BackgroundModels.html

from astropy.io import fits
from astropy.wcs import WCS
import reproject

# this is the Fermi galactic background map
gal_bg = fits.open('gll_iem_v07.fits')

wcs = WCS(gal_bg[0].header).dropaxis(2)

hpx_map, footprint = reproject.reproject_to_healpix((gal_bg[0].data[0], wcs), 'galactic', nside=nside)

Here hpx_map has nside number of NaNs and footprint has nside number of 0s. Let me know if this is unclear or doesn't work!

@lfarinaa
Copy link

A kind reminder that this is not fixed. These pixels correspond to the nside pixels that run along the meridian that bisects the rhomboid at the "back" of the healpix tesellation. See fig:
image
I would say that this could be a symptom that whatever backend is used by reproject_to_healpix (I think this would be map_coordinates) doesn't understand that the image wraps at -180/180 deg, and so the centers of these pixels appear to be beyond the domain of the image you are reprojecting.

As a stopgap, I'm re-interpolating from the neighboring reprojected pixels:

badPix=np.argwhere(np.isnan(hMap))
badPixNeigh=hp.pixelfunc.get_all_neighbours(nsideGalFlux,badPix)
for i in np.arange(0,nside):
    hMap[badPix[i]]=np.nanmean(hMap[badPixNeigh[:,i]])

(Renormalize afterwards)
Obviously, this in not a great solution. It would be great if someone could take a quick look at this.

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

3 participants