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 os 

2import numpy as np 

3import healpy as hp 

4from lsst.utils import getPackageDir 

5from lsst.sims.maf.utils import radec2pix 

6from . import BaseMap 

7 

8__all__ = ['StellarDensityMap'] 

9 

10class StellarDensityMap(BaseMap): 

11 """ 

12 Return the cumulative stellar luminosity function for each slicepoint. Units of stars per sq degree. 

13 Uses a healpix map of nside=64. Uses the nearest healpix point for other ra,dec values. 

14 

15 Parameters 

16 ---------- 

17 startype : str ('allstars', 'wdstars') 

18 Load the luminosity function for all stars ('allstars'), which includes main-sequence stars 

19 white dwarfs, blue horozontal branch, RR Lyrae, and Cepheids. The 'wdstars' option only includes 

20 white dwarf stars. 

21 filtername : str 

22 Filter to use. Options of u,g,r,i,z,y 

23 """ 

24 def __init__(self, startype='allstars', filtername='r'): 

25 self.mapDir = os.path.join(getPackageDir('sims_maps'), 'StarMaps') 

26 self.filtername = filtername 

27 self.keynames = [f'starLumFunc_{self.filtername}', f'starMapBins_{self.filtername}'] 

28 if startype == 'allstars': 

29 self.startype = '' 

30 else: 

31 self.startype = startype+'_' 

32 

33 def _readMap(self): 

34 filename = 'starDensity_%s_%snside_64.npz' % (self.filtername, self.startype) 

35 starMap = np.load(os.path.join(self.mapDir,filename)) 

36 self.starMap = starMap['starDensity'].copy() 

37 self.starMapBins = starMap['bins'].copy() 

38 self.starmapNside = hp.npix2nside(np.size(self.starMap[:,0])) 

39 

40 def run(self, slicePoints): 

41 self._readMap() 

42 

43 nsideMatch = False 

44 if 'nside' in slicePoints: 

45 if slicePoints['nside'] == self.starmapNside: 

46 slicePoints[f'starLumFunc_{self.filtername}'] = self.starMap 

47 nsideMatch = True 

48 if not nsideMatch: 

49 # Compute the healpix for each slicepoint on the nside=64 grid 

50 indx = radec2pix(self.starmapNside, slicePoints['ra'], slicePoints['dec']) 

51 slicePoints[f'starLumFunc_{self.filtername}'] = self.starMap[indx,:] 

52 

53 slicePoints[f'starMapBins_{self.filtername}'] = self.starMapBins 

54 return slicePoints