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-38595: Replace context usage in with base Config (using ChoiceField) #76

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 2 additions & 3 deletions pipelines/coaddColumnValidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ tasks:
connections.outputName: objectTableColumnValidate
atools.validPsfFluxMetric: ValidFracColumnMetric
atools.validPsfFluxMetric.vectorKey: 'psfFlux'
atools.validPsfFluxMetric.applyContext: CoaddContext
atools.validPsfFluxMetric.context: 'coadd'
atools.validCmodelFluxMetric: ValidFracColumnMetric
atools.validCmodelFluxMetric.vectorKey: 'cModelFlux'
atools.validCmodelFluxMetric.applyContext: CoaddContext
atools.validCmodelFluxMetric.context: 'coadd'
python: |
from lsst.analysis.tools.atools import *
from lsst.analysis.tools.contexts import *
32 changes: 12 additions & 20 deletions pipelines/coaddDiffMatchedQualityExtended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,50 @@ tasks:

# plots
atools.matchedRefCModelMagDiffPlot: MatchedRefCoaddCModelFluxPlot
atools.matchedRefCModelMagDiffPlot.applyContext: MatchedRefDiffContext
atools.matchedRefCModelMagDiffPlot.context: 'diff'

atools.matchedRefCModelFluxChiPlot: MatchedRefCoaddCModelFluxPlot
atools.matchedRefCModelFluxChiPlot.applyContext: MatchedRefChiContext
atools.matchedRefCModelFluxChiPlot.context: 'chi'

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

atools.matchedRefPositionXChiPlot: MatchedRefCoaddPositionPlot
atools.matchedRefPositionXChiPlot.variable: x
atools.matchedRefPositionXChiPlot.applyContext: MatchedRefChiContext
atools.matchedRefPositionXChiPlot.context: 'chi'

atools.matchedRefPositionYDiffPlot: MatchedRefCoaddPositionPlot
atools.matchedRefPositionYDiffPlot.variable: y
atools.matchedRefPositionYDiffPlot.applyContext: MatchedRefDiffContext
atools.matchedRefPositionYDiffPlot.context: 'diff'

atools.matchedRefPositionYChiPlot: MatchedRefCoaddPositionPlot
atools.matchedRefPositionYChiPlot.variable: y
atools.matchedRefPositionYChiPlot.applyContext: MatchedRefChiContext
atools.matchedRefPositionYChiPlot.context: 'chi'

# metrics
atools.matchedRefCModelMagDiffMetric: MatchedRefCoaddCModelFluxMetric
atools.matchedRefCModelMagDiffMetric.applyContext: MatchedRefDiffContext
atools.matchedRefCModelMagDiffMetric.context: 'diff'

atools.matchedRefCModelFluxChiMetric: MatchedRefCoaddCModelFluxMetric
atools.matchedRefCModelFluxChiMetric.applyContext: MatchedRefChiContext
atools.matchedRefCModelFluxChiMetric.context: 'chi'

atools.matchedRefPositionXDiffMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionXDiffMetric.variable: x
atools.matchedRefPositionXDiffMetric.applyContext: MatchedRefChiContext
atools.matchedRefPositionXDiffMetric.context: 'chi'

atools.matchedRefPositionXChiMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionXChiMetric.variable: x
atools.matchedRefPositionXChiMetric.applyContext: MatchedRefChiContext
atools.matchedRefPositionXChiMetric.context: 'chi'

atools.matchedRefPositionYDiffMetric: MatchedRefCoaddPositionMetric
atools.matchedRefPositionYDiffMetric.variable: y
atools.matchedRefPositionYDiffMetric.applyContext: MatchedRefDiffContext
atools.matchedRefPositionYDiffMetric.context: 'diff'

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

atools.matchedRefPositionYChiMetric.context: 'chi'

python: |
from lsst.analysis.tools.atools.diffMatched import (
Expand All @@ -66,8 +63,3 @@ tasks:
MatchedRefCoaddCModelFluxPlot,
MatchedRefCoaddPositionPlot,
)

from lsst.analysis.tools.contexts._contexts import (
MatchedRefDiffContext,
MatchedRefChiContext,
)
4 changes: 1 addition & 3 deletions pipelines/coaddQualityCore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tasks:
atools.e1Diff: E1Diff
atools.e2Diff: E2Diff
atools.skyFluxStatisticMetric: SkyFluxStatisticMetric
atools.skyFluxStatisticMetric.applyContext: CoaddContext
atools.skyFluxStatisticMetric.context: 'coadd'
atools.wPerpPSFP: WPerpPSF
atools.wPerpCModel: WPerpCModel
atools.xPerpPSFP: XPerpPSF
Expand All @@ -20,7 +20,6 @@ tasks:
atools.skyObjectHistPlot: SkyObjectHistPlot
python: |
from lsst.analysis.tools.atools import *
from lsst.analysis.tools.contexts import *
analyzeObjectTableSurveyCore:
class: lsst.analysis.tools.tasks.ObjectTableSurveyAnalysisTask
config:
Expand All @@ -29,7 +28,6 @@ tasks:
bands: ["i"]
python: |
from lsst.analysis.tools.atools import *
from lsst.analysis.tools.contexts import *
from lsst.analysis.tools.actions.plot import *
catalogMatchTract:
class: lsst.analysis.tools.tasks.catalogMatch.CatalogMatchTask
Expand Down
25 changes: 12 additions & 13 deletions pipelines/visitColumnValidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,39 @@ tasks:
connections.outputName: visitTableColumnValidate
atools.validPsfFluxMetric: ValidFracColumnMetric
atools.validPsfFluxMetric.vectorKey: 'psfFlux'
atools.validPsfFluxMetric.applyContext: VisitContext
atools.validPsfFluxMetric.context: 'visit'
atools.validAp03FluxMetric: ValidFracColumnMetric
atools.validAp03FluxMetric.vectorKey: 'ap03Flux'
atools.validAp03FluxMetric.applyContext: VisitContext
atools.validAp03FluxMetric.context: 'visit'
atools.validAp06FluxMetric: ValidFracColumnMetric
atools.validAp06FluxMetric.vectorKey: 'ap06Flux'
atools.validAp06FluxMetric.applyContext: VisitContext
atools.validAp06FluxMetric.context: 'visit'
atools.validAp09FluxMetric: ValidFracColumnMetric
atools.validAp09FluxMetric.vectorKey: 'ap09Flux'
atools.validAp09FluxMetric.applyContext: VisitContext
atools.validAp09FluxMetric.context: 'visit'
atools.validAp12FluxMetric: ValidFracColumnMetric
atools.validAp12FluxMetric.vectorKey: 'ap12Flux'
atools.validAp12FluxMetric.applyContext: VisitContext
atools.validAp12FluxMetric.context: 'visit'
atools.validAp17FluxMetric: ValidFracColumnMetric
atools.validAp17FluxMetric.vectorKey: 'ap17Flux'
atools.validAp17FluxMetric.applyContext: VisitContext
atools.validAp17FluxMetric.context: 'visit'
atools.validAp25FluxMetric: ValidFracColumnMetric
atools.validAp25FluxMetric.vectorKey: 'ap25Flux'
atools.validAp25FluxMetric.applyContext: VisitContext
atools.validAp25FluxMetric.context: 'visit'
atools.validAp35FluxMetric: ValidFracColumnMetric
atools.validAp35FluxMetric.vectorKey: 'ap35Flux'
atools.validAp35FluxMetric.applyContext: VisitContext
atools.validAp35FluxMetric.context: 'visit'
atools.validAp50FluxMetric: ValidFracColumnMetric
atools.validAp50FluxMetric.vectorKey: 'ap50Flux'
atools.validAp50FluxMetric.applyContext: VisitContext
atools.validAp50FluxMetric.context: 'visit'
atools.validAp70FluxMetric: ValidFracColumnMetric
atools.validAp70FluxMetric.vectorKey: 'ap70Flux'
atools.validAp70FluxMetric.applyContext: VisitContext
atools.validAp70FluxMetric.context: 'visit'
atools.validCalibFluxMetric: ValidFracColumnMetric
atools.validCalibFluxMetric.vectorKey: 'calibFlux'
atools.validCalibFluxMetric.applyContext: VisitContext
atools.validCalibFluxMetric.context: 'visit'
atools.validGaussianFluxMetric: ValidFracColumnMetric
atools.validGaussianFluxMetric.vectorKey: 'gaussianFlux'
atools.validGaussianFluxMetric.applyContext: VisitContext
atools.validGaussianFluxMetric.context: 'visit'
python: |
from lsst.analysis.tools.atools import *
from lsst.analysis.tools.contexts import *
3 changes: 1 addition & 2 deletions pipelines/visitQualityCore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ tasks:
# metrics.name = AMetricsClass
connections.outputName: sourceTableCore
atools.skyFluxVisitStatisticMetric: SkyFluxStatisticMetric
atools.skyFluxVisitStatisticMetric.applyContext: VisitContext
atools.skyFluxVisitStatisticMetric.context: 'visit'
atools.skySourceSkyPlot: SkySourceSkyPlot
atools.skySourceHistPlot: SkySourceHistPlot
python: |
from lsst.analysis.tools.atools import *
from lsst.analysis.tools.contexts import *
127 changes: 77 additions & 50 deletions python/lsst/analysis/tools/atools/astrometryWithReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
from __future__ import annotations

