Skip to content

Commit

Permalink
Merge branch 'main' into tickets/DM-39697
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi authored Jun 22, 2023
2 parents 518e0d9 + 737c078 commit 7def5fa
Show file tree
Hide file tree
Showing 18 changed files with 925 additions and 383 deletions.
61 changes: 22 additions & 39 deletions pipelines/coaddDiffMatchedQualityExtended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,50 @@ tasks:
connections.outputName: diff_matched_truth_summary_objectTable_tract

# plots
atools.matchedRefCModelMagDiff: MatchedRefCoaddCModelFluxPlot
atools.matchedRefCModelMagDiff.applyContext: MatchedRefDiffContext
atools.matchedRefCModelMagDiff: MatchedRefCoaddDiffMagPlot

atools.matchedRefCModelFluxChi: MatchedRefCoaddCModelFluxPlot
atools.matchedRefCModelFluxChi.applyContext: MatchedRefChiContext
atools.matchedRefMagChi: MatchedRefCoaddDiffMagPlot
atools.matchedRefMagChi.compute_chi: true

# TODO: Can this be a one liner?
atools.matchedRefPositionXDiff: MatchedRefCoaddPositionPlot
# TODO: variable must be defined before applyContext; can this be enforced?
# (the resulting error if not is not very informative)
atools.matchedRefPositionXDiff: MatchedRefCoaddDiffPositionPlot
atools.matchedRefPositionXDiff.variable: x
atools.matchedRefPositionXDiff.applyContext: MatchedRefDiffContext

atools.matchedRefPositionXChi: MatchedRefCoaddPositionPlot
atools.matchedRefPositionXChi: MatchedRefCoaddDiffPositionPlot
atools.matchedRefPositionXChi.variable: x
atools.matchedRefPositionXChi.applyContext: MatchedRefChiContext
atools.matchedRefPositionXChi.compute_chi: true

atools.matchedRefPositionYDiff: MatchedRefCoaddPositionPlot
atools.matchedRefPositionYDiff: MatchedRefCoaddDiffPositionPlot
atools.matchedRefPositionYDiff.variable: y
atools.matchedRefPositionYDiff.applyContext: MatchedRefDiffContext

atools.matchedRefPositionYChi: MatchedRefCoaddPositionPlot
atools.matchedRefPositionYChi: MatchedRefCoaddDiffPositionPlot
atools.matchedRefPositionYChi.variable: y
atools.matchedRefPositionYChi.applyContext: MatchedRefChiContext
atools.matchedRefPositionYChi.compute_chi: true

# metrics
atools.matchedRefCModelMagDiffMetric: MatchedRefCoaddCModelFluxMetric
atools.matchedRefCModelMagDiffMetric.applyContext: MatchedRefDiffContext
atools.matchedRefCModelMagDiffMetric: MatchedRefCoaddDiffMagMetric

atools.matchedRefCModelFluxChiMetric: MatchedRefCoaddCModelFluxMetric
atools.matchedRefCModelFluxChiMetric.applyContext: MatchedRefChiContext
atools.matchedRefMagChiMetric: MatchedRefCoaddDiffMagMetric
atools.matchedRefMagChiMetric.compute_chi: true

atools.matchedRefPositionXDiffMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionXDiffMetric: MatchedRefCoaddDiffPositionMetric
atools.matchedRefPositionXDiffMetric.variable: x
atools.matchedRefPositionXDiffMetric.applyContext: MatchedRefDiffContext

atools.matchedRefPositionXChiMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionXChiMetric: MatchedRefCoaddDiffPositionMetric
atools.matchedRefPositionXChiMetric.variable: x
atools.matchedRefPositionXChiMetric.applyContext: MatchedRefChiContext
atools.matchedRefPositionXChiMetric.compute_chi: true

atools.matchedRefPositionYDiffMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionYDiffMetric: MatchedRefCoaddDiffPositionMetric
atools.matchedRefPositionYDiffMetric.variable: y
atools.matchedRefPositionYDiffMetric.applyContext: MatchedRefDiffContext

