Skip to content

Commit

Permalink
Allow for any coordinate column in functor.
Browse files Browse the repository at this point in the history
Change to self._radians
  • Loading branch information
morriscb committed Sep 16, 2021
1 parent d2e589f commit 8e35e71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions python/lsst/pipe/tasks/functors.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,28 @@ def __call__(self, catalog, **kwargs):
class HtmIndex20(Functor):
"""Compute the level 20 HtmIndex for the catalog.
"""
columns = ['coord_ra', 'coord_dec']
name = "Htm20"
htmLevel = 20
_radians = True

def __init__(self, **kwargs):
def __init__(self, ra, decl, **kwargs):
self.pixelator = sphgeom.HtmPixelization(self.htmLevel)
self.ra = ra
self.decl = decl
self._columns = [self.ra, self.decl]
super().__init__(**kwargs)

def _func(self, df):

def computePixel(row):
sphPoint = geom.SpherePoint(row["coord_ra"],
row["coord_dec"],
geom.radians)
if self._radians:
sphPoint = geom.SpherePoint(row[self.ra],
row[self.decl],
geom.radians)
else:
sphPoint = geom.SpherePoint(row[self.ra],
row[self.decl],
geom.degrees)
return self.pixelator.index(sphPoint.getVector())

return df.apply(computePixel, axis=1)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functors.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def testHtm(self):
"""Test that HtmIndxes are created as expected.
"""
parq = self.simulateMultiParquet(self.dataDict)
func = HtmIndex20()
func = HtmIndex20("coord_ra", "coord_dec")

val = self._funcVal(func, parq)
# Test that the HtmIds come out as the ra/dec in dataDict.
Expand Down

0 comments on commit 8e35e71

Please sign in to comment.