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-35632: Port CModel PSFmag gal sky plot to analysis tools #14

Merged
merged 2 commits into from
Nov 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/lsst/analysis/tools/actions/plot/colorColorFitPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def makePlot(

# Add some useful information to the plot
bbox = dict(alpha=0.9, facecolor="white", edgecolor="none")
medMag = np.median(cast(Vector, mags))
medMag = np.nanmedian(cast(Vector, mags))

# TODO: GET THE SN FROM THE EARLIER PREP STEP
SN = "-"
Expand Down Expand Up @@ -318,9 +318,9 @@ def makePlot(
# Add a histogram
axHist.set_ylabel("Number")
axHist.set_xlabel("Distance to Line Fit")
medDists = np.median(dists)
madDists = sigmaMad(dists)
meanDists = np.mean(dists)
medDists = np.nanmedian(dists)
madDists = sigmaMad(dists, nan_policy="omit")
meanDists = np.nanmean(dists)

axHist.set_xlim(meanDists - 2.0 * madDists, meanDists + 2.0 * madDists)
lineMedian = axHist.axvline(medDists, color="k", label="Median: {:0.3f}".format(medDists))
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/analysis/tools/actions/plot/plotUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def extremaSort(xs):
ids : `np.array`
"""

med = np.median(xs)
med = np.nanmedian(xs)
dists = np.abs(xs - med)
ids = np.argsort(dists)
return ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ def _scatterPlot(

for (i, xEdge) in enumerate(xEdgesPlot):
ids = np.where((xs < xEdge) & (xs > xEdges[i]) & (np.isfinite(ys)))[0]
med = np.median(ys[ids])
sigMad = sigmaMad(ys[ids])
med = np.nanmedian(ys[ids])
sigMad = sigmaMad(ys[ids], nan_policy="omit")
meds[i] = med
sigMads[i] = sigMad
threeSigMadVerts[i, :] = [xEdge, med + 3 * sigMad]
Expand Down Expand Up @@ -619,7 +619,7 @@ def _scatterPlot(
plotMed = np.nanmedian(cast(Vector, data["yGalaxies"]))
# Ignore types below pending making this not working my accident
if len(xs) < 2: # type: ignore
meds = [np.median(ys)] # type: ignore
meds = [np.nanmedian(ys)] # type: ignore
if self.yLims:
ax.set_ylim(self.yLims[0], self.yLims[1]) # type: ignore
else:
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/analysis/tools/actions/plot/skyPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ def makePlot(
maxRa += 1e-5 # There is no reason to pick this number in particular
if minDec == maxDec:
maxDec += 1e-5 # There is no reason to pick this number in particular
med = np.median(colorVals)
mad = sigmaMad(colorVals)
med = np.nanmedian(colorVals)
mad = sigmaMad(colorVals, nan_policy="omit")
vmin = med - 2 * mad
vmax = med + 2 * mad
if self.fixAroundZero:
Expand Down
68 changes: 68 additions & 0 deletions python/lsst/analysis/tools/analysisPlots/magDiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This file is part of analysis_tools.
#
# 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/>.
from __future__ import annotations

__all__ = ("CModelSubPsfMagMeasSkyGalaxies",)

from ..actions.plot.skyPlot import SkyPlot
from ..actions.vector import CoaddPlotFlagSelector, GalaxySelector, LoadVector, MagDiff, SnSelector
from ..interfaces import AnalysisPlot


class CModelSubPsfMagMeasSkyGalaxies(AnalysisPlot):
"""Make a plot showing the difference between the cmodel magnitude and the
PSF magnitude. This plot shows the on sky distribution of these values
for galaxies.
"""

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

self.prep.selectors.flagSelector = CoaddPlotFlagSelector()
self.prep.selectors.flagSelector.bands = ["g", "r", "i"]

self.prep.selectors.snSelector = SnSelector()
self.prep.selectors.snSelector.bands = ["i"]
self.prep.selectors.snSelector.fluxType = "{band}_psfFlux"
self.prep.selectors.snSelector.threshold = 100

self.prep.selectors.galaxySelector = GalaxySelector()
self.prep.selectors.galaxySelector.columnKey = "{band}_extendedness"

# TODO: Can we make these defaults somewhere?
self.process.buildActions.xGalaxies = LoadVector()
self.process.buildActions.xGalaxies.vectorKey = "coord_ra"
self.process.buildActions.yGalaxies = LoadVector()
self.process.buildActions.yGalaxies.vectorKey = "coord_dec"
self.process.buildActions.galaxyStatMask = SnSelector()
self.process.buildActions.galaxyStatMask.fluxType = "{band}_psfFlux"

self.process.buildActions.zGalaxies = MagDiff()
self.process.buildActions.zGalaxies.col1 = "{band}_cModelFlux"
self.process.buildActions.zGalaxies.col2 = "{band}_psfFlux"

self.produce = SkyPlot()
self.produce.plotTypes = ["galaxies"]
self.produce.plotName = "CModel_sub_PSF_meas_galaxies_{band}"
self.produce.xAxisLabel = "R.A. (degrees)"
self.produce.yAxisLabel = "Dec. (degrees)"
self.produce.zAxisLabel = "CModel - PSF (mmag) (Meas)"
self.produce.plotOutlines = False