Coverage for python/lsst/sims/maf/maps/trilegalMap.py : 33%

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.utils import _hpid2RaDec, _equatorialFromGalactic, _buildTree, _xyz_from_ra_dec
6from . import BaseMap
8__all__ = ['TrilegalDensityMap']
11class TrilegalDensityMap(BaseMap):
12 """
13 Return the cumulative stellar luminosity function for each slicepoint. Units of stars per sq degree.
15 Parameters
16 ----------
17 filtername : str
18 Filter to use. Options of u,g,r,i,z,y
19 nside : int (64)
20 The HEALpix nside (can be 64 or 128)
21 ext : bool (False)
22 Use the full sky maps
23 """
24 def __init__(self, filtername='r', nside=64, ext=False):
25 self.mapDir = os.path.join(getPackageDir('sims_maps'), 'TriMaps')
26 self.filtername = filtername
27 self.nside = nside
28 self.ext = ext
30 def _readMap(self):
31 if self.ext:
32 filename = 'TRIstarDensity_%s_nside_%i_ext.npz' % (self.filtername, self.nside)
33 else:
34 filename = 'TRIstarDensity_%s_nside_%i.npz' % (self.filtername, self.nside)
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 # note, the trilegal maps are in galactic coordinates, and nested healpix.
40 gal_l, gal_b = _hpid2RaDec(self.nside, np.arange(hp.nside2npix(self.nside)), nest=True)
42 # Convert that to RA,dec. Then do nearest neighbor lookup.
43 ra, dec = _equatorialFromGalactic(gal_l, gal_b)
44 self.tree = _buildTree(ra, dec)
46 def run(self, slicePoints):
47 self._readMap()
49 x, y, z = _xyz_from_ra_dec(slicePoints['ra'], slicePoints['dec'])
51 dist, indices = self.tree.query(list(zip(x, y, z)))
53 slicePoints['starLumFunc_%s' % self.filtername] = self.starMap[indices, :]
54 slicePoints['starMapBins_%s' % self.filtername] = self.starMapBins
55 return slicePoints