4 from .plot
import ValidationPlot, compose_axis_label, get_unit
7 from .utilities
import erf
15 from .tolerate_missing_key_formatter
import TolerateMissingKeyFormatter
17 formatter = TolerateMissingKeyFormatter()
21 """Perform resolution analysis"""
24 default_outlier_z_score = 5.0
26 default_min_required_entries = 50
28 default_plot_name =
"{plot_name_prefix}_{subplot_name}{plot_name_postfix}"
30 default_plot_title =
"{subplot_title} of {quantity_name}{plot_title_postfix}"
32 default_which_plots = [
37 default_is_expert =
True
50 min_required_entries=None,
53 plot_title_postfix='',
54 referenceFileName=None,
56 """Performs a comparison of an estimated quantity to their truths by generating standardized validation plots."""
61 self.
unit = unit
or get_unit(quantity_name)
69 if outlier_z_score
is None:
95 self.
plots = collections.OrderedDict()
108 """Compares the concrete estimate to the truth and generates plots of the resolution
112 bin_values : array_like(float
113 The parametr used for binning
114 truths : array_like(float)
115 Sample of the true values
116 estimates : array_like(float)
117 Corresponding estimations
120 if is_expert
is None:
123 if which_plots
is None:
128 axis_label = compose_axis_label(quantity_name, self.
unit)
134 if plot_name
is None:
137 plot_name = formatter.format(plot_name,
138 quantity_name=quantity_name,
139 plot_name_prefix=plot_name_prefix,
143 if plot_title
is None:
146 plot_title = formatter.format(plot_title,
147 quantity_name=quantity_name,
151 residuals = estimates - truths
155 if "resolution" in which_plots:
159 resolution_values = []
164 assert (lower_bin < upper_bin)
165 bin_center = lower_bin + (upper_bin - lower_bin) / 2.0
166 assert (len(bin_values) == len(residuals))
169 sel_residuals = collections.deque()
171 for i
in range(len(bin_values)):
172 if bin_values[i] >= lower_bin
and bin_values[i] < upper_bin:
173 sel_residuals.append(residuals[i])
175 residuals_hist_name = formatter.format(plot_name, subplot_name=
"residuals") + \
176 "{}_to_{}".format(lower_bin, upper_bin)
178 vplot.hist(sel_residuals,
179 outlier_z_score=outlier_z_score,
181 vplot.xlabel = compose_axis_label(
"#Delta " + quantity_name +
" (estimate - truth)", self.
unit)
182 vplot.title = formatter.format(plot_title, subplot_title=
'Residual distribution')
186 gaus_sigma_err =
None
190 fit_res = vplot.fit_gaus(z_score=1)
193 params = fit_res.GetParams()
194 errs = fit_res.Errors()
196 gaus_mean = params[1]
197 gaus_sigma = params[2]
198 gaus_sigma_err = errs[2]
200 res_histogram += [(lower_bin, upper_bin, bin_center, vplot)]
201 self.
plots[
'residuals' + residuals_hist_name] = vplot
204 resolution_values += [(lower_bin, upper_bin, bin_center, gaus_sigma, gaus_sigma_err)]
206 resolution_graph_name = formatter.format(plot_name, subplot_name=
"resolution")
215 for v
in resolution_values:
224 resolution_graph.grapherrors((np.array(xs), np.array(xs_err)), (np.array(ys), np.array(ys_err)),
228 resolution_graph.title = formatter.format(plot_title, subplot_title=
'Resolution')
230 self.
plots[resolution_graph_name] = resolution_graph
237 """Get the contact person's name"""
242 """Set the contact person's name"""
244 for validation_plot
in list(self.
plots.values()):
245 validation_plot.contact = contact
248 """Write all validation plot to the given Root directory"""
249 for validation_plot
in list(self.
plots.values()):
250 validation_plot.write(tDirectory)