dynamic-characterization 0.0.1.dev0__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. dynamic_characterization-0.0.2/PKG-INFO +142 -0
  2. dynamic_characterization-0.0.2/README.md +104 -0
  3. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/dynamic_characterization/__init__.py +6 -1
  4. dynamic_characterization-0.0.2/dynamic_characterization/temporalis/__init__.py +15 -0
  5. dynamic_characterization-0.0.2/dynamic_characterization/temporalis/radiative_forcing.py +139 -0
  6. dynamic_characterization-0.0.2/dynamic_characterization/timex/__init__.py +23 -0
  7. dynamic_characterization-0.0.2/dynamic_characterization/timex/radiative_forcing.py +482 -0
  8. dynamic_characterization-0.0.2/dynamic_characterization.egg-info/PKG-INFO +142 -0
  9. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/dynamic_characterization.egg-info/SOURCES.txt +5 -1
  10. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/dynamic_characterization.egg-info/requires.txt +2 -0
  11. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/pyproject.toml +7 -1
  12. dynamic_characterization-0.0.1.dev0/PKG-INFO +0 -108
  13. dynamic_characterization-0.0.1.dev0/README.md +0 -72
  14. dynamic_characterization-0.0.1.dev0/dynamic_characterization.egg-info/PKG-INFO +0 -108
  15. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/LICENSE +0 -0
  16. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/MANIFEST.in +0 -0
  17. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/dynamic_characterization.egg-info/dependency_links.txt +0 -0
  18. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/dynamic_characterization.egg-info/top_level.txt +0 -0
  19. {dynamic_characterization-0.0.1.dev0 → dynamic_characterization-0.0.2}/setup.cfg +0 -0
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.1
2
+ Name: dynamic_characterization
3
+ Version: 0.0.2
4
+ Summary: Collection of dynamic characterization functions for life cycle inventories with temporal information
5
+ Author-email: Timo Diepers <timo.diepers@ltt.rwth-aachen.de>
6
+ Maintainer-email: Timo Diepers <timo.diepers@ltt.rwth-aachen.de>
7
+ Project-URL: source, https://github.com/TimoDiepers/dynamic_characterization
8
+ Project-URL: homepage, https://github.com/TimoDiepers/dynamic_characterization
9
+ Project-URL: tracker, https://github.com/TimoDiepers/dynamic_characterization/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Natural Language :: English
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pandas
24
+ Requires-Dist: numpy
25
+ Provides-Extra: testing
26
+ Requires-Dist: dynamic_characterization; extra == "testing"
27
+ Requires-Dist: pytest; extra == "testing"
28
+ Requires-Dist: pytest-cov; extra == "testing"
29
+ Requires-Dist: python-coveralls; extra == "testing"
30
+ Provides-Extra: dev
31
+ Requires-Dist: build; extra == "dev"
32
+ Requires-Dist: pre-commit; extra == "dev"
33
+ Requires-Dist: pylint; extra == "dev"
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Requires-Dist: pytest-cov; extra == "dev"
36
+ Requires-Dist: pytest-randomly; extra == "dev"
37
+ Requires-Dist: setuptools; extra == "dev"
38
+
39
+ # dynamic_characterization
40
+
41
+ [![Read the Docs](https://img.shields.io/readthedocs/timex?label=documentation)](https://dynamic-characterization.readthedocs.io/en/latest/)
42
+ [![PyPI - Version](https://img.shields.io/pypi/v/dynamic-characterization?color=%2300549f)](https://pypi.org/project/dynamic-characterization/)
43
+ [![Conda Version](https://img.shields.io/conda/v/diepers/dynamic_characterization?label=conda)](https://anaconda.org/diepers/dynamic_characterization)
44
+ ![Conda - License](https://img.shields.io/conda/l/diepers/bw_timex)
45
+
46
+ This is a collection of dynamic characterization functions for life cycle inventories with temporal information.
47
+
48
+ Here's an overview of what is currently included:
49
+
50
+ | impact category | metric | covered emissions | source
51
+ |-------|----------|----------|--|
52
+ | climate change | radiative forcing | CO2, CH4 |[bw_temporalis](https://github.com/brightway-lca/bw_temporalis/tree/main)|
53
+ | climate change | radiative forcing | 247 GHGs from [IPCC AR6 Ch.7](https://www.ipcc.ch/report/ar6/wg1/chapter/chapter-7/) |[bw_timex](https://github.com/brightway-lca/bw_timex/tree/main)|
54
+
55
+ ## What do dynamic characterization functions do?
56
+
57
+ The functions are meant to work with a common input format of the dynamic inventory, collected in a pandas DataFrame that looks like this:
58
+
59
+ | date | amount | flow | activity |
60
+ |-------|-------|------|----------|
61
+ | 101 | 33 | 1 | 2 |
62
+ | 312 | 21 | 4 | 2 |
63
+
64
+ 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:
65
+
66
+ | date | amount | flow | activity |
67
+ |------|--------|------|----------|
68
+ | 101 | 33 | 1 | 2 |
69
+ | 102 | 31 | 1 | 2 |
70
+ | 103 | 31 | 1 | 2 |
71
+ | 312 | 21 | 4 | 2 |
72
+ | 313 | 20 | 4 | 2 |
73
+ | 314 | 19 | 4 | 2 |
74
+
75
+ ## What do dynamic characterization functions look like?
76
+
77
+ Here's an example of what such a function could look like:
78
+
79
+ ```python
80
+ def characterize_something(series, period: int = 100, cumulative=False) -> pd.DataFrame:
81
+ date_beginning: np.datetime64 = series["date"].to_numpy()
82
+ date_characterized: np.ndarray = date_beginning + np.arange(
83
+ start=0, stop=period, dtype="timedelta64[Y]"
84
+ ).astype("timedelta64[s]")
85
+
86
+ decay_multipliers: list = np.array(
87
+ [
88
+ 1.234 * (1 - np.exp(-year / 56.789))
89
+ for year in range(period)
90
+ ]
91
+ )
92
+
93
+ forcing = pd.Series(data=series.amount * decay_multipliers, dtype="float64")
94
+ if not cumulative:
95
+ forcing = forcing.diff(periods=1).fillna(0)
96
+
97
+ return pd.DataFrame(
98
+ {
99
+ "date": pd.Series(data=date_characterized, dtype="datetime64[s]"),
100
+ "amount": forcing,
101
+ "flow": series.flow,
102
+ "activity": series.activity,
103
+ }
104
+ )
105
+ ````
106
+
107
+ ## Installation
108
+
109
+ You can install `dynamic_characterization` via [pip] from [PyPI]:
110
+
111
+ ```console
112
+ $ pip install dynamic_characterization
113
+ ```
114
+
115
+ Alternatively, you can also use conda:
116
+
117
+ ```console
118
+ $ conda install -c diepers dynamic_characterization
119
+ ```
120
+
121
+ ## Contributing
122
+
123
+ Contributions are very welcome.
124
+ To learn more, see the [Contributor Guide][Contributor Guide].
125
+
126
+ ## License
127
+
128
+ Distributed under the terms of the [BSD 3 Clause license][License],
129
+ _dynamic_characterization_ is free and open source software.
130
+
131
+ ## Issues
132
+
133
+ If you encounter any problems,
134
+ please [file an issue][Issue Tracker] along with a detailed description.
135
+
136
+
137
+ <!-- github-only -->
138
+
139
+ [command-line reference]: https://dynamic-characterization.readthedocs.io/en/latest/usage.html
140
+ [License]: https://github.com/TimoDiepers/dynamic_characterization/blob/main/LICENSE
141
+ [Contributor Guide]: https://github.com/TimoDiepers/dynamic_characterization/blob/main/CONTRIBUTING.md
142
+ [Issue Tracker]: https://github.com/TimoDiepers/dynamic_characterization/issues
@@ -0,0 +1,104 @@
1
+ # dynamic_characterization
2
+
3
+ [![Read the Docs](https://img.shields.io/readthedocs/timex?label=documentation)](https://dynamic-characterization.readthedocs.io/en/latest/)
4
+ [![PyPI - Version](https://img.shields.io/pypi/v/dynamic-characterization?color=%2300549f)](https://pypi.org/project/dynamic-characterization/)
5
+ [![Conda Version](https://img.shields.io/conda/v/diepers/dynamic_characterization?label=conda)](https://anaconda.org/diepers/dynamic_characterization)
6
+ ![Conda - License](https://img.shields.io/conda/l/diepers/bw_timex)
7
+
8
+ This is a collection of dynamic characterization functions for life cycle inventories with temporal information.
9
+
10
+ Here's an overview of what is currently included:
11
+
12
+ | impact category | metric | covered emissions | source
13
+ |-------|----------|----------|--|
14
+ | climate change | radiative forcing | CO2, CH4 |[bw_temporalis](https://github.com/brightway-lca/bw_temporalis/tree/main)|
15
+ | climate change | radiative forcing | 247 GHGs from [IPCC AR6 Ch.7](https://www.ipcc.ch/report/ar6/wg1/chapter/chapter-7/) |[bw_timex](https://github.com/brightway-lca/bw_timex/tree/main)|
16
+
17
+ ## What do dynamic characterization functions do?
18
+
19
+ The functions are meant to work with a common input format of the dynamic inventory, collected in a pandas DataFrame that looks like this:
20
+
21
+ | date | amount | flow | activity |
22
+ |-------|-------|------|----------|
23
+ | 101 | 33 | 1 | 2 |
24
+ | 312 | 21 | 4 | 2 |
25
+
26
+ 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:
27
+
28
+ | date | amount | flow | activity |
29
+ |------|--------|------|----------|
30
+ | 101 | 33 | 1 | 2 |
31
+ | 102 | 31 | 1 | 2 |
32
+ | 103 | 31 | 1 | 2 |
33
+ | 312 | 21 | 4 | 2 |
34
+ | 313 | 20 | 4 | 2 |
35
+ | 314 | 19 | 4 | 2 |
36
+
37
+ ## What do dynamic characterization functions look like?
38
+
39
+ Here's an example of what such a function could look like:
40
+
41
+ ```python
42
+ def characterize_something(series, period: int = 100, cumulative=False) -> pd.DataFrame:
43
+ date_beginning: np.datetime64 = series["date"].to_numpy()
44
+ date_characterized: np.ndarray = date_beginning + np.arange(
45
+ start=0, stop=period, dtype="timedelta64[Y]"
46
+ ).astype("timedelta64[s]")
47
+
48
+ decay_multipliers: list = np.array(
49
+ [
50
+ 1.234 * (1 - np.exp(-year / 56.789))
51
+ for year in range(period)
52
+ ]
53
+ )
54
+
55
+ forcing = pd.Series(data=series.amount * decay_multipliers, dtype="float64")
56
+ if not cumulative:
57
+ forcing = forcing.diff(periods=1).fillna(0)
58
+
59
+ return pd.DataFrame(
60
+ {
61
+ "date": pd.Series(data=date_characterized, dtype="datetime64[s]"),
62
+ "amount": forcing,
63
+ "flow": series.flow,
64
+ "activity": series.activity,
65
+ }
66
+ )
67
+ ````
68
+
69
+ ## Installation
70
+
71
+ You can install `dynamic_characterization` via [pip] from [PyPI]:
72
+
73
+ ```console
74
+ $ pip install dynamic_characterization
75
+ ```
76
+
77
+ Alternatively, you can also use conda:
78
+
79
+ ```console
80
+ $ conda install -c diepers dynamic_characterization
81
+ ```
82
+
83
+ ## Contributing
84
+
85
+ Contributions are very welcome.
86
+ To learn more, see the [Contributor Guide][Contributor Guide].
87
+
88
+ ## License
89
+
90
+ Distributed under the terms of the [BSD 3 Clause license][License],
91
+ _dynamic_characterization_ is free and open source software.
92
+
93
+ ## Issues
94
+
95
+ If you encounter any problems,
96
+ please [file an issue][Issue Tracker] along with a detailed description.
97
+
98
+
99
+ <!-- github-only -->
100
+
101
+ [command-line reference]: https://dynamic-characterization.readthedocs.io/en/latest/usage.html
102
+ [License]: https://github.com/TimoDiepers/dynamic_characterization/blob/main/LICENSE
103
+ [Contributor Guide]: https://github.com/TimoDiepers/dynamic_characterization/blob/main/CONTRIBUTING.md
104
+ [Issue Tracker]: https://github.com/TimoDiepers/dynamic_characterization/issues
@@ -4,7 +4,12 @@ Collection of dynamic characterization functions for life cycle inventories with
4
4
 
5
5
  __all__ = (
6
6
  "__version__",
7
+ "temporalis",
8
+ "timex",
7
9
  # Add functions and variables you want exposed in `dynamic_characterization.` namespace here
8
10
  )
9
11
 
10
- __version__ = "0.0.1dev0"
12
+ __version__ = "0.0.2"
13
+
14
+ from . import temporalis
15
+ from . import timex
@@ -0,0 +1,15 @@
1
+ """
2
+ Dynamic characterization functions from the bw_temporalis package (https://github.com/brightway-lca/bw_temporalis).
3
+ """
4
+
5
+ __all__ = (
6
+ "__version__",
7
+ "characterize_co2",
8
+ "characterize_methane",
9
+ # Add functions and variables you want exposed in `dynamic_characterization.` namespace here
10
+ )
11
+
12
+ __version__ = "0.0.1"
13
+
14
+ from .radiative_forcing import characterize_co2
15
+ from .radiative_forcing import characterize_methane
@@ -0,0 +1,139 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+
4
+
5
+ def characterize_co2(
6
+ series,
7
+ period: int | None = 100,
8
+ cumulative: bool | None = False,
9
+ ) -> pd.DataFrame:
10
+ """
11
+ Calculate the cumulative or marginal radiative forcing (CRF) from CO2 for each year in a given period.
12
+
13
+ If `cumulative` is True, the cumulative CRF is calculated. If `cumulative` is False, the marginal CRF is calculated.
14
+ Takes a single row of the TimeSeries Pandas DataFrame (corresponding to a set of (`date`/`amount`/`flow`/`activity`).
15
+ For each year in the given period, the CRF is calculated.
16
+ Units are watts/square meter/kilogram of CO2.
17
+
18
+ Returns
19
+ -------
20
+ A TimeSeries dataframe with the following columns:
21
+ - date: datetime64[s]
22
+ - amount: float
23
+ - flow: str
24
+ - activity: str
25
+
26
+ Notes
27
+ -----
28
+ See also the relevant scientific publication on CRF: https://doi.org/10.5194/acp-13-2793-2013
29
+ See also the relevant scientific publication on the numerical calculation of CRF: http://pubs.acs.org/doi/abs/10.1021/acs.est.5b01118
30
+
31
+ See Also
32
+ --------
33
+ characterize_methane: The same function for CH4
34
+ """
35
+
36
+ # functional variables and units (from publications listed in docstring)
37
+ RE = 1.76e-15 # Radiative forcing (W/m2/kg)
38
+ alpha_0, alpha_1, alpha_2, alpha_3 = 0.2173, 0.2240, 0.2824, 0.2763
39
+ tau_1, tau_2, tau_3 = 394.4, 36.54, 4.304
40
+ decay_term = lambda year, alpha, tau: alpha * tau * (1 - np.exp(-year / tau))
41
+
42
+ date_beginning: np.datetime64 = series["date"].to_numpy()
43
+ date_characterized: np.ndarray = date_beginning + np.arange(
44
+ start=0, stop=period, dtype="timedelta64[Y]"
45
+ ).astype("timedelta64[s]")
46
+
47
+ decay_multipliers: np.ndarray = np.array(
48
+ [
49
+ RE
50
+ * (
51
+ alpha_0 * year
52
+ + decay_term(year, alpha_1, tau_1)
53
+ + decay_term(year, alpha_2, tau_2)
54
+ + decay_term(year, alpha_3, tau_3)
55
+ )
56
+ for year in range(period)
57
+ ]
58
+ )
59
+
60
+ forcing = pd.Series(data=series.amount * decay_multipliers, dtype="float64")
61
+ if not cumulative:
62
+ forcing = forcing.diff(periods=1).fillna(0)
63
+
64
+ return pd.DataFrame(
65
+ {
66
+ "date": pd.Series(data=date_characterized, dtype="datetime64[s]"),
67
+ "amount": forcing,
68
+ "flow": series.flow,
69
+ "activity": series.activity,
70
+ }
71
+ )
72
+
73
+
74
+ def characterize_methane(series, period: int = 100, cumulative=False) -> pd.DataFrame:
75
+ """
76
+ Calculate the cumulative or marginal radiative forcing (CRF) from CH4 for each year in a given period.
77
+
78
+ If `cumulative` is True, the cumulative CRF is calculated. If `cumulative` is False, the marginal CRF is calculated.
79
+ Takes a single row of the TimeSeries Pandas DataFrame (corresponding to a set of (`date`/`amount`/`flow`/`activity`).
80
+ For earch year in the given period, the CRF is calculated.
81
+ Units are watts/square meter/kilogram of CH4.
82
+
83
+ Parameters
84
+ ----------
85
+ series : array-like
86
+ A single row of the TimeSeries dataframe.
87
+ period : int, optional
88
+ Time period for calculation (number of years), by default 100
89
+ cumulative : bool, optional
90
+ Should the RF amounts be summed over time?
91
+
92
+ Returns
93
+ -------
94
+ A TimeSeries dataframe with the following columns:
95
+ - date: datetime64[s]
96
+ - amount: float
97
+ - flow: str
98
+ - activity: str
99
+
100
+ Notes
101
+ -----
102
+ See also the relevant scientific publication on CRF: https://doi.org/10.5194/acp-13-2793-2013
103
+ See also the relevant scientific publication on the numerical calculation of CRF: http://pubs.acs.org/doi/abs/10.1021/acs.est.5b01118
104
+
105
+ See Also
106
+ --------
107
+ characterize_co2: The same function for CO2
108
+ """
109
+
110
+ # functional variables and units (from publications listed in docstring)
111
+ f1 = 0.5 # Unitless
112
+ f2 = 0.15 # Unitless
113
+ alpha = 1.27e-13 # Radiative forcing (W/m2/kg)
114
+ tau = 12.4 # Lifetime (years)
115
+
116
+ date_beginning: np.datetime64 = series["date"].to_numpy()
117
+ date_characterized: np.ndarray = date_beginning + np.arange(
118
+ start=0, stop=period, dtype="timedelta64[Y]"
119
+ ).astype("timedelta64[s]")
120
+
121
+ decay_multipliers: list = np.array(
122
+ [
123
+ (1 + f1 + f2) * alpha * tau * (1 - np.exp(-year / tau))
124
+ for year in range(period)
125
+ ]
126
+ )
127
+
128
+ forcing = pd.Series(data=series.amount * decay_multipliers, dtype="float64")
129
+ if not cumulative:
130
+ forcing = forcing.diff(periods=1).fillna(0)
131
+
132
+ return pd.DataFrame(
133
+ {
134
+ "date": pd.Series(data=date_characterized, dtype="datetime64[s]"),
135
+ "amount": forcing,
136
+ "flow": series.flow,
137
+ "activity": series.activity,
138
+ }
139
+ )
@@ -0,0 +1,23 @@
1
+ """
2
+ Dynamic characterization functions from the bw_timex package (https://github.com/brightway-lca/bw_timex).
3
+ """
4
+
5
+ __all__ = (
6
+ "__version__",
7
+ "characterize_co2",
8
+ "characterize_co2_uptake",
9
+ "characterize_co",
10
+ "characterize_ch4",
11
+ "characterize_n2o",
12
+ "create_generic_characterization_function",
13
+ # Add functions and variables you want exposed in `dynamic_characterization.` namespace here
14
+ )
15
+
16
+ __version__ = "0.0.1"
17
+
18
+ from .radiative_forcing import characterize_co2
19
+ from .radiative_forcing import characterize_co2_uptake
20
+ from .radiative_forcing import characterize_co
21
+ from .radiative_forcing import characterize_ch4
22
+ from .radiative_forcing import characterize_n2o
23
+ from .radiative_forcing import create_generic_characterization_function