Skip to content

Commit

Permalink
Add test for no good sources in finalizeCharacterization
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenam committed Nov 1, 2023
1 parent fd27f1b commit e885677
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test_finalizeCharacterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#
"""Test FinalizeCharacterizationTask.
"""
import logging
import unittest
import numpy as np
import pandas as pd

import lsst.utils.tests
import lsst.afw.table as afwTable
import lsst.pipe.base as pipeBase

from lsst.pipe.tasks.finalizeCharacterization import (FinalizeCharacterizationConfig,
Expand All @@ -41,6 +43,7 @@ def __init__(self, **kwargs):
pipeBase.PipelineTask.__init__(self, **kwargs)

self.makeSubtask('reserve_selection')
self.makeSubtask('source_selector')


class FinalizeCharacterizationTestCase(lsst.utils.tests.TestCase):
Expand Down Expand Up @@ -209,6 +212,33 @@ def test_concat_isolate_star_cats_no_sources(self):

self.assertGreater(len(iso), 0)

def test_compute_psf_and_ap_corr_map_no_sources(self):
"""Test log message when there are no good sources after selection."""
# Create an empty source catalog.
src_schema = afwTable.SourceTable.makeMinimalSchema()
src_schema.addField('base_GaussianFlux_instFlux', type='F', doc='Flux field')
src_schema.addField('base_GaussianFlux_instFluxErr', type='F', doc='Flux field')
src = afwTable.SourceCatalog(src_schema)

# Set defaults and placeholders for required positional arguments.
self.finalizeCharacterizationTask.config.source_selector['science'].flags.bad = []
visit = 0
detector = 0
exposure = None
isolated_source_table = None
with self.assertLogs(level=logging.WARNING) as cm:
psf, ap_corr_map, measured_src = self.finalizeCharacterizationTask.compute_psf_and_ap_corr_map(
visit,
detector,
exposure,
src,
isolated_source_table
)
self.assertIn(
"No good sources remain after cuts for visit {}, detector {}".format(visit, detector),
cm.output[0]
)


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit e885677

Please sign in to comment.