plans.datasets.analyst#
Classes for statistical analysis of environmental and hydrological data.
Classes
|
The Bayes Theorem Analyst Object |
|
The Bivariate object. |
|
Univariate data with locations, held in a |
|
Attribute computed from the data on first use, and kept until it is set to None. |
|
The Univariate object |
- class plans.datasets.analyst.LazyStat(getter)[source]#
Bases:
objectAttribute computed from the data on first use, and kept until it is set to None.
- class plans.datasets.analyst.Univar(name='MyUnivar', alias='Uv0')[source]#
Bases:
DataSetThe Univariate object
- 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.
- 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.ndarrayorpandas.DataFrame) – vector or dataframe, with one record for each value- Returns:
the same sequence
- Return type:
numpy.ndarrayorpandas.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 objectgs (
matplotlib.gridspec.GridSpec) – grid of the figurespecs (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 builtspecs (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 objectspecs (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 builtspecs (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 objectgs (
matplotlib.gridspec.GridSpec) – grid of the figurespecs (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 thelayoutsattribute.Layouts, set by
view_specs["layout"]:Layout
Panels
fullData, histogram and CDF, with the statistics table.
miniData, histogram and CDF.
simpleData only.
simple-shallowData only, in a shallow figure.
qqQ-Q plot.
defaultSame panels of
mini, in the figure offull.View specs, set by
view_specs[key] = valuebefore the call:Key
Default
Description
style"wien"Name of the plot style. See
plans.viewer.set_style().folderauto
Folder of the saved figure.
filenameauto
Name of the saved figure, without extension.
fig_format"jpg"Format of the saved figure.
dpi300Resolution of the saved figure.
titleauto
Title of the figure.
xvarauto
Not in use.
yvarauto
Not in use.
xlabelauto
Label of the x axis.
ylabelauto
Label of the y axis.
color"tab:grey"Color of the data.
xminNone
Not in use.
xmaxNone
Not in use.
yminNone
Not in use.
ymaxNone
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_fieldauto
Column of values. Set with the data.
xlabel_cdf"P(X)"Label of the x axis of the CDF.
xlabel_qqauto
Label of the x axis of the Q-Q panel.
data_labelauto
Label of the data in the legend.
data_legendFalseShow 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_textNone
Color of the mean label. None is gray.
scheme_cmap"equal"Color scheme:
"continuous", or classes by"equal","quantiles"and other schemes ofplans.stochastic.binning.get_bins().n_classes_cmap5Number of classes of the color map. Not used if
"continuous".cmap"viridis"Name of the color map.
alpha0.8Opacity of the data. None sets it by the number of points.
alpha_hist1Opacity of the histogram.
alpha_cdf1Opacity of the CDF.
rangeNone
Range of the y axis, as
[low, high]. None is set from the data.range_xNone
Range of the x axis, as
[low, high]. None is set from the data.plot_meanTrueShow the mean line.
plot_mean_dataFalseShow the mean line also on the data panel.
linestyle_mean"solid"Line style of the mean.
pad_mean1Spaces between the mean label and its line.
plot_mean_labelTrueShow the mean label.
hist_densityTrueNot in use.
bins20Number of histogram bins, or the width of the bins if
bins_density.bins_densityFalseTake
binsas the width of the bins.ax_data0Internal. Index of the data axis.
ax_hist1Internal. Index of the histogram axis. False has no histogram.
ax_cdf2Internal. Index of the CDF axis. False has no CDF.
x_stats0.04Horizontal position of the statistics table, as a share of the figure.
x_stats_sep0.2Space between columns of the statistics table.
y_stats0.3Vertical position of the statistics table, as a share of the figure.
zorder_data1Drawing order of the data.
zorder_histh1Drawing order of the histogram.
zorder_cdf1Drawing order of the CDF.
scatter_factor4Space at each side of the points, in widths of the band of points.
colorize_scatterFalseColor the scatter markers by the color map.
box_width0.4Width of the boxplot.
box_showfliersTrueShow 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_figis True, else None- Return type:
matplotlib.figure.Figureor 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.Axesor bool) – axis to plot on. Nothing is plotted if Falsey_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 valuesax (
matplotlib.axes.Axesor bool) – axis to plot on. Nothing is plotted if Falsespecs (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 valuesax (
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 valuesax (
matplotlib.axes.Axesor bool) – axis to plot on. Nothing is plotted if Falsespecs (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 CDFax (
matplotlib.axes.Axesor bool) – axis to plot on. Nothing is plotted if Falsespecs (dict) – plot specification dictionary (from
view_specs)formatter (
matplotlib.ticker.Formatter) – [optional] formatter of the y axispx_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 valuesax (
matplotlib.axes.Axesor bool) – axis to plot on. Nothing is plotted if Falsespecs (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 objectstats_df (
pandas.DataFrame) – dataframe of basic statisticsx (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 objectls_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 histogramhist_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. Acontinuousscheme 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 valuesspecs (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 dataax (
matplotlib.axes.Axes) – axis to plot onscheme (str) – classification scheme, such as
equalorquantilescmap (str) – name of the color map
n_classes (int) – number of classes
side (str) – side of the axis,
leftorrightwidth_factor (float) – width of the bar as a fraction of the axis (1 over this value)
- Returns:
None
- Return type:
None
- 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_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 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 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().
- class plans.datasets.analyst.GeoUnivar(name='MyGeoUnivar', alias='GV0')[source]#
Bases:
UnivarUnivariate data with locations, held in a
GeoDataFrame. Adds a map panel to the visuals ofUnivar.- _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
fullMap, data, histogram and CDF, with the statistics table.
miniMap, data, histogram and CDF.
View specs, set by
view_specs[key] = valuebefore the call:Key
Default
Description
style"wien"Name of the plot style. See
plans.viewer.set_style().folderauto
Folder of the saved figure.
filenameauto
Name of the saved figure, without extension.
fig_format"jpg"Format of the saved figure.
dpi300Resolution of the saved figure.
titleauto
Title of the figure.
xvarauto
Not in use.
yvarauto
Not in use.
xlabelauto
Not in use. The data panel has no label on its x axis.
ylabelauto
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.
xminNone
Not in use.
xmaxNone
Not in use.
yminNone
Not in use.
ymaxNone
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_fieldauto
Column of values. Set with the data.
xlabel_cdf"P(X)"Label of the x axis of the CDF.
xlabel_qqauto
Label of the x axis of the Q-Q panel.
data_labelauto
Label of the data in the legend.
data_legendFalseShow 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_textNone
Color of the mean label. None is gray.
scheme_cmap"equal"Color scheme:
"continuous", or classes by"equal","quantiles"and other schemes ofplans.stochastic.binning.get_bins(). Outer classes reach the ends ofrange.n_classes_cmap5Number of classes of the color map. Not used if
"continuous".cmap"viridis"Name of the color map.
alpha0.8Opacity of the data. None sets it by the number of points.
alpha_hist1Opacity of the histogram.
alpha_cdf1Opacity of the CDF.
rangeNone
Range of the y axis and of the colors, as
[low, high]. None is set from the data.range_xNone
Range of the x axis, as
[low, high]. None is set from the data.plot_meanTrueShow the mean line.
plot_mean_dataFalseShow the mean line also on the data panel.
linestyle_mean"solid"Line style of the mean.
pad_mean1Spaces between the mean label and its line.
plot_mean_labelTrueShow the mean label.
hist_densityTrueNot in use.
bins20Number of histogram bins, or the width of the bins if
bins_density.bins_densityFalseTake
binsas the width of the bins.ax_data1Internal. Index of the data axis.
ax_hist2Internal. Index of the histogram axis. False has no histogram.
ax_cdf3Internal. Index of the CDF axis. False has no CDF.
ax_cbar4Internal. Index of the axis of the color bar.
x_stats0.5Horizontal position of the annotations, as a share of the figure.
x_stats_sep0.155Space between columns of the annotations.
y_stats0.11Space between the lateral panels and the annotations, as a share of the figure. They never pass the bottom of the map.
zorder_data1Drawing order of the data.
zorder_histh1Drawing order of the histogram.
zorder_cdf1Drawing order of the CDF.
scatter_factor1Space 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_scatterFalseColor the scatter markers by the color map.
box_width0.4Width of the boxplot.
box_showfliersTrueShow the outliers of the boxplot.
subtitle_map"Map"Title of the map. None hides it.
ax_map0Internal. Index of the map axis.
zorder_map3Drawing order of the data on the map.
helper_geometryNone
A
geopandas.GeoDataFrameto 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_helper0.8Width of the edge of the helper geometry.
zorder_helper4Drawing order of the helper geometry. Below
zorder_mapto stay under the data.empty_mapFalseHide the data on the map, leaving only the helper geometry.
grid_mapTrueShow the grid of the map, at the coordinates of the ticks.
n_ticks_map3Number of ticks on each axis of the map.
marker_map"o"Marker of the points.
markersize_map10Size of the points.
edgecolor_map"none"Edge color of the points or polygons.
cbar_mapTrueShow the color bar of the map. A triangular tip marks a side where
rangeclips the data.cbar_scatterFalseShow a strip of the color map inside the data panel. Off if
colorize_scatter.cbar_histhFalseShow 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_figis True, else None- Return type:
matplotlib.figure.Figureor 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
varfieldattribute.
- 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 thevarfieldcolumn, and the geometry. Rows with missing values are dropped.- Parameters:
input_df (
geopandas.GeoDataFrame) – data with values and locationsinput_varfield (str) – [optional] name of the column of values. Default is the
varfieldattribute.
- 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 objectgs (
matplotlib.gridspec.GridSpec) – grid of the figurespecs (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 objectgs (
matplotlib.gridspec.GridSpec) – grid of the figurespecs (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 objectspecs (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 oncmap (
matplotlib.colors.Colormap) – color mapnorm (
matplotlib.colors.Normalize) – norm of the color schemespecs (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 onspecs (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 barcmap (
matplotlib.colors.Colormap) – color mapnorm (
matplotlib.colors.Normalize) – norm of the color schemedata (
numpy.ndarray) – vector of data without nan valuesspecs (dict) – plot specification dictionary
- Returns:
None
- Return type:
None
- class plans.datasets.analyst.Bivar(name='MyBivar', alias='Bv0')[source]#
Bases:
DataSetThe Bivariate object.
Holds a paired
x/ysample in apandas.DataFrame(sorted byx) and supports fitting simple regression models (seemodelsattribute) 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)
- 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
xfieldinput_yfield (str) – [optional] name of the y column in file. Default uses
yfieldin_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 valuesy (
numpy.ndarray) – array of y values
- Returns:
None
- Return type:
None
- 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
- _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_histhcalls.
- view(show=True, return_fig=False)[source]#
Get the visualization. Layout is set by
view_specs["layout"](fullormodel).Layouts, set by
view_specs["layout"]:Layout
Panels
fullScatter with histograms on the sides.
modelModel, error, error histogram, Q-Q and error variance.
defaultSame as
full.View specs, set by
view_specs[key] = valuebefore the call:Key
Default
Description
style"wien"Name of the plot style. See
plans.viewer.set_style().folderauto
Folder of the saved figure.
filenameauto
Name of the saved figure, without extension.
fig_format"jpg"Format of the saved figure.
dpi300Resolution of the saved figure.
titleauto
Title of the figure.
xvarauto
Not in use.
yvarauto
Not in use.
xlabelauto
Label of the x axis.
ylabelauto
Label of the y axis.
color"tab:grey"Color of the data.
xminNone
Not in use.
xmaxNone
Not in use.
yminNone
Not in use.
ymaxNone
Not in use.
layout"full"Name of the layout. See the table of layouts.
model_type"Linear"Model of the
modellayout:"Linear","Power"or"Power_zero".subtitle_dataNone
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_varianceauto
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_textNone
Color of the mean label. None is gray.
alpha0.8Opacity of the data.
alpha_hist1Opacity of the histogram.
alpha_error0.8Opacity of the errors.
rangeNone
Range of the y axis, as
[low, high]. None is set from the data.range_xNone
Range of the x axis, as
[low, high]. None is set from the data.range_eNone
Range of the errors, as
[low, high]. None is symmetric, set from the data.plot_meanTrueShow the mean line.
linestyle_mean"solid"Line style of the mean.
pad_mean1Spaces between the mean label and its line.
plot_mean_labelTrueShow the mean label.
binsNone
Number of histogram bins. None uses the Freedman-Diaconis rule.
bins_densityFalseTake
binsas the width of the bins.zorder_data1Drawing order of the data.
zorder_model2Drawing order of the model.
zorder_histh1Drawing 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_figis 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:
objectThe 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