plans.datasets.analyst#

Classes for statistical analysis of environmental and hydrological data.

Classes

Bayes(df_hypotheses[, name, nomenclature, ...])

The Bayes Theorem Analyst Object

Bivar([name, alias])

The Bivariate object.

GeoUnivar([name, alias])

Univariate data with locations, held in a GeoDataFrame.

LazyStat(getter)

Attribute computed from the data on first use, and kept until it is set to None.

Univar([name, alias])

The Univariate object

class plans.datasets.analyst.LazyStat(getter)[source]#

Bases: object

Attribute computed from the data on first use, and kept until it is set to None.

__init__(getter)[source]#
__set_name__(owner, name)[source]#
__get__(obj, owner=None)[source]#
__set__(obj, value)[source]#
class plans.datasets.analyst.Univar(name='MyUnivar', alias='Uv0')[source]#

Bases: DataSet

The Univariate object

__init__(name='MyUnivar', alias='Uv0')[source]#
stats_df#

Attribute computed from the data on first use, and kept until it is set to None.

freq_df#

Attribute computed from the data on first use, and kept until it is set to None.

weibull_df#

Attribute computed from the data on first use, and kept until it is set to None.

_set_fields()[source]#

Set catalog fields names. Expected to increment superior methods.

get_metadata()[source]#

Get a dictionary with object metadata. Expected to increment superior methods.

Note

Metadata does not necessarily inclue all object attributes.

Returns:

dictionary with all metadata

Return type:

dict

load_data(file_data, input_varfield=None, in_sep=';')[source]#

Load data from file. Expected to overwrite superior methods.

Parameters:

file_data (str) – file path to data.

Returns:

None

Return type:

None

set_array(array)[source]#

Set array to data

Parameters:

array (numpy.ndarray) – Numpy array

Returns:

None

Return type:

None

update()[source]#

Refresh the attributes and statistics from the current data.

Returns:

None

Return type:

None

_reset_stats()[source]#

Drop the statistics, to be computed again on next use.

Returns:

None

Return type:

None

_get_values()[source]#

Get the values of the variable, without missing data.

Returns:

vector of values

Return type:

numpy.ndarray

_thin(data)[source]#

Get the part of a sequence worth drawing on a panel. Here, all of it.

Parameters:

data (numpy.ndarray or pandas.DataFrame) – vector or dataframe, with one record for each value

Returns:

the same sequence

Return type:

numpy.ndarray or pandas.DataFrame

get_normality(clevel=0.95)[source]#

Get normality analysis using standard tests

Parameters:

clevel (float) – confidence level

Returns:

dataframe of assessment results

Return type:

pandas.DataFrame

get_frequency()[source]#

Get data frequencies

Returns:

result dataframe

Return type:

pandas.DataFrame

get_basic_stats()[source]#

Get basic statistics data of the variable field.

Returns:

DataFrame with statistics and their values.

Return type:

pandas.DataFrame

get_cdf_weibull()[source]#

Get the Weibull model for the data

Returns:

model dataframe

Return type:

pandas.DataFrame

get_cdf_gumbel()[source]#

Get the Gumbel CDF for the data (it assumes that is a maxima dataset)

Returns:

multiple results from the assessment

Return type:

dict

_plot(fig, gs, specs)[source]#

Plot on figure based on layout.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • gs (matplotlib.gridspec.GridSpec) – grid of the figure

  • specs (dict) – plot specification dictionary

Returns:

figure object

Return type:

matplotlib.figure.Figure

_plot_full(fig, specs, formatter)[source]#

Plot the data, histogram and CDF panels, and the statistics table.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object with the axes already built

  • specs (dict) – plot specification dictionary

  • formatter (matplotlib.ticker.Formatter) – formatter of the y axis

Returns:

None

Return type:

None

_plot_annotations(fig, specs)[source]#

Plot the annotations of the figure. Here, the basic statistics.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • specs (dict) – plot specification dictionary

Returns:

None

Return type:

None

_plot_qq(fig, specs, formatter)[source]#

Plot the Q-Q panel.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object with the axes already built

  • specs (dict) – plot specification dictionary

  • formatter (matplotlib.ticker.Formatter) – formatter of the y axis

Returns:

None

Return type:

None

_build_axes(fig, gs, specs)[source]#

Add subplots to figure based on layout.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • gs (matplotlib.gridspec.GridSpec) – grid of the figure

  • specs (dict) – plot specification dictionary

Returns:

figure object

Return type:

matplotlib.figure.Figure

_get_fig_specs()[source]#

