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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

import numpy as np 

import healpy as hp 

import os 

from lsst.sims.maf.utils import radec2pix 

from lsst.utils import getPackageDir 

 

 

__all__ = ['EBVhp'] 

 

 

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

""" 

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

 

nside: Healpixel resolution (2^x) 

ra: RA (can take numpy array) 

dec: Dec (can take numpy array) 

pixles: Healpixel IDs 

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

""" 

 

22 ↛ 23line 22 didn't jump to line 23, because the condition on line 22 was never true if (ra is None) & (dec is None) & (pixels is None): 

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

 

# Load the map 

if not hasattr(EBVhp, 'nside'): 

EBVhp.nside = nside 

 

29 ↛ 36line 29 didn't jump to line 36, because the condition on line 29 was never false if (not hasattr(EBVhp, 'dustmap')) | (EBVhp.nside != nside) : 

EBVhp.nside = nside 

ebvDataDir = getPackageDir('sims_maps') 

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

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

 

# If we are interpolating to arbitrary positions 

if interp: 

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

else: 

# If we know the pixel indices we want 

if pixels is not None: 

result = EBVhp.dustMap[pixels] 

# Look up 

else: 

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

result = EBVhp.dustMap[pixels] 

 

return result