Skip to content

Commit

Permalink
refactor: change name from direct to venting emitter (#303)
Browse files Browse the repository at this point in the history
* refactor: change name from direct to venting emitter
  • Loading branch information
frodehk authored Nov 29, 2023
1 parent f8e5052 commit 8d03822
Show file tree
Hide file tree
Showing 30 changed files with 169 additions and 169 deletions.
2 changes: 1 addition & 1 deletion docs/docs/about/migration_guides/v7_to_v8.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ See [INSTALLATION](../references/keywords/INSTALLATIONS.md),
[GENERATORSET](../references/keywords/GENERATORSETS.md),
[CONSUMERS](../references/keywords/CONSUMERS.md),
[FUELCONSUMERS](../references/keywords/FUELCONSUMERS.md),
[DIRECT_EMITTER](../references/keywords/DIRECT_EMITTERS.md)
[VENTING_EMITTER](../references/keywords/VENTING_EMITTERS.md)
for more details about the relevant keywords.
:::tip Are you using power from shore?
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/about/modelling/setup/installations/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ INSTALLATIONS:
FUEL: <fuel specification for installation 1>
HCEXPORT: <hydrocarbon export specification for installation 1>
REGULARITY: <regularity specification for installation 1>
DIRECT_EMITTERS: <direct emissions specification for installation 1>
VENTING_EMITTERS: <direct emissions specification for installation 1>
CATEGORY: <category for installation 1>
- NAME: <name of installation 2>
GENERATORSETS: <generator set specifications for installation 2>
FUELCONSUMERS: <fuel consumer specifications for installation 2>
FUEL: <fuel specification for installation 2>
HCEXPORT: <hydrocarbon export specification for installation 2>
REGULARITY: <regularity specification for installation 2>
DIRECT_EMITTERS: <direct emissions specification for installation 2>
VENTING_EMITTERS: <direct emissions specification for installation 2>
CATEGORY: <category for installation 2>
- ...
~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/about/references/keywords/EMISSION_NAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| Required | Child of | Children/Options |
|------------|---------------------------|------------------------------------|
| Yes | `DIRECT_EMITTERS` | None |
| Yes | `VENTING_EMITTERS` | None |

## Description
Name of an entity.
Expand All @@ -16,10 +16,10 @@ EMISSION_NAME: <name>
~~~~~~~~

## Example
Usage in [DIRECT_EMITTERS](/about/references/keywords/DIRECT_EMITTERS.md):
Usage in [VENTING_EMITTERS](/about/references/keywords/VENTING_EMITTERS.md):

~~~~~~~~yaml
DIRECT_EMITTERS:
VENTING_EMITTERS:
- EMISSION_NAME: CH4
~~~~~~~~

2 changes: 1 addition & 1 deletion docs/docs/about/references/keywords/EMITTER_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

| Required | Child of | Children/Options |
|------------|---------------------------|-------------------|
| No | `DIRECT_EMITTERS` | `EMISSION_RATE` |
| No | `VENTING_EMITTERS` | `EMISSION_RATE` |

## Description
The emitter model specifies the data to calculate the direct emissions on an installation. This data is used to set up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DIRECT_EMITTERS
# VENTING_EMITTERS

[INSTALLATIONS](/about/references/keywords/INSTALLATIONS.md) /
[DIRECT_EMITTERS](/about/references/keywords/DIRECT_EMITTERS.md)
[VENTING_EMITTERS](/about/references/keywords/VENTING_EMITTERS.md)


| Required | Child of | Children/Options |
Expand All @@ -10,14 +10,14 @@


## Description
The [DIRECT_EMITTERS](/about/references/keywords/DIRECT_EMITTERS.md) keyword covers the direct emissions on the installation
The [VENTING_EMITTERS](/about/references/keywords/VENTING_EMITTERS.md) keyword covers the direct emissions on the installation
that are not consuming energy. The attributes [NAME](/about/references/keywords/NAME.md),
[EMISSION_NAME](/about/references/keywords/EMISSION_NAME.md), [CATEGORY](/about/references/keywords/CATEGORY.md) and
[EMITTER_MODEL](/about/references/keywords/EMITTER_MODEL.md) are required.

## Format
~~~~~~~~yaml
DIRECT_EMITTER:
VENTING_EMITTER:
- NAME: <emitter name>
EMISSION_NAME: <emission name>
CATEGORY: <category>
Expand All @@ -26,14 +26,14 @@ DIRECT_EMITTER:

## Example
~~~~~~~~yaml
DIRECT_EMITTER:
- NAME: SomeDirectEmitter
VENTING_EMITTER:
- NAME: SomeVentingEmitter
EMISSION_NAME: CH4
CATEGORY: COLD-VENTING-FUGITIVE
EMITTER_MODEL:
<emitter model data>
...
- NAME: SomeOtherDirectEmitter
- NAME: SomeOtherVentingEmitter
EMISSION_NAME: C2H6
CATEGORY: COLD-VENTING-FUGITIVE
EMITTER_MODEL:
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_python_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@
" generator_set_a,\n",
" flare,\n",
" ],\n",
" direct_emitters=[],\n",
" venting_emitters=[],\n",
" )\n",
" ],\n",
")\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,49 @@
from libecalc.expression import Expression


class DirectEmitter:
class VentingEmitter:
"""A class for direct (not fuel based) emissions."""

def __init__(self, direct_emitter_dto: dto.DirectEmitter):
"""We model a Direct Emitter as a Fuel Consumer, where the emission rate (kg/day) and
def __init__(self, venting_emitter_dto: dto.VentingEmitter):
"""We model a Venting Emitter as a Fuel Consumer, where the emission rate (kg/day) and
the fuel rate (unit-less) are handled as 1 to 1.
This means that we can simulate a direct emission as a normal fuel consumer the same,
but using the simplification mentioned above.
"""
logger.debug(f"Creating DirectEmitter: {direct_emitter_dto.name}")
logger.debug(f"Creating VentingEmitter: {venting_emitter_dto.name}")

self.direct_emitter_dto = direct_emitter_dto
self.venting_emitter_dto = venting_emitter_dto
self.temporal_fuel_model = FuelModel(
{
start_time: FuelType(
name=direct_emitter_dto.name,
# This is the DIRECT-EMITTER CATEGORY which is fed into the fuel modet -> fuel validation error
name=venting_emitter_dto.name,
# This is the VENTING-EMITTER CATEGORY which is fed into the fuel modet -> fuel validation error
# Commented out, meaning the fuel model has CATEGORY set to None
# user_defined_category=direct_emitter_dto.user_defined_category,
# user_defined_category=venting_emitter_dto.user_defined_category,
emissions=[
Emission(
name=direct_emitter_dto.emission_name,
name=venting_emitter_dto.emission_name,
factor=Expression.setup_from_expression(1), # See docstring. # See docstring
)
],
)
for start_time, emitter_model in direct_emitter_dto.emitter_model.items()
for start_time, emitter_model in venting_emitter_dto.emitter_model.items()
}
)

self.temporal_emission_rate_model = TemporalModel(
{
start_time: emitter_model.emission_rate
for start_time, emitter_model in direct_emitter_dto.emitter_model.items()
for start_time, emitter_model in venting_emitter_dto.emitter_model.items()
}
)

def evaluate(
self,
variables_map: VariablesMap,
) -> Dict[str, EmissionResult]:
logger.debug(f"Evaluating DirectEmitter: {self.direct_emitter_dto.name}")
logger.debug(f"Evaluating VentingEmitter: {self.venting_emitter_dto.name}")
fuel_rate = self.evaluate_fuel_rate(variables_map=variables_map)
return self.temporal_fuel_model.evaluate_emissions(
variables_map=variables_map,
Expand Down
6 changes: 3 additions & 3 deletions src/libecalc/core/ecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from libecalc.common.units import Unit
from libecalc.common.utils.rates import TimeSeriesInt, TimeSeriesString
from libecalc.core.consumers.consumer_system import ConsumerSystem
from libecalc.core.consumers.direct_emitter import DirectEmitter
from libecalc.core.consumers.factory import create_consumer
from libecalc.core.consumers.generator_set import Genset
from libecalc.core.consumers.legacy_consumer.component import Consumer
from libecalc.core.consumers.venting_emitter import VentingEmitter
from libecalc.core.models.fuel import FuelModel
from libecalc.core.result import ComponentResult, EcalcModelResult
from libecalc.core.result.emission import EmissionResult
Expand Down Expand Up @@ -169,6 +169,6 @@ def evaluate_emissions(
emission_results[consumer_dto.id] = fuel_model.evaluate_emissions(
variables_map=variables_map, fuel_rate=np.asarray(energy_usage.values)
)
elif isinstance(consumer_dto, dto.DirectEmitter):
emission_results[consumer_dto.id] = DirectEmitter(consumer_dto).evaluate(variables_map=variables_map)
elif isinstance(consumer_dto, dto.VentingEmitter):
emission_results[consumer_dto.id] = VentingEmitter(consumer_dto).evaluate(variables_map=variables_map)
return emission_results
14 changes: 7 additions & 7 deletions src/libecalc/core/graph_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:
consumer_result.component_result.energy_usage, regularity=regularity
).to_stream_day(),
)
else: # COMPRESSOR_SYSTEM, PUMP_SYSTEM, GENERIC, TURBINE, DIRECT_EMITTER
else: # COMPRESSOR_SYSTEM, PUMP_SYSTEM, GENERIC, TURBINE, VENTING_EMITTER
obj = parse_obj_as(
libecalc.dto.result.ComponentResult,
{
Expand Down Expand Up @@ -1191,7 +1191,7 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:

for installation in asset.installations:
regularity = regularities[installation.id] # Already evaluated regularities
for direct_emitter in installation.direct_emitters:
for venting_emitter in installation.venting_emitters:
energy_usage = TimeSeriesRate(
timesteps=self.variables_map.time_vector,
values=[0.0] * self.variables_map.length,
Expand All @@ -1200,13 +1200,13 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:
rate_type=RateType.CALENDAR_DAY,
)
sub_components.append(
libecalc.dto.result.DirectEmitterResult(
id=direct_emitter.id,
name=direct_emitter.name,
componentType=direct_emitter.component_type,
libecalc.dto.result.VentingEmitterResult(
id=venting_emitter.id,
name=venting_emitter.name,
componentType=venting_emitter.component_type,
component_level=ComponentLevel.CONSUMER,
parent=installation.id,
emissions=self._parse_emissions(self.emission_results[direct_emitter.id], regularity),
emissions=self._parse_emissions(self.emission_results[venting_emitter.id], regularity),
timesteps=self.variables_map.time_vector,
is_valid=TimeSeriesBoolean(
timesteps=self.variables_map.time_vector,
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/dto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from libecalc.dto.components import (
Asset,
BaseConsumer,
DirectEmitter,
ElectricityConsumer,
EmitterModel,
FuelConsumer,
GeneratorSet,
Installation,
VentingEmitter,
)
from libecalc.dto.emission import Emission
from libecalc.dto.models import (
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/dto/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ComponentType(str, Enum):
PUMP_V2 = "PUMP@v2"
GENERIC = "GENERIC"
# TURBINE = "TURBINE"
DIRECT_EMITTER = "DIRECT_EMITTER"
VENTING_EMITTER = "VENTING_EMITTER"
TRAIN_V2 = "TRAIN@V2"

def __lt__(self, other: "ComponentType"): # type: ignore[override]
Expand Down
14 changes: 7 additions & 7 deletions src/libecalc/dto/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class EmitterModel(EcalcBaseModel):
_default_emission_rate = validator("emission_rate", allow_reuse=True, pre=True)(convert_expression)


class DirectEmitter(BaseEquipment):
component_type = ComponentType.DIRECT_EMITTER
class VentingEmitter(BaseEquipment):
component_type = ComponentType.VENTING_EMITTER
emission_name: EmissionNameStr
emitter_model: Dict[datetime, EmitterModel]

Expand Down Expand Up @@ -335,7 +335,7 @@ class Installation(BaseComponent):
user_defined_category: Optional[InstallationUserDefinedCategoryType] = None
hydrocarbon_export: Dict[datetime, Expression]
fuel_consumers: List[Union[GeneratorSet, FuelConsumer, ConsumerSystem]] = Field(default_factory=list)
direct_emitters: List[DirectEmitter] = Field(default_factory=list)
venting_emitters: List[VentingEmitter] = Field(default_factory=list)

@property
def id(self) -> str:
Expand Down Expand Up @@ -365,7 +365,7 @@ def check_user_defined_category(cls, user_defined_category, values):
def get_graph(self) -> ComponentGraph:
graph = ComponentGraph()
graph.add_node(self)
for component in [*self.fuel_consumers, *self.direct_emitters]:
for component in [*self.fuel_consumers, *self.venting_emitters]:
if hasattr(component, "get_graph"):
graph.add_subgraph(component.get_graph())
else:
Expand Down Expand Up @@ -399,7 +399,7 @@ def get_component_ids_for_installation_id(self, installation_id: str) -> List[st
for electricity_consumer in fuel_consumer.consumers:
component_ids.append(electricity_consumer.id)

for emitter in installation.direct_emitters:
for emitter in installation.venting_emitters:
component_ids.append(emitter.id)
return component_ids

Expand All @@ -415,9 +415,9 @@ def validate_unique_names(cls, values):
for installation in values["installations"]:
names.append(installation.name)
fuel_consumers = installation.fuel_consumers
direct_emitters = installation.direct_emitters
venting_emitters = installation.venting_emitters

names.extend([direct_emitter.name for direct_emitter in direct_emitters])
names.extend([venting_emitter.name for venting_emitter in venting_emitters])
for fuel_consumer in fuel_consumers:
names.append(fuel_consumer.name)
if isinstance(fuel_consumer, GeneratorSet):
Expand Down
2 changes: 1 addition & 1 deletion src/libecalc/dto/result/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
CompressorResult,
ConsumerModelResult,
ConsumerSystemResult,
DirectEmitterResult,
EcalcModelResult,
GeneratorSetResult,
GenericConsumerResult,
GenericModelResult,
InstallationResult,
PumpModelResult,
PumpResult,
VentingEmitterResult,
)
6 changes: 3 additions & 3 deletions src/libecalc/dto/result/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ class CompressorResult(EquipmentResultBase):
streams: List[TimeSeriesStreamConditions] = None # Optional because only in v2


class DirectEmitterResult(EquipmentResultBase):
componentType: Literal[ComponentType.DIRECT_EMITTER]
class VentingEmitterResult(EquipmentResultBase):
componentType: Literal[ComponentType.VENTING_EMITTER]


class ConsumerModelResultBase(NodeInfo, CommonResultBase):
Expand Down Expand Up @@ -242,7 +242,7 @@ class GenericModelResult(ConsumerModelResultBase):
CompressorResult,
PumpResult,
GenericConsumerResult,
DirectEmitterResult,
VentingEmitterResult,
],
Field(discriminator="componentType"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
genset_sampled,
late_start_consumer,
late_start_consumer_evolving_type,
methane_direct,
methane_venting,
pump_system_el_consumer,
salt_water_injection_tabular,
simplified_compressor_system,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,10 +971,10 @@ def variable_speed_compressor_train_multiple_input_streams_and_interstage_pressu


@pytest.fixture
def methane_direct(regularity) -> dto.DirectEmitter:
return dto.DirectEmitter(
name="methane_direct",
component_type=ComponentType.DIRECT_EMITTER,
def methane_venting(regularity) -> dto.VentingEmitter:
return dto.VentingEmitter(
name="methane_venting",
component_type=ComponentType.VENTING_EMITTER,
user_defined_category={datetime(1900, 1, 1): ConsumerUserDefinedCategoryType.COLD_VENTING_FUGITIVE},
emission_name="CH4",
emitter_model={
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def all_energy_usage_models_dto(
compressor_system,
turbine_driven_compressor_train,
compressor_system_variable_speed_compressor_trains,
methane_direct,
methane_venting,
flare,
all_energy_usage_models_variables,
) -> DTOCase:
Expand Down Expand Up @@ -1103,8 +1103,8 @@ def all_energy_usage_models_dto(
turbine_driven_compressor_train,
compressor_system_variable_speed_compressor_trains,
],
direct_emitters=[
methane_direct,
venting_emitters=[
methane_venting,
],
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ INSTALLATIONS:
- SIM1;GAS_PROD {/} 2
SUCTION_PRESSURE: 50
DISCHARGE_PRESSURE: 250
DIRECT_EMITTERS:
- NAME: methane_direct
VENTING_EMITTERS:
- NAME: methane_venting
EMISSION_NAME: CH4
CATEGORY: COLD-VENTING-FUGITIVE
EMITTER_MODEL:
Expand Down
Loading

0 comments on commit 8d03822

Please sign in to comment.