clevar.match_metrics.scaling.array_funcs module

@file clevar/match_metrics/scaling/array_funcs.py

Main scaling functions using arrays.

clevar.match_metrics.scaling.array_funcs.plot(values1, values2, err1=None, err2=None, ax=None, plt_kwargs=None, err_kwargs=None, values_color=None, add_cb=True, cb_kwargs=None, **kwargs)[source]

Scatter plot with errorbars and color based on input

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • err1 (array, None) – Errors of component x and y.

  • err2 (array, None) – Errors of component x and y.

  • ax (matplotlib.axes, None) – Ax to add plot. If equals None, one is created.

  • plt_kwargs (dict, None) – Additional arguments for pylab.scatter

  • err_kwargs (dict, None) – Additional arguments for pylab.errorbar

  • values_color (array, None) – Values for color (cmap scale).

  • add_cb (bool) – Plot colorbar when values_color is not None.

  • cb_kwargs (dict, None) – Colorbar arguments

  • add_bindata (bool) – Plot binned data used for fit (default=False).

  • add_fit (bool) – Fit and plot binned dat (default=False).

  • fit_err2 (array, None) – Error of component 2 (set to err2 if not provided).

  • fit_log (bool) – Bin and fit in log values (default=False).

  • fit_statistics (str) –

    Statistics to be used in fit (default=mean). Options are:

    • individual : Use each point

    • mode : Use mode of component 2 distribution in each comp 1 bin, requires bins2.

    • mean : Use mean of component 2 distribution in each comp 1 bin, requires bins2.

  • fit_bins1 (array, None) – Bins for component 1 (default=10).

  • fit_bins2 (array, None) – Bins for component 2 (default=30).

  • fit_legend_kwargs (dict, None) – Additional arguments for plt.legend.

  • fit_bindata_kwargs (dict, None) – Additional arguments for pylab.errorbar.

  • fit_plt_kwargs (dict, None) – Additional arguments for plot of fit pylab.scatter.

  • fit_label_components (tuple (of strings)) – Names of fitted components in fit line label, default=(‘x’, ‘y’).

Returns

info

Information of data in the plots, it contains the sections:

  • ax: ax used in the plot.

  • ax_cb (optional): ax of colorbar

  • binned_data (optional): input data for fitting, with values:

    • x: x values in fit (log of values if log=True).

    • y: y values in fit (log of values if log=True).

    • y_err: errorbar on y values (error_log if log=True).

  • fit (optional): fitting output dictionary, with values:

    • pars: fitted parameter.

    • cov: covariance of fitted parameters.

    • func: fitting function with fitted parameter.

    • func_plus: fitting function with fitted parameter plus 1x scatter.

    • func_minus: fitting function with fitted parameter minus 1x scatter.

    • func_scat: scatter of fited function.

    • func_dist: P(y|x) - Probability of having y given a value for x, assumes normal distribution and uses scatter of the fitted function.

    • func_scat_interp: interpolated scatter from data.

    • func_dist_interp: P(y|x) using interpolated scatter.

  • plots (optional): additional plots:

    • fit: fitted data

    • errorbar: binned data

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_density(values1, values2, bins1=30, bins2=30, ax_rotation=0, rotation_resolution=30, xscale='linear', yscale='linear', err1=None, err2=None, ax=None, plt_kwargs=None, add_cb=True, cb_kwargs=None, err_kwargs=None, **kwargs)[source]