Get figure specs by merging view specs, layout specs and grid specs.

Returns:

figure specs

Return type:

dict

_set_view_specs()[source]#

Set view specifications. Expected to overwrite superior methods.

Returns:

None

Return type:

None

view(show=True, return_fig=False)[source]#

Get the visualization. Layout is set by view_specs["layout"]. The options are the keys of the layouts attribute.

Layouts, set by view_specs["layout"]:

Layout

Panels

full

Data, histogram and CDF, with the statistics table.

mini

Data, histogram and CDF.

simple

Data only.

simple-shallow

Data only, in a shallow figure.

qq

Q-Q plot.

default

Same panels of mini, in the figure of full.

View specs, set by view_specs[key] = value before the call:

Key

Default

Description

style

"wien"

Name of the plot style. See plans.viewer.set_style().

folder

auto

Folder of the saved figure.

filename

auto

Name of the saved figure, without extension.

fig_format

"jpg"

Format of the saved figure.

dpi

300

Resolution of the saved figure.

title

auto

Title of the figure.

xvar

auto

Not in use.

yvar

auto

Not in use.

xlabel

auto

Label of the x axis.

ylabel

auto

Label of the y axis.

color

"tab:grey"

Color of the data.

xmin

None

Not in use.

xmax

None

Not in use.

ymin

None

Not in use.

ymax

None

Not in use.

layout

"full"

Name of the layout. See the table of layouts.

data_plot

"scatter"

Plot of the data panel: "scatter" or "boxplot".

subtitle_data

"Data"

Title of the data panel. None hides it.

subtitle_box

"Boxplot"

Title of the data panel, if a boxplot.

subtitle_hist

"Histogram"

Title of the histogram. None hides it.

subtitle_cdf

"CDF"

Title of the CDF. None hides it.

subtitle_qq

"Q-Q"

Title of the Q-Q panel. None hides it.

yvar_field

auto

Column of values. Set with the data.

xlabel_cdf

"P(X)"

Label of the x axis of the CDF.

xlabel_qq

auto

Label of the x axis of the Q-Q panel.

data_label

auto

Label of the data in the legend.

data_legend

False

Show the legend of the data panel.

color_hist

"tab:grey"

Color of the histogram.

color_cdf

"black"

Color of the CDF.

color_mean

"red"

Color of the mean line.

color_mean_text

None

Color of the mean label. None is gray.

scheme_cmap

"equal"

Color scheme: "continuous", or classes by "equal", "quantiles" and other schemes of plans.stochastic.binning.get_bins().

n_classes_cmap

5

Number of classes of the color map. Not used if "continuous".

cmap

"viridis"

Name of the color map.

alpha

0.8

Opacity of the data. None sets it by the number of points.

alpha_hist

1

Opacity of the histogram.

alpha_cdf

1

Opacity of the CDF.

range

None

Range of the y axis, as [low, high]. None is set from the data.

range_x

None

Range of the x axis, as [low, high]. None is set from the data.

plot_mean

True

Show the mean line.

plot_mean_data

False

Show the mean line also on the data panel.

linestyle_mean

"solid"

Line style of the mean.

pad_mean

1

Spaces between the mean label and its line.

plot_mean_label

True

Show the mean label.

hist_density

True

Not in use.

bins

20

Number of histogram bins, or the width of the bins if bins_density.

bins_density

False

Take bins as the width of the bins.

ax_data

0

Internal. Index of the data axis.

ax_hist

1

Internal. Index of the histogram axis. False has no histogram.

ax_cdf

2

Internal. Index of the CDF axis. False has no CDF.

x_stats

0.04

Horizontal position of the statistics table, as a share of the figure.

x_stats_sep

0.2

Space between columns of the statistics table.

y_stats

0.3

Vertical position of the statistics table, as a share of the figure.

zorder_data

1

Drawing order of the data.

zorder_histh

1

Drawing order of the histogram.

zorder_cdf

1

Drawing order of the CDF.

scatter_factor

4

Space at each side of the points, in widths of the band of points.

colorize_scatter

False

Color the scatter markers by the color map.

box_width

0.4

Width of the boxplot.

box_showfliers

True

Show the outliers of the boxplot.

gs_*

auto

Internal. Replaced by the shared grid of plans.viewer.

Parameters:
  • show (bool) – option for showing instead of saving

  • return_fig (bool) – option for returning the figure object

Returns:

figure object if return_fig is True, else None

Return type:

matplotlib.figure.Figure or None

static plot_mean(ax, y_mu, xmin, xmax, specs, label_right=False)[source]#

