Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions config/coaddDepthMetricsWholeSkyPlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Configuration for instances of lsst.analysis.tools.tasks.WholeSkyAnalysisTask
# that aggregate metrics from the standard configuration of
# lsst.analysis.tools.tasks.AssociatedSourcesTractAnalysisTask.

from lsst.analysis.tools.atools import WholeSkyPlotTool

# Keys with band:
keysWithBand = [
"coadd_depth_summary_metrics_depth_above_threshold_1_{band}_mean",
"coadd_depth_summary_metrics_depth_above_threshold_3_{band}_mean",
"coadd_depth_summary_metrics_depth_above_threshold_5_{band}_mean",
"coadd_depth_summary_metrics_depth_above_threshold_12_{band}_mean",
]

for key in keysWithBand:
atoolName = key.replace("_{band}", "")
setattr(config.atools, atoolName, WholeSkyPlotTool)

atool = getattr(config.atools, atoolName)
setattr(atool, "metric", key)

plot = getattr(getattr(atool, 'produce'), 'plot')
setattr(plot, "showOutliers", False)
setattr(plot, "showNaNs", False)
setattr(plot, "labelTracts", True)
setattr(plot, "colorBarMin", 0.0)
setattr(plot, "colorBarMax", 100.0)
setattr(plot, "colorBarRange", 1.0)

config.addOutputNamePrefix = True
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions pipelines/coaddDepthMetrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
description: |
Tier1 plots and metrics to assess coadd quality.
tasks:
analyzeCoaddDepthCore:
class: lsst.analysis.tools.tasks.CoaddDepthSummaryTask
config:
connections.coaddName: template
coaddDepthMetricTract:
class: lsst.analysis.tools.tasks.CoaddDepthTableTractAnalysisTask
config:
connections.coaddName: template
connections.outputName: "template_coadd_depth_summary"
atools.coadd_depth_summary_metrics: CoaddQualityCheck
python: |
from lsst.analysis.tools.atools import CoaddQualityCheck
coaddDepthPlot:
class: lsst.analysis.tools.tasks.CoaddDepthSummaryPlotTask
config:
connections.coaddName: template
connections.outputName: "template"
atools.n_image: CoaddQualityPlot
python: |
from lsst.analysis.tools.atools import CoaddQualityPlot
makeCoaddDepthSummaryMetricTable:
class: lsst.analysis.tools.tasks.MakeMetricTableTask
config:
connections.metricBundleName: "coadd_depth_summary_metrics"
connections.outputTableName: "coadd_depth_summary_metrics_table"
inputDataDimensions: ["skymap", "tract"]
coaddDepthSummaryMetricTableWholeSkyPlot:
class: lsst.analysis.tools.tasks.WholeSkyAnalysisTask
config:
connections.inputName: "coadd_depth_summary_metrics_table"
connections.outputName: "template"
file: $ANALYSIS_TOOLS_DIR/config/coaddDepthMetricsWholeSkyPlot.py
1 change: 1 addition & 0 deletions python/lsst/analysis/tools/actions/plot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .barPlots import *
from .calculateRange import *
from .coaddDepthPlot import *
from .colorColorFitPlot import *
from .completenessPlot import *
from .diaSkyPlot import *
Expand Down
198 changes: 198 additions & 0 deletions python/lsst/analysis/tools/actions/plot/coaddDepthPlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# 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__ = ("CoaddDepthPlot",)

from typing import TYPE_CHECKING, Any, Mapping

import matplotlib.pyplot as plt
from lsst.skymap.tractInfo import ExplicitTractInfo
from lsst.utils.plotting import publication_plots, set_rubin_plotstyle
from matplotlib.figure import Figure
from matplotlib.lines import Line2D

from ...interfaces import PlotAction, Vector
from .plotUtils import addPlotInfo

if TYPE_CHECKING:
from ...interfaces import KeyedData, KeyedDataSchema

bands_dict = publication_plots.get_band_dicts()


class CoaddDepthPlot(PlotAction):
"""Make a plot of pixels per coadd depth."""

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

def getInputSchema(self) -> KeyedDataSchema:
base: list[tuple[str, type[Vector]]] = []
base.append(("patch", Vector))
base.append(("band", Vector))
base.append(("depth", Vector))
base.append(("pixels", Vector))
return base

def __call__(
self,
data: KeyedData,
tractInfo: ExplicitTractInfo,
**kwargs,
) -> Figure:
self._validateInput(data, tractInfo)

if not isinstance(tractInfo, ExplicitTractInfo):
raise TypeError(f"Input `tractInfo` type must be {ExplicitTractInfo} not {type(tractInfo)}.")

return self.makePlot(data, tractInfo, **kwargs)

