Skip to content

Commit

Permalink
fix: remove emission intensities (#637)
Browse files Browse the repository at this point in the history
ECALC-1699
  • Loading branch information
olelod authored Oct 14, 2024
1 parent 6e3fe89 commit fb2b638
Show file tree
Hide file tree
Showing 15 changed files with 397 additions and 2,868 deletions.
91 changes: 48 additions & 43 deletions docs/docs/changelog/next.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
---
slug: latest
title: Next
authors: ecalc-team
tags: [release, eCalc]
sidebar_position: -1002
---

# eCalc



## New Features

- In the results, the fluid streams entering and leaving a compressor train are now defined separately from the fluid
streams entering and leaving the individual compressor stages (pressure, temperature, composition, density, etc.).
This used to be covered only by reporting the inlet/outlet pressures before choking.
If there is any upstream choking, this will happen between the inlet of the compressor train, and the inlet of the
first compressor stage. This means that in a situation with upstream choking, the fluid stream entering the compressor
train will have higher e.g. pressure and density than the fluid stream entering the first compressor stage. If there
is any downstream choking, this will happen between the outlet of the last compressor stage and the outlet of the
compressor train. This means that in a situation with downstream choking, the fluid stream leaving the compressor
train will have lower e.g. pressure and density than the fluid stream leaving the last compressor stage.
- `POWER_ADJUSTMENT_FACTOR` for models: Optional factor to adjust the power (MW). Previously only the `POWER_ADJUSTMENT_CONSTANT` has been available for models, now it is possible to adjust/scale the power with a constant and a factor. It can be used to calibrate equipment.

## Fixes

- If a compressor train is not able to reach the requested inlet or outlet pressure, both the compressor stages and
the compressor train used to be reported as invalid. This is now changed. If the compressor stages are operating within
their capacity, they will now be reported as valid even if the compressor train as a whole is not able to reach
the requested inlet or outlet pressures.

## Breaking changes

- This version includes a rewrite of the yaml validation, which should catch more errors than before.

Main changes:
- Economics has been removed. TAX, PRICE and QUOTA keywords will now give an error.
- Misplaced keywords will now cause an error instead of being ignored.

- H2O is no longer supported in composition. Use 'water' instead.

- The CLI command `ecalc show results` has been removed. The reason being additional maintenance for something that did not seem to be used a lot.
---
slug: latest
title: Next
authors: ecalc-team
tags: [release, eCalc]
sidebar_position: -1002
---

# eCalc



## New Features

- In the results, the fluid streams entering and leaving a compressor train are now defined separately from the fluid
streams entering and leaving the individual compressor stages (pressure, temperature, composition, density, etc.).
This used to be covered only by reporting the inlet/outlet pressures before choking.
If there is any upstream choking, this will happen between the inlet of the compressor train, and the inlet of the
first compressor stage. This means that in a situation with upstream choking, the fluid stream entering the compressor
train will have higher e.g. pressure and density than the fluid stream entering the first compressor stage. If there
is any downstream choking, this will happen between the outlet of the last compressor stage and the outlet of the
compressor train. This means that in a situation with downstream choking, the fluid stream leaving the compressor
train will have lower e.g. pressure and density than the fluid stream leaving the last compressor stage.
- `POWER_ADJUSTMENT_FACTOR` for models: Optional factor to adjust the power (MW). Previously only the
`POWER_ADJUSTMENT_CONSTANT` has been available for models, now it is possible to adjust/scale the power with a
constant and a factor. It can be used to calibrate equipment.

## Fixes

- If a compressor train is not able to reach the requested inlet or outlet pressure, both the compressor stages and
the compressor train used to be reported as invalid. This is now changed. If the compressor stages are operating within
their capacity, they will now be reported as valid even if the compressor train as a whole is not able to reach
the requested inlet or outlet pressures.

- Emission intensities are no longer calculated and reported in the results, due to the following discrepancies:
CO2 intensity is defined as the total emission divided by the total HC export. eCalc only calculates the future data, so the correct CO2 intensity should be found by adding the historical to these future data. The hydrocarbon export rate is still reported to help the user calculate the CO2 intensity outside of eCalc.
Methane intensity was incorrectly calculated based on HC export. The common definition is the methane emission divided by the natural gas throughput of the wanted equipment- or installation level. This is safest done outside of eCalc to ensure proper definition.
## Breaking changes

- This version includes a rewrite of the yaml validation, which should catch more errors than before.

Main changes:
- Economics has been removed. TAX, PRICE and QUOTA keywords will now give an error.
- Misplaced keywords will now cause an error instead of being ignored.

- H2O is no longer supported in composition. Use 'water' instead.

- The CLI command `ecalc show results` has been removed. The reason being additional maintenance for something that did not seem to be used a lot.
83 changes: 0 additions & 83 deletions src/libecalc/common/utils/calculate_emission_intensity.py

This file was deleted.

41 changes: 0 additions & 41 deletions src/libecalc/common/utils/rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,47 +711,6 @@ def to_rate(self, regularity: Optional[List[float]] = None) -> TimeSeriesRate:
)


