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-41189: update and fix bitrot for MultiVisitCoveragePlot action #226

Merged
merged 8 commits into from
Mar 21, 2024
17 changes: 13 additions & 4 deletions python/lsst/analysis/tools/actions/keyedData/stellarLocusFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,19 @@ def _stellarLocusFit(xs, ys, mags, paramDict):
fitParams = _setFitParamsNans(fitParams, fitPoints, paramDict)
return fitParams

p1 = np.array([0, bODR0])
p2 = np.array([-bODR0 / mODR0, 0])
if np.abs(sum(p1 - p2) < 1e12): # p1 and p2 must be different.
p2 = np.array([(1.0 - bODR0 / mODR0), 1.0])
# Compute two points along the line (making sure not to extrapolate
# way off the plot limits, especially for the near vertical fits).
if np.abs(mODR0) > 1:
p1 = np.array([1.0, mODR0 + bODR0])
p2 = np.array([(1.0 - bODR0) / mODR0, 1.0])
else:
p1 = np.array([0, bODR0])
p2 = np.array([-bODR0 / mODR0, 0])
if np.abs(sum(p1 - p2)) < 1e-12: # p1 and p2 must be different.
if np.abs(mODR0) > 1:
p2 = np.array([(1.5 - bODR0) / mODR0, 1.5])
else:
p2 = np.array([(1.0 - bODR0) / mODR0, 1.0])