atools.matchedRefPositionYChiMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionYChiMetric: MatchedRefCoaddDiffPositionMetric
atools.matchedRefPositionYChiMetric.variable: y
atools.matchedRefPositionYChiMetric.applyContext: MatchedRefChiContext

atools.matchedRefPositionYChiMetric.compute_chi: true

python: |
from lsst.analysis.tools.atools.diffMatched import (
MatchedRefCoaddCModelFluxMetric,
MatchedRefCoaddPositionMetric,
)
from lsst.analysis.tools.atools.diffMatched import (
MatchedRefCoaddCModelFluxPlot,
MatchedRefCoaddPositionPlot,
)
from lsst.analysis.tools.contexts._contexts import (
MatchedRefDiffContext,
MatchedRefChiContext,
MatchedRefCoaddDiffMagMetric,
MatchedRefCoaddDiffPositionMetric,
MatchedRefCoaddDiffMagPlot,
MatchedRefCoaddDiffPositionPlot,
)
24 changes: 23 additions & 1 deletion pipelines/coaddQualityExtended.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
description: |
Tier2 plots and metrics to assess coadd quality
Tier2 atools and metrics to assess coadd quality
tasks:
analyzeObjectTableExtended:
class: lsst.analysis.tools.tasks.ObjectTableTractAnalysisTask
config:
connections.outputName: objectTableExtended
# set plots to run
atools.ap12PsfSky: Ap12PsfSkyPlot
atools.shapeSizeDetRadiusVsCmodelMag: SizeMagnitudePlot
atools.shapeSizeDetRadiusVsCmodelMag.size_type: "determinantRadius"
atools.shapeSizeDetRadiusVsCmodelMag.mag_x: "cmodel_err"
atools.shapeSizeDetRadiusVsCmodelMag.size_y: "shape_slot"
atools.shapeSizeDetRadiusVsCmodelMag.applyContext: CoaddContext
atools.shapeSizeDetRadiusVsPsfMag: SizeMagnitudePlot
atools.shapeSizeDetRadiusVsPsfMag.size_type: "determinantRadius"
atools.shapeSizeDetRadiusVsPsfMag.mag_x: "psf_err"
atools.shapeSizeDetRadiusVsPsfMag.size_y: "shape_slot"
atools.shapeSizeDetRadiusVsPsfMag.applyContext: CoaddContext
atools.cModelBulgeSizeVsCmodelBulgeMag: SizeMagnitudePlot
atools.cModelBulgeSizeVsCmodelBulgeMag.size_type: "singleColumnSize"
atools.cModelBulgeSizeVsCmodelBulgeMag.mag_x: "bulge_err"
atools.cModelBulgeSizeVsCmodelBulgeMag.size_y: "bulge"
atools.cModelBulgeSizeVsCmodelBulgeMag.applyContext: CoaddContext
atools.cModelDiskSizeVsCmodelDiskMag: SizeMagnitudePlot
atools.cModelDiskSizeVsCmodelDiskMag.size_type: "singleColumnSize"
atools.cModelDiskSizeVsCmodelDiskMag.mag_x: "disk_err"
atools.cModelDiskSizeVsCmodelDiskMag.size_y: "disk"
atools.cModelDiskSizeVsCmodelDiskMag.applyContext: CoaddContext
python: |
from lsst.analysis.tools.atools import *
from lsst.analysis.tools.contexts import *
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class ScatterPlotWithTwoHists(PlotAction):
xAxisLabel = Field[str](doc="Label to use for the x axis", optional=False)
yAxisLabel = Field[str](doc="Label to use for the y axis", optional=False)
magLabel = Field[str](doc="Label to use for the magnitudes used for SNR", optional=False)

