ResultsDb¶
- class rubin_sim.maf.db.ResultsDb(out_dir=None, database=None, verbose=False)¶
Bases:
object
The ResultsDb is a sqlite database containing information on the metrics run via MAF, the plots created, the display information (such as captions), and any summary statistics output.
Methods Summary
build_summary_name
(metric_name, ...[, ...])Standardize a complete summary metric name, combining the metric + slicer + summary + info_label
close
()Close connection to database.
Downgrade resultsDb to work with v0.10<MAF< v1.0 There is also a 'upgradeDatabase' to update to the newer style with 'metric_info_label.
Return a list of all metric_ids.
get_metric_data_files
([metric_id])Get the metric data filenames for all or a single metric.
get_metric_display_info
([metric_id])Get the contents of the metrics and displays table, together with the 'basemetric_name' (optionally, for metric_id list).
get_metric_id
(metric_name[, slicer_name, ...])Find metric bundle Ids from the metric table.
get_metric_id_like
([metric_name_like, ...])Find metric bundle Ids from the metric table, but search for names 'like' the values.
get_metric_info
([metric_id, with_sim_name])Get the simple metric info, without display information.
get_plot_files
([metric_id, with_sim_name])Return the metric_id, name, info_label, and all plot info (optionally for metric_id list).
Return a list of the run_names for the metric bundles in the database.
get_summary_stats
([metric_id, summary_name, ...])Get the summary stats (optionally for metric_id list).
open
()Open connection to database
Update the results_db from 'metricMetaData' to 'metric_info_label' and now also changing the camel case to snake case (metricId to metric_id, etc.).
update_display
(metric_id, display_dict[, ...])Add a row to or update a row in the displays table.
update_metric
(metric_name, slicer_name, ...)Add a row to or update a row in the metrics table.
update_plot
(metric_id, plot_type, plot_file)Add a row to or update a row in the plot table.
update_summary_stat
(metric_id, summary_name, ...)Add a row to or update a row in the summary statistic table.
Methods Documentation
- static build_summary_name(metric_name, metric_info_label, slicer_name, summary_stat_name=None)¶
Standardize a complete summary metric name, combining the metric + slicer + summary + info_label
- close()¶
Close connection to database.
- downgrade_database()¶
Downgrade resultsDb to work with v0.10<MAF< v1.0 There is also a ‘upgradeDatabase’ to update to the newer style with ‘metric_info_label.
- get_all_metric_ids()¶
Return a list of all metric_ids.
- get_metric_data_files(metric_id=None)¶
Get the metric data filenames for all or a single metric. Returns a list.
- get_metric_display_info(metric_id=None)¶
Get the contents of the metrics and displays table, together with the ‘basemetric_name’ (optionally, for metric_id list). Returns a numpy array of the metric information + display information.
One underlying assumption here is that all metrics have some display info. In newer batches, this may not be the case, as the display info gets auto-generated when the metric is plotted.
- get_metric_id(metric_name, slicer_name=None, metric_info_label=None, run_name=None)¶
Find metric bundle Ids from the metric table.
- get_metric_id_like(metric_name_like=None, slicer_name_like=None, metric_info_label_like=None, run_name=None)¶
Find metric bundle Ids from the metric table, but search for names ‘like’ the values. (instead of a strict match from get_metric_id).
- get_metric_info(metric_id=None, with_sim_name=False)¶
Get the simple metric info, without display information.
- Parameters:
- Returns:
- plotFiles
numpy.recarray
metric_id
The metric ID
metric_name
The metric name
basemetric_names
The base metric names
slicer_name
The name of the slicer used in the bundleGroup
sql_constraint
The full sql constraint used in the bundleGroup
metric_info_label
Metadata extracted from the
sql_constraint
(usually the filter)metric_datafile
The file name of the file with the metric data itself.
run_name
The name of the run plotted (if
with_sim_name
wasTrue
)
- plotFiles
- get_plot_files(metric_id=None, with_sim_name=False)¶
Return the metric_id, name, info_label, and all plot info (optionally for metric_id list). Returns a numpy array of the metric information + plot file names.
- Parameters:
- Returns:
- plotFiles
numpy.recarray
metric_id
The metric ID
metric_name
The metric name
metric_info_label
info_label extracted from the sql constraint (usually the filter)
plot_type
The plot type
plot_file
The full plot file (pdf by default)
thumb_file
A plot thumbnail file name (png)
run_name
The name of the run plotted (if
with_sim_name
wasTrue
)
- plotFiles
- get_run_name()¶
Return a list of the run_names for the metric bundles in the database.
- get_summary_stats(metric_id=None, summary_name=None, summary_name_like=None, summary_name_notlike=None, with_sim_name=False)¶
Get the summary stats (optionally for metric_id list). Optionally, also specify the summary metric name. Returns a numpy array of the metric information + summary statistic information.
- Parameters:
- metric_id
int
orlist
ofint
Metric bundle Ids to match from the metric table
- summary_name
str
, opt Match this summary statistic name exactly.
- summary_name_like
str
, opt Partial match to this summary statistic name.
- summary_name_notlike
str
, opt Exclude summary statistics with summary names like this.
- with_sim_name
bool
, opt If True, add the run_name to the returned numpy recarray.
- metric_id
- Returns:
- summarystats
np.recarray
Numpy recarray containing the selected summary statistic information.
- summarystats
- open()¶
Open connection to database
- update_database()¶
Update the results_db from ‘metricMetaData’ to ‘metric_info_label’ and now also changing the camel case to snake case (metricId to metric_id, etc.).
This updates results_db to work with the current version of MAF, including RunComparison and showMaf. There is also a ‘downgrade_database’ to revert to the older style with ‘metricMetadata.
- update_display(metric_id, display_dict, overwrite=True)¶
Add a row to or update a row in the displays table.
- update_metric(metric_name, slicer_name, run_name, sql_constraint, metric_info_label, metric_datafile)¶
Add a row to or update a row in the metrics table.
- Parameters:
- metric_name
str
Name of the Metric
- slicer_name
str
Name of the Slicer
- run_name
str
Name of the simulation (run_name, simName, run_name..)
- sql_constraint
str
sql_constraint relevant for the metric bundle
- metric_info_label
str
Information associated with the metric. Could be derived from the sql_constraint or could be a more descriptive version, specified by the user.
- metric_datafile
str
The data file the metric bundle output is stored in.
- metric_name
- Returns:
- metric_id
int
The Id number of this metric in the metrics table.
- If same metric (same metric_name, slicer_name, run_name, sql_constraint, infoLabel)
- already exists, it does nothing.
- metric_id
- update_plot(metric_id, plot_type, plot_file, overwrite=False)¶
Add a row to or update a row in the plot table.
- Parameters:
- metric_id
int
The metric Id of this metric bundle in the metrics table
- plot_type
str
The type of this plot (oneDbinned data, healpix map, etc.)
- plot_file
str
The filename for this plot
- overwrite
bool
Replaces existing row with the same metric_id and plot_type, if True. Default False, in which case additional plot is added to output (e.g. with different range)
- metric_id
- update_summary_stat(metric_id, summary_name, summary_value, ntry=3, pause_time=100)¶
Add a row to or update a row in the summary statistic table.
Most summary statistics will be a simple name (string) + value (float) pair. For special summary statistics which must return multiple values, the base name can be provided as ‘name’, together with a np recarray as ‘value’, where the recarray also has ‘name’ and ‘value’ columns (and each name/value pair is then saved as a summary statistic associated with this same metric_id).
- Parameters:
- metric_id
int
The metric Id of this metric bundle
- summary_name
str
The name of this summary statistic
- summary_value:
float
ornumpy.ndarray
The value for this summary statistic. If this is a numpy recarray, then it should also have ‘name’ and ‘value’ columns to save each value to rows in the summary statistic table.
- ntry
int
, opt The number of times to retry if database is locked. Default 3 times.
- pause_time
int
, opt Time to wait until trying again. Default 100s.
- metric_id