|
26 | 26 | import astropy.units as u
|
27 | 27 | import warnings
|
28 | 28 |
|
| 29 | +import lsst.afw.image |
29 | 30 | import lsst.afw.table
|
30 | 31 | import lsst.meas.algorithms
|
31 | 32 | import lsst.meas.base.tests
|
@@ -56,28 +57,35 @@ def setUp(self):
|
56 | 57 | schema.addField("nChild", np.int32, "Number of children")
|
57 | 58 | schema.addField("detect_isPrimary", "Flag", "Is primary detection?")
|
58 | 59 | schema.addField("sky_source", "Flag", "Empty sky region.")
|
| 60 | + |
| 61 | + self.xCol = "centroid_x" |
| 62 | + self.yCol = "centroid_y" |
| 63 | + schema.addField(self.xCol, float, "Centroid x value.") |
| 64 | + schema.addField(self.yCol, float, "Centroid y value.") |
| 65 | + |
59 | 66 | self.catalog = lsst.afw.table.SourceCatalog(schema)
|
60 | 67 | self.catalog.reserve(10)
|
61 | 68 | self.config = self.Task.ConfigClass()
|
| 69 | + self.exposure = None |
62 | 70 |
|
63 | 71 | def tearDown(self):
|
64 | 72 | del self.catalog
|
65 | 73 |
|
66 | 74 | def check(self, expected):
|
67 | 75 | task = self.Task(config=self.config)
|
68 |
| - results = task.run(self.catalog) |
| 76 | + results = task.run(self.catalog, exposure=self.exposure) |
69 | 77 | self.assertListEqual(results.selected.tolist(), expected)
|
70 | 78 | self.assertListEqual([src.getId() for src in results.sourceCat],
|
71 | 79 | [src.getId() for src, ok in zip(self.catalog, expected) if ok])
|
72 | 80 |
|
73 | 81 | # Check with pandas.DataFrame version of catalog
|
74 |
| - results = task.run(self.catalog.asAstropy().to_pandas()) |
| 82 | + results = task.run(self.catalog.asAstropy().to_pandas(), exposure=self.exposure) |
75 | 83 | self.assertListEqual(results.selected.tolist(), expected)
|
76 | 84 | self.assertListEqual(list(results.sourceCat['id']),
|
77 | 85 | [src.getId() for src, ok in zip(self.catalog, expected) if ok])
|
78 | 86 |
|
79 | 87 | # Check with astropy.table.Table version of catalog
|
80 |
| - results = task.run(self.catalog.asAstropy()) |
| 88 | + results = task.run(self.catalog.asAstropy(), exposure=self.exposure) |
81 | 89 | self.assertListEqual(results.selected.tolist(), expected)
|
82 | 90 | self.assertListEqual(list(results.sourceCat['id']),
|
83 | 91 | [src.getId() for src, ok in zip(self.catalog, expected) if ok])
|
@@ -369,6 +377,40 @@ def testFiniteRaDec(self):
|
369 | 377 |
|
370 | 378 | self.check([False, False, True, True, True])
|
371 | 379 |
|
| 380 | + def testCullFromMaskedRegion(self): |
| 381 | + # Test that objects whose centroids land on specified mask(s) are |
| 382 | + # culled. |
| 383 | + maskNames = ["NO_DATA", "BLAH"] |
| 384 | + noDataPoints = [[0, 0], [3, 2]] |
| 385 | + self.exposure = lsst.afw.image.ExposureF(5, 5) |
| 386 | + mask = self.exposure.mask |
| 387 | + for maskName in maskNames: |
| 388 | + if maskName not in mask.getMaskPlaneDict(): |
| 389 | + mask.addMaskPlane(maskName) |
| 390 | + num = 5 |
| 391 | + for _ in range(num): |
| 392 | + self.catalog.addNew() |
| 393 | + self.catalog[self.xCol][:] = 5.0 |
| 394 | + self.catalog[self.yCol][:] = 5.0 |
| 395 | + |
| 396 | + # Set first two entries in catalog to land maskNames region. |
| 397 | + for i, noDataPoint in enumerate(noDataPoints): |
| 398 | + # Flip x & y for numpy array convention. |
| 399 | + mask.array[noDataPoint[1]][noDataPoint[0]] = mask.getPlaneBitMask( |
| 400 | + maskNames[min(i, len(maskNames) - 1)] |
| 401 | + ) |
| 402 | + self.catalog[self.xCol][i] = noDataPoint[0] |
| 403 | + self.catalog[self.yCol][i] = noDataPoint[1] |
| 404 | + |
| 405 | + self.config.doCullFromMaskedRegion = True |
| 406 | + self.config.cullFromMaskedRegion.xColName = self.xCol |
| 407 | + self.config.cullFromMaskedRegion.yColName = self.yCol |
| 408 | + self.config.cullFromMaskedRegion.badMaskNames = maskNames |
| 409 | + self.check([False, False, True, True, True]) |
| 410 | + # Reset config back to False and None for other tests. |
| 411 | + self.config.doCullFromMaskedRegion = False |
| 412 | + self.exposure = None |
| 413 | + |
372 | 414 |
|
373 | 415 | class TestBaseSourceSelector(lsst.utils.tests.TestCase):
|
374 | 416 | """Test the API of the Abstract Base Class with a trivial example."""
|
|
0 commit comments