Plot the mean as a horizontal line, with an optional label.

Parameters:
  • ax (matplotlib.axes.Axes or bool) – axis to plot on. Nothing is plotted if False

  • y_mu (float) – mean value

  • xmin (float) – start of the line

  • xmax (float) – end of the line

  • specs (dict) – plot specification dictionary (from view_specs)

  • label_right (bool) – place the label at the right side of the panel

Returns:

None

Return type:

None

static plot_scatter(data, ax, specs, formatter=None)[source]#

Plot the data points in their original order.

Parameters:
  • data (numpy.ndarray) – vector of data without nan values

  • ax (matplotlib.axes.Axes or bool) – axis to plot on. Nothing is plotted if False

  • specs (dict) – plot specification dictionary (from view_specs)

  • formatter (matplotlib.ticker.Formatter) – [optional] formatter of the y axis

Returns:

None

Return type:

None

static plot_boxplot(data, ax, specs, formatter=None)[source]#

Plot a vertical boxplot of the data, sharing the y range of the other panels.

Parameters:
  • data (numpy.ndarray) – vector of data without nan values

  • ax (matplotlib.axes.Axes) – target axes. If False, nothing is plotted.

  • specs (dict) – plot specification dictionary (from view_specs)

  • formatter (matplotlib.ticker.Formatter) – [optional] y axis tick formatter

Returns:

None

Return type:

None

static plot_histh(data, ax, specs, formatter=None)[source]#

Plot a horizontal histogram.

Parameters:
  • data (numpy.ndarray) – vector of data without nan values

  • ax (matplotlib.axes.Axes or bool) – axis to plot on. Nothing is plotted if False

  • specs (dict) – plot specification dictionary (from view_specs)

  • formatter (matplotlib.ticker.Formatter) – [optional] formatter of the y axis

Returns:

output of the histogram, or None if there is no axis

Return type:

tuple or None

static plot_cdf(cdf_df, ax, specs, formatter=None, px_field='P(X)', var_field='Data', y_mu=None)[source]#

Plot the CDF, as exceedance probability.

Parameters:
  • cdf_df (pandas.DataFrame) – dataframe of the CDF

  • ax (matplotlib.axes.Axes or bool) – axis to plot on. Nothing is plotted if False

  • specs (dict) – plot specification dictionary (from view_specs)

  • formatter (matplotlib.ticker.Formatter) – [optional] formatter of the y axis

  • px_field (str) – name of the probability field

  • var_field (str) – name of the variable field

  • y_mu (float) – [optional] mean of the data. Default is the mean of the curve.

Returns:

None

Return type:

None

static plot_qq(data, ax, specs, formatter=None)[source]#

Plot data quantiles against normal quantiles. The line is the normal distribution with the mean and standard deviation of the data.

Parameters:
  • data (numpy.ndarray) – vector of data without nan values

  • ax (matplotlib.axes.Axes or bool) – axis to plot on. Nothing is plotted if False

  • specs (dict) – plot specification dictionary (from view_specs)

  • formatter (matplotlib.ticker.Formatter) – [optional] formatter of the y axis

Returns:

None

Return type:

None

static plot_stats(fig, stats_df, x=0.5, y=0.4, sep=0.2)[source]#

Plot two columns of basic statistics as text on the figure.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • stats_df (pandas.DataFrame) – dataframe of basic statistics

  • x (float) – position of the first column, in figure fraction

  • y (float) – position of the top of the columns, in figure fraction

  • sep (float) – distance between the columns, in figure fraction

Returns:

figure object

Return type:

matplotlib.figure.Figure

static get_stats_columns(stats_df)[source]#

Get two columns of lines of text, with the basic statistics.

Parameters:

stats_df (pandas.DataFrame) – dataframe of basic statistics

Returns:

list of columns, each one a list of lines

Return type:

list

static plot_text_columns(fig, ls_columns, x, y, sep, y_min=None)[source]#

Plot columns of annotations on the figure, from the top down. With a lower limit, lines get closer if needed, so the columns never pass it.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • ls_columns (list) – list of columns, each one a list of lines of text

  • x (float) – position of the first column, in figure fraction

  • y (float) – position of the top of the columns, in figure fraction

  • sep (float) – distance between the columns, in figure fraction

  • y_min (float) – [optional] lower limit of the columns, in figure fraction

Returns:

None

Return type:

None

static set_hist_xaxis(ax, hist_max)[source]#

Set the x axis of a horizontal histogram, with three integer labels in percent. The first is the zero, on the y axis.