# Sigma clip points based on perpendicular distance (in mmag) to
# current fit.
Expand Down
42 changes: 29 additions & 13 deletions python/lsst/analysis/tools/actions/plot/multiVisitCoveragePlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class MultiVisitCoveragePlot(PlotAction):
"threshold is nPointMinThresh/number of science detectors in the given ``camera``.",
default=400,
)
showExtremeOutliers = Field[bool](
doc="Use overlaid scatter points to show the x-y positions of the 15% most extreme values?",
default=True,
)
unitsDict = DictField[str, str](
doc="A dict mapping a parameter to its appropriate units (for label plotting).",
default={
Expand All @@ -92,6 +96,7 @@ class MultiVisitCoveragePlot(PlotAction):
"yFp": "mm",
"medianE": "",
"psfStarScaledDeltaSizeScatter": "",
"psfTraceRadiusDelta": "pixel",
},
)
sortedFullBandList = ListField[str](
Expand Down Expand Up @@ -126,6 +131,7 @@ class MultiVisitCoveragePlot(PlotAction):
"psfStarDeltaE1Median",
"psfStarDeltaE2Median",
"psfStarScaledDeltaSizeScatter",
"psfTraceRadiusDelta",
"llcra",
"lrcra",
"ulcra",
Expand Down Expand Up @@ -308,10 +314,12 @@ def makePlot(

if makeWarpConfig is None:
maxEllipResidual = 0.007
maxScaledSizeScatter = 0.009
maxScaledSizeScatter = 0.019
maxPsfTraceRadiusDelta = 0.7
else:
maxEllipResidual = makeWarpConfig.select.value.maxEllipResidual # type: ignore
maxScaledSizeScatter = makeWarpConfig.select.value.maxScaledSizeScatter # type: ignore
maxPsfTraceRadiusDelta = makeWarpConfig.select.value.maxPsfTraceRadiusDelta # type: ignore

cameraName = "" if camera is None else camera.getName()
if self.projection == "focalPlane":
Expand Down Expand Up @@ -425,6 +433,8 @@ def makePlot(
vMaxDict[zKey] = maxScaledSizeScatter
elif zKey == "astromOffsetMean" and self.projection != "raDec":
vMaxDict[zKey] = min(maxMeanDistanceArcsec, 1.1 * nanMean(zKeySorted.tail(nPercent)))
elif zKey == "maxPsfTraceRadiusDelta":
vMaxDict[zKey] = maxPsfTraceRadiusDelta
else:
vMaxDict[zKey] = nanMean(zKeySorted.tail(nPercent))

Expand Down Expand Up @@ -487,7 +497,7 @@ def makePlot(
else:
cmap = mpl.cm.get_cmap(self.cmapName).copy()

if zKey in ["medianE", "psfStarScaledDeltaSizeScatter"]:
if zKey in ["medianE", "psfStarScaledDeltaSizeScatter", "psfTraceRadiusDelta"]:
cmap.set_over("red")
elif (
zKey in ["astromOffsetMean"]
Expand Down Expand Up @@ -551,6 +561,7 @@ def makePlot(
isSorted=False,
vmin=vMinDict[zKey],
vmax=vMaxDict[zKey],
showExtremeOutliers=self.showExtremeOutliers,
scatPtSize=ptSize,
)
if self.projection == "raDec":
Expand All @@ -573,6 +584,7 @@ def makePlot(
isSorted=False,
vmin=vMinDict[zKey],
vmax=vMaxDict[zKey],
showExtremeOutliers=self.showExtremeOutliers,
scatPtSize=ptSize,
)

Expand Down Expand Up @@ -643,10 +655,11 @@ def makePlot(
# Add a shaded area of the size of a detector for reference.
if self.plotDetectorOutline and self.projection == "raDec":
if camera is None:
log.warning(
"Config plotDetectorOutline is True, but no camera was provided. "
"Reference detector outline will not be included in the plot."
)
if iRow == 0 and iCol == 0:
log.warning(
"Config plotDetectorOutline is True, but no camera was provided. "
"Reference detector outline will not be included in the plot."
)
else:
# Calculate area of polygon with known vertices.
x1, x2, x3, x4 = (
Expand Down Expand Up @@ -750,10 +763,11 @@ def makePlot(

cbLabel = zKey
if zKey not in self.unitsDict:
log.warning(
"Data column {} does not have an entry in unitsDict config. Units "
"will not be included in the colorbar text.".format(zKey)
)
if iRow == 0 and iCol == 0:
log.warning(
"Data column {} does not have an entry in unitsDict config. Units "
"will not be included in the colorbar text.".format(zKey)
)
elif len(self.unitsDict[zKey]) > 0:
cbLabel = "{} ({})".format(zKey, self.unitsDict[zKey])

Expand Down Expand Up @@ -837,11 +851,13 @@ def _planeAreaSelector(
downSelectedData : `lsst.analysis.tools.interfaces.KeyedData`
The down-selected catalog.
"""
xSelector = RangeSelector(key=xKey, minimum=xMin, maximum=xMax)
ySelector = RangeSelector(key=yKey, minimum=yMin, maximum=yMax)
xSelector = RangeSelector(vectorKey=xKey, minimum=xMin, maximum=xMax)
ySelector = RangeSelector(vectorKey=yKey, minimum=yMin, maximum=yMax)

totMask = xSelector(data) & ySelector(data)
downSelectedData = data[totMask]
downSelectedData = {}
for key in data.keys():
downSelectedData[key] = data[key][totMask]

return downSelectedData

Expand Down
8 changes: 4 additions & 4 deletions python/lsst/analysis/tools/tasks/ccdVisitTableAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class CcdVisitTableAnalysisConnections(

def __init__(self, *, config=None):
super().__init__(config=config)
# No metrics are computed for this task, so remove output dataset.
self.outputs.remove("metrics")
if not config.introspectMakeWarpConfig:
self.inputs.remove("makeWarpConfig")

Expand All @@ -79,8 +77,10 @@ class CcdVisitTableAnalysisConfig(AnalysisBaseConfig, pipelineConnections=CcdVis
introspectMakeWarpConfig = Field[bool](
doc="Whether to introspect the makeWarp_config dataset to obtain the actual "
"maxEllipResidual and maxScalesSizeScatter thresholds in this run? Set to "
"False if makeWarp has not yet been run on given collection.",
default=True,
"True only if makeWarp has been run on given collection. When False, a default "
"set of threshold values (meant to reflect current stack defaults) will be set "
"for reference.",
default=False,
)


Expand Down