Scatter plot with errorbars and color based on point density

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • bins1 (array, None) – Bins for component x and y (for density colors).

  • bins2 (array, None) – Bins for component x and y (for density colors).

  • ax_rotation (float) – Angle (in degrees) for rotation of axis of binning. Overwrites use of (bins1, bins2)

  • rotation_resolution (int) – Number of bins to be used when ax_rotation!=0.

  • xscale (str) – Scale for x/y axis.

  • yscale (str) – Scale for x/y axis.

  • err1 (array, None) – Errors of component x and y.

  • err2 (array, None) – Errors of component x and y.

  • ax (matplotlib.axes, None) – Ax to add plot. If equals None, one is created.

  • plt_kwargs (dict, None) – Additional arguments for pylab.scatter

  • add_cb (bool) – Plot colorbar

  • cb_kwargs (dict, None) – Colorbar arguments

  • err_kwargs (dict, None) – Additional arguments for pylab.errorbar

  • add_bindata (bool) – Plot binned data used for fit (default=False).

  • add_fit (bool) – Fit and plot binned dat (default=False).

  • **fit_kwargs – Other fit arguments (see fit_* paramters in scaling.array_funcs.plot for more info).

Returns

info

Information of data in the plots, it contains the sections:

  • ax: ax used in the plot.

  • ax_cb (optional): ax of colorbar

  • binned_data (optional): input data for fitting (see scaling.array_funcs.plot for more info).

  • fit (optional): fitting output dictionary (see scaling.array_funcs.plot for more info).

  • plots (optional): fit and binning plots (see scaling.array_funcs.plot for more info).

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_density_dist(values1, values2, bins1=30, bins2=30, ax_rotation=0, rotation_resolution=30, xscale='linear', yscale='linear', err1=None, err2=None, plt_kwargs=None, add_cb=True, cb_kwargs=None, err_kwargs=None, fig_kwargs=None, fig_pos=(0.1, 0.1, 0.95, 0.95), fig_frac=(0.8, 0.01, 0.02), vline_kwargs=None, **kwargs)[source]

Scatter plot with errorbars and color based on point density with distribution panels.

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • bins1 (array, None) – Bins for component x and y (for density colors).

  • bins2 (array, None) – Bins for component x and y (for density colors).

  • ax_rotation (float) – Angle (in degrees) for rotation of axis of binning. Overwrites use of (bins1, bins2) on main plot.

  • rotation_resolution (int) – Number of bins to be used when ax_rotation!=0.

  • xscale (str) – Scale for x/y axis.

  • yscale (str) – Scale for x/y axis.

  • err1 (array, None) – Errors of component x and y.

  • err2 (array, None) – Errors of component x and y.

  • plt_kwargs (dict, None) – Additional arguments for pylab.scatter

  • add_cb (bool) – Plot colorbar

  • cb_kwargs (dict, None) – Colorbar arguments

  • err_kwargs (dict, None) – Additional arguments for pylab.errorbar

  • fig_kwargs (dict, None) – Additional arguments for plt.subplots

  • fig_pos (tuple) – List with edges for the figure. Must be in format (left, bottom, right, top)

  • fig_frac (tuple) – Sizes of each panel in the figure. Must be in the format (main_panel, gap, colorbar) and have values: [0, 1]. Colorbar is only used with add_cb key.

  • add_bindata (bool) – Plot binned data used for fit (default=False).

  • add_fit (bool) – Fit and plot binned dat (default=False).

  • **fit_kwargs – Other fit arguments (see fit_* paramters in scaling.array_funcs.plot for more info).

  • vline_kwargs (dict, None) – Arguments for vlines marking bins in main plot, used in plt.axvline.

Returns

info

Information of data in the plots, it contains the sections:

  • fig: matplotlib.figure.Figure object.

  • axes: dictionary with each ax of the plot.

  • binned_data (optional): input data for fitting (see scaling.array_funcs.plot for more info).

  • fit (optional): fitting output dictionary (see scaling.array_funcs.plot for more info).

  • plots (optional): fit and binning plots (see scaling.array_funcs.plot for more info).

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_density_metrics(values1, values2, bins1=30, bins2=30, ax_rotation=0, rotation_resolution=30, xscale='linear', yscale='linear', err1=None, err2=None, metrics_mode='simple', metrics=['std'], plt_kwargs=None, add_cb=True, cb_kwargs=None, err_kwargs=None, metrics_kwargs=None, fig_kwargs=None, fig_pos=(0.1, 0.1, 0.95, 0.95), fig_frac=(0.8, 0.01, 0.02), **kwargs)[source]

