import healpy as hp
import numpy as np
%matplotlib inline
Investigating a question about healpy on Stackoverflow
hp.disable_warnings()
= 16
nside = hp.nside2npix(nside) npix
= hp.ma(np.arange(npix, dtype=np.float32)) m
= np.zeros(npix, dtype=np.bool)
mask 75), np.radians(105))] = 1
mask[hp.query_strip(nside, np.radians(0,0, lonlat=True), np.radians(40))] = 1 mask[hp.query_disc(nside, hp.dir2vec(
= mask m.mask
; hp.mollview(m)
= hp.Rotator(coord=["G","E"]) gal2eq
= gal2eq.rotate_map_pixel(m) m_rotated
= gal2eq.rotate_map_pixel(m.mask) mask_rotated
hp.mollview(mask_rotated)
hp.mollview(m_rotated.mask)
Now in the first case healpy
fills the map with UNSEEN
and then interpolation is handled by HEALPix C++
. I don’t know how internally HEALPix handles that. In the second case we pass a map of 0 and 1 and HEALPix does the interpolation, but we don’t trigger any special case of handling UNSEEN
values.
# consider all values less than 1 masked
== 1) np.testing.assert_array_equal(m_rotated.mask, mask_rotated
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-13-aa7e79abeb94> in <module> 1 # consider all values less than 1 masked ----> 2 np.testing.assert_array_equal(m_rotated.mask, mask_rotated == 1) [... skipping hidden 2 frame] AssertionError: Arrays are not equal Mismatched elements: 105 / 3072 (3.42%) x: array([False, False, False, ..., False, False, False]) y: array([False, False, False, ..., False, False, False])
# consider only values of 1 masked
> 0) np.testing.assert_array_equal(m_rotated.mask, mask_rotated
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-14-47376e435ed3> in <module> 1 # consider only values of 1 masked ----> 2 np.testing.assert_array_equal(m_rotated.mask, mask_rotated > 0) [... skipping hidden 2 frame] AssertionError: Arrays are not equal Mismatched elements: 169 / 3072 (5.5%) x: array([False, False, False, ..., False, False, False]) y: array([False, False, False, ..., False, False, False])
# try a value close to 1
> .9) np.testing.assert_array_equal(m_rotated.mask, mask_rotated
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-15-acaca61476b4> in <module> 1 # try a value close to 1 ----> 2 np.testing.assert_array_equal(m_rotated.mask, mask_rotated > .9) [... skipping hidden 2 frame] AssertionError: Arrays are not equal Mismatched elements: 26 / 3072 (0.846%) x: array([False, False, False, ..., False, False, False]) y: array([False, False, False, ..., False, False, False])
# try a value close to 1
> .999) np.testing.assert_array_equal(m_rotated.mask, mask_rotated
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-16-7f299a009890> in <module> 1 # try a value close to 1 ----> 2 np.testing.assert_array_equal(m_rotated.mask, mask_rotated > .999) [... skipping hidden 2 frame] AssertionError: Arrays are not equal Mismatched elements: 1 / 3072 (0.0326%) x: array([False, False, False, ..., False, False, False]) y: array([False, False, False, ..., False, False, False])
# try a value close to 1
> .9999) np.testing.assert_array_equal(m_rotated.mask, mask_rotated