Parameters:
  • ax (matplotlib.axes.Axes) – axis of the histogram

  • hist_max (float) – largest share of data in a bar, as a fraction

Returns:

None

Return type:

None

static get_dynamic_alpha(n_points)[source]#

Get the opacity of a cloud of points, which gets lower as they get denser.

Parameters:

n_points (int) – number of points

Returns:

opacity

Return type:

float

static get_cmap_norm(data, specs)[source]#

Get the color map and the norm of the color scheme, so all panels agree.

Colors span specs["range"], or the data if it is None, so a color bar shares the y axis of the other panels. A continuous scheme changes smoothly along it. Other schemes make one flat color for each class of value, with the outer classes reaching the ends of the range.

Parameters:
  • data (numpy.ndarray) – vector of data without nan values

  • specs (dict) – plot specification dictionary (from view_specs)

Returns:

color map and norm

Return type:

tuple

static plot_cbar(data, ax, scheme, cmap='viridis', n_classes=5, side='right', width_factor=16)[source]#

Plot a vertical color bar of the data classes, inside the axis.

Parameters:
  • data (numpy.ndarray) – vector of data

  • ax (matplotlib.axes.Axes) – axis to plot on

  • scheme (str) – classification scheme, such as equal or quantiles

  • cmap (str) – name of the color map

  • n_classes (int) – number of classes

  • side (str) – side of the axis, left or right

  • width_factor (float) – width of the bar as a fraction of the axis (1 over this value)

Returns:

None

Return type:

None

static test_distribution(test_name, stat, p, clevel=0.95, distr='normal')[source]#

See plans.stochastic.normality.test_distribution().

static test_normality_ks(data, clevel=0.95)[source]#

See plans.stochastic.normality.test_normality_ks().

static test_normality_sw(data, clevel=0.95)[source]#

See plans.stochastic.normality.test_normality_sw().

static test_normality_dp(data, clevel=0.95)[source]#

See plans.stochastic.normality.test_normality_dp().

static get_tx(fx)[source]#

Return period. See plans.stochastic.frequency.get_tx().

static gumbel_fx(x, a, b)[source]#

Gumbel F(X). See plans.stochastic.frequency.gumbel_fx().

static gumbel_tx(x, a, b)[source]#

Gumbel T(X). See plans.stochastic.frequency.gumbel_tx().

static gumbel_freqfactor(tx=2)[source]#

See plans.stochastic.frequency.gumbel_freqfactor().

static gumbel_se(std_sample, n_sample, tx)[source]#

Gumbel SE. See plans.stochastic.frequency.gumbel_se().

static empirical_px(ranks)[source]#

Empirical P(X). See plans.stochastic.frequency.empirical_px().

static weibull_px(ranks)[source]#

Weibull P(X). See plans.stochastic.frequency.weibull_px().

static gringorten_px(ranks)[source]#

See plans.stochastic.frequency.gringorten_px().

static sample_gamma(size, shape=3, scale=1, shape_mode=None, n_min=None, n_max=None, rng=None)[source]#

Sample gamma. See plans.stochastic.sampling.sample_gamma().

static get_nbins_fd(data)[source]#

Freedman-Diaconis bins. See plans.stochastic.binning.get_nbins_fd().

static get_nbins_sturges(data)[source]#

Sturges bins. See plans.stochastic.binning.get_nbins_sturges().

static get_nbins_scott(data)[source]#

Scott bins. See plans.stochastic.binning.get_nbins_scott().

static get_nbins_density(n_units, data_range)[source]#

Bins by width. See plans.stochastic.binning.get_nbins_density().

static get_nbins_by_rule(data, rule=None)[source]#

Bins by rule. See plans.stochastic.binning.get_nbins_by_rule().

static get_histogram(data, bins=100, rule=None)[source]#

Histogram. See plans.stochastic.binning.get_histogram().

static qqplot(data)[source]#

QQ-plot data. See plans.stochastic.descriptive.qqplot().

static trace_variance(data)[source]#

See plans.stochastic.descriptive.trace_variance().

static get_bins(data, n_bins=5, scheme='equal')[source]#

Class boundaries. See plans.stochastic.binning.get_bins().

static bins_equal(data, n_bins)[source]#

Equal bins. See plans.stochastic.binning.bins_equal().

static bins_quantiles(data, n_bins=5)[source]#

Quantile bins. See plans.stochastic.binning.bins_quantiles().

static classify(data, bins=None, n_classes=5, scheme='equal')[source]#

Classify data. See plans.stochastic.binning.classify().

static quantiles_classify(data, n_classes=5)[source]#

See plans.stochastic.binning.quantiles_classify().