class TimeSeriesIntensity(TimeSeries[float]):
@field_validator("values", mode="before")
@classmethod
def convert_none_to_nan(cls, v: Any, info: ValidationInfo) -> List[TimeSeriesValue]:
if isinstance(v, list):
# convert None to nan
return [i if i is not None else math.nan for i in v]
return v

def resample(
self, freq: Frequency, include_start_date: bool = True, include_end_date: bool = True
) -> TimeSeriesIntensity:
"""
Resample emission intensity according to given frequency.
Slinear is used in order to only interpolate, not extrapolate.
Args:
freq: The frequency the time series should be resampled to
Returns:
TimeSeriesIntensity resampled to the given frequency
"""
if freq is Frequency.NONE:
return self.model_copy()

ds = pd.Series(index=self.timesteps, data=self.values)
new_timeseries = resample_time_steps(
self.timesteps, frequency=freq, include_start_date=include_start_date, include_end_date=include_end_date
)
ds_interpolated = ds.reindex(ds.index.union(new_timeseries)).interpolate("slinear")

# New resampled pd.Series
ds_resampled = ds_interpolated.reindex(new_timeseries)

return TimeSeriesIntensity(
timesteps=new_timeseries,
values=ds_resampled.to_numpy().tolist(),
unit=self.unit,
)