__all__ = (
"CoordinateConfig",
"TargetRefCatDeltaRAScatterPlot",
"TargetRefCatDeltaDecScatterPlot",
"TargetRefCatDeltaRASkyPlot",
"TargetRefCatDeltaDecSkyPlot",
)

from lsst.pex.config import Field
from lsst.pex.config import ChoiceField, Config, Field

from ..actions.plot.scatterplotWithTwoHists import ScatterPlotStatsAction, ScatterPlotWithTwoHists
from ..actions.plot.skyPlot import SkyPlot
Expand All @@ -41,10 +42,19 @@
VectorSelector,
)
from ..interfaces import AnalysisTool
from .coaddVisit import CoaddVisitConfig
from .genericPrep import CoaddPrep, VisitPrep


class TargetRefCatDelta(AnalysisTool):
class CoordinateConfig(Config):
coordinate = ChoiceField[str](
doc="The name of the sky coordinate",
allowed={"RA": "Right Ascension", "Dec": "Declination"},
optional=False,
)


class TargetRefCatDelta(AnalysisTool, CoaddVisitConfig, CoordinateConfig):
"""Plot the difference in milliseconds between a target catalog and a
reference catalog for the coordinate set in `setDefaults`.
"""
Expand All @@ -53,37 +63,42 @@ class TargetRefCatDelta(AnalysisTool):
doc="Does this AnalysisTool support band as a name parameter", default=True
)

def coaddContext(self) -> None:
self.prep = CoaddPrep()
self.process.buildActions.starSelector.vectorKey = "{band}_extendedness"
self.process.buildActions.mags = MagColumnNanoJansky(vectorKey="{band}_psfFlux")
self.process.filterActions.psfFlux = DownselectVector(
vectorKey="{band}_psfFlux", selector=VectorSelector(vectorKey="starSelector")
)
self.process.filterActions.psfFluxErr = DownselectVector(
vectorKey="{band}_psfFluxErr", selector=VectorSelector(vectorKey="starSelector")
)

