diff --git a/romancal/regtest/test_catalog.py b/romancal/regtest/test_catalog.py index c3c055b30..de1a13cf2 100644 --- a/romancal/regtest/test_catalog.py +++ b/romancal/regtest/test_catalog.py @@ -3,18 +3,33 @@ import asdf import pytest +from romancal.source_catalog.source_catalog_step import SourceCatalogStep from romancal.stpipe import RomanStep # mark all tests in this module pytestmark = [pytest.mark.bigdata, pytest.mark.soctests] +input_filenames = [ + "r0099101001001001001_F158_visit_i2d.asdf", + "r0000101001001001001_0001_wfi01_cal.asdf", +] + +field_list = [ + "ra_centroid", # DMS374 positions on ICRF + "dec_centroid", # DMS374 positions on ICRF + "aper_total_flux", # DMS375 fluxes + "aper30_flux", # DMS399 aperture fluxes + "aper50_flux", # DMS399 aperture fluxes + "aper70_flux", # DMS399 aperture fluxes + "is_extended", # DMS376 type of source + "aper_total_flux_err", # DMS386 flux uncertainties + "flags", # DMS387 dq_flags +] + @pytest.fixture( scope="module", - params=[ - "r0099101001001001001_F158_visit_i2d.asdf", - "r0000101001001001001_0001_wfi01_cal.asdf", - ], + params=input_filenames, ids=["L3", "L2"], ) def run_source_catalog(rtdata_module, request): @@ -50,14 +65,72 @@ def fields(catalog): @pytest.mark.parametrize( "field", - ( - "ra_centroid", # DMS374 positions on ICRF - "dec_centroid", # DMS374 positions on ICRF - "aper_total_flux", # DMS375 fluxes - "is_extended", # DMS376 type of source - "aper_total_flux_err", # DMS386 flux uncertainties - "flags", # DMS387 dq_flags - ), + field_list, ) def test_has_field(fields, field): assert field in fields + + +def test_deblend_source_catalog(rtdata_module): + rtdata = rtdata_module + inputfn = input_filenames[1] # use L2 image; could have picked either one + rtdata.get_data(f"WFI/image/{inputfn}") + rtdata.input = inputfn + + step = SourceCatalogStep() + + outputfn1 = inputfn.rsplit("_", 1)[0] + "_cat.asdf" + args = [ + "romancal.step.SourceCatalogStep", + rtdata.input, + "--deblend", + "False", + "--output_file", + outputfn1, + ] + RomanStep.from_cmdline(args) + outputfn2 = inputfn.rsplit("_", 1)[0] + "_deblend_cat.asdf" + rtdata.output = outputfn2 + args = [ + "romancal.step.SourceCatalogStep", + rtdata.input, + "--deblend", + "True", + "--output_file", + outputfn2, + ] + RomanStep.from_cmdline(args) + + af1 = asdf.open(outputfn1) + af2 = asdf.open(outputfn2) + nsrc1 = len(af1["roman"]["source_catalog"]) + nsrc2 = len(af2["roman"]["source_catalog"]) + step.log.info( + "DMS393: Deblended source catalog contains more sources " + f"({nsrc2}) than undeblended ({nsrc1})? " + + ("PASS" if nsrc2 > nsrc1 else "FAIL") + ) + assert nsrc2 > nsrc1 + + +def test_kernel_detection(rtdata_module): + rtdata = rtdata_module + inputfn = input_filenames[1] # use L2 image; could have picked either one + rtdata.get_data(f"WFI/image/{inputfn}") + rtdata.input = inputfn + outputfn = inputfn.rsplit("_", 1)[0] + "_kernel10_cat.asdf" + step = SourceCatalogStep() + args = [ + "romancal.step.SourceCatalogStep", + rtdata.input, + "--kernel_fwhm", + "10", + "--output_file", + outputfn, + ] + RomanStep.from_cmdline(args) + af = asdf.open(outputfn) + fields = af["roman"]["source_catalog"].dtype.names + for field in field_list: + assert field in field_list + step.log.info("DMS391: Used alternative kernel to detect sources. PASS") diff --git a/romancal/scripts/make_regtestdata.sh b/romancal/scripts/make_regtestdata.sh index a6031dd35..6160f18fb 100644 --- a/romancal/scripts/make_regtestdata.sh +++ b/romancal/scripts/make_regtestdata.sh @@ -186,11 +186,6 @@ cp L3_regtest_asn.json $outdir/roman-pipeline/dev/WFI/image/ cp ${l3name}_i2d.asdf $outdir/roman-pipeline/dev/WFI/image/ cp ${l3name}_i2d.asdf $outdir/roman-pipeline/dev/truth/WFI/image/ -# L3 catalog -strun romancal.step.SourceCatalogStep ${l3name}_i2d.asdf -cp ${l3name}_cat.asdf $outdir/roman-pipeline/dev/truth/WFI/image/ - - l3name="r0099101001001001001_r274dp63x31y81_prompt_F158" asn_from_list r0000101001001001001_0001_wfi01_cal.asdf r0000101001001001001_0002_wfi01_cal.asdf r0000101001001001001_0003_wfi01_cal.asdf -o L3_mosaic_asn.json --product-name $l3name --target r274dp63x31y81 strun roman_mos L3_mosaic_asn.json @@ -202,11 +197,20 @@ cp ${l3name}_i2d.asdf $outdir/roman-pipeline/dev/truth/WFI/image/ strun romancal.step.SourceCatalogStep ${l3name}_i2d.asdf cp ${l3name}_cat.asdf $outdir/roman-pipeline/dev/truth/WFI/image/ - # L2 catalog strun romancal.step.SourceCatalogStep r0000101001001001001_0001_wfi01_cal.asdf cp r0000101001001001001_0001_wfi01_cat.asdf $outdir/roman-pipeline/dev/truth/WFI/image/ +cp r0000101001001001001_0001_wfi01_segm.asdf $outdir/roman-pipeline/dev/truth/WFI/image/ + +# L2 catalog with larger kernel +strun romancal.step.SourceCatalogStep r0000101001001001001_0001_wfi01_cal.asdf --kernel_fwhm 10 --output_file r0000101001001001001_0001_wfi01_kernel10_cat.asdf +cp r0000101001001001001_0001_wfi01_kernel10_cat.asdf $outdir/roman-pipeline-dev/truth/WFI/image +cp r0000101001001001001_0001_wfi01_kernel10_segm.asdf $outdir/roman-pipeline-dev/truth/WFI/image +# L2 catalog using deblending +strun romancal.step.SourceCatalogStep r0000101001001001001_0001_wfi01_cal.asdf --deblend True --output_file r0000101001001001001_0001_wfi01_deblend_cat.asdf +cp r0000101001001001001_0001_wfi01_deblend_cat.asdf $outdir/roman-pipeline-dev/truth/WFI/image +cp r0000101001001001001_0001_wfi01_deblend_segm.asdf $outdir/roman-pipeline-dev/truth/WFI/image l3name="r0099101001001001001_F158_visit_r274dp63x31y81" asn_from_list --product-name=$l3name r0000101001001001001_0001_wfi01_cal.asdf r0000101001001001001_0002_wfi01_cal.asdf r0000101001001001001_0003_wfi01_cal.asdf -o L3_m1_asn.json diff --git a/romancal/tests/dms_requirement_tests.json b/romancal/tests/dms_requirement_tests.json index 2d6588492..526ef447b 100644 --- a/romancal/tests/dms_requirement_tests.json +++ b/romancal/tests/dms_requirement_tests.json @@ -108,6 +108,15 @@ "DMS387": [ "romancal.regtest.test_catalog.test_has_field" ], + "DMS391": [ + "romancal.regtest.test_kernel_detection" + ], + "DMS393": [ + "romancal.regtest.test_deblend_source_catalog" + ], + "DMS399": [ + "romancal.regtest.test_catalog.test_has_field" + ], "DMS400": [ "romancal.regtest.test_mos_pipeline.test_steps_ran", "romancal.regtest.test_mos_pipeline.test_added_background",