fitbenchmarking.results_processing.base_table module
Implements the base class for the tables.
- class fitbenchmarking.results_processing.base_table.Table(results, best_results, options, group_dir, pp_locations, table_name)
Bases:
object
Base class for the FitBenchmarking HTML and text output tables.
When inheriting from this, it may be useful to override the following functions as required:
get_value
display_str
get_error_str
get_link_str
- create_pandas_data_frame(html=False)
Creates a pandas data frame of results
- Parameters
html (bool. defaults to False) – Whether to make the dataframe for html or plain text
- Returns
DataFrame with string representations of results
- Return type
pandas.DataFrame
- create_results_dict()
Generate a dictionary of results lists with rows and columns as the key and list elements respectively. This is used to create HTML and csv tables. This is stored in self.sorted_results
- display_str(value)
Converts a value generated by
get_value()
into a string respresentation to be used in the tables. Base class implementation takes the relative and absolute values and usesself.output_string_type
as a template for the string format. This can be overridden to adequately display the results.- Parameters
value (tuple) – Relative and absolute values
- Returns
string representation of the value for display in the table.
- Return type
str
- property file_path
Getter function for the path to the table
- Returns
path to table
- Return type
str
- get_colour_df(like_df=None)
Generate a dataframe of colours to add to the html rendering.
If like_df is passed this will use the column and row indexes of that dataframe.
- Parameters
like_df (pandas.DataFrame) – The dataframe to copy headings from. Defaults to None.
- Returns
A dataframe with colourings as strings
- Return type
pandas.DataFrame
- get_colours_for_row(results)
Get the colours as strings for the given results in the table. The base class implementation, for example, uses the first value from self.get_value and
colour_map
,colour_ulim
andcmap_range
withinOptions
.- Parameters
result (list[fitbenchmarking.utils.fitbm_result.FittingResult]) – Results to get the colours for.
- Returns
The colour to use for each cell in the list and Foreground colours for the text as html rgb strings e.g. ‘rgb(255, 255, 255)’
- Return type
tuple[list[str], list[str]]
- get_description()
Generates table description from class docstrings and converts them into html
- Returns
Dictionary containing table descriptions
- Return type
dict
- static get_error_str(result, error_template='[{}]')
Get the error string for a result based on error_template This can be overridden if tables require different error formatting.
- Parameters
result (FittingResult) – The result to get the error string for
- Returns
A string representation of the error
- Return type
str
- get_hyperlink(result, val_str, text_col)
Generates the hyperlink for a given result
- Parameters
result (fitbenchmarking.utils.ftibm_result.FittingResult) – The result to generate a string for
val_str (str) – Preprocessed val_str to display
text_col (str) – Foreground colour for the text as html rgb strings e.g. ‘rgb(255, 255, 255)’
- Returns
The hyperlink representation.
- Return type
str
- get_link_str(result)
Get the link as a string for the result. This can be overridden if tables require different links.
- Parameters
result (FittingResult) – The result to get the link for
- Returns
The link to go to when the cell is selected
- Return type
string
- get_str_dict(html=False)
Create a dictionary with the table values as strings for display.
- Returns
The dictionary of strings for the table
- Return type
dict[list[str]]
- get_str_result(result, text_col=None, html=False)
Given a single result, generate the string to display in this table. The html flag can be used to switch between a plain text and html format.
This is intended to be easily extensible by overriding the following functions:
get_value
display_str
get_error_str
get_link_str
If you find yourself overriding this, please consider if changes could be made to allow future tables to benefit.
- Parameters
result (fitbenchmarking.utils.ftibm_result.FittingResult) – The result to generate a string for
text_col (list[str]) – Foreground colours for the text as html rgb strings e.g. ‘rgb(255, 255, 255)’
html (bool) – Flag to control whether to generate a html string or plain text. Defaults to False.
- Returns
The string representation.
- Return type
str
- abstract get_value(result)
Gets the main value to be reported in the tables for a given result
If more than one value is returned please note that the first value will be used in the default colour handling.
- Parameters
result (FittingResult) – The result to generate the values for.
- Returns
The value to convert to a string for the tables
- Return type
tuple(float)
- minimizer_dropdown_html() str
Generates the HTML for a dropdown checklist of minimizers.
- Returns
HTML for a dropdown checklist of minimizers.
- Return type
str
- problem_dropdown_html() str
Generates the HTML for a dropdown checklist of problem sets.
- Returns
HTML for a dropdown checklist of problem sets.
- Return type
str
- save_colourbar(fig_dir, n_divs=100, sz_in=(3, 0.8)) str
Generates a png of a labelled colourbar using matplotlib.
- Parameters
fig_dir (str) – path to figures directory
n_divs (int) – number of divisions of shading in colourbar
sz_in (list[float] - 2 elements) – dimensions of png in inches [width, height]
- Returns
The relative path to the colourbar image.
- Return type
str
- property table_title
Getter function for table name if self._table_title is None
- Returns
name of table
- Return type
str
- to_csv_file()
Generate a plain text version of the table
- Returns
Plain text table output
- Return type
str
- to_html()
Generate a html version of the table.
- Returns
HTML table output
- Return type
str
- static vals_to_colour(vals, cmap, cmap_range, log_ulim)
Converts an array of values to a list of hexadecimal colour strings using logarithmic sampling from a matplotlib colourmap according to relative value.
- Parameters
vals (list[float]) – values in the range [0, 1] to convert to colour strings
cmap (matplotlib colourmap object) – matplotlib colourmap
cmap_range (list[float], 2 elements) – values in range [0, 1] for colourmap cropping
log_ulim (float) – log10 of worst shading cutoff value
- Returns
Colours as hex strings for each input value and Foreground colours for the text as html rgb strings e.g. ‘rgb(255, 255, 255)’
- Return type
tuple[list[str], list[str]]
- fitbenchmarking.results_processing.base_table.background_to_text(background_col, contrast_threshold)
Determines the foreground color for the table elements. The optimum color is selected from two options - white and black. White is selected if its contrast ratio is greater than the contrast threshold. However, If the contrast ratio of white text does not meet the requirement, then the text color which provides the greatest contrast ratio is selected.
- Parameters
background_col – a list of r,g,b values [0, 255]
contrast_threshold (float) – the threshold value [0, 21]
- Returns
Foreground colour for the text as html rgb strings e.g. ‘rgb(255, 255, 255)’
- Return type
str
- fitbenchmarking.results_processing.base_table.calculate_contrast(background, foreground)
Calculates the contrast ratio between the background and foreground colors. Visit link for more info: https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html#dfn-contrast-ratio
- Parameters
background – list of r, g, b values representing background [0, 255]
foreground (list[int]) – list of r, g, b values representing foreground [0, 255]
- Returns
the contrast ratio [0, 21]
- Return type
float
- fitbenchmarking.results_processing.base_table.calculate_luminance(rgb)
Calculates the relative luminance. Visit link for more info: https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html#dfn-relative-luminance
- Parameters
rgb – a list containing r, g, b values [0, 255]
- Returns
the luminance [0, 1]
- Return type
float