Coverage for python/lsst/sims/maf/slicers/healpixSDSSSlicer.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 numpy as np
2from .healpixSlicer import HealpixSlicer
3from functools import wraps
4import matplotlib.path as mplPath
5from lsst.sims.maf.utils.mafUtils import gnomonic_project_toxy
6from lsst.sims.maf.plots import HealpixSDSSSkyMap
8__all__ = ['HealpixSDSSSlicer']
10class HealpixSDSSSlicer(HealpixSlicer):
11 """For use with SDSS stripe 82 square images """
12 def __init__(self, nside=128, lonCol ='RA1' , latCol='Dec1', verbose=True,
13 useCache=True, radius=17./60., leafsize=100, **kwargs):
14 """Using one corner of the chip as the spatial key and the diagonal as the radius. """
15 super(HealpixSDSSSlicer,self).__init__(verbose=verbose,
16 lonCol=lonCol, latCol=latCol,
17 radius=radius, leafsize=leafsize,
18 useCache=useCache,nside=nside )
19 self.cornerLables = ['RA1', 'Dec1', 'RA2','Dec2','RA3','Dec3','RA4','Dec4']
20 self.plotFuncs = [HealpixSDSSSkyMap,]
22 def setupSlicer(self, simData, maps=None):
23 """
24 Use simData[self.lonCol] and simData[self.latCol]
25 (in radians) to set up KDTree.
26 """
27 self._runMaps(maps)
28 self._buildTree(simData[self.lonCol], simData[self.latCol], self.leafsize)
29 self._setRad(self.radius)
30 self.corners = simData[self.cornerLables]
31 @wraps(self._sliceSimData)
32 def _sliceSimData(islice):
33 """Return indexes for relevant opsim data at slicepoint
34 (slicepoint=lonCol/latCol value .. usually ra/dec)."""
35 sx, sy, sz = self._treexyz(self.slicePoints['ra'][islice], self.slicePoints['dec'][islice])
36 # Query against tree.
37 initIndices = self.opsimtree.query_ball_point((sx, sy, sz), self.rad)
38 # Loop through all the images and check if the slicepoint is inside the corners of the chip
39 # XXX--should check if there's a better/faster way to do this.
40 # Maybe in the setupSlicer loop through each image, and use the contains_points method to test all the
41 # healpixels simultaneously? Then just have a dict with keys = healpix id and values = list of indices?
42 # That way _sliceSimData is just doing a dict look-up and we can get rid of the spatialkey kwargs.
45 indices=[]
46 # Gnomic project all the corners that are near the slice point, centered on slice point
47 x1,y1 = gnomonic_project_toxy(self.corners['RA1'][initIndices], self.corners['Dec1'][initIndices],
48 self.slicePoints['ra'][islice], self.slicePoints['dec'][islice])
49 x2,y2 = gnomonic_project_toxy(self.corners['RA2'][initIndices], self.corners['Dec2'][initIndices],
50 self.slicePoints['ra'][islice], self.slicePoints['dec'][islice])
51 x3,y3 = gnomonic_project_toxy(self.corners['RA3'][initIndices], self.corners['Dec3'][initIndices],
52 self.slicePoints['ra'][islice], self.slicePoints['dec'][islice])
53 x4,y4 = gnomonic_project_toxy(self.corners['RA4'][initIndices], self.corners['Dec4'][initIndices],
54 self.slicePoints['ra'][islice], self.slicePoints['dec'][islice])
56 for i,ind in enumerate(initIndices):
57 # Use matplotlib to make a polygon on
58 bbPath = mplPath.Path(np.array([[x1[i], y1[i]],
59 [x2[i], y2[i]],
60 [x3[i], y3[i]],
61 [x4[i], y4[i]],
62 [x1[i], y1[i]]] ))
63 # Check if the slicepoint is inside the image corners and append to list if it is
64 if bbPath.contains_point((0.,0.)) == 1:
65 indices.append(ind)
67 return {'idxs':indices,
68 'slicePoint':{'sid':self.slicePoints['sid'][islice],
69 'ra':self.slicePoints['ra'][islice],
70 'dec':self.slicePoints['dec'][islice]}}
71 setattr(self, '_sliceSimData', _sliceSimData)