bonsai_ipcc package

Subpackages

Submodules

bonsai_ipcc.core module

class bonsai_ipcc.core.IPCC(_external_metadata=None, _ext_functions=None)[source]

Bases: object

create_sample(dfs, constraints=None)[source]

Add sample to parameter tables.

For parameter tables in which values are related and constraint, Dirichlet distribution is used for samples. For other parameter tables, sample is determined independently using the best fit distribution.

Argument

dfsdict

key is name of paramter, value is df

constraints: dict
key is name of parameter, value is dict with

group_py: [“year”, “region”, “product”]

sizeint

sample size

returns:

revised parameter tables with sample array

rtype:

dict of dfs

get_metadata(volume, chapter, parameter)[source]

Get the metadata of a parameter.

Argument

volumestring

volume name

chapterstring

chapter name

paramaterstring

parameter name

returns:

VALUE – metadata pointing to the source in the IPCC pdf documents (year, volume, chapter, page, equation)

rtype:

dict

static inspect(func)[source]

Get the required parameters of a tier method.

Argument

funcfunction

tier sequence of a volume, chapter

returns:

VALUE – parameter names

rtype:

list of str

search_metadata(keyword)[source]

Get parameters that contain keyword in the description.

Argument

volumestring

volume name

chapterstring

chapter name

keywordstring

keyword to search for

returns:

(parameter name, description)

rtype:

list of tuples

class bonsai_ipcc.core.PPF[source]

Bases: IPCC

bonsai_ipcc.log_setup module

bonsai_ipcc.log_setup.setup_logger(level=20)[source]

bonsai_ipcc.sample module

bonsai_ipcc.sample.create_sample(dfs, constraints=None, size=1000)[source]

Add sample to parameter tables.

For parameter tables in which values are related and constraint, Dirichlet distribution is used for samples. For other parameter tables, sample is determined independently using the best fit distribution.

Argument

dfsdict

key is name of paramter, value is df

constraints: dict
key is name of parameter, value is dict with

group_py: [“year”, “region”, “product”]

sizeint

sample size

returns:

revised parameter tables with sample array

rtype:

dict of dfs

bonsai_ipcc.uncertainties module

Chapter 3 (Uncertainties) of Volume 1 (General Guidance and Reporting)

Min and max values provided by the IPCC guidelines are considerred to be 2.5th and 97.5th percentile, respectively (p 3.9).

Two ways of uncertainty propagation are implemented: analytical error propagation and Monte Carlo simulation. If analytical error propagation is choosen, asymmetric parameter ranges are transferred by a simple rule of thumb into symmetric ranges. If Monte Carlo, propability distributions can be determined automatically in regard to the properties of the parameter (by “check”).

bonsai_ipcc.uncertainties.analytical(min95, max95)[source]

Creates ufloat value to be used in error propagation. Simple asumption of normal distribution.

Argument

minfloat

2.5th percentile

maxfloat

97.5th percentile

returns:

VALUE

rtype:

ufloat

bonsai_ipcc.uncertainties.monte_carlo(min95, max95, default=None, abs_min=None, abs_max=None, size=1000, distribution='check')[source]

Creates numpy array of random numbers to be used in monte carlo simulation. Choices of different distributions possible.

Argument

minfloat

2.5th percentile

maxfloat

97.5th percentile

defaultfloat

default value (mean)

abs_minfloat

theoretic lower bound of parameter

abs_maxfloat

theoretic upper bound of parameter

distributionstr

Specifies type of density distribution. ‘normal’, ‘lognormal’, ‘truncnormal’, ‘uniform’, ‘check’ for automatized choice

sizeint

Number of random numbers to be generated.

returns:

VALUE

rtype:

numpy.array

bonsai_ipcc.uncertainties.one_side_trunc(mobs, sobs)[source]

Helper function for adjusting mean and sd for one-sided truncated normal distribution.

Given observed mean m > 0.0 and std-dev, 0.0 < s < m, return parameter mean and std-dev of one-sided truncated Gaussian distribution X, with X > 0.0

Rodrigues 2015, Maximum-Entropy Prior Uncertainty and Correlation of Statistical Economic Data: Supplementary Informatiom.

Argument

mobsfloat

observed mean

sobsfloat

observed standard deviation

returns:

VALUES – adjusted mean, adjusted standard deviation

rtype:

float, float

bonsai_ipcc.uncertainties.sample_dirichlet(default, max95, abs_max, size=1000)[source]

Calculate samples for interconnected parameters.

Argument

defaultlist

list of default values

max95list

list of 97.5 percentiles

abs_maxlist

list of absolute maximum

sizeint

sample size

returns:

each parameters sample in a row

rtype:

np.array

bonsai_ipcc.uncertainties.two_side_trunc(mobs, sobs, vmin, vmax)[source]

Helper function for adjusting mean and sd for two-sided truncated normal distribution.

Given observed mean m, std-dev s, lower and upper bounds, vmin and vmax, (all floats) such that: vmin < mobs < vmax, and 0.0 < sobs < min(mobs - vmin, vmax - mobs)

Argument

mobsfloat

observed mean

sobsfloat

observed standard deviation

vminfloat

absolut minimum

vmaxfloat

absolut maximum

returns:

VALUES – adjusted mean, adjusted standard deviation

rtype:

float, float

Module contents