General concept

This tutorial demonstrates basic concepts of the package.

import bonsai_ipcc
my_ipcc = bonsai_ipcc.IPCC()
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/tmp/ipykernel_4991/1308313284.py in ?()
----> 1 import bonsai_ipcc
      2 my_ipcc = bonsai_ipcc.IPCC()

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/__init__.py in ?()
      5 from os import listdir
      6 from os.path import dirname
      7 from pathlib import Path
      8 
----> 9 from .core import IPCC, PPF
     10 from .log_setup import setup_logger
     11 
     12 # setup the default logger

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/core.py in ?()
      4 
      5 import pandas as pd
      6 import yaml
      7 
----> 8 from . import agriculture, industry, ppf, waste
      9 from ._metadata import MetaData  # TODO
     10 from .sample import create_sample
     11 

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/waste/__init__.py in ?()
----> 1 from . import biological, incineration, swd, waste_generation, wastewater

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/waste/incineration/__init__.py in ?()
----> 1 from . import elementary, sequence
      2 from ._data import concordance, dimension, parameter

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/waste/incineration/sequence.py in ?()
     20 import logging
     21 
     22 from ..._sequence import Sequence
     23 from . import elementary as elem
---> 24 from ._data import concordance as conc
     25 from ._data import dimension as dim
     26 from ._data import parameter as par
     27 

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/waste/incineration/_data.py in ?()
      1 from ..._data import Concordance, Dimension, Parameter
      2 
----> 3 dimension = Dimension(path_in="data/", activitycode="incineration", productcode="waste")
      4 
      5 parameter = Parameter(["data/waste/incineration/", "data/waste/waste_generation/"])
      6 

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/_data.py in ?(self, path_in, activitycode, productcode)
     38                             df = self._filter_dataframe(df, activitycode)
     39                         elif filename == "dim_product.csv":
     40                             df = self._filter_dataframe(df, productcode)
     41                         setattr(self, filename[4:-4], df)
---> 42                     except Exception:
     43                         # print(f"error reading {filename}")
     44                         raise Exception

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/_data.py in ?(self, df, code)
     52             if row["parent_code"] == code:
     53                 # Add the child code to the list
     54                 child_codes.append(index)
     55                 # Recursively call the function to find child codes of this child code
---> 56                 child_codes.extend(self._filter_dataframe(df, index).index.tolist())
     57 
     58         # Filter the DataFrame to include all child codes found
     59         filtered_df = df.loc[child_codes]

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/bonsai_ipcc/_data.py in ?(self, df, code)
     47         # Initialize list to store child codes
     48         child_codes = []
     49 
     50         # Iterate through the index of the DataFrame to find child codes
---> 51         for index, row in df.iterrows():
     52             if row["parent_code"] == code:
     53                 # Add the child code to the list
     54                 child_codes.append(index)

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/pandas/core/frame.py in ?(self)
   1555         columns = self.columns
   1556         klass = self._constructor_sliced
   1557         using_cow = using_copy_on_write()
   1558         for k, v in zip(self.index, self.values):
-> 1559             s = klass(v, index=columns, name=k).__finalize__(self)
   1560             if using_cow and self._mgr.is_single_block:
   1561                 s._mgr.add_references(self._mgr)  # type: ignore[arg-type]
   1562             yield k, s

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/pandas/core/generic.py in ?(self, other, method, **kwargs)
   6277                 # One could make the deepcopy unconditionally, but a deepcopy
   6278                 # of an empty dict is 50x more expensive than the empty check.
   6279                 self.attrs = deepcopy(other.attrs)
   6280 
-> 6281             self.flags.allows_duplicate_labels = other.flags.allows_duplicate_labels
   6282             # For subclasses using _metadata.
   6283             for name in set(self._metadata) & set(other._metadata):
   6284                 assert isinstance(name, str)