Scatter plot with errorbars and color based on point density with scatter and bias panels

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • bins1 (array, None) – Bins for component x and y.

  • bins2 (array, None) – Bins for component x and y.

  • ax_rotation (float) – Angle (in degrees) for rotation of axis of binning. Overwrites use of (bins1, bins2) on main plot.

  • rotation_resolution (int) – Number of bins to be used when ax_rotation!=0.

  • xscale (str) – Scale for x/y axis.

  • yscale (str) – Scale for x/y axis.

  • err1 (array, None) – Errors of component x and y.

  • err2 (array, None) – Errors of component x and y.

  • metrics_mode (str) –

    Mode to run metrics. Options are:

    • simple : metrics for values2.

    • log : metrics for log10(values2).

    • diff : metrics for values2-values1.

    • diff_log : metrics for log10(values2)-log10(values1).

    • diff_z : metrics for (values2-values1)/(1+values1).

  • metrics (list) –

    List of mettrics to be plotted. Possibilities are:

    • ’mean’ : compute the mean of values for points within each bin.

    • ’std’ : compute the standard deviation within each bin.

    • ’median’ : compute the median of values for points within each bin.

    • ’count’ : compute the count of points within each bin.

    • ’sum’ : compute the sum of values for points within each bin.

    • ’min’ : compute the minimum of values for points within each bin.

    • ’max’ : compute the maximum of values for point within each bin.

    • ’p_#’ : compute half the width where a percentile of data is found. Number must be between 0-100 (ex: ‘p_68’, ‘p_95’, ‘p_99’).

  • plt_kwargs (dict, None) – Additional arguments for pylab.scatter

  • add_cb (bool) – Plot colorbar

  • cb_kwargs (dict, None) – Colorbar arguments

  • err_kwargs (dict, None) – Additional arguments for pylab.errorbar

  • metrics_kwargs (dict, None) – Dictionary of dictionary configs for each metric plots.

  • fig_kwargs (dict, None) – Additional arguments for plt.subplots

  • fig_pos (tuple) – List with edges for the figure. Must be in format (left, bottom, right, top)

  • fig_frac (tuple) – Sizes of each panel in the figure. Must be in the format (main_panel, gap, colorbar) and have values: [0, 1]. Colorbar is only used with add_cb key.

  • add_bindata (bool) – Plot binned data used for fit (default=False).

  • add_fit (bool) – Fit and plot binned dat (default=False).

  • **fit_kwargs – Other fit arguments (see fit_* paramters in scaling.array_funcs.plot for more info).

Returns

info

Information of data in the plots, it contains the sections:

  • fig: matplotlib.figure.Figure object.

  • axes: dictionary with each ax of the plot.

  • metrics: dictionary with the plots for each metric.

  • binned_data (optional): input data for fitting (see scaling.array_funcs.plot for more info).

  • fit (optional): fitting output dictionary (see scaling.array_funcs.plot for more info).

  • plots (optional): fit and binning plots (see scaling.array_funcs.plot for more info).

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_density_panel(values1, values2, values_panel, bins_panel, bins1=30, bins2=30, ax_rotation=0, rotation_resolution=30, xscale='linear', yscale='linear', err1=None, err2=None, plt_kwargs=None, add_cb=True, cb_kwargs=None, err_kwargs=None, panel_kwargs_list=None, panel_kwargs_errlist=None, fig_kwargs=None, add_label=True, label_format=<function <lambda>>, **kwargs)[source]

