def _buildTree(self, simDataRa, simDataDec, leafsize=100): """Build KD tree on simDataRA/Dec using utility function from mafUtils. simDataRA, simDataDec = RA and Dec values (in radians). leafsize = the number of Ra/Dec pointings in each leaf node.""" self.opsimtree = simsUtils._buildTree(simDataRa, simDataDec, leafsize)
def _readMap(self): filename = 'TRIstarDensity_%s_nside_%i.npz' % (self.filtername, self.nside) starMap = np.load(os.path.join(self.mapDir, filename)) self.starMap = starMap['starDensity'].copy() self.starMapBins = starMap['bins'].copy() self.starmapNside = hp.npix2nside(np.size(self.starMap[:, 0])) # note, the trilegal maps are in galactic coordinates, and nested healpix. gal_l, gal_b = _hpid2RaDec(self.nside, np.arange(hp.nside2npix(self.nside)), nest=True) # Convert that to RA,dec. Then do nearest neighbor lookup. ra, dec = _equatorialFromGalactic(gal_l, gal_b) self.tree = _buildTree(ra, dec)
def __init__(self, raCol='fieldRA', decCol='fieldDec', degrees=True): self.colsReq = [raCol, decCol] self.units = ['#'] self.raCol = raCol self.decCol = decCol self.degrees = degrees fields_db = FieldsDatabase() # Returned RA/Dec coordinates in degrees fieldid, ra, dec = fields_db.get_id_ra_dec_arrays("select * from Field;") asort = np.argsort(fieldid) self.tree = _buildTree(np.radians(ra[asort]), np.radians(dec[asort]))
def testKDTreeAPI(self): """ Make sure the API provided by scipy to the kdTree algorithm is functional. """ _ra = np.linspace(0., 2.*np.pi) _dec = np.linspace(-np.pi, np.pi) Ra, Dec = np.meshgrid(_ra, _dec) tree = utils._buildTree(Ra.flatten(), Dec.flatten()) x, y, z = utils._xyz_from_ra_dec(_ra, _dec) indx = tree.query_ball_point(list(zip(x, y, z)), utils.xyz_angular_radius()) self.assertEqual(indx.shape, _ra.shape)
def testKDTreeAPI(self): """ Make sure the API provided by scipy to the kdTree algorithm is functional. """ _ra = np.linspace(0., 2. * np.pi) _dec = np.linspace(-np.pi, np.pi) Ra, Dec = np.meshgrid(_ra, _dec) tree = utils._buildTree(Ra.flatten(), Dec.flatten()) x, y, z = utils._xyz_from_ra_dec(_ra, _dec) indx = tree.query_ball_point(list(zip(x, y, z)), utils.xyz_angular_radius()) self.assertEqual(indx.shape, _ra.shape)
def _make_fields(self): """ Make tesselation of the sky """ # RA and dec in radians fields = read_fields() # crop off so we only worry about things that are up good = np.where(fields['dec'] > (self.alt_limit_rad - self.fov_rad))[0] self.fields = fields[good] self.fields_empty = np.zeros(self.fields.size) # we'll use a single tessellation of alt az leafsize = 100 self.tree = _buildTree(self.fields['RA'], self.fields['dec'], leafsize, scale=None)
def hp_kd_tree(nside=None, leafsize=100, scale=1e5): """ Generate a KD-tree of healpixel locations Parameters ---------- nside : int A valid healpix nside leafsize : int (100) Leafsize of the kdtree Returns ------- tree : scipy kdtree """ if nside is None: nside = set_default_nside() hpid = np.arange(hp.nside2npix(nside)) ra, dec = _hpid2RaDec(nside, hpid) return _buildTree(ra, dec, leafsize, scale=scale)