def visitContext(self) -> None:
self.parameterizedBand = False
self.prep = VisitPrep()
self.process.buildActions.starSelector.vectorKey = "extendedness"
self.process.buildActions.mags = MagColumnNanoJansky(vectorKey="psfFlux")
self.process.filterActions.psfFlux = DownselectVector(
vectorKey="psfFlux", selector=VectorSelector(vectorKey="starSelector")
)
self.process.filterActions.psfFluxErr = DownselectVector(
vectorKey="psfFluxErr", selector=VectorSelector(vectorKey="starSelector")
def finalize(self):
AnalysisTool().finalize()
if self.context == "coadd":
self.prep = CoaddPrep()
self.process.buildActions.starSelector.vectorKey = "{band}_extendedness"
self.process.buildActions.mags = MagColumnNanoJansky(vectorKey="{band}_psfFlux")
self.process.filterActions.psfFlux = DownselectVector(
vectorKey="{band}_psfFlux", selector=VectorSelector(vectorKey="starSelector")
)
self.process.filterActions.psfFluxErr = DownselectVector(
vectorKey="{band}_psfFluxErr", selector=VectorSelector(vectorKey="starSelector")
)
elif self.context == "visit":
self.parameterizedBand = False
self.prep = VisitPrep()
self.process.buildActions.starSelector.vectorKey = "extendedness"
self.process.buildActions.mags = MagColumnNanoJansky(vectorKey="psfFlux")
self.process.filterActions.psfFlux = DownselectVector(
vectorKey="psfFlux", selector=VectorSelector(vectorKey="starSelector")
)
self.process.filterActions.psfFluxErr = DownselectVector(
vectorKey="psfFluxErr", selector=VectorSelector(vectorKey="starSelector")
)
else:
raise ValueError(f"Unsupported {self.context=}")

coordStr = self.coordinate.lower()
self.process.buildActions.astromDiff = AstromDiff(
col1=f"coord_{coordStr}_target", col2=f"coord_{coordStr}_ref"
)
self.produce.plot.yAxisLabel = f"${self.coordinate}_{{target}} - {self.coordinate}_{{ref}}$ (marcsec)"

def setDefaults(self, coordinate):
def setDefaults(self):
super().setDefaults()

self.process.buildActions.starSelector = StarSelector()
coordStr = coordinate.lower()
self.process.buildActions.astromDiff = AstromDiff(
col1=f"coord_{coordStr}_target", col2=f"coord_{coordStr}_ref"
)

self.process.filterActions.xStars = DownselectVector(
vectorKey="mags", selector=VectorSelector(vectorKey="starSelector")
Expand All @@ -101,7 +116,8 @@ def setDefaults(self, coordinate):

self.produce.plot.plotTypes = ["stars"]
self.produce.plot.xAxisLabel = "PSF Magnitude (mag)"
self.produce.plot.yAxisLabel = f"${coordinate}_{{target}} - {coordinate}_{{ref}}$ (marcsec)"
# Placeholder
self.produce.plot.yAxisLabel = ""
self.produce.plot.magLabel = "PSF Magnitude (mag)"


Expand All @@ -111,7 +127,8 @@ class TargetRefCatDeltaRAScatterPlot(TargetRefCatDelta):
"""

def setDefaults(self):
super().setDefaults(coordinate="RA")
super().setDefaults()
self.coordinate = "RA"


class TargetRefCatDeltaDecScatterPlot(TargetRefCatDelta):
Expand All @@ -120,10 +137,11 @@ class TargetRefCatDeltaDecScatterPlot(TargetRefCatDelta):
"""

def setDefaults(self):
super().setDefaults(coordinate="Dec")
super().setDefaults()
self.coordinate = "Dec"


class TargetRefCatDeltaSkyPlot(AnalysisTool):
class TargetRefCatDeltaSkyPlot(AnalysisTool, CoaddVisitConfig, CoordinateConfig):
"""Base class for plotting the RA/Dec distribution of stars, with the
difference between the RA or Dec of the target and reference catalog as
the color.
Expand All @@ -133,37 +151,44 @@ class TargetRefCatDeltaSkyPlot(AnalysisTool):
doc="Does this AnalysisTool support band as a name parameter", default=True
)

def coaddContext(self) -> None:
self.prep = CoaddPrep()
def finalize(self):
AnalysisTool().finalize()
if self.context == "coadd":
self.prep = CoaddPrep()

self.process.buildActions.starStatMask = SnSelector()
self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux"
self.process.buildActions.starStatMask = SnSelector()
self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux"
elif self.context == "visit":
self.parameterizedBand = False
self.prep = VisitPrep()

def visitContext(self) -> None:
self.parameterizedBand = False
self.prep = VisitPrep()

self.process.buildActions.starStatMask = SnSelector()
self.process.buildActions.starStatMask.fluxType = "psfFlux"

def setDefaults(self, coordinate):
super().setDefaults()
self.process.buildActions.starStatMask = SnSelector()
self.process.buildActions.starStatMask.fluxType = "psfFlux"
else:
raise ValueError(f"Unsupported {self.context=}")

coordStr = coordinate.lower()
coordStr = self.coordinate.lower()
self.process.buildActions.zStars = AstromDiff(
col1=f"coord_{coordStr}_target", col2=f"coord_{coordStr}_ref"
)
self.produce.plotName = f"astromDiffSky_{self.coordinate}"
self.produce.zAxisLabel = f"${self.coordinate}_{{target}} - {self.coordinate}_{{ref}}$ (marcsec)"

def setDefaults(self):
super().setDefaults()

self.process.buildActions.xStars = LoadVector()
self.process.buildActions.xStars.vectorKey = "coord_ra_target"
self.process.buildActions.yStars = LoadVector()
self.process.buildActions.yStars.vectorKey = "coord_dec_target"

self.produce = SkyPlot()
self.produce.plotTypes = ["stars"]
self.produce.plotName = f"astromDiffSky_{coordinate}"
self.produce.xAxisLabel = "R.A. (degrees)"
self.produce.yAxisLabel = "Dec. (degrees)"
self.produce.zAxisLabel = f"${coordinate}_{{target}} - {coordinate}_{{ref}}$ (marcsec)"
# Placeholders
self.produce.zAxisLabel = ""
self.produce.plotName = ""
self.produce.plotOutlines = False


Expand All @@ -173,7 +198,8 @@ class TargetRefCatDeltaRASkyPlot(TargetRefCatDeltaSkyPlot):
"""

def setDefaults(self):
super().setDefaults(coordinate="RA")
super().setDefaults()
self.coordinate = "RA"


class TargetRefCatDeltaDecSkyPlot(TargetRefCatDeltaSkyPlot):
Expand All @@ -182,4 +208,5 @@ class TargetRefCatDeltaDecSkyPlot(TargetRefCatDeltaSkyPlot):
"""

def setDefaults(self):
super().setDefaults(coordinate="Dec")
super().setDefaults()
self.coordinate = "Dec"
Loading