Technical guide¶
Dynamic Life Cycle Assessment¶
-
class
bw2temporalis.dynamic_lca.
DynamicLCA
(demand, worst_case_method, t0=None, max_calc_number=10000.0, cutoff=0.001, loop_cutoff=10, group=False, grouping_field='tempo_group', log=False, lca_object=None)¶ Calculate a dynamic LCA, where processes, emissions, and CFs can vary throughout time.If an already (statically) characterized LCA object is passed calculate its dynamic LCA (useful when doing several dynamic LCA for same database but different the FUs).
- Args:
- demand (dict): The functional unit. Same format as in LCA class.
- worst_case_method (tuple): LCIA method. Same format as in LCA class.
- cutoff (float, default=0.005): Cutoff criteria to stop LCA calculations. Relative score of total, i.e. 0.005 will cutoff if a dataset has a score less than 0.5 percent of the total.
- max_calc_number (int, default=10000): Maximum number of LCA calculations to perform.
- loop_cutoff (int, default=10): Maximum number of times loops encountered will be traversed.
- t0 (datetime, default=np.datetime64(‘now’)): datetime of the year zero (i.e. the one of the functional unit).
- group (Boolean, default=False): When ‘True’ groups the impact upstream for each of the processes based on the values of grouping_field
- grouping_field (string, default=’tempo_group’: The bw2 field to look for when grouping impacts upstream. When ``group`==True and a process has grouping_field==whatever the impacts are grouped upstream with name ``whatever` untill another process with grouping_field==another name is found. If grouping_field==True it simply uses the name of the process
- log (int, default=False): If True to make log file
- lca_object (LCA object,default=None): do dynamic LCA for the object passed (must have “characterized_inventory” i.e. LCA_object.lcia() has been called)
-
calculate
()¶ Calculate
-
save_dLCI
(folderpath=None)¶ Save the results of DynamicLCA to a (compressed)
bw2lci
file containing dictionary like ``’timeline’:timeline object, ‘demand’:dLCI demand ‘wc_method’:dLCI worst_case_method The file is saved to the current working directory by default with the filename=demandkey_worstcase_method. Restoration is done using ‘bw2temporalis.timeline.load_LCI’. Args:- folderpath (str, default=None): the filepath of the timeline (without file extension)
-
class
bw2temporalis.multi_dlca.
MultiDynamicLCA
(cs_name, IA='static', by_process=False, dLCA_kwargs={}, IA_kwargs={})¶ Wrapper class for performing dynamic LCI or LCIA with many functional units and IA methods. When performing LCA using dynamic LCIA need to pass
IA='dynamic'
and adynamic_calculation_setups
name ascs_name
while when using static LCIA needIA='static'
andcalculation_setups
name again ascs_name
.- Args:
- cs_name (string): name of the
dynamic_calculation_setups
(whenIA='dynamic'
) orcalculation_setup
(whenIA='static'
). - IA (string,default=`static`): if a static or a dynamic IA will be used.
- by_process (Boolean,default=False): if True return results of LCIA by single process.
- dLCA_kwargs (dict): optional arguments to pass to the class DynamicLCA (passed as {argument_name:value} ).
- IA_kwargs (dict): optional arguments for the methods characterize_dynamic and/or characterize_static (passed as {argument_name:value} ).
- cs_name (string): name of the
-
multi_lca
(return_dataframe=False)¶ Method for performing multiple dynamic LCA calculations (both LCI and LCIA) with many functional units and LCIA methods. It creates self.dlca_results, which is a dictionary with keys=[functional_unit:method] and values = [years,impacts].
If
to_dataframe=True
returns the results in the form of a pandas dataframe Args: * to_dataframe (Boolean, default=False): if to return the results in pandas dataframe format
-
multi_lcia_from_saved_LCI
(folderpath, return_dataframe=False)¶ Method for performing multiple dynamic LCIA using already performed and saved dynamic LCI as results of
save_multi_lci
. Usefull when LCIA for the same FU need to be performed many time and want to avoid redoing every time also the LCI.It creates self.dlca_results, which is a dictionary with keys=[functional_unit:method] and values = [years,impacts]. If
to_dataframe=True
returns the results in the form of a pandas dataframe- Args:
- folderpath (string): folder where the
bw2lci
files are saved. It must have the name in the form ofcalculationssetupsname_IA
otherwise an error is returned - to_dataframe (Boolean, default=False): if to return the results in pandas dataframe format
- folderpath (string): folder where the
-
save_multi_lci
(folderpath=None)¶ Method for performing multiple dynamic LCI with many functional units and worst case LCIA methods and save their timelines using
bw2temporalis.DynamicLCA.save_dLCI
. Usefull when LCA for the same FU need to be performed many time and want to avoid redoing every time also the LCI.It doesn’t return anything but saves all the results in a folder with name
calculationssetupsname_IA
. The results are bw2lci files with name in the form of FU key_FU amount in the passed folderpath (or current folder if not passed)- Args:
- folderpath (string,default=None): folder where to save the results. default is current current directory
-
to_dataframe
(folderpath=None, transpose=True)¶ - Put the results of multi_lca in a pandas dataframe. When transpose=True columns are FU keys, FU amount, IA and years. When a filepath_excel is passed it saves the file as excel file
- Args:
- transpose (Boolean,default=True): If to transpose the df with columns as FU keys, FU amount, IA and years.
- export (Boolean,default=False): If to export the dataframe as an xlsx file
- folderpath (string,default=`None`): If a folderpath is provided export the dataframe as an xlsx file
- Returns:
- pandas.Dataframe with the name of the calculation setup and the IA e.g``my_calculation_setups_dynamic``.
-
bw2temporalis.dyn_methods.timedependent_lca.
time_dependent_LCA
(demand, dynIAM='GWP', t0=None, TH=100, DynamicLCA_kwargs={}, characterize_dynamic_kwargs={})¶ - calculate dynamic GWP or GTP for the functional unit and the time horizon indicated following the approach of Levausseur (2010, doi: 10.1021/es9030003).
It also consider climate effect of forest regrowth of biogenic CO2 (Cherubini 2011 doi: 10.1111/j.1757-1707.2011.01102.x) assuming a rotation lenght of 100 yrs.
Note that TH is calculated on the basis of t0 i.e. also if first emissions occurs before t0 everyting is characterzied till t0+TH. This imply that, for instance, co2 emissions occuring before t0 but due to demand has an impact that his higher than
- Args:
- demand (dict): The functional unit. Same format as in LCA.
- t0 (datetime,default = now): year 0 of the time horizon considered.
- TH (int,default =100): lenght of the time horizon in years. This TH is calculate on the basis of t0 i.e. also if first emissions occurs before t0 everyting is characterzied till t0=Th
- dynIAM (string, default=’GWP’): Dynamic IA Method, can be ‘GWP’ or ‘GTP’.
- DynamicLCA_kwargs (dict, default=None): optional argument to be passed for DynamicLCA.
- characterize_dynamic_kwargs (dict, default=None): optional arguments to be passed for characterize_dynamic.
Timeline¶
-
class
bw2temporalis.timeline.
Timeline
(data=None)¶ Sum and group elements over time. Timeline calculations produce a list of [(datetime, amount)] tuples.
-
add
(dt, flow, ds, amount)¶ Add a new flow from a dataset at a certain time.
-
characterize_dynamic
(method, data=None, cumulative=True, stepped=False, bio_st_emis_yr=None, bio_st_decay=None, rot_stand=None)¶ Characterize a Timeline object with a dynamic impact assessment method. Return a nested list of year and impact Args:
- method (tuple): The dynamic impact assessment method.
- data (Timeline object; default=None): ….
- cumulative (bool; default=True): when True return cumulative impact over time.
- stepped (bool; default=True):…
- bio_st_emis_yr (int; default=None): year when the biogenic carbon from stand is emitted, by default at yr=0.
- bio_st_decay (str; default=None): emission profile of biogenic carbon from stand .
- rot_stand (int; default=None): lenght of rotation of forest stands.
-
characterize_dynamic_by_flow
(method, characterize_dynamic_kwargs={})¶ Characterize a Timeline object with a static impact assessment method separately by flow Return a dictionary with flow name as key and a nested list of year and impact as value Args:
- method (tuple): The dynamic impact assessment method.
- characterize_dynamic_kwargs (dictionary; default={}): optional arguments (passed as key=argument name, value= argument value) passed to the called function characterize_dynamic (e.g. ‘cumulative’:True). See characterize_dynamic for the possible arguments to pass
-
characterize_dynamic_by_process
(method, characterize_dynamic_kwargs={})¶ Characterize a Timeline object with a static impact assessment method separately by process Return a dictionary with process name as key and a nested list of year and impact as value Args:
- method (tuple): The dynamic impact assessment method.
- characterize_dynamic_kwargs (dictionary; default={}): optional arguments (passed as key=argument name, value= argument value) passed to the called function characterize_dynamic (e.g. ‘cumulative’:True). See characterize_dynamic for the possible arguments to pass
-
characterize_static
(method, data=None, cumulative=True, stepped=False)¶ Characterize a Timeline object with a static impact assessment method.
- Args:
- method (tuple): The static impact assessment method.
- data (Timeline object; default=None): ….
- cumulative (bool; default=True): when True return cumulative impact over time.
- stepped (bool; default=True):…
-
characterize_static_by_flow
(method, characterize_static_kwargs={})¶ Characterize a Timeline object with a static impact assessment method separately by flow Return a dictionary with flow name as key and a nested list of year and impact as value Args:
- method (tuple): The static impact assessment method.
- characterize_static_kwargs (dictionary; default={}): optional arguments (passed as key=argument name, value= argument value) passed to the called function characterize_static (e.g.’cumulative’:True). See characterize_static for the possible arguments to pass
-
characterize_static_by_process
(method, characterize_static_kwargs={})¶ Characterize a Timeline object with a static impact assessment method separately by process Return a dictionary with process name as key and a nested list of year and impact as value Args:
- method (tuple): The static impact assessment method.
- characterize_static_kwargs (dictionary; default={}): optional arguments (passed as key=argument name, value= argument value) passed to the called function characterize_static (e.g.’cumulative’:True). See characterize_static for the possible arguments to pass
-
flows
()¶ Get set of flows in timeline
-
processes
()¶ Get set of processes in timeline
-
sort
()¶ Sort the raw timeline data. Characterized data is already sorted.
-
timeline_for_activity
(activity)¶ Create a new Timeline for a particular activity.
-
timeline_for_flow
(flow)¶ Create a new Timeline for a particular flow.
-
total_amount_for_flow
(flow)¶ Return cumulative amount of the flow passed
-
total_flow_for_activity
(flow, activity)¶ Return cumulative amount of the flow passed for the activity passed
-
Temporal Distribution¶
-
class
bw2temporalis.temporal_distribution.
TemporalDistribution
(times, values)¶ A container for a series of values spread over time. Args:
- times (ndarray): 1D array containg temporal info of values with type timedelta64 or datetime64 .
- values (ndarray): 1D array containg values with type float
Times and values must have same lenght and element of values must correspond to the element of times with the same index.
-
cumulative
()¶ Return new temporal distribution with cumulative values
-
datetime_to_timedelta
(dt)¶ Convert TD.times of type datetime64 to timedelta64 based on the datetime64 passed
-
timedelta_to_datetime
(dt)¶ Convert TD.times of type timedelta64 to datetime.datetime based on the datetime64 passed
Impact Assessment methods¶
-
class
bw2temporalis.dynamic_ia_methods.
DynamicMethods
(dirpath=None)¶ A dictionary for dynamic impact assessment method metadata. File data is saved in
dynamic-methods.json
.
-
class
bw2temporalis.dynamic_ia_methods.
DynamicIAMethod
(name)¶ A dynamic impact assessment method. Not translated into matrices, so no
process
method.-
create_functions
(data=None)¶ Take method data that defines functions in strings, and turn them into actual Python code. Returns a dictionary with flows as keys and functions as values.
-
from_static_method
(name)¶ Turn a static LCIA method into a dynamic one.
The dynamic method should not be registered yet.
name is the name (tuple) of an existing static method.
-
to_worst_case_method
(name, lower=None, upper=None, dynamic=True, register=True)¶ - Create a static LCA method using the worst case for each dynamic CF function.
- Default time interval over which to test for maximum CF is datetime.now() to datetime.now()+relativedelta(years=100).
- Args:
- name (string): method name.
- lower (datetime, default=datetime(2010, 1, 1): lower bound of the interval to consider.
- upper (datetime, default=lower + relativedelta(years=100): upper bound of the interval to consider.
- dynamic (bool, default=True): If total CF function of time of emission
- register (bool, default=True): If to register the method
-
Dynamic Impact Assessment methods¶
-
bw2temporalis.dyn_methods.method_creation.
create_climate_methods
(overwrite_constants=False)¶ Create the dynamic LCIA methods for AGTP and Radiative Forcing that are calculated every year over 500 years for each GHG emissions. Gasses from custom biosphere database can be added simpy adding their names to gas_name_in_biosphere
All the work is based on the library ghgforcing built by Greg Schively. It can be downloaded from https://github.com/gschivley/ghgforcing.
- Args:
- overwrite_constants (Boolean, default=False): Recreate clilmate constants even if the constants.pkl file already exists.