def _validateInput(
self,
data: KeyedData,
tractInfo: ExplicitTractInfo,
) -> None:
needed = set(k[0] for k in self.getInputSchema())
if not needed.issubset(data.keys()):
raise ValueError(f"Input data does not contain all required keys: {self.getInputSchema()}")

def makePlot(
self,
data: KeyedData,
tractInfo: ExplicitTractInfo,
plotInfo: Mapping[str, str] | None = None,
**kwargs: Any,
) -> Figure:
"""Make the plot.

Parameters
----------
`KeyedData`
The catalog to plot the points from.
tractInfo : `~lsst.skymap.tractInfo.ExplicitTractInfo`
The tract info object.
plotInfo : `dict`
A dictionary of the plot information.

Returns
-------
fig : `~matplotlib.figure.Figure`
The resulting figure.

Examples
--------
An example coaddDepthPlot may be seen below:

.. image:: /_static/analysis_tools/coaddDepthPlotExample.png
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add an example figure here, please? Sophie Reed pointed this out to me when I recently made a new plot action. An example is here (but most other plot actions have them, too). It took me a while to figure out where I needed to put the plot - it goes in doc/_static/analysis_tools/ in this repo, then the doc generator finds it when it builds the docs for the website. Pretty nifty!

set_rubin_plotstyle()
fig = plt.figure(dpi=300, figsize=(20, 20))

# Get number of vertical and horizontal patches in the tract.
num_patches_x, num_patches_y = tractInfo.getNumPatches()

max_depth = max(data["depth"])
max_pixels = max(data["pixels"])

plt.subplots_adjust(hspace=0, wspace=0)

patch_counter = (num_patches_x * num_patches_y) - num_patches_x # The top left corner of a tract
m = 0 # subplot index
while patch_counter >= 0:
for n in range(num_patches_x): # column index
ax = plt.subplot(num_patches_x, num_patches_y, m + 1)
patch_mask = data["patch"] == patch_counter

if patch_counter in data["patch"]:
uniqueBands = set(data["band"][patch_mask])
for band in uniqueBands:
color = bands_dict["colors"][band]
markerstyle = bands_dict["symbols"][band]
band_mask = data["band"] == band

tot_mask = (patch_mask) & (band_mask)

ax.plot(
data["depth"][tot_mask],
data["pixels"][tot_mask],
color=color,
linewidth=0,
ls=None,
marker=markerstyle,
ms=4,
alpha=0.75,
label=f"{band}",
)
ax.grid(alpha=0.5)

# Chart formatting
# Need a solution for ax.set_xscale when max_depth is high,
# but not all patches/bands have quality coverage.
ax.set_yscale("log")
ax.set_xlim(0, max_depth + 5)
ax.set_ylim(5, max_pixels)
# Can we somehow generalize ax.set_xticks?
# ax.set_xticks(np.arange(0, max_depth, 20))
ax.tick_params(axis="both", which="minor")
ax.tick_params(axis="both", which="both", top=False, right=False)

# Only label axes of the farmost left and bottom row of plots
if n != 0:
ax.set_yticklabels([])
ax.tick_params(axis="y", which="both", length=0)
if patch_counter not in range(num_patches_x):
ax.set_xticklabels([])
ax.tick_params(axis="x", which="both", length=0)

ax.set_title(f"patch {patch_counter}", y=0.85)
patch_counter += 1
m += 1
patch_counter -= 2 * (n + 1)
fig.supxlabel("Number of input visits (n_image depth)", y=0.075)
fig.supylabel("Count (pixels)", x=0.075)
legend_elements = [
Line2D(
[0], [0], color=bands_dict["colors"]["u"], lw=0, marker=bands_dict["symbols"]["u"], label="u"
),
Line2D(
[0], [0], color=bands_dict["colors"]["g"], lw=0, marker=bands_dict["symbols"]["g"], label="g"
),
Line2D(
[0], [0], color=bands_dict["colors"]["r"], lw=0, marker=bands_dict["symbols"]["r"], label="r"
),
Line2D(
[0], [0], color=bands_dict["colors"]["i"], lw=0, marker=bands_dict["symbols"]["i"], label="i"
),
Line2D(
[0], [0], color=bands_dict["colors"]["z"], lw=0, marker=bands_dict["symbols"]["z"], label="z"
),
Line2D(
[0], [0], color=bands_dict["colors"]["y"], lw=0, marker=bands_dict["symbols"]["y"], label="y"
),
]
plt.legend(handles=legend_elements, loc="upper left", bbox_to_anchor=(1.05, 10))

if plotInfo is not None:
fig = addPlotInfo(fig, plotInfo)

return fig
Loading
Loading