MetricBundle¶
- class rubin_sim.maf.metric_bundles.MetricBundle(metric, slicer, constraint=None, stacker_list=None, run_name='run name', metadata=None, info_label=None, plot_dict=None, display_dict=None, summary_metrics=None, maps_list=None, file_root=None, plot_funcs=None)¶
Bases:
object
The MetricBundle is defined by a combination of a (single) metric, slicer and constraint - together these define a unique combination of an opsim benchmark. An example would be: a CountMetric, a HealpixSlicer, and a constraint ‘filter=”r”’.
After the metric is evaluated over the slice_points of the slicer, the resulting metric values are saved in the MetricBundle.
The MetricBundle also saves the summary metrics to be used to generate summary statistics over those metric values, as well as the resulting summary statistic values.
Plotting parameters and display parameters (for showMaf) are saved in the MetricBundle, as well as additional info_label such as the opsim run name, and relevant stackers and maps to apply when calculating the metric values.
- Parameters:
- metric
metric
The Metric class to run per slice_point
- slicer
slicer
The Slicer to apply to the incoming visit data (the observations).
- constraint
str
or None, opt A (sql-style) constraint to apply to the visit data, to apply a broad sub-selection.
- stacker_list
list
ofstacker
, opt A list of pre-configured stackers to use to generate additional columns per visit. These will be generated automatically if needed, but pre-configured versions will override these.
- run_name
str
, opt The name of the simulation being run. This will be added to output files and plots. Setting it prevents file conflicts when running the same metric on multiple simulations, and provides a way to identify which simulation is being analyzed.
- metadata
str
, opt A deprecated version of info_label (below). Values set by metadata will be used for info_label. If both are set, info_label is used.
- info_label
str
or None, opt Information to add to the output metric data file name and plot labels. If this is not provided, it will be auto-generated from the constraint (if any). Setting this provides an easy way to specify different configurations of a metric, a slicer, or just to rewrite your constraint into friendlier terms. (i.e. a constraint like ‘note not like “%DD%”’ can become “non-DD” in the file name and plot labels by specifying info_label).
- plot_dict
dict
of plotting parameters, opt Specify general plotting parameters, such as x/y/color limits.
- display_dict
dict
of display parameters, opt Specify parameters for showMaf web pages, such as the side bar labels and figure captions. Keys: ‘group’, ‘subgroup’, ‘caption’, and ‘order’ (such as to set metrics in filter order, etc)
- summary_metrics
list
ofmetrics
A list of summary metrics to run to summarize the primary metric, such as MedianMetric, etc.
- maps_list
list
ofmaps
A list of pre-configured maps to use for the metric. This will be auto-generated if specified by the metric class, but pre-configured versions will override these.
- metric
Attributes Summary
Methods Summary
compute_summary_stats
([results_db])Compute summary statistics on metric_values, using summaryMetrics (metricbundle list).
load
(filename)Create a metric bundle and load its content from disk.
Set up and call the baseSlicer outputJSON method, to output to IO string.
plot
([plot_handler, plot_func, ...])Create all plots available from the slicer.
read
(filename)Read metric_values and associated info_label from disk.
reduce_metric
(reduce_func[, ...])Run 'reduceFunc' (any function that operates on self.metric_values).
set_display_dict
([display_dict, results_db])Set or update any property of display_dict.
set_plot_dict
(plot_dict)Set or update any property of plot_dict.
set_plot_funcs
(plot_funcs)Set or reset the plotting functions.
set_run_name
(run_name[, update_file_root])Set (or reset) the run_name.
set_summary_metrics
(summary_metrics)Set (or reset) the summary metrics for the metricbundle.
write
([comment, out_dir, outfile_suffix, ...])Write metric_values (and associated info_label) to disk.
write_db
([results_db, outfile_suffix])Write the metric_values to the database
Attributes Documentation
- col_info = <rubin_sim.maf.stackers.get_col_info.ColInfo object>¶
Methods Documentation
- compute_summary_stats(results_db=None)¶
Compute summary statistics on metric_values, using summaryMetrics (metricbundle list).
- Parameters:
- results_dbOptional[ResultsDb]
ResultsDb object to use to store the summary statistic values on disk.
- classmethod load(filename)¶
Create a metric bundle and load its content from disk.
- Parameters:
- filenamestr
The file from which to read the metric bundle data.
- output_json()¶
Set up and call the baseSlicer outputJSON method, to output to IO string.
- Returns:
- io
IO object containing JSON data representing the metric bundle data.
- plot(plot_handler=None, plot_func=None, outfile_suffix=None, savefig=False)¶
Create all plots available from the slicer. plotHandler holds the output directory info, etc.
- Parameters:
- plot_handlerOptional[PlotHandler]
The plot_handler saves the output location and results_db connection for a set of plots.
- plot_funcOptional[BasePlotter]
Any plotter function. If not specified, the plotters in self.plotFuncs will be used.
- outfile_suffixOptional[str]
Optional string to append to the end of the plot output files. Useful when creating sequences of images for movies.
- savefigOptional[bool]
Flag indicating whether or not to save the figure to disk. Default is False.
- Returns:
- dict
Dictionary of plot_type:figure number key/value pairs, indicating what plots were created and what matplotlib figure numbers were used.
- read(filename)¶
Read metric_values and associated info_label from disk. Overwrites any data currently in metricbundle.
- Parameters:
- filenamestr
The file from which to read the metric bundle data.
- reduce_metric(reduce_func, reduce_func_name=None, reduce_plot_dict=None, reduce_display_dict=None)¶
Run ‘reduceFunc’ (any function that operates on self.metric_values). Typically reduceFunc will be the metric reduce functions, as they are tailored to expect the metric_values format. reduceDisplayDict and reducePlotDicts are displayDicts and plotDicts to be applied to the new metricBundle.
- Parameters:
- reduce_funcFunc
Any function that will operate on self.metric_values (typically metric.reduce* function).
- reduce_plot_dictOptional[dict]
Plot dictionary for the results of the reduce function.
- reduce_display_dictOptional[dict]
Display dictionary for the results of the reduce function.
- Returns:
- MetricBundle
New metric bundle, inheriting info_label from this metric bundle, but containing the new metric values calculated with the ‘reduceFunc’.
- set_display_dict(display_dict=None, results_db=None)¶
Set or update any property of display_dict.
- Parameters:
- display_dictOptional[dict]
Dictionary of display parameters for showMaf. Expected keywords: ‘group’, ‘subgroup’, ‘order’, ‘caption’. ‘group’, ‘subgroup’, and ‘order’ control where the metric results are shown on the showMaf page. ‘caption’ provides a caption to use with the metric results. These values are saved in the results database.
- results_dbOptional[ResultsDb]
A MAF results database, used to save the display parameters.
- set_plot_dict(plot_dict)¶
Set or update any property of plot_dict.
- Parameters:
- plot_dictdict
A dictionary of plotting parameters. The usable keywords vary with each rubin_sim.maf.plots Plotter.
- set_plot_funcs(plot_funcs)¶
Set or reset the plotting functions.
The default is to use all the plotFuncs associated with the slicer, which is what happens in self.plot if setPlotFuncs is not used to override self.plotFuncs.
- Parameters:
- plot_funcsList[BasePlotter]
The plotter or plotters to use to generate visuals for this metric.
- set_run_name(run_name, update_file_root=True)¶
Set (or reset) the run_name. FileRoot will be updated accordingly if desired.
- Parameters:
- run_name: str
Run Name, which will become part of the fileRoot.
- fileRoot: bool, optional
Flag to update the fileRoot with the run_name. Default True.
- set_summary_metrics(summary_metrics)¶
Set (or reset) the summary metrics for the metricbundle.
- Parameters:
- summary_metricsList[BaseMetric]
Instantiated summary metrics to use to calculate summary statistics for this metric.
- write(comment='', out_dir='.', outfile_suffix=None, results_db=None)¶
Write metric_values (and associated info_label) to disk.
- Parameters:
- commentOptional[str]
Any additional comments to add to the output file
- out_dirOptional[str]
The output directory
- outfile_suffixOptional[str]
Additional suffix to add to the output files (typically a numerical suffix for movies)
- results_dbOptional[ResultsDb]
Results database to store information on the file output
- write_db(results_db=None, outfile_suffix=None)¶
Write the metric_values to the database