Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import numpy as np 

2import healpy as hp 

3import os 

4from lsst.sims.maf.utils import radec2pix 

5from lsst.utils import getPackageDir 

6 

7 

8__all__ = ['EBVhp'] 

9 

10 

11def EBVhp(nside, ra=None,dec=None, pixels=None, interp=False): 

12 """ 

13 Read in a healpix dust map and return values for given RA, Dec values 

14 

15 nside: Healpixel resolution (2^x) 

16 ra: RA (can take numpy array) 

17 dec: Dec (can take numpy array) 

18 pixles: Healpixel IDs 

19 interp: Should returned values be interpolated (True) or just nearest neighbor(False) 

20 """ 

21 

22 if (ra is None) & (dec is None) & (pixels is None): 

23 raise RuntimeError("Need to set ra,dec or pixels.") 

24 

25 # Load the map 

26 if not hasattr(EBVhp, 'nside'): 

27 EBVhp.nside = nside 

28 

29 if (not hasattr(EBVhp, 'dustmap')) | (EBVhp.nside != nside) : 

30 EBVhp.nside = nside 

31 ebvDataDir = getPackageDir('sims_maps') 

32 filename = 'DustMaps/dust_nside_%i.npz'%EBVhp.nside 

33 EBVhp.dustMap = np.load(os.path.join(ebvDataDir,filename))['ebvMap'] 

34 

35 # If we are interpolating to arbitrary positions 

36 if interp: 

37 result = hp.get_interp_val(EBVhp.dustMap, np.pi/2. - dec , ra ) 

38 else: 

39 # If we know the pixel indices we want 

40 if pixels is not None: 

41 result = EBVhp.dustMap[pixels] 

42 # Look up 

43 else: 

44 pixels = radec2pix(EBVhp.nside,ra,dec) 

45 result = EBVhp.dustMap[pixels] 

46 

47 return result