/builds/bonsamurais/bonsai/util/ipcc/.tox/docs/lib/python3.12/site-packages/pandas/core/generic.py in ?(self)
--> 405     @final
    406     @property
    407     def flags(self) -> Flags:
    408         """

KeyboardInterrupt: 

Structure

The structure of the package is as followed:

  • ipcc.<volume>.<chapter>.sequence.<tier_name>

  • ipcc.<volume>.<chapter>.parameter.<parameter_name>

  • ipcc.<volume>.<chapter>.dimension.<dimension_name>

  • ipcc.<volume>.<chapter>.concordance.<concordance_name>

  • ipcc.<volume>.<chapter>.elementary.<equation_name>

Get information about a tier sequence

help(my_ipcc.waste.incineration.sequence.tier1_co2)
Help on function tier1_co2 in module ipcc.waste.incineration.sequence:

tier1_co2(year=2010, region='BG', wastetype='msw_food', incintype='open_burn', uncertainty='def')
    Tier 1 method CO2 Emissions.
    
    Default data to quantify waste generation, composition and management practice
    (requirement: incineration or open burning is not a key category)
    
    Argument
    ---------
    year : int
        year under study
    region : str
        region under study
    wastetype : str
        Fraction of solid waste.
    incintype : str
        Type of incineration.
    uncertainty : str
        'analytical', 'monte_carlo' or a property dimension, e.g. 'def'
    
    Returns
    -------
    VALUE: DataClass
        Inlcudes the results of each step of the sequence.

Inspect the involved parameters

my_ipcc.inspect(my_ipcc.waste.incineration.sequence.tier1_co2)
['cf',
 'SW',
 'isw_gen_rate',
 'msw_frac_to_incin',
 'of',
 'fcf',
 'msw_type_frac',
 'gdp',
 'b_frac',
 'isw_frac_to_incin',
 'urb_population',
 'msw_gen_rate',
 'dm',
 'total_population',
 'incintype_frac',
 'p_frac']

Show the table of a parameter

my_ipcc.waste.incineration.parameter.dm.head()
value unit
year region waste_type property
2006 World msw_food def 0.40 kg/kg
msw_garden def 0.40 kg/kg
msw_paper def 0.90 kg/kg
msw_wood def 0.84 kg/kg
msw_textiles def 0.80 kg/kg
help(my_ipcc.waste.incineration.elementary.msw_to_incin)
Help on function msw_to_incin in module ipcc.waste.waste_generation.elementary:

msw_to_incin(urb_population, msw_gen_rate, msw_frac_to_incin, msw_type_frac)
    Equation 2.y (not explicit in guidelines, tier 1)
    
    Calculates the amount of municipal solid waste (MSW) disposed to incineration sites,
    by using default data from chapter 2 (Waste Generation, Composition amd Management).
    
    Argument
    --------
    urb_population (cap/year) : float
        Urban population of a region in a given year.
    msw_gen_rate (t/cap) : float
        rate of municipal solid waste per capita.
    msw_frac_to_incin (kg/kg) : float
        Fraction of waste disposed to incineration in municipal solid waste.
    
    Returns
    -------
    VALUE: float
        amount of certain MSW type which is incinerated (tonnes/year)

Check dimension tables of the parameter msw_frac_to_swds

my_ipcc.waste.incineration.dimension.region
description region_type
code
AF Afghanistan country
AX Åland Islands country
AL Albania country
DZ Algeria country
AS American Samoa country
... ... ...
ANT Antarctica continent
AFR Africa continent
EUR Europe continent
ASI Asia continent
AUS Australia and New Zealand continent

285 rows × 2 columns

my_ipcc.waste.incineration.dimension.year.head()
description
code
0 place holder for emtpy tables
1900 year in which activity occurs
1901 year in which activity occurs
1902 year in which activity occurs
1903 year in which activity occurs
my_ipcc.waste.incineration.dimension.property
description remarks
code
def default mean
min minimum 2.5th percentile
max maximum 97.5th percentile
abs_max absolute maximun theoretical upper bound
abs_min absolute minimum theoretical lower bound
dummy place holder for emtpy tables NaN

Concordance tables

Concordance tables are used to automated reading parameter values within a tier sequence. When reading the parameter value for a certain dimension, in general, this value is specified in the parameter table.

However, the requirement to define all parameter values for each dimension explicitally in the parameter table would lead to a lot of repetition. To avoid this, the concept of concordance tables is used. Each attribute of a dimension can be hierarchically mapped to others. When using the concordance table for a dimension, the algorithm checks automatically if values for other dimension attributes are available in the parameter table

Let´s have a look to the concordance table for the dimension ‘region’.

my_ipcc.waste.incineration.concordance.region.head()
unregion geographicregion continent world
country
AF Southern Asia NaN ASI World
AX Northern Europe NaN EUR World
AL Southern Europe NaN EUR World
DZ Northern Africa NaN AFR World
AS Polynesia NaN AUS World

When reading a parameter within a sequence for the region Albania (‘AL’), the algorithm would start trying to find the value for ‘AL’. If there is no value for ‘AL’ in the parameter table, it would try to find the value for ‘Southern Europe’, stepwise until to the last item of the column. In this case this is ‘World’, which indicates the validity of the parameter value for all regions.

(‘NaN’ is skipped during the approach)

my_ipcc.waste.incineration.concordance.year.head()
cat3 cat2 cat1 cat0
cat4
2006 2019 NaN NaN NaN
2007 2006 2019.0 NaN NaN
2008 2006 2019.0 NaN NaN
2009 2006 2019.0 NaN NaN
2010 2006 2019.0 NaN NaN

Look at the additional tutorials how to run a tier sequence.