Coverage for python/lsst/sims/maf/maps/stellarDensityMap.py : 28%

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
8__all__ = ['StellarDensityMap']
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.
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 if startype == 'allstars':
28 self.startype = ''
29 else:
30 self.startype = startype+'_'
32 def _readMap(self):
33 filename = 'starDensity_%s_%snside_64.npz' % (self.filtername, self.startype)
34 starMap = np.load(os.path.join(self.mapDir,filename))
35 self.starMap = starMap['starDensity'].copy()
36 self.starMapBins = starMap['bins'].copy()
37 self.starmapNside = hp.npix2nside(np.size(self.starMap[:,0]))
39 def run(self, slicePoints):
40 self._readMap()
42 nsideMatch = False
43 if 'nside' in slicePoints:
44 if slicePoints['nside'] == self.starmapNside:
45 slicePoints[f'starLumFunc_{self.filtername}'] = self.starMap
46 nsideMatch = True
47 if not nsideMatch:
48 # Compute the healpix for each slicepoint on the nside=64 grid
49 indx = radec2pix(self.starmapNside, slicePoints['ra'], slicePoints['dec'])
50 slicePoints[f'starLumFunc_{self.filtername}'] = self.starMap[indx,:]
52 slicePoints[f'starMapBins_{self.filtername}'] = self.starMapBins
53 return slicePoints