Skip to content

Commit

Permalink
Merge pull request #87 from lsst/tickets/DM-35589
Browse files Browse the repository at this point in the history
DM-35589: Change HEALPix backend from healpy to hpgeom.
  • Loading branch information
erykoff committed Jul 21, 2022
2 parents e448b5f + e27b0f4 commit 85af353
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 5 additions & 7 deletions python/lsst/fgcmcal/fgcmLoadReferenceCatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""

import numpy as np
import healpy as hp
import hpgeom as hpg
from astropy import units

import lsst.pex.config as pexConfig
Expand Down Expand Up @@ -143,11 +143,10 @@ def getFgcmReferenceStarsHealpix(self, nside, pixel, filterList, nest=False):
"""

# Determine the size of the sky circle to load
theta, phi = hp.pix2ang(nside, pixel, nest=nest)
center = lsst.geom.SpherePoint(phi * lsst.geom.radians, (np.pi/2. - theta) * lsst.geom.radians)
lon, lat = hpg.pixel_to_angle(nside, pixel, nest=nest, degrees=False)
center = lsst.geom.SpherePoint(lon * lsst.geom.degrees, lat * lsst.geom.radians)

corners = hp.boundaries(nside, pixel, step=1, nest=nest)
theta_phi = hp.vec2ang(np.transpose(corners))
theta_phi = hpg.boundaries(nside, pixel, step=1, nest=nest, lonlat=False)

radius = 0.0 * lsst.geom.radians
for ctheta, cphi in zip(*theta_phi):
Expand All @@ -161,8 +160,7 @@ def getFgcmReferenceStarsHealpix(self, nside, pixel, filterList, nest=False):
center.getDec().asDegrees(),
radius.asDegrees(),
filterList)
catPix = hp.ang2pix(nside, np.radians(90.0 - fgcmRefCat['dec']),
np.radians(fgcmRefCat['ra']), nest=nest)
catPix = hpg.angle_to_pixel(nside, fgcmRefCat['ra'], fgcmRefCat['dec'], nest=nest)

inPix, = np.where(catPix == pixel)

Expand Down
14 changes: 8 additions & 6 deletions python/lsst/fgcmcal/fgcmOutputProducts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import copy

import numpy as np
import healpy as hp
import hpgeom as hpg
import esutil
from astropy import units

Expand Down Expand Up @@ -582,10 +582,12 @@ def _computeReferenceOffsets(self, stdCat, lutCat, physicalFilterMap, bands):
# Note that there is an assumption here that the ra/dec coords stored
# on-disk are in radians, and therefore that starObs['coord_ra'] /
# starObs['coord_dec'] return radians when used as an array of numpy float64s.
theta = np.pi/2. - stdCat['coord_dec']
phi = stdCat['coord_ra']

ipring = hp.ang2pix(self.config.referencePixelizationNside, theta, phi)
ipring = hpg.angle_to_pixel(
self.config.referencePixelizationNside,
stdCat['coord_ra'],
stdCat['coord_dec'],
degrees=False,
)
h, rev = esutil.stat.histogram(ipring, rev=True)

gdpix, = np.where(h >= self.config.referencePixelizationMinStars)
Expand Down Expand Up @@ -685,7 +687,7 @@ def _computeOffsetOneBand(self, sourceMapper, badStarKey,
rec.set(badStarKey, True)

exposure = afwImage.ExposureF()
exposure.setFilterLabel(filterLabel)
exposure.setFilter(filterLabel)

if refFluxFields[b_index] is None:
# Need to find the flux field in the reference catalog
Expand Down
4 changes: 2 additions & 2 deletions tests/test_loadref_hsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import unittest
import os
import numpy as np
import healpy as hp
import hpgeom as hpg
import esutil
import tempfile

Expand Down Expand Up @@ -131,7 +131,7 @@ def test_fgcmLoadReference(self):

refCat = loadCat.getFgcmReferenceStarsHealpix(nside, pixel, filterList)

ipring = hp.ang2pix(nside, np.radians(90.0 - refCat['dec']), np.radians(refCat['ra']))
ipring = hpg.angle_to_pixel(nside, refCat['ra'], refCat['dec'], nest=False)
self.assertEqual(pixel, np.max(ipring))
self.assertEqual(pixel, np.min(ipring))

Expand Down

0 comments on commit 85af353

Please sign in to comment.