Skip to content

Commit

Permalink
chore: add method to convert to time series
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehk committed Sep 19, 2023
1 parent e8b321f commit 6ac0320
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/libecalc/core/graph_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from libecalc.dto.graph import Graph
from libecalc.dto.models.consumer_system import CompressorSystemConsumerFunction
from libecalc.dto.result.emission import EmissionIntensityResult
from libecalc.dto.result.results import CompressorModelResult
from libecalc.dto.types import RateType
from libecalc.dto.utils.aggregators import aggregate_emissions, aggregate_is_valid
from libecalc.expression import Expression
Expand Down Expand Up @@ -304,64 +305,71 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:

# Convert rates in stage results from lists to time series:
for stage_result in model.stage_results:
stage_result.asv_recirculation_loss_mw = TimeSeriesRate(
timesteps=self.timesteps,
values=stage_result.asv_recirculation_loss_mw
if stage_result.asv_recirculation_loss_mw is not None
else [math.nan] * len(model.timesteps),
# stage_result.asv_recirculation_loss_mw = TimeSeriesRate(
# timesteps=model.timesteps,
# values=stage_result.asv_recirculation_loss_mw
# if stage_result.asv_recirculation_loss_mw is not None
# else [math.nan] * len(model.timesteps),
# unit=Unit.MEGA_WATT,
# rate_type=RateType.STREAM_DAY,
# )

stage_result.asv_recirculation_loss_mw = CompressorModelResult.to_time_series(
self=model,
stage_result=stage_result.asv_recirculation_loss_mw,
unit=Unit.MEGA_WATT,
rate_type=RateType.STREAM_DAY,
)

stage_result.energy_usage = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.energy_usage
if stage_result.energy_usage is not None
else [math.nan] * len(model.timesteps),
unit=stage_result.energy_usage_unit,
rate_type=RateType.STREAM_DAY,
)
stage_result.mass_rate_kg_per_hr = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.mass_rate_kg_per_hr
if stage_result.mass_rate_kg_per_hr is not None
else [math.nan] * len(model.timesteps),
unit=Unit.KILO_PER_HOUR,
rate_type=RateType.STREAM_DAY,
)
stage_result.mass_rate_before_asv_kg_per_hr = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.mass_rate_before_asv_kg_per_hr
if stage_result.mass_rate_before_asv_kg_per_hr is not None
else [math.nan] * len(model.timesteps),
unit=Unit.KILO_PER_HOUR,
rate_type=RateType.STREAM_DAY,
)
stage_result.power = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.power
if stage_result.power is not None
else [math.nan] * len(model.timesteps),
unit=stage_result.power_unit,
rate_type=RateType.STREAM_DAY,
)
stage_result.inlet_stream_condition.actual_rate_m3_per_hr = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.inlet_stream_condition.actual_rate_m3_per_hr
if stage_result.inlet_stream_condition.actual_rate_m3_per_hr is not None
else [math.nan] * len(model.timesteps),
unit=Unit.ACTUAL_VOLUMETRIC_M3_PER_HOUR,
rate_type=RateType.STREAM_DAY,
)
stage_result.inlet_stream_condition.actual_rate_before_asv_m3_per_hr = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.inlet_stream_condition.actual_rate_before_asv_m3_per_hr
if stage_result.inlet_stream_condition.actual_rate_before_asv_m3_per_hr is not None
else [math.nan] * len(model.timesteps),
unit=Unit.ACTUAL_VOLUMETRIC_M3_PER_HOUR,
rate_type=RateType.STREAM_DAY,
)
stage_result.inlet_stream_condition.density_kg_per_m3 = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.inlet_stream_condition.density_kg_per_m3
if stage_result.inlet_stream_condition.density_kg_per_m3 is not None
else [math.nan] * len(model.timesteps),
Expand All @@ -370,23 +378,23 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:
)

stage_result.outlet_stream_condition.actual_rate_m3_per_hr = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.outlet_stream_condition.actual_rate_m3_per_hr
if stage_result.outlet_stream_condition.actual_rate_m3_per_hr is not None
else [math.nan] * len(model.timesteps),
unit=Unit.ACTUAL_VOLUMETRIC_M3_PER_HOUR,
rate_type=RateType.STREAM_DAY,
)
stage_result.outlet_stream_condition.actual_rate_before_asv_m3_per_hr = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.outlet_stream_condition.actual_rate_before_asv_m3_per_hr
if stage_result.outlet_stream_condition.actual_rate_before_asv_m3_per_hr is not None
else [math.nan] * len(model.timesteps),
unit=Unit.ACTUAL_VOLUMETRIC_M3_PER_HOUR,
rate_type=RateType.STREAM_DAY,
)
stage_result.outlet_stream_condition.density_kg_per_m3 = TimeSeriesRate(
timesteps=self.timesteps,
timesteps=model.timesteps,
values=stage_result.outlet_stream_condition.density_kg_per_m3
if stage_result.outlet_stream_condition.density_kg_per_m3 is not None
else [math.nan] * len(model.timesteps),
Expand Down
10 changes: 10 additions & 0 deletions src/libecalc/dto/result/results.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import math
from operator import attrgetter
from typing import Any, Dict, List, Literal, Optional, Union

Expand All @@ -8,6 +9,7 @@
from libecalc.common.time_utils import Frequency
from libecalc.common.units import Unit
from libecalc.common.utils.rates import (
RateType,
TimeSeriesBoolean,
TimeSeriesFloat,
TimeSeriesInt,
Expand Down Expand Up @@ -151,6 +153,14 @@ class CompressorModelResult(ConsumerModelResultBase):
energy_usage_unit: Unit
power_unit: Unit

def to_time_series(self, stage_result: list, unit: Unit) -> TimeSeriesRate:
return TimeSeriesRate(
timesteps=self.timesteps,
values=stage_result if stage_result is not None else [math.nan] * len(self.timesteps),
unit=unit,
rate_type=RateType.STREAM_DAY,
)


class GenericModelResult(ConsumerModelResultBase):
"""Generic consumer result component."""
Expand Down

0 comments on commit 6ac0320

Please sign in to comment.