class plans.datasets.analyst.GeoUnivar(name='MyGeoUnivar', alias='GV0')[source]#

Bases: Univar

Univariate data with locations, held in a GeoDataFrame. Adds a map panel to the visuals of Univar.

__init__(name='MyGeoUnivar', alias='GV0')[source]#
_set_fields()[source]#

Set catalog fields names. Expected to increment superior methods.

_set_view_specs()[source]#

Set view specifications. Expected to overwrite superior methods.

Returns:

None

Return type:

None

view(show=True, return_fig=False)[source]#

Get the visualization, with a map as the first panel.

Layouts, set by view_specs["layout"]:

Layout

Panels

full

Map, data, histogram and CDF, with the statistics table.

mini

Map, data, histogram and CDF.

View specs, set by view_specs[key] = value before the call:

Key

Default

Description

style

"wien"

Name of the plot style. See plans.viewer.set_style().

folder

auto

Folder of the saved figure.

filename

auto

Name of the saved figure, without extension.

fig_format

"jpg"

Format of the saved figure.

dpi

300

Resolution of the saved figure.

title

auto

Title of the figure.

xvar

auto

Not in use.

yvar

auto

Not in use.

xlabel

auto

Not in use. The data panel has no label on its x axis.

ylabel

auto

Label of the color bar, which holds the y axis of the panels. On the data panel if there is no color bar.

color

"tab:grey"

Color of the data.

xmin

None

Not in use.

xmax

None

Not in use.

ymin

None

Not in use.

ymax

None

Not in use.

layout

"full"

Name of the layout. See the table of layouts.

data_plot

"scatter"

Plot of the data panel: "scatter" or "boxplot".

subtitle_data

"Data"

Title of the data panel. None hides it.

subtitle_box

"Boxplot"

Title of the data panel, if a boxplot.

subtitle_hist

"Histogram"

Title of the histogram. None hides it.

subtitle_cdf

"CDF"

Title of the CDF. None hides it.

subtitle_qq

"Q-Q"

Title of the Q-Q panel. None hides it.

yvar_field

auto

Column of values. Set with the data.

xlabel_cdf

"P(X)"

Label of the x axis of the CDF.

xlabel_qq

auto

Label of the x axis of the Q-Q panel.

data_label

auto

Label of the data in the legend.

data_legend

False

Show the legend of the data panel.

color_hist

"tab:grey"

Color of the histogram.

color_cdf

"black"

Color of the CDF.

color_mean

"red"

Color of the mean line.

color_mean_text

None

Color of the mean label. None is gray.

scheme_cmap

"equal"

Color scheme: "continuous", or classes by "equal", "quantiles" and other schemes of plans.stochastic.binning.get_bins(). Outer classes reach the ends of range.

n_classes_cmap

5

Number of classes of the color map. Not used if "continuous".

cmap

"viridis"

Name of the color map.

alpha

0.8

Opacity of the data. None sets it by the number of points.

alpha_hist

1

Opacity of the histogram.

alpha_cdf

1

Opacity of the CDF.

range

None

Range of the y axis and of the colors, as [low, high]. None is set from the data.

range_x

None

Range of the x axis, as [low, high]. None is set from the data.

plot_mean

True

Show the mean line.

plot_mean_data

False

Show the mean line also on the data panel.

linestyle_mean

"solid"

Line style of the mean.

pad_mean

1

Spaces between the mean label and its line.

plot_mean_label

True

Show the mean label.

hist_density

True

Not in use.

bins

20

Number of histogram bins, or the width of the bins if bins_density.

bins_density

False

Take bins as the width of the bins.

ax_data

1

Internal. Index of the data axis.

ax_hist

2

Internal. Index of the histogram axis. False has no histogram.

ax_cdf

3

Internal. Index of the CDF axis. False has no CDF.

ax_cbar

4

Internal. Index of the axis of the color bar.

x_stats

0.5

Horizontal position of the annotations, as a share of the figure.

x_stats_sep

0.155

Space between columns of the annotations.

y_stats

0.11

Space between the lateral panels and the annotations, as a share of the figure. They never pass the bottom of the map.

zorder_data

1

Drawing order of the data.

zorder_histh

1

Drawing order of the histogram.

zorder_cdf

1

Drawing order of the CDF.

scatter_factor

1

Space at each side of the points, in widths of the band of points. The default makes a band of 1/3 of the x axis.

colorize_scatter

False

Color the scatter markers by the color map.

box_width

0.4

Width of the boxplot.

box_showfliers

True

Show the outliers of the boxplot.

