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

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.keynames = [f'starLumFunc_{self.filtername}', f'starMapBins_{self.filtername}']
28 self.nside = nside
29 self.ext = ext
31 def _readMap(self):
32 if self.ext:
33 filename = 'TRIstarDensity_%s_nside_%i_ext.npz' % (self.filtername, self.nside)
34 else:
35 filename = 'TRIstarDensity_%s_nside_%i.npz' % (self.filtername, self.nside)
36 starMap = np.load(os.path.join(self.mapDir, filename))
37 self.starMap = starMap['starDensity'].copy()
38 self.starMapBins = starMap['bins'].copy()
39 self.starmapNside = hp.npix2nside(np.size(self.starMap[:, 0]))
40 # note, the trilegal maps are in galactic coordinates, and nested healpix.
41 gal_l, gal_b = _hpid2RaDec(self.nside, np.arange(hp.nside2npix(self.nside)), nest=True)
43 # Convert that to RA,dec. Then do nearest neighbor lookup.
44 ra, dec = _equatorialFromGalactic(gal_l, gal_b)
45 self.tree = _buildTree(ra, dec)
47 def run(self, slicePoints):
48 self._readMap()
50 x, y, z = _xyz_from_ra_dec(slicePoints['ra'], slicePoints['dec'])
52 dist, indices = self.tree.query(list(zip(x, y, z)))
54 slicePoints['starLumFunc_%s' % self.filtername] = self.starMap[indices, :]
55 slicePoints['starMapBins_%s' % self.filtername] = self.starMapBins
56 return slicePoints