petab.visualize.helper_functions¶
This file should contain the functions, which PEtab internally needs for plotting, but which are not meant to be used by non-developers and should hence not be directly visible/usable when using import petab.visualize.
Functions
|
Check the columns in measurement file, if non-mandotory columns does not exist, create default columns |
|
Check the columns in Visu_Spec file, if non-mandotory columns does not exist, create default columns |
|
Helper function for plotting data and simulations, which checks the visualization setting, if no visualization specification file is provided. |
|
Create dataset id list and corresponding plot legends. |
|
Helper function for plotting data and simulations, open figure and axes |
|
Helper function for plotting data and simulations, which updates vis_spec file if necessary or creates a default visualization table and updates/creates DATASET_ID column of exp_data. |
|
only makes sense if DATASET_ID is not in vis_spec.columns? |
|
Group the data, which should be plotted and return it as dataframe. |
|
Helper function for plotting data and simulations, which creates a default visualization table and updates/creates DATASET_ID column of exp_data |
Helper function for creating values for columns PLOT_ID, DATASET_ID, LEGEND_ENTRY, Y_VALUES for visualization specification file. |
|
|
Handle dataset plot |
|
Helper function for plotting data and simulations, which imports data from PEtab files. |
|
constructs an index for subsetting of the dataframe according to what is specified in plot_spec. |
-
class
petab.visualize.helper_functions.
Number
¶ Bases:
object
All numbers inherit from this class.
If you just want to check if an argument x is a number, without caring what kind, use isinstance(x, Number).
-
petab.visualize.helper_functions.
check_ex_exp_columns
(exp_data: pandas.core.frame.DataFrame, dataset_id_list: List[List[str]], sim_cond_id_list: List[List[str]], sim_cond_num_list: List[List[int]], observable_id_list: List[List[str]], observable_num_list: List[List[int]], exp_conditions: pandas.core.frame.DataFrame, sim: Optional[bool] = False) → Tuple[pandas.core.frame.DataFrame, List[List[str]], Dict]¶ Check the columns in measurement file, if non-mandotory columns does not exist, create default columns
- Returns
A tuple of experimental DataFrame, list of datasetIds and dictionary of plot legends, corresponding to the datasetIds
-
petab.visualize.helper_functions.
check_ex_visu_columns
(vis_spec: pandas.core.frame.DataFrame, exp_data: pandas.core.frame.DataFrame, exp_conditions: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame¶ Check the columns in Visu_Spec file, if non-mandotory columns does not exist, create default columns
- Returns
Updated visualization specification DataFrame
-
petab.visualize.helper_functions.
check_vis_spec_consistency
(exp_data: pandas.core.frame.DataFrame, dataset_id_list: Optional[List[List[str]]] = None, sim_cond_id_list: Optional[List[List[str]]] = None, sim_cond_num_list: Optional[List[List[int]]] = None, observable_id_list: Optional[List[List[str]]] = None, observable_num_list: Optional[List[List[int]]] = None) → str¶ Helper function for plotting data and simulations, which checks the visualization setting, if no visualization specification file is provided.
For documentation, see main function plot_data_and_simulation()
- Returns
Specifies the grouping of data to plot.
- Return type
group_by
-
petab.visualize.helper_functions.
create_dataset_id_list
(simcond_id_list: List[List[str]], simcond_num_list: List[List[int]], observable_id_list: List[List[str]], observable_num_list: List[List[int]], exp_data: pandas.core.frame.DataFrame, exp_conditions: pandas.core.frame.DataFrame, group_by: str) → Tuple[pandas.core.frame.DataFrame, List[List[str]], Dict, Dict]¶ Create dataset id list and corresponding plot legends. Additionally, update/create DATASET_ID column of exp_data
- Parameters
group_by – defines grouping of data to plot
- Returns
A tuple of experimental DataFrame, list of datasetIds and dictionary of plot legends, corresponding to the datasetIds
For additional documentation, see main function plot_data_and_simulation()
-
petab.visualize.helper_functions.
create_figure
(uni_plot_ids: numpy.ndarray, plots_to_file: bool) → Tuple[matplotlib.figure.Figure, Union[Dict[str, matplotlib.axes._subplots.AxesSubplot], np.ndarray[plt.Subplot]]]¶ Helper function for plotting data and simulations, open figure and axes
- Parameters
uni_plot_ids – Array with unique plot indices
plots_to_file – Indicator if plots are saved to file
- Returns
fig (Figure object of the created plot.)
ax (Axis object of the created plot.)
-
petab.visualize.helper_functions.
create_or_update_vis_spec
(exp_data: pandas.core.frame.DataFrame, exp_conditions: pandas.core.frame.DataFrame, vis_spec: Optional[pandas.core.frame.DataFrame] = None, dataset_id_list: Optional[List[List[str]]] = None, sim_cond_id_list: Optional[List[List[str]]] = None, sim_cond_num_list: Optional[List[List[int]]] = None, observable_id_list: Optional[List[List[str]]] = None, observable_num_list: Optional[List[List[int]]] = None, plotted_noise: Optional[str] = 'MeanAndSD')¶ Helper function for plotting data and simulations, which updates vis_spec file if necessary or creates a default visualization table and updates/creates DATASET_ID column of exp_data. As a result, a visualization specification file exists with columns PLOT_ID, DATASET_ID, Y_VALUES and LEGEND_ENTRY
- Returns
A tuple of visualization specification DataFrame and experimental DataFrame.
-
petab.visualize.helper_functions.
expand_vis_spec_settings
(vis_spec, columns_dict)¶ only makes sense if DATASET_ID is not in vis_spec.columns?
- Returns
A visualization specification DataFrame
-
petab.visualize.helper_functions.
get_data_to_plot
(plot_spec: pandas.core.series.Series, m_data: pandas.core.frame.DataFrame, simulation_data: pandas.core.frame.DataFrame, condition_ids: numpy.ndarray, col_id: str, simulation_field: str = 'simulation') → pandas.core.frame.DataFrame¶ Group the data, which should be plotted and return it as dataframe.
- Parameters
plot_spec – information about contains defined data format (visualization file)
m_data – contains defined data format (measurement file)
simulation_data – contains defined data format (simulation file)
condition_ids – contains all unique condition IDs which should be plotted in one figure (can be found in measurementData file, column simulationConditionId)
col_id – the name of the column in visualization file, whose entries should be unique (depends on condition in column xValues)
simulation_field – Column name in
simulation_data
that contains the actual simulation result.
- Returns
Contains the data which should be plotted (Mean and Std)
- Return type
data_to_plot
-
petab.visualize.helper_functions.
get_default_vis_specs
(exp_data: pandas.core.frame.DataFrame, exp_conditions: pandas.core.frame.DataFrame, dataset_id_list: Optional[List[List[str]]] = None, sim_cond_id_list: Optional[List[List[str]]] = None, sim_cond_num_list: Optional[List[List[int]]] = None, observable_id_list: Optional[List[List[str]]] = None, observable_num_list: Optional[List[List[int]]] = None, plotted_noise: Optional[str] = 'MeanAndSD') → Tuple[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame]¶ Helper function for plotting data and simulations, which creates a default visualization table and updates/creates DATASET_ID column of exp_data
- Returns
A tuple of visualization specification DataFrame and experimental DataFrame.
For documentation, see main function plot_data_and_simulation()
-
petab.visualize.helper_functions.
get_vis_spec_dependent_columns_dict
(exp_data: pandas.core.frame.DataFrame, exp_conditions: pandas.core.frame.DataFrame, dataset_id_list: Optional[List[List[str]]] = None, sim_cond_id_list: Optional[List[List[str]]] = None, sim_cond_num_list: Optional[List[List[int]]] = None, observable_id_list: Optional[List[List[str]]] = None, observable_num_list: Optional[List[List[int]]] = None) → Tuple[pandas.core.frame.DataFrame, Dict]¶ Helper function for creating values for columns PLOT_ID, DATASET_ID, LEGEND_ENTRY, Y_VALUES for visualization specification file. DATASET_ID column of exp_data is updated accordingly.
- Returns
A tuple of experimental DataFrame and a dictionary with values for columns PLOT_ID, DATASET_ID, LEGEND_ENTRY, Y_VALUES for visualization specification file.
-
petab.visualize.helper_functions.
handle_dataset_plot
(plot_spec: pandas.core.series.Series, ax: matplotlib.axes._axes.Axes, exp_data: pandas.core.frame.DataFrame, exp_conditions: pandas.core.frame.DataFrame, sim_data: pandas.core.frame.DataFrame)¶ Handle dataset plot
-
petab.visualize.helper_functions.
import_from_files
(data_file_path: str, condition_file_path: str, simulation_file_path: str, dataset_id_list: List[List[str]], sim_cond_id_list: List[List[str]], sim_cond_num_list: List[List[int]], observable_id_list: List[List[str]], observable_num_list: List[List[int]], plotted_noise: str, visualization_file_path: Optional[str] = None) → Tuple[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame, pandas.core.frame.DataFrame, pandas.core.frame.DataFrame]¶ Helper function for plotting data and simulations, which imports data from PEtab files. If visualization_file_path is not provided, the visualisation specification DataFrame will be generated automatically.
For documentation, see main function plot_data_and_simulation()
- Returns
A tuple of experimental data, experimental conditions, visualization specification and simulation data DataFrames.
-
petab.visualize.helper_functions.
matches_plot_spec
(df: pandas.core.frame.DataFrame, col_id: str, x_value: Union[float, str], plot_spec: pandas.core.series.Series) → pandas.core.series.Series¶ constructs an index for subsetting of the dataframe according to what is specified in plot_spec.
- Parameters
df – pandas data frame to subset, can be from measurement file or simulation file
col_id – name of the column that will be used for indexing in x variable
x_value – subsetted x value
plot_spec – visualization spec from the visualization file
- Returns
Boolean series that can be used for subsetting of the passed dataframe
- Return type
index
-
petab.visualize.helper_functions.
plot_lowlevel
(plot_spec: pandas.core.series.Series, ax: matplotlib.pyplot.Axes, conditions: pandas.core.series.Series, ms: pandas.core.frame.DataFrame, plot_sim: bool) → matplotlib.pyplot.Axes¶ Plotting routine / preparations: set properties of figure and plot the data with given specifications (lineplot with errorbars, or barplot)
- Parameters
plot_spec – contains defined data format (visualization file)
ax – axes to which to plot
conditions – Values on x-axis
ms – contains measurement data which should be plotted
plot_sim – tells whether or not simulated data should be plotted as well
- Returns
Updated axis object.