Scatter plot with errorbars and color based on point density with panels

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • values_panel (array) – Values to bin data in panels

  • bins_panel (array, int) – Bins defining panels

  • bins1 (array, None) – Bins for component x and y (for density colors).

  • bins2 (array, None) – Bins for component x and y (for density colors).

  • ax_rotation (float) – Angle (in degrees) for rotation of axis of binning. Overwrites use of (bins1, bins2)

  • rotation_resolution (int) – Number of bins to be used when ax_rotation!=0.

  • xscale (str) – Scale for x/y axis.

  • yscale (str) – Scale for x/y axis.

  • err1 (array, None) – Errors of component x and y.

  • err2 (array, None) – Errors of component x and y.

  • ax (matplotlib.axes, None) – Ax to add plot. If equals None, one is created.

  • plt_kwargs (dict, None) – Additional arguments for pylab.scatter

  • add_cb (bool) – Plot colorbar

  • cb_kwargs (dict, None) – Colorbar arguments

  • err_kwargs (dict, None) – Additional arguments for pylab.errorbar

  • panel_kwargs_list (list, None) – List of additional arguments for plotting each panel (using pylab.plot). Must have same size as len(bins2)-1

  • panel_kwargs_errlist (list, None) – List of additional arguments for plotting each panel (using pylab.errorbar). Must have same size as len(bins2)-1

  • fig_kwargs (dict, None) – Additional arguments for plt.subplots

  • add_label (bool) – Add bin label to panel

  • label_format (function) – Function to format the values of the bins

  • add_bindata (bool) – Plot binned data used for fit (default=False).

  • add_fit (bool) – Fit and plot binned dat (default=False).

  • **fit_kwargs – Other fit arguments (see fit_* paramters in scaling.array_funcs.plot for more info).

Returns

info

Information of data in the plots, it contains the sections:

  • fig: matplotlib.figure.Figure object.

  • axes: matplotlib.axes used in the plot.

  • ax_cb (optional): ax of colorbar

  • binned_data (optional): input data for fitting (see scaling.array_funcs.plot for more info).

  • fit (optional): fitting output dictionary (see scaling.array_funcs.plot for more info).

  • plots (optional): fit and binning plots (see scaling.array_funcs.plot for more info).

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_dist(values1, values2, bins1_dist, bins2, values_aux=None, bins_aux=5, log_vals=False, log_aux=False, transpose=False, shape='steps', plt_kwargs=None, line_kwargs_list=None, fig_kwargs=None, legend_kwargs=None, panel_label_prefix='', add_panel_label=True, panel_label_format=<function <lambda>>, add_line_label=True, line_label_format=<function <lambda>>)[source]

Plot distribution of a parameter, binned by other component in panels, and an optional secondary component in lines.

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • bins1_dist (array, int) – Bins for distribution of component 1.

  • bins2 (array, int) – Bins for component 2 (for panels/lines).

  • values_aux (array) – Auxiliary component (to bin data in lines/panels).

  • bins_aux (array, int) – Bins for component aux (for lines/panels).

  • log_vals (bool) – Log scale for values (and int bins)

  • log_aux (bool) – Log scale for aux values (and int bins)

  • transpose (bool) – Invert lines and panels

  • shape (str) – Shape of the lines. Can be steps or line.

  • plt_kwargs (dict, None) – Additional arguments for pylab.plot

  • line_kwargs_list (list, None) – List of additional arguments for plotting each line (using pylab.plot). Must have same size as len(bins_aux)-1

  • fig_kwargs (dict, None) – Additional arguments for plt.subplots

  • legend_kwargs (dict, None) – Additional arguments for plt.legend

  • add_panel_label (bool) – Add bin label to panel

  • panel_label_format (function) – Function to format the values of the bins

  • panel_label_prefix (str) – Prefix to add to panel label

  • add_line_label (bool) – Add bin label to line

  • line_label_format (function) – Function to format the values of the bins

Returns

info

Information of data in the plots, it contains the sections:

  • fig: matplotlib.figure.Figure object.

  • axes: matplotlib.axes used in the plot.

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_metrics(values1, values2, bins1=30, bins2=30, mode='simple', metrics=['mean', 'std'], metrics_kwargs=None, fig_kwargs=None, legend_kwargs=None)[source]