subtitle_map

"Map"

Title of the map. None hides it.

ax_map

0

Internal. Index of the map axis.

zorder_map

3

Drawing order of the data on the map.

helper_geometry

None

A geopandas.GeoDataFrame to overlay on the map, in the same CRS as the data.

facecolor_helper

"none"

Fill color of the helper geometry.

edgecolor_helper

"black"

Edge color of the helper geometry.

linewidth_helper

0.8

Width of the edge of the helper geometry.

zorder_helper

4

Drawing order of the helper geometry. Below zorder_map to stay under the data.

empty_map

False

Hide the data on the map, leaving only the helper geometry.

grid_map

True

Show the grid of the map, at the coordinates of the ticks.

n_ticks_map

3

Number of ticks on each axis of the map.

marker_map

"o"

Marker of the points.

markersize_map

10

Size of the points.

edgecolor_map

"none"

Edge color of the points or polygons.

cbar_map

True

Show the color bar of the map. A triangular tip marks a side where range clips the data.

cbar_scatter

False

Show a strip of the color map inside the data panel. Off if colorize_scatter.

cbar_histh

False

Show a strip of the color map inside the histogram.

gs_*

auto

Internal. Replaced by the shared grid of plans.viewer.

Parameters:
  • show (bool) – option for showing instead of saving

  • return_fig (bool) – option for returning the figure object

Returns:

figure object if return_fig is True, else None

Return type:

matplotlib.figure.Figure or None

load_data(file_data, layer_name, input_varfield=None)[source]#

Load data from file. Expected to overwrite superior methods.

Parameters:
  • file_data (str) – file path to data.

  • layer_name (str) – name of the layer in the file

  • input_varfield (str) – [optional] name of the column of values. Default is the varfield attribute.

Returns:

None

Return type:

None

set_data(input_df, input_varfield=None)[source]#

Set data from a GeoDataFrame, which is left untouched. Keeps only the values, as the varfield column, and the geometry. Rows with missing values are dropped.

Parameters:
  • input_df (geopandas.GeoDataFrame) – data with values and locations

  • input_varfield (str) – [optional] name of the column of values. Default is the varfield attribute.

Returns:

None

Return type:

None

static _build_axes(fig, gs, specs)[source]#

Add subplots to figure based on layout.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • gs (matplotlib.gridspec.GridSpec) – grid of the figure

  • specs (dict) – plot specification dictionary

Returns:

figure object

Return type:

matplotlib.figure.Figure

_plot(fig, gs, specs)[source]#

Plot on figure based on layout.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • gs (matplotlib.gridspec.GridSpec) – grid of the figure

  • specs (dict) – plot specification dictionary

Returns:

figure object

Return type:

matplotlib.figure.Figure

_get_annotation_columns()[source]#

Get the columns of annotations. Expected to increment superior methods.

Returns:

list of columns, each one a list of lines of text

Return type:

list

_plot_annotations(fig, specs)[source]#

Plot the annotations in the space below the lateral panels, down to the bottom of the map at most.

Parameters:
  • fig (matplotlib.figure.Figure) – figure object

  • specs (dict) – plot specification dictionary

Returns:

None

Return type:

None

_get_cmap_norm(specs)[source]#

Get the color map and the norm of the map panel.

Parameters:

specs (dict) – plot specification dictionary

Returns:

color map and norm

Return type:

tuple

_draw_map(ax, cmap, norm, specs)[source]#

Draw the data on the map panel. Expected to overwrite superior methods.

Parameters:
  • ax (matplotlib.axes.Axes) – axis to plot on

  • cmap (matplotlib.colors.Colormap) – color map

  • norm (matplotlib.colors.Normalize) – norm of the color scheme

  • specs (dict) – plot specification dictionary

Returns:

None

Return type:

None

_plot_map(ax, specs)[source]#

Plot the data and the helper geometry on the map panel, with the color bar.

Parameters:
  • ax (matplotlib.axes.Axes) – axis to plot on

  • specs (dict) – plot specification dictionary

Returns:

None

Return type:

None

static plot_cbar_map(ax, cmap, norm, data, specs)[source]#

Plot the vertical color bar, with its labels on the left. It spans the range of the panels at its right, so it reads as their y axis.

Classes are spaced by their width and labeled at their boundaries. A triangular tip marks a side where the norm clips the data, outside the rows of the panels.

Parameters:
  • ax (matplotlib.axes.Axes) – axis of the color bar

  • cmap (matplotlib.colors.Colormap) – color map

  • norm (matplotlib.colors.Normalize) – norm of the color scheme

  • data (numpy.ndarray) – vector of data without nan values

  • specs (dict) – plot specification dictionary

