Skip to content

Feature: provide method to integrate time series values. #136

@ahobeost

Description

@ahobeost

TRNSYS provides printegrators to integrate values over specific periods.
If specific values are missed, the entire simulation needs to be run again, while printing this value.
If a value is available at a lower level, this integration can be done in post-processing.

The following is some suggested code that would do this:

def integrate_values(df: _pd.DataFrame, column: str, new_index: _pd.DatetimeIndex,
                     to_type: _tp.Literal["hourly", "daily", "weekly", "monthly"],
                     time_step_in_minutes: int | None = None
                     ):
    if to_type == "hourly":
        index = df.index.hour
    elif to_type == "daily":
        index = df.index.date
    elif to_type == "weekly":
        index = df.index.week
    elif to_type == "monthly":
        index = df.index.month

    df_integrated = df.groupby(index)[column].sum()
    df_integrated.index = new_index
    if time_step_in_minutes is not None:
        conversion_factor = 60./time_step_in_minutes
        df_integrated /= conversion_factor

    return df_integrated

sim.step["el_from_grid_trnsys"] = sim.step["ElecPelGrid_kW"].clip(lower=0)
sim.monthly["el_from_grid_trnsys"] = integrate_values(sim.step, "el_from_grid_trnsys",
                                                          new_index=sim.monthly.index, to_type="monthly",
                                                          time_step_in_minutes=2)

sim.step["el_grid_feed_in_trnsys"] = abs(sim.step["ElecPelGrid_kW"].clip(upper=0))
sim.monthly["el_grid_feed_in_trnsys"] = integrate_values(sim.step, "el_grid_feed_in_trnsys",
                                                             new_index=sim.monthly.index, to_type="monthly",
                                                             time_step_in_minutes=2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions