Emission Profile Calculator
Collection of classes and functions for managing and calculating emission profiles of emissions from multiple reservoirs constructed at different dates.
- class reemission.emission_profile.Emission(value: float, unit: dataclasses.InitVar[str] = <property object>)
Represents emission as emission value + unit. .. note:
The emission quantity is defined by a value and a unit. The unit can be changed using the `set_unit()` method. The class supports addition and subtraction of emission quantities, converting units if necessary.
- value
The emission value.
- Type:
float
- unit
The unit of the emission (read-only; use set_unit() to modify).
- Type:
str
- set_unit(new_unit)
Converts the emission quantity to a different unit.
- __add__(emission2)
Adds two emission quantities.
- __sub__(emission2)
Subtracts two emission quantities.
- __sub__(emission2: Emission) Emission
Subtracts two emission quantities, converting units if necessary.
- copy() Emission
Return a copy of this Emission object.
- set_unit(new_unit: str) None
Converts the emission quantity to a different unit. :param new_unit: The new unit to convert to. :type new_unit: str
- Raises:
ValueError – If the new unit is not recognized.
- property unit: str
- value: float
- class reemission.emission_profile.EmissionProfile(values: Iterable[Emission], years: Iterable[int])
Stores and manipulates emission profiles. Inherits from Iterator to allow iteration over emission quantities.
Note
The emission profile is defined by a list of emission quantities and their corresponding years. The emission quantities must have the same unit. The years must be in ascending order.
- Raises:
ValueError – If the lengths of the emission quantities and years do not match.
ValueError – If the emission quantities do not have the same unit.
- values
List of emission quantities.
- Type:
Iterable[EmissionQuantity]
- years
List of corresponding years.
- Type:
Iterable[int]
- __next__()
Returns the next emission quantity.
- convert_unit(new_unit)
Converts all emission quantities to a new unit.
- unit(check_consistency)
Returns the unit of the emission profile.
- _is_equally_spaced(spacing)
Checks if the years are equally spaced.
- interpolate(spacing)
Interpolates the emission profile to have equally spaced years.
- plot()
Plots the emission profile.
- to_series(construction_year, interpolate)
Converts the emission profile to a Pandas Series.
- __next__()
Returns the next emission quantity in the profile. :raises StopIteration: If there are no more emission quantities to return.
- classmethod from_profile_function(profile_fun: Callable[[int], Emission], years: Iterable[int]) EmissionProfile
Alternative constructor: Creates an EmissionProfile from a callable and a range of years.
- Parameters:
profile_fun (Callable[[int], Emission]) – The function to calculate emissions.
years (Iterable[int]) – The range of years.
- Returns:
The calculated emission profile.
- Return type:
- integrate(start_year: int | None = None, end_year: int | None = None) Emission
Integrates the emission profile over a range of years.
Note
Uses scipy’s trapezoidal rule.
- Parameters:
start_year (Optional[int]) – The start year for the integration.
end_year (Optional[int]) – The end year for the integration.
- Returns:
The integrated emission quantity.
- Return type:
EmissionQuantity
- interpolate(spacing: int = 1) EmissionProfile
Creates a new emission profile with equally spaced years.
- Parameters:
spacing (int) – The interval between consecutive years in the new profile. Default is 1.
- Returns:
A new emission profile with equally spaced years.
- Return type:
Notes
If the current profile already has the specified spacing, it is returned as-is.
The interpolation is performed using linear interpolation.
- Raises:
YearsNotEquallySpacedError – If the years in the current profile are not equally spaced.
- plot(title: str = 'Emission Profile') None
Plots the emission profile.
- Parameters:
title (str) – The title of the plot.
Notes
The x-axis represents the years.
The y-axis represents the emission values with appropriate units.
- set_unit(new_unit: str) None
Sets all emission quantities in the profile to a different unit.
- to_series(construction_year: int, interpolate: bool = True) EmissionProfileSeries
Converts the emission profile (a list of emission quantities) to a Pandas Series with DateTimeIndex.
Hint
Allows subsequent addition of multiple profiles with different lengths and starting/ending in different years.
- Parameters:
construction_year (int) – The construction year of the reservoir.
interpolate (bool) – Whether to interpolate the profile if years are not equally spaced. Default is True.
- Raises:
YearsNotEquallySpacedError – If emissions in are not equally spaced.
- Returns:
The emission profile as a Pandas Series.
- Return type:
- property unit: str
Returns the unit of the emission profile.
- values: Iterable[Emission]
- years: Iterable[int]
- class reemission.emission_profile.EmissionProfileSeries(values: Series, unit: str)
Represents an emission profile as a Pandas Series.
- values
The emission profile values.
- Type:
pd.Series[Emission]
- unit
The unit of the emission profile.
- Type:
str
- plot(title, marker, linestyle, linewidth)
Plots the emission profile.
- __add__()
Adds two emission profiles.
- combine()
Combines multiple emission profiles.
- __add__(other: EmissionProfileSeries) EmissionProfileSeries
Adds two emission profiles, aligning them by index and checking unit consistency.
- classmethod combine(profiles: Iterable[EmissionProfileSeries]) EmissionProfileSeries
Combines multiple emission profiles.
- plot(title: str = 'Combined Profile', linewidth: float = 1.0) None
Plots the emission profile as a Pandas time-series.
- Parameters:
title (str) – The title of the plot.
linewidth (float) – The line width.
- unit: str
- values: Series
- exception reemission.emission_profile.YearsNotEquallySpacedError(message: str)
Custom exception raised if years in the emission profile are not equally spaced.
- reemission.emission_profile.calculate_age(construction_year: int, year: int) int
Calculates the asset age in years.
- reemission.emission_profile.calculate_status(construction_year: int, year: int) AssetConstructionStage
Determines the asset status (EXISTING/FUTURE) based on its age.
- reemission.emission_profile.pretty_unit(unit: str) str
Converts a unit string to a more human-readable format. :param unit: The unit string to convert. :type unit: str
- Returns:
The human-readable unit string.
- Return type:
str