Returns:

None

Return type:

None

class plans.datasets.analyst.Bivar(name='MyBivar', alias='Bv0')[source]#

Bases: DataSet

The Bivariate object.

Holds a paired x/y sample in a pandas.DataFrame (sorted by x) and supports fitting simple regression models (see models attribute) and assessing their errors.

Examples

from plans.datasets.analyst import Bivar

bv = Bivar(name="StageDischarge", alias="SD")
bv.set_data(x=vct_h, y=vct_q)
bv.fit(model_type="Power")

# scatter with marginal histograms
bv.view(show=True)

# model panel
bv.view_specs["layout"] = "model"
bv.view_specs["model_type"] = "Power"
bv.view(show=True)
__init__(name='MyBivar', alias='Bv0')[source]#
_set_fields()[source]#

Set catalog fields names. Expected to increment superior methods.

get_metadata()[source]#

Get a dictionary with object metadata. Expected to increment superior methods.

Returns:

dictionary with all metadata

Return type:

dict

load_data(file_data, input_xfield=None, input_yfield=None, in_sep=';')[source]#

Load data from file. Expected to overwrite superior methods.

Parameters:
  • file_data (str) – file path to data.

  • input_xfield (str) – [optional] name of the x column in file. Default uses xfield

  • input_yfield (str) – [optional] name of the y column in file. Default uses yfield

  • in_sep (str) – column separator of file

Returns:

None

Return type:

None

set_data(x, y)[source]#

Set paired arrays to data.

Parameters:
  • x (numpy.ndarray) – array of x values

  • y (numpy.ndarray) – array of y values

Returns:

None

Return type:

None

_clean_data(df)[source]#

Drop missing pairs, sort by x and reset index.

update()[source]#

Refresh mutable attributes based on data. Expected to increment superior methods.

Returns:

None

Return type:

None

fit(model_type='Linear')[source]#

Fit model to data using least squares.

Parameters:

model_type (str) – model type. Options: Linear, Power, Power_zero

Returns:

None

Return type:

None

update_model(params_mean, params_sd=None, model_type='Linear')[source]#

Update model based on parameters.

Parameters:
  • params_mean (list) – mean of parameters

  • params_sd (list) – [optional] standard deviation of parameters

  • model_type (str) – model type. Options: Linear, Power, Power_zero

Returns:

None

Return type:

None

_update_model_data(model_type='Linear')[source]#

Update model predictions and errors (model minus observed) on data.

get_error_normality(model_type='Linear', clevel=0.95)[source]#

Get normality analysis of model errors using standard tests.

Parameters:
  • model_type (str) – model type. Options: Linear, Power, Power_zero

  • clevel (float) – confidence level

Returns:

dataframe of assessment results

Return type:

pandas.DataFrame

_set_view_specs()[source]#

Set view specifications. Expected to overwrite superior methods.

Returns:

None

Return type:

None

_get_fig_specs()[source]#

Get figure specs by merging view specs, layout sizes and grid specs.

_build_axes(fig, gs, specs)[source]#

Add subplots to figure based on layout.

_plot(fig, gs, specs)[source]#

Plot on figure based on layout.

_plot_full(fig, specs)[source]#

Plot scatter with marginal histograms.

_plot_model(fig, specs)[source]#

Plot model panel: fit, error, error histogram, Q-Q and variance tracing.

static _get_histh_specs(specs, data)[source]#

Get a specs copy suited for marginal Univar.plot_histh calls.

view(show=True, return_fig=False)[source]#

Get the visualization. Layout is set by view_specs["layout"] (full or model).

Layouts, set by view_specs["layout"]:

Layout

Panels

full

Scatter with histograms on the sides.

model

Model, error, error histogram, Q-Q and error variance.

default

Same as full.

View specs, set by view_specs[key] = value before the call:

Key

Default

Description

style

"wien"

Name of the plot style. See plans.viewer.set_style().

folder

auto

Folder of the saved figure.

filename

auto

Name of the saved figure, without extension.

fig_format

"jpg"

Format of the saved figure.

dpi

300

Resolution of the saved figure.

title

auto

Title of the figure.

xvar

auto

Not in use.

yvar

auto

Not in use.

xlabel

auto

Label of the x axis.

ylabel

auto

Label of the y axis.

color

"tab:grey"

Color of the data.

xmin

None

Not in use.

xmax

None

Not in use.

ymin

None

Not in use.

ymax

None

Not in use.

layout

"full"

Name of the layout. See the table of layouts.

model_type

"Linear"

Model of the model layout: "Linear", "Power" or "Power_zero".

subtitle_data

None

Title of the scatter panel. None hides it.

subtitle_model

"Model"

Title of the model panel. None hides it.

subtitle_error

"Error"

Title of the error panel. None hides it.

subtitle_variance

auto

Title of the error variance panel. None hides it.

subtitle_qq

"Q-Q"

Title of the Q-Q panel. None hides it.

color_hist

"tab:grey"

Color of the histogram.

color_model

"black"

Color of the model.

color_error

"tab:grey"

Color of the errors.

color_variance

"darkred"

Color of the error variance.

color_mean

"red"

Color of the mean line.

color_mean_text

None

Color of the mean label. None is gray.

alpha

0.8

Opacity of the data.

alpha_hist

1

Opacity of the histogram.

alpha_error

0.8

Opacity of the errors.

range

None

Range of the y axis, as [low, high]. None is set from the data.

range_x

None

Range of the x axis, as [low, high]. None is set from the data.

range_e

None

Range of the errors, as [low, high]. None is symmetric, set from the data.

plot_mean

True

Show the mean line.

linestyle_mean

"solid"

Line style of the mean.

pad_mean

1

Spaces between the mean label and its line.

plot_mean_label

True

Show the mean label.

bins

None

Number of histogram bins. None uses the Freedman-Diaconis rule.

bins_density

False

Take bins as the width of the bins.

zorder_data

1

Drawing order of the data.

zorder_model

2

Drawing order of the model.

zorder_histh

1

Drawing order of the histogram.

gs_*

auto

Internal. Replaced by the shared grid of plans.viewer.

Parameters:
  • show (bool) – option for showing instead of saving

  • return_fig (bool) – option for returning the figure object

Returns:

figure object if return_fig is True, else None

Return type:

matplotlib.figure.Figure | None

static get_metrics(observed, predicted)[source]#

Get all fit metrics. See plans.stochastic.metrics.get_metrics().

static pearson(x, y)[source]#

Compute Pearson r. See plans.stochastic.metrics.pearson().

static spearman(x, y)[source]#

Compute Spearman rho. See plans.stochastic.metrics.spearman().

static rsq(observed, predicted)[source]#

Compute R2. See plans.stochastic.metrics.rsq().

static rmse(observed, predicted)[source]#

Compute RMSE. See plans.stochastic.metrics.rmse().

static mae(observed, predicted)[source]#

Compute MAE. See plans.stochastic.metrics.mae().

static bias(observed, predicted)[source]#

Compute Bias (%). See plans.stochastic.metrics.bias().

class plans.datasets.analyst.Bayes(df_hypotheses, name='myBayes', nomenclature=None, gridsize=100)[source]#

Bases: object

The Bayes Theorem Analyst Object

__init__(df_hypotheses, name='myBayes', nomenclature=None, gridsize=100)[source]#

Deploy the Bayes Analyst :param df_hypotheses: dataframe listing all model hypotheses. Must contain a field Name (of parameter), Min and Max. :type df_hypotheses: :class:pandas.DataFrame :param name: name of analyst :type name: str :param nomenclature: dictionary for rename nomenclature :type nomenclature: dict :param gridsize: grid resolution in histrograms (bins) :type gridsize: int

_reset_nomenclature(dct_names)[source]#

Reset nomenclature :param dct_names: dictionary to rename nomenclatures :type dct_names: dict :return: None :rtype: None

_insert_new_step()[source]#

convenience void function for inserting new step objects :return: None :rtype:

_accumulate(n_step)[source]#

convenience void function for accumulate probability :param n_step: step number to accumulate :type n_step: int :return: None :rtype: none

conditionalize(dct_evidence, s_varfield='E', s_weightfield='W')[source]#

Conditionalize procedure of the Bayes Theorem :param dct_evidence: base_object of evidence dataframes :type dct_evidence: dict :param s_varfield: name of variable field in evidence dataframes :type s_varfield: str :param s_weightfield: name of weights field in evidence dataframes :type s_weightfield: str :return: None :rtype: none

plot_step(n_step, folder='C:/sample', filename='bayes', specs=None, dpi=300, show=False)[source]#

Void function for plot pannel of conditionalization step :param n_step: step number :type n_step: int :param folder: export folder :type folder: str :param filename: file name :type filename: str :param specs: plot specs base_object :type specs: dict :param dpi: plot resolution :type dpi: int :param show: control to show plot instead of saving :type show: bool :return: None :rtype: None