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-35722: Catch errors in setting the HeavyFootprint peak flux #59

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion python/lsst/meas/extensions/scarlet/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from dataclasses import dataclass
import json
from typing import Any
import logging
import numpy as np
from scarlet.bbox import Box, overlapped_slices
from scarlet.lite import LiteBlend, LiteFactorizedComponent, LiteObservation, LiteSource, LiteParameter
from scarlet.lite.measure import weight_sources
import traceback

from lsst.geom import Box2I, Extent2I, Point2I, Point2D
from lsst.afw.detection.multiband import heavyFootprintToImage
Expand All @@ -27,6 +29,8 @@
"scarletToData",
]

logger = logging.getLogger(__name__)


@dataclass
class ScarletComponentData:
Expand Down Expand Up @@ -508,7 +512,15 @@ def updateBlendRecords(blendData, catalog, modelPsf, observedPsf, redistributeIm
# Set the flux at the center of the model
peak = heavy.peaks[0]
img = heavyFootprintToImage(heavy, fill=0.0)
sourceRecord.set("deblend_peak_instFlux", img.image[Point2I(peak["i_x"], peak["i_y"])])
try:
sourceRecord.set("deblend_peak_instFlux", img.image[Point2I(peak["i_x"], peak["i_y"])])
except Exception:
srcId = sourceRecord.getId()
x = peak["i_x"]
y = peak["i_y"]
logger.warn(f"Source {srcId} at {x},{y} could not set the peak flux with error:")
traceback.print_exc()
Copy link
Member

Choose a reason for hiding this comment

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

This should not be called because it won't go to the logging system and we can't tell where it will turn up. Instead you should use logger.exception() and that would print your log message above and also include the exception traceback.

sourceRecord.set("deblend_peak_instFlux", np.nan)

# Set the metrics columns.
# TODO: remove this once DM-34558 runs all deblender metrics
Expand Down