Plot metrics of 1 component.

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • bins1 (array, None) – Bins for component x and y.

  • bins2 (array, None) – Bins for component x and y.

  • mode (str) –

    Mode to run metrics. Options are:

    • simple : metrics for values2.

    • log : metrics for log10(values2).

    • diff : metrics for values2-values1.

    • diff_log : metrics for log10(values2)-log10(values1).

    • diff_z : metrics for (values2-values1)/(1+values1).

  • metrics (list) –

    List of mettrics to be plotted. Possibilities are:

    • ’mean’ : compute the mean of values for points within each bin.

    • ’std’ : compute the standard deviation within each bin.

    • ’median’ : compute the median of values for points within each bin.

    • ’count’ : compute the count of points within each bin.

    • ’sum’ : compute the sum of values for points within each bin.

    • ’min’ : compute the minimum of values for points within each bin.

    • ’max’ : compute the maximum of values for point within each bin.

    • ’p_#’ : compute half the width where a percentile of data is found. Number must be between 0-100 (ex: ‘p_68’, ‘p_95’, ‘p_99’).

    If ‘.fill’ is added to each metric, it will produce a filled region between (-metric, metric).

  • metrics_kwargs (dict, None) – Dictionary of dictionary configs for each metric plots.

  • fig_kwargs (dict, None) – Additional arguments for plt.subplots

  • legend_kwargs (dict, None) – Additional arguments for plt.legend

Returns

info

Information of data in the plots, it contains the sections:

  • fig: matplotlib.figure.Figure object.

  • axes: matplotlib.axes used in the plot.

Return type

dict

clevar.match_metrics.scaling.array_funcs.plot_panel(values1, values2, values_panel, bins_panel, err1=None, err2=None, values_color=None, plt_kwargs=None, err_kwargs=None, add_cb=True, cb_kwargs=None, panel_kwargs_list=None, panel_kwargs_errlist=None, fig_kwargs=None, add_label=True, label_format=<function <lambda>>, **kwargs)[source]

Scatter plot with errorbars and color based on input with panels

Parameters
  • values1 (array) – Components x and y for plot.

  • values2 (array) – Components x and y for plot.

  • values_color (array, None) – Values for color (cmap scale)

  • values_panel (array) – Values to bin data in panels

  • bins_panel (array, int) – Bins defining panels

  • err1 (array, None) – Errors of component x and y.

  • err2 (array, None) – Errors of component x and y.

  • values_color – Values for color (cmap scale).

  • plt_kwargs (dict, None) – Additional arguments for pylab.scatter

  • err_kwargs (dict, None) – Additional arguments for pylab.errorbar

  • add_cb (bool) – Plot colorbar when values_color is not None.

  • cb_kwargs (dict, None) – Colorbar arguments

  • panel_kwargs_list (list, None) – List of additional arguments for plotting each panel (using pylab.plot). Must have same size as len(bins2)-1

  • panel_kwargs_errlist (list, None) – List of additional arguments for plotting each panel (using pylab.errorbar). Must have same size as len(bins2)-1

  • fig_kwargs (dict, None) – Additional arguments for plt.subplots

  • add_label (bool) – Add bin label to panel

  • label_format (function) – Function to format the values of the bins

  • add_bindata (bool) – Plot binned data used for fit (default=False).

  • add_fit (bool) – Fit and plot binned dat (default=False).

  • **fit_kwargs – Other fit arguments (see fit_* paramters in scaling.array_funcs.plot for more info).

Returns

info

Information of data in the plots, it contains the sections:

  • fig: matplotlib.figure.Figure object.

  • axes: matplotlib.axes used in the plot.

  • ax_cb (optional): ax of colorbar

  • binned_data (optional): input data for fitting (see scaling.array_funcs.plot for more info).

  • fit (optional): fitting output dictionary (see scaling.array_funcs.plot for more info).

  • plots (optional): fit and binning plots (see scaling.array_funcs.plot for more info).

Return type

dict