Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: include direct emitter results in ltp export #305

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/changelog/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* remove economy from ecalc ([#282](https://github.com/equinor/ecalc/issues/282))
* graph.components and graph.get_component renamed to nodes and get_node
* add type to consumers in system
* change name from DIRECT_EMITTERS to VENTING_EMITTERS in input Yaml-file ([#303](https://github.com/equinor/ecalc/pull/303))

### Features

Expand Down
21 changes: 21 additions & 0 deletions src/libecalc/presentation/exporter/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,27 @@ def query(
if self.fuel_type_category is None or fuel_category == self.fuel_type_category:
if self.emission_type is None or emission.name == self.emission_type:
aggregated_result[timestep] += emission_volume

# Add emissions from direct emitters, but ensure that emissions are not counted twice.
# Direct emissions have no fuel, and should not count when asking for emissions for a given fuel
if self.fuel_type_category is None:
frodehk marked this conversation as resolved.
Show resolved Hide resolved
for venting_emitter in installation_dto.venting_emitters:
temporal_category = TemporalModel(venting_emitter.user_defined_category)
for period, category in temporal_category.items():
if self.consumer_categories is None or category in self.consumer_categories:
emissions = installation_graph.get_emissions(venting_emitter.id)

for emission in emissions.values():
emission_volumes = (
TimeSeriesRate.from_timeseries_stream_day_rate(emission.rate, regularity=regularity)
.for_period(period)
.to_volumes()
)
unit_in = emission_volumes.unit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are making assumptions on unit here, right? Assuming all emissions have the same unit. So setting unit_in here is to make sure it is set if the above condition (for fuel_consumers) is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emission.rate.unit is set before the query (e.g. t/d), in the to_volumes() it is converted to t. So the assumption is made earlier. The docs states that the emission rate should be in kg/day, and the assumption is done in FuelModel.evaluate_emissions(), where kg/d is converted to t/d - hence, assuming input is kg/d.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, for this to fail the unit for fuel_consumers (emissions) and direct emitter would have to be different, and that is something we control.

It won't be an issue when adding units to venting_emitter either as we will convert into kg (probably). Is that something you are planning to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am adding unit to venting_emitter in another ongoing pr (will convert to kg as well).

for timestep, emission_volume in emission_volumes.datapoints():
if self.emission_type is None or emission.name == self.emission_type:
aggregated_result[timestep] += emission_volume

if aggregated_result:
sorted_result = dict(dict(sorted(zip(aggregated_result.keys(), aggregated_result.values()))).items())
sorted_result = {**dict.fromkeys(installation_time_steps, 0.0), **sorted_result}
Expand Down