From ba0e79d3545be44009c4a141d87cd4fd237ac828 Mon Sep 17 00:00:00 2001 From: Eddie Schlafly Date: Tue, 5 Nov 2024 11:12:19 -0500 Subject: [PATCH 1/6] Initial commit with new aperture, deblending, kernel source detection test. --- romancal/regtest/test_catalog.py | 58 +++++++++++++++++++++-- romancal/tests/dms_requirement_tests.json | 3 ++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/romancal/regtest/test_catalog.py b/romancal/regtest/test_catalog.py index c3c055b30..df2460364 100644 --- a/romancal/regtest/test_catalog.py +++ b/romancal/regtest/test_catalog.py @@ -8,13 +8,15 @@ # 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", +] + @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): @@ -54,6 +56,9 @@ def fields(catalog): "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 @@ -61,3 +66,48 @@ def fields(catalog): ) def test_has_field(fields, field): assert field in fields + + +def test_deblend_source_catalog(rtdata_module): + rtdata = rtdata_module + inputfn = input_filenames[1] + rtdata.get_data(f"WFI/image/{inputfn}") + rtdata.input = inputfn + + 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']) + from romancal.source_catalog.source_catalog_step import SourceCatalogStep + step = SourceCatalogStep() + step.log.info( + "DMS393: Deblended source catalog contains more sources " + f"({nsrc2}) than undeblended ({nsrc1})? " + + ('PASS' if nsrc2 > nsrc1 else 'FAIL')) + print('hello!') + # can't figure out where these log messages are going?? + assert nsrc2 > nsrc1 + # what's the nicer way to do this with fixtures? + + +def test_kernel_detection(rtdata_module): + rtdata = rtdata_module + inputfn = input_filenames[1] + rtdata.get_data(f"WFI/image/{inputfn}") + rtdata.input = inputfn + outputfn = inputfn.rsplit("_", 1)[0] + "_kernel10_cat.asdf" + args = ["romancal.step.SourceCatalogStep", rtdata.input, + "--kernel_fwhm", "20", "--output_file", outputfn] + RomanStep.from_cmdline(args) + af = asdf.open(outputfn) + # test_has_fields on this catalog with the large kernel? diff --git a/romancal/tests/dms_requirement_tests.json b/romancal/tests/dms_requirement_tests.json index 2d6588492..95e14513f 100644 --- a/romancal/tests/dms_requirement_tests.json +++ b/romancal/tests/dms_requirement_tests.json @@ -108,6 +108,9 @@ "DMS387": [ "romancal.regtest.test_catalog.test_has_field" ], + "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", From 146e9fda3216315d7cb2bbd96fd1c341f11c36a3 Mon Sep 17 00:00:00 2001 From: Eddie Schlafly Date: Tue, 5 Nov 2024 11:16:42 -0500 Subject: [PATCH 2/6] Add tests to json list. --- romancal/tests/dms_requirement_tests.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/romancal/tests/dms_requirement_tests.json b/romancal/tests/dms_requirement_tests.json index 95e14513f..526ef447b 100644 --- a/romancal/tests/dms_requirement_tests.json +++ b/romancal/tests/dms_requirement_tests.json @@ -108,6 +108,12 @@ "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" ], From e95988ced666551b1f289a7b282df6ac81e26ff5 Mon Sep 17 00:00:00 2001 From: Eddie Schlafly Date: Tue, 5 Nov 2024 15:08:44 -0500 Subject: [PATCH 3/6] Updating logging and asserts. --- romancal/regtest/test_catalog.py | 44 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/romancal/regtest/test_catalog.py b/romancal/regtest/test_catalog.py index df2460364..faea4c7d9 100644 --- a/romancal/regtest/test_catalog.py +++ b/romancal/regtest/test_catalog.py @@ -4,6 +4,7 @@ import pytest from romancal.stpipe import RomanStep +from romancal.source_catalog.source_catalog_step import SourceCatalogStep # mark all tests in this module pytestmark = [pytest.mark.bigdata, pytest.mark.soctests] @@ -13,6 +14,17 @@ "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", @@ -51,18 +63,7 @@ def fields(catalog): @pytest.mark.parametrize( - "field", - ( - "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 - ), + "field", field_list, ) def test_has_field(fields, field): assert field in fields @@ -70,10 +71,12 @@ def test_has_field(fields, field): def test_deblend_source_catalog(rtdata_module): rtdata = rtdata_module - inputfn = input_filenames[1] + 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] @@ -88,26 +91,25 @@ def test_deblend_source_catalog(rtdata_module): af2 = asdf.open(outputfn2) nsrc1 = len(af1['roman']['source_catalog']) nsrc2 = len(af2['roman']['source_catalog']) - from romancal.source_catalog.source_catalog_step import SourceCatalogStep - step = SourceCatalogStep() step.log.info( "DMS393: Deblended source catalog contains more sources " f"({nsrc2}) than undeblended ({nsrc1})? " + ('PASS' if nsrc2 > nsrc1 else 'FAIL')) - print('hello!') - # can't figure out where these log messages are going?? assert nsrc2 > nsrc1 - # what's the nicer way to do this with fixtures? def test_kernel_detection(rtdata_module): rtdata = rtdata_module - inputfn = input_filenames[1] + 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", "20", "--output_file", outputfn] + "--kernel_fwhm", "10", "--output_file", outputfn] RomanStep.from_cmdline(args) af = asdf.open(outputfn) - # test_has_fields on this catalog with the large kernel? + 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") From 0947ca510ec52963c62328fb0b2c660cf4aeed3f Mon Sep 17 00:00:00 2001 From: Eddie Schlafly Date: Tue, 5 Nov 2024 15:16:18 -0500 Subject: [PATCH 4/6] Update regtestdata script. --- romancal/scripts/make_regtestdata.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/romancal/scripts/make_regtestdata.sh b/romancal/scripts/make_regtestdata.sh index a6031dd35..5b1cc41af 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,17 @@ 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/ +# 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 + +# 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 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 From 20b6c2dfa593d7394ac42d8e3345bdac4e49cd06 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Nov 2024 20:29:38 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- romancal/regtest/test_catalog.py | 65 +++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/romancal/regtest/test_catalog.py b/romancal/regtest/test_catalog.py index faea4c7d9..de1a13cf2 100644 --- a/romancal/regtest/test_catalog.py +++ b/romancal/regtest/test_catalog.py @@ -3,8 +3,8 @@ import asdf import pytest -from romancal.stpipe import RomanStep 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] @@ -15,17 +15,18 @@ ] 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 + "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=input_filenames, @@ -63,7 +64,8 @@ def fields(catalog): @pytest.mark.parametrize( - "field", field_list, + "field", + field_list, ) def test_has_field(fields, field): assert field in fields @@ -78,25 +80,38 @@ def test_deblend_source_catalog(rtdata_module): step = SourceCatalogStep() outputfn1 = inputfn.rsplit("_", 1)[0] + "_cat.asdf" - args = ["romancal.step.SourceCatalogStep", rtdata.input, - "--deblend", "False", "--output_file", outputfn1] + 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] + 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']) + 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')) + + ("PASS" if nsrc2 > nsrc1 else "FAIL") + ) assert nsrc2 > nsrc1 - + def test_kernel_detection(rtdata_module): rtdata = rtdata_module @@ -105,11 +120,17 @@ def test_kernel_detection(rtdata_module): 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] + 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 + 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") From ea5763ffb298d972cd7a7eae15a8d3600148205a Mon Sep 17 00:00:00 2001 From: Eddie Schlafly Date: Tue, 5 Nov 2024 15:36:05 -0500 Subject: [PATCH 6/6] Also copy segmentation images to regtest dir. --- romancal/scripts/make_regtestdata.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/romancal/scripts/make_regtestdata.sh b/romancal/scripts/make_regtestdata.sh index 5b1cc41af..6160f18fb 100644 --- a/romancal/scripts/make_regtestdata.sh +++ b/romancal/scripts/make_regtestdata.sh @@ -200,14 +200,17 @@ 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