Sample data

This tutorial shows a way to use samples for a given parameter value. When running Monte Carlo simulation for multiple tier sequences which use the same parameter, this can be helpful to ensure that all sequences allways use the same value of the sample.

import bonsai_ipcc
my_ipcc = bonsai_ipcc.IPCC()

Provide sample data as numpy.array

Instead of having float values it is possible to provide the values in a numpy.array. Each array represents potential values of a parameter. Usually the arrays include thousands of values to allow robust Monte Carlo simulation.

In this example we only have a sample of 4 values. To make sure that the sequences work, all numpay.array must have the same length. To provide the data as a sample, use the property “sample” in the dataframe.

import pandas as pd
import numpy as np

d = {
    "year": [ 2011],
    "region": [ "DE"],
    "property": [ "sample"],
    "value": [np.array([38000000.0, 36000000.0, 39000000.0, 32000000.0])],
    "unit": ["MUSD/yr",],
}    
my_ipcc.waste.incineration.parameter.gdp = pd.DataFrame(d).set_index(["year", "region", "property"])

d = {
    "year": [ 2011],
    "region": ["DE"],
    "property": ["sample"],
    "value": [np.array([0.0012, 0.0018, 0.0018, 0.0012])],
    "unit": ["Gg/MUSD",],
}
my_ipcc.waste.incineration.parameter.isw_gen_rate = pd.DataFrame(d).set_index(["year", "region", "property"])

d = {
    "year": [2011],
    "region": ["DE"],
    "product": ["isw_rubber"],
    "property": ["sample"],
    "value": [np.array([0.1,0.07,0.08,0.05])],
    "unit": ["t/t"],
}
my_ipcc.waste.incineration.parameter.isw_type_frac = pd.DataFrame(d).set_index(
    ["year", "region", "product", "property"])
      
d = {
    "year": [2011],
    "region": ["DE"],
    "property": ["sample"],
    "value": [np.array([0.37, 0.38, 0.36, 0.35])],
    "unit": ["kg/kg"],
}
my_ipcc.waste.incineration.parameter.isw_frac_to_incin = pd.DataFrame(d).set_index(
    ["year", "region", "property"])
    
d = {
    "year": [2011],
    "region": ["DE"],
    "activity": ["inc_unspecified"],
    "property": ["sample"],
    "value": [np.array([0.9, 0.99, 0.98, 0.97])],
    "unit": ["kg/kg"],
}
my_ipcc.waste.incineration.parameter.incintype_frac = pd.DataFrame(d).set_index(
    ["year", "region", "activity", "property"])

d = {
    "year": [2011],
    "region": ["DE"],
    "waste_type": ["isw_rubber"],
    "property": ["sample"],
    "value": [np.array([0.86, 0.89, 0.86, 0.88])],
    "unit": ["kg/kg"],
}
my_ipcc.waste.incineration.parameter.dm = pd.DataFrame(d).set_index(
    ["year", "region", "waste_type", "property"])

d = {
    "year": [2011],
    "region": ["DE"],
    "waste_type": ["isw_rubber"],
    "property": ["sample"],
    "value": [np.array([0.67, 0.66, 0.64, 0.67])],
    "unit": ["kg/kg"],
}
my_ipcc.waste.incineration.parameter.cf = pd.DataFrame(d).set_index(
    ["year", "region", "waste_type", "property"])

d = {
    "region": ["DE"],
    "waste_type": ["isw_rubber"],
    "incin_type": ["inc_unspecified"],
    "property": ["sample"],
    "value": [np.array([0.32, 0.33, 0.34, 0.37])],
    "unit": ["kg/kg"],
}
my_ipcc.waste.incineration.parameter.fcf = pd.DataFrame(d).set_index(
    ["region", "waste_type", "incin_type", "property"])

d = {
    "region": ["EUR"],
    "waste_type": ["isw_rubber"],
    "incin_type": ["inc_unspecified"],
    "property": ["sample"],
    "value": [np.array([1.0, 1.0, 0.98, 0.99])],
    "unit": ["kg/kg"],
}
my_ipcc.waste.incineration.parameter.of = pd.DataFrame(d).set_index(
    ["region", "waste_type", "incin_type", "property"])

Run a sequence

To run a sequence with the sampled data option, use uncertainty="sample.

my_tier = my_ipcc.waste.incineration.sequence.tier1_co2(
    year=2011,
    region="DE",
    product="isw_rubber",
    activity="inc_unspecified",
    uncertainty="sample",
)
2025-04-30 15:47:49,824 - INFO - Incineration sequence started --->
/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/_sequence.py:118: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`
  new_c = conc_df.loc[c][j]
2025-04-30 15:47:49,833 - INFO - 'Coordinates ('DE', 'isw_rubber', 'inc_unspecified')' has been replaced by '['EUR', 'isw_rubber', 'inc_unspecified']' during reading parameter table 'of'
2025-04-30 15:47:49,833 - INFO - ---> Incineration sequence finalized.

The result is also stored in a np.array.

my_tier.co2_emissions.value
array([1026.60585984, 1212.86133017, 1332.326064  ,  516.18672484])