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-38004: Fix metrics printing in histPlot #70

Merged
merged 2 commits into from Feb 23, 2023
Merged

Conversation

psferguson
Copy link
Contributor

fix behavior where default stats are not shown

default_stats_panel_bool = self.panels[panel].statsPanel.stat1 is None
default_stats_panel_bool &= self.panels[panel].statsPanel.stat2 is None
default_stats_panel_bool &= self.panels[panel].statsPanel.stat3 is None

Copy link
Contributor

Choose a reason for hiding this comment

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

So what happens if you set, say, stat2, but not stat1 or stat3? If it must be all or none, the config settings should be validated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think I have setup config validation correctly, so that if must be all or none.
I also set the task to fail if somehow a incorrectly configured panel makes it to the _makePanel method

@psferguson psferguson marked this pull request as draft February 15, 2023 19:18
@@ -429,14 +443,21 @@ def _makePanel(self, data, panel, ax, colors, label_font_size=9, legend_font_siz
if self.panels[panel].referenceValue is not None:
ax = self._addReferenceLines(ax, panel, panel_range, legend_font_size=legend_font_size)

if self.panels[panel].statsPanel is None:
# check if we should use the default stats panel or if a custom one
Copy link
Contributor

Choose a reason for hiding this comment

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

The first word should be capitalized.

raise FieldValidationError(self.__class__.stat2, self, msg)
if not bool(self.stat3):
raise FieldValidationError(self.__class__.stat3, self, msg)

Copy link
Contributor

Choose a reason for hiding this comment

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

With this raise structure, it seems we only get to know about the first offending entry, so, e.g. if one tried to specify only stat2, we would learn that step1 wasn't set but would get no warning about step3? Also, the need for all three should also be made clear in the config parameter docs as well (with the hopes that if the reader reads them, they would not encounter this validation error). Speaking of those docs, I find the wording confusing as I don't know what "the first/second/third scalar statistics" are/are meant to be (and why fixed at three?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, I had hoped the error message when a validation fails If one stat is configured, all 3 stats must be configured, would be enough, but I am open to suggestion on how to improve this. Would you recommend checking them all and setting a flag if they fail, and then returning an error that specifies which ones fail.

They are fixed at 3 because of how the statsPanel was implemented in hist plot:

legend_labels = (
([""] * (len(handles) + 1))
+ [stats_dict["statLabels"][0]]
+ [f"{x:.3g}" for x in stats_dict["stat1"]]
+ [stats_dict["statLabels"][1]]
+ [f"{x:.3g}" for x in stats_dict["stat2"]]
+ [stats_dict["statLabels"][2]]
+ [f"{x:.3g}" for x in stats_dict["stat3"]]
)

I think format was chosen to get the right spacing and behavior for the 3 column default case, but breaks if more or fewer columns are provided, and does not easily generalize.

I called them stat1/2/3 because they are supposed to be very general, I wanted to make an easy way showing metrics (such as PA1 and PF1) on a hist plot. I also wanted to make sure the metric calculation used the same code as the stat panel in the histogram; this is why the stats are computed as a build action and passed to hist plot for the produce stage. I am open to calling them something else, but am not sure what would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I leave this all up to you (i.e. I don't really have better suggestions that wouldn't involve a level of verbosity along the lines of your explanations above that some may not like...)! Personally, I'd prefer just to get the message that If one stat is configured, all 3 stats must be configured with no attempt to identify which ones are invalid as opposed to a partial (and thus potentially misleading) list (i.e. specify all or none).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately pex.config.FieldValidationError requires a specific field to be raised (and can only mention 1 field), so I implemented a ValueError in the validation portion with a generic message example here:
ValueError: plots.skySourceHistPlot.produce.panels['panel_sn'].statsPanel : If one stat is configured, all 3 stats must be configured

@psferguson psferguson marked this pull request as ready for review February 23, 2023 01:59
@psferguson psferguson merged commit df25860 into main Feb 23, 2023
@psferguson psferguson deleted the tickets/DM-38004 branch February 23, 2023 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants