Skip to content
Open
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
22 changes: 12 additions & 10 deletions python/lsst/analysis/tools/actions/plot/completenessPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class CompletenessHist(PlotAction):
)
legendLocation = Field[str](doc="Legend position within main plot", default="lower left")
mag_ref_label = Field[str](
doc="Label for the completeness x axis.", default="{band}-band Reference Magnitude"
doc="Label for the completeness x axis.", default="{band}-band {name_flux} Magnitude"
)
mag_target_label = Field[str](
doc="Label for the purity x axis.", default="{band}-band Measured Magnitude"
doc="Label for the purity x axis.", default="{band}-band {name_flux} Magnitude"
)
object_label = Field[str](doc="Label for measured objects", default="Object")
reference_label = Field[str](doc="Label for reference objects", default="Reference")
Expand Down Expand Up @@ -202,19 +202,21 @@ def makePlot(self, data, plotInfo, **kwargs):
(data[names["completeness_good_match"]], False, self.color_right, "Correct Class"),
)

mag_ref_label = self.mag_ref_label
if "{band}" in mag_ref_label:
mag_ref_label = mag_ref_label.format(band=band)
mag_target_label = self.mag_target_label
if "{band}" in mag_target_label:
mag_target_label = mag_target_label.format(band=band)
# If the user left the name_flux template in the label value
# but never formatted it, apply a sensible generic default
mag_labels = {
"ref": (self.mag_ref_label, "Reference"),
"target": (self.mag_target_label, "Measured"),
}
for key, (label, name_flux_default) in mag_labels.items():
mag_labels[key] = label.format(band=band, name_flux=name_flux_default)

plots = {
"Completeness": {
"count_type": self.reference_label,
"counts": data[names["count_ref"]],
"lines": lineTuples,
"xlabel": mag_ref_label,
"xlabel": mag_labels["ref"],
},
}
if self.show_purity:
Expand All @@ -226,7 +228,7 @@ def makePlot(self, data, plotInfo, **kwargs):
(data[names["purity_bad_match"]], False, self.color_wrong, "Incorrect class"),
(data[names["purity_good_match"]], False, self.color_right, "Correct class"),
),
"xlabel": mag_target_label,
"xlabel": mag_labels["target"],
}

# idx == 0 should be completeness; update this if that assumption
Expand Down
20 changes: 19 additions & 1 deletion python/lsst/analysis/tools/atools/diffMatched.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,28 @@ def finalize(self):
overrides["color_counts"] = galaxies_color()
elif name_type == self.type_stars:
overrides["color_counts"] = stars_color()
plot_action = CompletenessHist(
action=completeness_plot,
)
# Since the plot action is made on the fly, it can't be
# configured in a pipeline yaml. This makes the keys
# formattable, but (unfortunately) in a way that's hard
# to discover or document.
for label_type in ("ref", "target"):
name_mag_label = f"mag_{label_type}_label"
label = getattr(plot_action, name_mag_label)
if "{name_flux}" in label:
name_flux = getattr(self, f"config_mag_{label_type}").name_flux
# Still no support for partial formatting, i.e.
# if {band} is in label and it's not a kwarg of
# format, it will raise a KeyError
kwargs_format = {"band": "{band}"} if "{band}" in label else {}
label = label.format(name_flux=name_flux, **kwargs_format)
setattr(plot_action, name_mag_label, label)
setattr(
self.produce.plot.actions,
object_class,
CompletenessHist(action=completeness_plot),
plot_action,
)

def reconfigure_dependent_magnitudes(
Expand Down
Loading