legendLocation = Field[str](doc="Legend position within main plot", default="upper left")
nBins = Field[float](doc="Number of bins on x axis", default=40.0)
plot2DHist = Field[bool](
doc="Plot a 2D histogram in dense areas of points on the scatter plot."
Expand Down Expand Up @@ -652,7 +654,7 @@ def _scatterPlot(
handles=linesForLegend,
ncol=4,
fontsize=6,
loc="upper left",
loc=self.legendLocation,
framealpha=0.9,
edgecolor="k",
borderpad=0.4,
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/analysis/tools/actions/vector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .calcBinnedStats import *
from .calcMomentSize import *
from .calcRhoStatistics import *
from .calcShapeSize import *
from .ellipticity import *
from .mathActions import *
from .selectors import *
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/analysis/tools/actions/vector/calcBinnedStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

class CalcBinnedStatsAction(KeyedDataAction):
key_vector = Field[str](doc="Vector on which to compute statistics")
name_prefix = Field[str](doc="Field name to append stat names to")
name_suffix = Field[str](doc="Field name to append to stat names")
name_prefix = Field[str](default="", doc="Field name to append stat names to")
name_suffix = Field[str](default="", doc="Field name to append to stat names")
selector_range = ConfigurableActionField[RangeSelector](doc="Range selector")

def getInputSchema(self, **kwargs) -> KeyedDataSchema:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations

__all__ = ("CalcShapeSize",)
__all__ = ("CalcMomentSize",)

import numpy as np
from lsst.pex.config import Field, FieldValidationError
Expand All @@ -29,25 +29,26 @@
from ...interfaces import KeyedData, KeyedDataSchema, Vector, VectorAction


class CalcShapeSize(VectorAction):
r"""Calculate a size: :math:`(I_{xx}I_{yy}-I_{xy}^2)^{\frac{1}{4}}`
(determinant radius) or :math:`\sqrt{(I_{xx}+I_{yy})/2}`
(trace radius).
class CalcMomentSize(VectorAction):
r"""Calculate a size based on 2D moments.
Given a 2x2 matrix of moments (i.e. moment of inertia), two sizes can be
defined as follows:
Determinant radius: :math:`(I_{xx}I_{yy}-I_{xy}^2)^{\frac{1}{4}}`
Trace radius: :math:`\sqrt{(I_{xx}+I_{yy})/2}`
The square of size measure is typically expressed either as the arithmetic
mean of the eigenvalues of the moment matrix (trace radius) or as the
geometric mean of the eigenvalues (determinant radius), which can be
specified using the `sizeType` parameter. Both of these measures give the
:math:`\sigma^2` parameter for a 2D Gaussian.
specified using the `sizeType` parameter. Both of these measures
correspond to the :math:`\sigma^2` parameter for a 2D Gaussian.
Notes
-----
Since lensing preserves surface brightness, the determinant radius relates
the magnification cleanly as it is derived from the area of isophotes, but
have a slightly higher chance of being NaNs for noisy moment estimates.
Notes
-----
This is a size measurement used for doing QA on the ellipticity
of the sources.
"""

colXx = Field[str](
Expand Down Expand Up @@ -91,12 +92,8 @@ def getInputSchema(self) -> KeyedDataSchema:

def __call__(self, data: KeyedData, **kwargs) -> Vector:
if self.sizeType == "trace":
size = np.power(
0.5
* (
data[self.colXx.format(**kwargs)] + data[self.colYy.format(**kwargs)] # type: ignore
), # type: ignore
0.5,
size = np.sqrt(
0.5 * (data[self.colXx.format(**kwargs)] + data[self.colYy.format(**kwargs)]) # type: ignore
)
else:
size = np.power(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from lsst.pex.config import ChoiceField, Config, ConfigField, Field, FieldValidationError

from ...interfaces import KeyedData, KeyedDataAction, Vector
from .calcShapeSize import CalcShapeSize
from .calcMomentSize import CalcMomentSize
from .ellipticity import CalcE, CalcEDiff
from .mathActions import FractionalDifference

Expand Down Expand Up @@ -385,13 +385,13 @@ def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
calcEDiff = CalcEDiff(colA=calcEMeas, colB=calcEpsf)

calcSizeResidual = FractionalDifference(
actionA=CalcShapeSize(
actionA=CalcMomentSize(
colXx=self.colXx,
colYy=self.colYy,
colXy=self.colXy,
sizeType=self.sizeType,
),
actionB=CalcShapeSize(
actionB=CalcMomentSize(
colXx=self.colPsfXx,
colYy=self.colPsfYy,
colXy=self.colPsfXy,
Expand Down
74 changes: 73 additions & 1 deletion python/lsst/analysis/tools/actions/vector/mathActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
"ConstantValue",
"AddVector",
"SubtractVector",
"DivideVector",
"MultiplyVector",
"DivideVector",
"SquareVector",
"SqrtVector",
"RaiseFromBaseVector",
"RaiseToPowerVector",
"Log10Vector",
"FractionalDifference",
)

Expand Down Expand Up @@ -116,6 +121,73 @@ def __call__(self, data: KeyedData, **kwargs) -> Vector:
return vecA / vecB


class SqrtVector(VectorAction):
"""Calculate sqrt(A)"""

actionA = ConfigurableActionField(doc="Action which supplies vector A", dtype=VectorAction)

def getInputSchema(self) -> KeyedDataSchema:
yield from self.actionA.getInputSchema() # type: ignore

def __call__(self, data: KeyedData, **kwargs) -> Vector:
vecA = self.actionA(data, **kwargs) # type: ignore
return np.sqrt(vecA)


class SquareVector(VectorAction):
"""Calculate A**2"""

actionA = ConfigurableActionField(doc="Action which supplies vector A", dtype=VectorAction)

def getInputSchema(self) -> KeyedDataSchema:
yield from self.actionA.getInputSchema() # type: ignore

def __call__(self, data: KeyedData, **kwargs) -> Vector:
vecA = self.actionA(data, **kwargs) # type: ignore
return vecA * vecA


class RaiseFromBaseVector(VectorAction):
"""Calculate n**A"""

actionA = ConfigurableActionField(doc="Action which supplies vector A", dtype=VectorAction)
base = Field[float](doc="The base value to raise to the power of vector values")

def getInputSchema(self) -> KeyedDataSchema:
yield from self.actionA.getInputSchema() # type: ignore

def __call__(self, data: KeyedData, **kwargs) -> Vector:
vecA = self.actionA(data, **kwargs) # type: ignore
return self.base**vecA


class RaiseToPowerVector(VectorAction):
"""Calculate A**n"""

actionA = ConfigurableActionField(doc="Action which supplies vector A", dtype=VectorAction)
power = Field[float](doc="The power to raise the vector to")

def getInputSchema(self) -> KeyedDataSchema:
yield from self.actionA.getInputSchema() # type: ignore

def __call__(self, data: KeyedData, **kwargs) -> Vector:
vecA = self.actionA(data, **kwargs) # type: ignore
return vecA**self.power


class Log10Vector(VectorAction):
"""Calculate log10(A)"""

actionA = ConfigurableActionField(doc="Action which supplies vector A", dtype=VectorAction)

def getInputSchema(self) -> KeyedDataSchema:
yield from self.actionA.getInputSchema() # type: ignore

def __call__(self, data: KeyedData, **kwargs) -> Vector:
vecA = self.actionA(data, **kwargs) # type: ignore
return np.log10(vecA)


class FractionalDifference(VectorAction):
"""Calculate (A-B)/B."""

Expand Down
3 changes: 3 additions & 0 deletions python/lsst/analysis/tools/atools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from .coveragePlots import *
from .diffMatched import *
from .fluxMetrics import *
from .genericBuild import *
from .genericPrep import *
from .genericProduce import *
from .limitingMagnitudeMetric import *
from .magDiff import *
from .numericalValidity import *
Expand All @@ -14,6 +16,7 @@
from .seeingMetric import *
from .shapes import *
from .simpleDiaPlot import *
from .sizeMagnitude import *
from .skyFluxStatisticMetrics import *
from .skyObject import *
from .skySource import *
Expand Down
Loading

0 comments on commit 7def5fa

Please sign in to comment.