Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brightway-lca/dynamic_characterization
Collection of dynamic characterization functions for life cycle inventories with temporal information
https://github.com/brightway-lca/dynamic_characterization
Last synced: about 2 months ago
JSON representation
Collection of dynamic characterization functions for life cycle inventories with temporal information
- Host: GitHub
- URL: https://github.com/brightway-lca/dynamic_characterization
- Owner: brightway-lca
- License: bsd-3-clause
- Created: 2024-06-12T09:20:25.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T15:54:14.000Z (2 months ago)
- Last Synced: 2024-10-23T11:36:11.915Z (2 months ago)
- Language: Jupyter Notebook
- Homepage:
- Size: 1.62 MB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# dynamic_characterization
[![Read the Docs](https://img.shields.io/readthedocs/timex?label=documentation)](https://dynamic-characterization.readthedocs.io/en/latest/)
[![PyPI - Version](https://img.shields.io/pypi/v/dynamic-characterization?color=%2300549f)](https://pypi.org/project/dynamic-characterization/)
[![Conda Version](https://img.shields.io/conda/v/diepers/dynamic_characterization?label=conda)](https://anaconda.org/diepers/dynamic_characterization)
![Conda - License](https://img.shields.io/conda/l/diepers/bw_timex)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/brightway-lca/dynamic_characterization/main?labpath=notebooks%2Fdynamic_characterization_demo.ipynb)This is a package for the dynamic characterization of Life Cycle Inventories with temporal information. It includes a collection of dynamic characterization functions for various environmental flows. We also provide a simple interface to apply these functions to an existing dynamic LCI (coming from, e.g., [bw_temporalis](https://github.com/brightway-lca/bw_temporalis) or [bw_timex](https://github.com/brightway-lca/bw_timex)).
The following dynamic characterization functions are currently included:
| module |impact category | metric | covered emissions | source
|--------|-------|----------|----------|--|
| ipcc_ar6 | climate change | radiative forcing | 247 GHGs | radiative efficiencies & lifetimes from [IPCC AR6 Ch.7](https://www.ipcc.ch/report/ar6/wg1/chapter/chapter-7/) |
| original_temporalis_functions| climate change | radiative forcing | CO2, CH4 |[bw_temporalis](https://github.com/brightway-lca/bw_temporalis/tree/main)|## What do dynamic characterization functions do?
The functions are meant to work with a common input format of the dynamic inventory, collected in a pandas DataFrame that looks like this:
| date | amount | flow | activity |
|-------|-------|------|----------|
| 101 | 33 | 1 | 2 |
| 312 | 21 | 4 | 2 |Each function takes one row of this dynamic inventory dataframe (i.e. one emission at one point in time) and transform it according to some metric. The output generated by applying a very simple function to both rows of the input dataframe could look like:
| date | amount | flow | activity |
|------|--------|------|----------|
| 101 | 33 | 1 | 2 |
| 102 | 31 | 1 | 2 |
| 103 | 31 | 1 | 2 |
| 312 | 21 | 4 | 2 |
| 313 | 20 | 4 | 2 |
| 314 | 19 | 4 | 2 |## How do I use this package?
The workflow could look like this:
```python
import pandas as pd
from dynamic_characterization import characterize
from dynamic_characterization.ipcc_ar6 import characterize_co2, characterize_ch4# defining a dummy dynamic inventory that you somehow got
dynamic_inventory_df = pd.DataFrame(
data={
"date": pd.Series(
data=[
"15-12-2020",
"20-12-2020",
"25-05-2022",
],
dtype="datetime64[s]",
),
"amount": pd.Series(data=[10.0, 20.0, 50.0], dtype="float64"),
"flow": pd.Series(data=[1, 1, 3], dtype="int"),
"activity": pd.Series(data=[2, 2, 4], dtype="int"),
}
)df_characterized = characterize(
dynamic_inventory_df,
metric="radiative_forcing", # could also be GWP
characterization_function_dict={
1: characterize_co2,
3: characterize_ch4,
},
time_horizon=2,
)
```If you use this package with [Brightway](https://docs.brightway.dev/en/latest/), stuff can get even easier: if you have an impact assessment method at hand, you can pass it to the characterize function via the `base_lcia_method` attribute and we'll try to automatically match the flows that are characterized in that method to the flows we have characterization functions for. This matching is based on the names or the CAS numbers, depending on the flow. The function call could look like this then:
```python
method = ('EF v3.1', 'climate change', 'global warming potential (GWP100)')df_characterized = characterize(
dynamic_inventory_df,
metric="radiative_forcing", # could also be GWP
base_lcia_method=method,
time_horizon=2,)
```## What do dynamic characterization functions look like?
Here's an example of what such a function could look like:
```python
def example_characterization_function(series: namedtuple, period: int = 2) -> namedtuple:
date_beginning: np.datetime64 = series.date.to_numpy()
dates_characterized: np.ndarray = date_beginning + np.arange(
start=0, stop=period, dtype="timedelta64[D]"
).astype("timedelta64[s]")amount_beginning: float = series.amount
# in reality, this would probably something more complex like an exponential decay function
amount_characterized: np.ndarray = amount_beginning - np.arange(
start=0, stop=period, dtype="int"
)return namedtuple("CharacterizedRow", ["date", "amount", "flow", "activity"])(
date=np.array(dates_characterized, dtype="datetime64[s]"),
amount=amount_characterized,
flow=series.flow,
activity=series.activity,
)
````## Installation
You can install `dynamic_characterization` via [pip] from [PyPI]:
```console
$ pip install dynamic_characterization
```Alternatively, you can also use conda:
```console
$ conda install -c diepers dynamic_characterization
```## Contributing
Contributions are very welcome.
To learn more, see the [Contributor Guide][Contributor Guide].## License
Distributed under the terms of the [BSD 3 Clause license][License],
_dynamic_characterization_ is free and open source software.## Issues
If you encounter any problems,
please [file an issue][Issue Tracker] along with a detailed description.## Support
If you have any questions or need help, do not hesitate to contact Timo Diepers ([[email protected]](mailto:[email protected]))
[command-line reference]: https://dynamic-characterization.readthedocs.io/en/latest/usage.html
[License]: https://github.com/TimoDiepers/dynamic_characterization/blob/main/LICENSE
[Contributor Guide]: https://github.com/TimoDiepers/dynamic_characterization/blob/main/CONTRIBUTING.md
[Issue Tracker]: https://github.com/TimoDiepers/dynamic_characterization/issues