reproject icon indicating copy to clipboard operation
reproject copied to clipboard

Nans appearing in reproject_to_healpix

Open runburg opened this issue 3 years ago • 3 comments

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.

runburg avatar Mar 30 '22 23:03 runburg

A MWE would be helpful, thanks!

astrofrog avatar Mar 31 '22 07:03 astrofrog

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!

runburg avatar Mar 31 '22 23:03 runburg

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.

lfarinaa avatar Jan 19 '24 11:01 lfarinaa

@lfarinaa @runburg - this might be fixed by https://github.com/astropy/reproject/pull/459 - could you check?

astrofrog avatar Jul 25 '24 12:07 astrofrog

@runburg - looks like with #459 there are no longer any NaN values in the output of reproject_to_healpix for your example.

astrofrog avatar Jul 25 '24 13:07 astrofrog

It works fine now, as far as I can tell. I'd say you can close this. Thanks! For reference: image

lfarinaa avatar Jul 25 '24 22:07 lfarinaa

Thanks for confirming!

astrofrog avatar Jul 25 '24 22:07 astrofrog