Skip to content

Commit

Permalink
Add check for exposure contains in diaForcedSources.
Browse files Browse the repository at this point in the history
Rename trim_to_bbox to trim_to_exposure.

Directly use Box2D.contains

Add two more test points outside of ccd.
  • Loading branch information
morriscb committed Jan 9, 2020
1 parent 8085082 commit 68d9fe3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
25 changes: 24 additions & 1 deletion python/lsst/ap/association/diaForcedSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run(self, dia_objects, expIdBits, exposure, diffim):
diffim,
exposure)

return output_forced_sources
return self._trim_to_exposure(output_forced_sources, exposure)

def _convert_from_pandas(self, input_objects):
"""Create minimal schema SourceCatalog from a pandas DataFrame.
Expand Down Expand Up @@ -264,3 +264,26 @@ def _calibrate_and_merge(self,
output_catalog.drop(columns=self.config.dropColumns, inplace=True)

return output_catalog

def _trim_to_exposure(self, catalog, exposure):
"""Remove DiaForcedSources that are outside of the bounding box region.
Paramters
---------
catalog : `pandas.DataFrame`
DiaForcedSources to check against the exposure bounding box.
exposure : `lsst.afw.image.Exposure`
Exposure to check against.
Returns
-------
output : `pandas.DataFrame`
DataFrame trimmed to only the objects within the exposure bounding
box.
"""
bbox = geom.Box2D(exposure.getBBox())

xS = catalog.loc[:, "x"]
yS = catalog.loc[:, "y"]

return catalog[bbox.contains(xS, yS)]
22 changes: 21 additions & 1 deletion tests/test_diaForcedSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ def create_test_dia_objects(n_points, wcs, startPos=100):
src['id'] = src_idx
src.setCoord(wcs.pixelToSky(startPos + src_idx,
startPos + src_idx))

# Add points outside of the CCD.
# Fully outside.
src = objects.addNew()
src['id'] = 10000000
src.setCoord(wcs.pixelToSky(-100000,
-100000))
# y outside
src = objects.addNew()
src['id'] = 10000001
src.setCoord(wcs.pixelToSky(100,
-100000))
# x outside
src = objects.addNew()
src['id'] = 10000001
src.setCoord(wcs.pixelToSky(-100000,
100))

return objects


Expand Down Expand Up @@ -182,7 +200,9 @@ def testRun(self):
106381.94840437356, 106370.59980584883,
106369.27608815048]

self.assertEqual(len(dia_forced_sources), len(self.testDiaObjects))
# Should be number of test objects minus one as one object is purposely
# outside of the ccd area.
self.assertEqual(len(dia_forced_sources), len(self.testDiaObjects) - 3)
self.assertEqual(len(dia_forced_sources.columns),
self.expected_n_columns)

Expand Down

0 comments on commit 68d9fe3

Please sign in to comment.