Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-47535: Add unit test for reprocessVisitImage and enable useCiLimits on its deblending. #44

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin.src/ci_imsim_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def run(self, currentState: BuildState):
"-p", "$DRP_PIPE_DIR/pipelines/LSSTCam-imSim/DRP-ci_imsim.yaml",
"--skip-existing",
"--save-qgraph", os.path.join(self.runner.RunDir, QGRAPH_FILE),
"--config", f"reprocessVisitImage:deblend.useCiLimits={not self.arguments.no_limit_deblend}",
Copy link
Contributor

@parejkoj parejkoj Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this? I removed the calibrate line above, and I'm not sure it's really necessary here. Maybe it is necessary for reprocessVisitImage?

EDIT: oh, I see I did add it for reprocessVisitImage on #43 . I'm still not sure it's really necessary, but I guess it's not worth quibbling over.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure how much faster it makes ci_imsim, but I assume it was added for a good reason initially and I imagine that reasoning would apply to reprocessVisitImage as well.

"--config", f"deblend:multibandDeblend.processSingles={self.arguments.process_singles}",
"--config", f"deblend:multibandDeblend.useCiLimits={not self.arguments.no_limit_deblend}",
)
Expand Down
87 changes: 87 additions & 0 deletions tests/test_reprocessVisitImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This file is part of ci_hsc_gen3.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os
import unittest

import lsst.utils.tests
import numpy as np
from lsst.daf.butler import Butler
from lsst.utils import getPackageDir


class TestReprocessVisitImageOutputs(lsst.utils.tests.TestCase):
"""Test the output data products of reprocessVisitImage task make sense.

This is a regression test and not intended for scientific validation.
"""

def setUp(self):
self.butler = Butler(os.path.join(getPackageDir("ci_imsim"), "DATA"),
writeable=False, collections=["LSSTCam-imSim/runs/ci_imsim"])
self.dataId = {"detector": 55, "visit": 206039, "band": "y"}
self.exposure = self.butler.get("pvi", self.dataId)
self.catalog = self.butler.get("sources_footprints_detector", self.dataId)

def test_schema(self):
"""Test that the schema init-output agrees with the catalog output."""
schema_cat = self.butler.get("sources_schema")
self.assertEqual(schema_cat.schema, self.catalog.schema)

def testLocalPhotoCalibColumns(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do hope that we can remove LocalPhotoCalib from the catalogs in the future, since they'll have calibrated values. Not sure if that's ticketed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transform*Table catalog implementations are pandas-heavy and one of the bits of the stack I'm least familiar with, and that makes me really not want to wade in to them as long as they're working. So if we ever do fix this, I think it'll be because we decide to do a full rewrite of that stuff, and that won't benefit much from a more targeted ticket.

"""Check that the catalog's photoCalib columns are consistent with the
ratio of its instFlux and flux columns.
"""
randomRows = [0, 8, 20]
for rowNum in randomRows:
record = self.catalog[rowNum]
self.assertAlmostEqual(
record["base_PsfFlux_flux"]/record["base_PsfFlux_instFlux"],
record['base_LocalPhotoCalib']
)

def testLocalWcsColumns(self):
"""Check the exposure's wcs match local wcs columns in the catalog.
"""
# Check a few rows:
randomRows = [1, 9, 21]
for rowNum in randomRows:
record = self.catalog[rowNum]
centroid = record.getCentroid()
trueCdMatrix = np.radians(self.exposure.getWcs().getCdMatrix(centroid))

self.assertAlmostEqual(record['base_LocalWcs_CDMatrix_1_1'], trueCdMatrix[0, 0])
self.assertAlmostEqual(record['base_LocalWcs_CDMatrix_2_1'], trueCdMatrix[1, 0])
self.assertAlmostEqual(record['base_LocalWcs_CDMatrix_1_2'], trueCdMatrix[0, 1])
self.assertAlmostEqual(record['base_LocalWcs_CDMatrix_2_2'], trueCdMatrix[1, 1])
self.assertAlmostEqual(
self.exposure.getWcs().getPixelScale(centroid).asRadians(),
np.sqrt(np.fabs(record['base_LocalWcs_CDMatrix_1_1']*record['base_LocalWcs_CDMatrix_2_2']
- record['base_LocalWcs_CDMatrix_2_1']*record['base_LocalWcs_CDMatrix_1_2'])))


def setup_module(module):
lsst.utils.tests.init()


if __name__ == "__main__":
lsst.utils.tests.init()
unittest.main()