pygcam.mcs.analysis

Functions for plotting and performing analysis on simulation results.

API

pygcam.mcs.analysis.analyzeSimulation(args)

Analyze a simulation by reading parameters and results from the database.

pygcam.mcs.analysis.analyzeSimulationNew(args)

Analyze a simulation by reading parameters and results from the database.

pygcam.mcs.analysis.getCorrDF(inputs, output)

Generate a DataFrame with rank correlations between each input vector and the given output vector, and sort by abs(correlation), descending.

Parameters:
  • inputs – (pandas.DataFrame) input values for each parameter and trial
  • output – (pandas.Series) output values for one result, per trial
Returns:

(pandas.DataFrame) two columns, “spearman” and “abs”, the prior holding the Spearman correlations between each input and the output vector, and the latter with the absolute values of these correlations. The DataFrame is indexed by variable name and sorted by “abs”, descending.

pygcam.mcs.analysis.normalizeDF(df)

Perform max-min normalization on all columns. :param df: (pandas.DataFrame) data to operate on :return: (pandas.DataFrame) normalized values.

pygcam.mcs.analysis.normalizeSeries(series)

Normalize a series by dividing each element by the sum

pygcam.mcs.analysis.plotConvergence(simId, expName, paramName, values, show=True, save=False)

Examine the first 3 moments (mean, std, skewness) in the data set for increasing number (N) of values, growing by the given increment. Optionally plot the relationship between each of the moments and N, so we can when (if) convergence occurs.

pygcam.mcs.analysis.plotGroupSensitivityResults(varName, data, filename=None, extra=None, maxVars=None, printIt=True)

Sum the normalized contribution to variance for subscripted parameters, along with contribution from unsubscripted ones. For example, we sum the contributions for “ETA[1,5]” and “ETA[1,6]” into “ETA”.

pygcam.mcs.analysis.plotInputDistributions(simId, inputDF)

Plot the input values individually to test that the distributions are as expected

pygcam.mcs.analysis.plotSensitivityResults(varName, data, filename=None, extra=None, maxVars=None, printIt=True)

Prints results and generates a tornado plot with normalized squares of Spearman rank correlations between an output variable and all input variables.

pygcam.mcs.analysis.plotTornado(data, colname='value', labelsize=9, title=None, color=None, height=0.8, maxVars=15, rlabels=None, xlabel='Contribution to variance', figsize=None, show=True, filename=None, extra=None, extraColor='grey', extraLoc='right', importanceCSV=None)
Parameters:
  • data – A sorted DataFrame or Series indexed by variable name, with column named ‘value’ and if rlabels is set, a column of that name holding descriptive labels to display.
  • labelsize – font size for labels
  • title – If not None, the title to show
  • color – The color of the horizontal bars
  • height – Bar height
  • maxVars – The maximum number of variables to display
  • rlabels – If not None, the name of a column holding values to show on the right
  • xlabel – Label for X-axis
  • figsize – tuple for desired figure size. Defaults to (12,6) if rlabels else (8,6).
  • show – If True, the figure is displayed on screen
  • filename – If not None, the figure is saved to this file
  • extra – Extra text to display in a lower corner of the plot (see extraLoc)
  • extraColor – (str) color for extra text
  • extraLoc – (str) location of extra text, i.e., ‘right’, or ‘left’.
  • importanceCSV – (str) None, or the name of a file into which to save CSV data used to plot the tornado.
Returns:

nothing

pygcam.mcs.analysis.printExtraText(fig, text, loc='top', color='lightgrey', weight='ultralight', fontsize='xx-small')

Print ‘extra’ text at the top, bottom, right, or left edge of the figure.

pygcam.mcs.analysis.saveForEMA(simId, expNames, resultNames, inputDF, filename)

Save simulation results to the specified tar.gz file. The results are stored as csv files. There is an x.csv, and a csv for each outcome. In addition, there is a metadata csv which contains the datatype information for each of the columns in the x array. Unlike the version of this function in the EMA Workbench, this version collects data from the SQL database to generate a file in the required format.

Parameters:
  • simId – (int) the id of the simulation
  • expNames – (list of str) the names of the experiments to save results for
  • resultNames – (list of str) all model input values, each row holding values for 1 trial
  • inputDF – (pandas.DataFrame) the input data
  • filename – (str) the path of the file
Raises:

IOError if file not found

Returns:

none

pygcam.mcs.analysis.spearmanCorrelation(inputs, results)

Compute Spearman ranked correlation and normalized Spearman ranked correlation between values in a DataFrame of inputs and a Series of results. Returns a Series with the spearman rank correlation values.

Parameters:
  • inputs – (pandas.DataFrame) input values for each parameter and trial
  • results – (pandas.Series) values for one model result, per trial
Returns:

(pandas.Series) rank correlations of each input to the output vector.