class TimeSeriesStreamDayRate(TimeSeriesFloat):
"""
Domain/core layer only.
Expand Down
41 changes: 0 additions & 41 deletions src/libecalc/presentation/json_result/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from libecalc.common.temporal_model import TemporalModel
from libecalc.common.time_utils import Period
from libecalc.common.units import Unit
from libecalc.common.utils.calculate_emission_intensity import (
compute_emission_intensity_by_yearly_buckets,
)
from libecalc.common.utils.rates import (
RateType,
TimeSeriesBoolean,
Expand All @@ -37,7 +34,6 @@
aggregate_is_valid,
)
from libecalc.presentation.json_result.result.emission import (
EmissionIntensityResult,
PartialEmissionResult,
)
from libecalc.presentation.json_result.result.results import (
Expand Down Expand Up @@ -132,32 +128,6 @@ def get_requested_compressor_pressures(
return TemporalModel(evaluated_temporal_energy_usage_models)


def _compute_intensity(
hydrocarbon_export_rate: TimeSeriesRate,
emissions: Dict[str, PartialEmissionResult],
) -> List[EmissionIntensityResult]:
hydrocarbon_export_cumulative = hydrocarbon_export_rate.to_volumes().cumulative()
emission_intensities = []
for key in emissions:
cumulative_rate_kg = emissions[key].rate.to_volumes().to_unit(Unit.KILO).cumulative()
intensity_sm3 = cumulative_rate_kg / hydrocarbon_export_cumulative
intensity_yearly_sm3 = compute_emission_intensity_by_yearly_buckets(
emission_cumulative=cumulative_rate_kg,
hydrocarbon_export_cumulative=hydrocarbon_export_cumulative,
)
emission_intensities.append(
EmissionIntensityResult(
name=emissions[key].name,
timesteps=emissions[key].timesteps,
intensity_sm3=intensity_sm3.model_dump(), # Converted to TimeSeriesIntensity
intensity_boe=intensity_sm3.to_unit(Unit.KG_BOE).model_dump(),
intensity_yearly_sm3=intensity_yearly_sm3.model_dump(),
intensity_yearly_boe=intensity_yearly_sm3.to_unit(Unit.KG_BOE).model_dump(),
)
)
return emission_intensities


def _to_full_result(
emissions: Dict[str, PartialEmissionResult],
) -> Dict[str, libecalc.presentation.json_result.result.EmissionResult]:
Expand Down Expand Up @@ -385,10 +355,6 @@ def _evaluate_installations(
energy_usage_cumulative=energy_usage.to_volumes().cumulative(),
hydrocarbon_export_rate=hydrocarbon_export_rate,
emissions=_to_full_result(aggregated_emissions),
emission_intensities=_compute_intensity(
hydrocarbon_export_rate=hydrocarbon_export_rate,
emissions=aggregated_emissions,
),
regularity=TimeSeriesFloat(
timesteps=expression_evaluator.get_time_vector(),
values=regularity.values,
Expand Down Expand Up @@ -1265,7 +1231,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
hydrocarbon_export_rate=TimeSeriesRate.from_timeseries_stream_day_rate(
consumer_result.component_result.hydrocarbon_export_rate, regularity=regularity
),
emission_intensities=consumer_result.component_result.emission_intensities,
timesteps=consumer_result.component_result.timesteps,
id=consumer_result.component_result.id,
is_valid=consumer_result.component_result.is_valid,
Expand Down Expand Up @@ -1540,12 +1505,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
energy_usage_cumulative=asset_energy_usage_cumulative,
hydrocarbon_export_rate=asset_hydrocarbon_export_rate_core,
emissions=_to_full_result(asset_aggregated_emissions),
emission_intensities=_compute_intensity(
hydrocarbon_export_rate=asset_hydrocarbon_export_rate_core,
emissions=asset_aggregated_emissions,
)
if installation_results
else [],
)

return Numbers.format_results_to_precision(
Expand Down
9 changes: 0 additions & 9 deletions src/libecalc/presentation/json_result/result/emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from libecalc.common.units import Unit
from libecalc.common.utils.rates import (
TimeSeriesFloat,
TimeSeriesIntensity,
TimeSeriesRate,
TimeSeriesVolumesCumulative,
)
Expand Down Expand Up @@ -65,11 +64,3 @@ def from_emission_core_result(cls, emission_result: EmissionCoreResult, regulari
timesteps=emission_result.timesteps,
rate=TimeSeriesRate.from_timeseries_stream_day_rate(emission_result.rate, regularity),
)


class EmissionIntensityResult(TabularTimeSeries):
name: str
intensity_sm3: TimeSeriesIntensity
intensity_boe: TimeSeriesIntensity
intensity_yearly_sm3: TimeSeriesIntensity
intensity_yearly_boe: TimeSeriesIntensity
2 changes: 0 additions & 2 deletions src/libecalc/presentation/json_result/result/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
)
from libecalc.presentation.json_result.result.base import EcalcResultBaseModel
from libecalc.presentation.json_result.result.emission import (
EmissionIntensityResult,
EmissionResult,
)
from libecalc.presentation.json_result.result.tabular_time_series import (
Expand Down Expand Up @@ -70,7 +69,6 @@ class AssetResult(ComponentResultBase):

componentType: Literal[ComponentType.ASSET]
hydrocarbon_export_rate: TimeSeriesRate
emission_intensities: List[EmissionIntensityResult]
power_electrical: Optional[TimeSeriesRate] = None
power_electrical_cumulative: Optional[TimeSeriesVolumesCumulative] = None
power_mechanical: Optional[TimeSeriesRate] = None
Expand Down
Loading

0 comments on commit fb2b638

Please sign in to comment.