Postprocessing Package
postprocessing.chart_singleday module
Charts for a single day.
- class postprocessing.chart_singleday.ChartSingleDay(output: Any, component_name: str, units: Any, directory_path: str, time_correction_factor: float, output_description: str, data: Any, day: Any = 0, month: Any = 0, output2: Any | None = None, figure_format: Any | None = None, path_checker=None)
Bases:
Chart,ChartFontsAndSizeFor making visualisations for a single day.
- static build_day_slice(data: Series, month: int, day: int, time_correction_factor: float, label_months_lowercase: List[str], title: str) Tuple[Series, str]
Compute the slice of
datafor a single day and the matching plot title.This is the pure, side-effect-free core of
get_day_data(). It does neither touchselfnor the filesystem, so it can be unit-tested with a plainpandas.Seriesand noChartconstruction (whose parentChart.__init__would otherwise wire up directory paths and theresult_path_providersingleton).- Args:
data: The full time-series to slice. month: Zero-based month index (0 = January, … 11 = December). day: Zero-based day-of-month index within that month (0 = 1st). time_correction_factor:
seconds_per_timestep / 3600; its reciprocalgives the number of timesteps per hour.
label_months_lowercase: The month labels indexed by
month. title: The base plot title the date string is appended to.- Returns:
A
(data_slice, plot_title)tuple, wheredata_sliceis the sub-series covering the requested day (or the originaldatawhen the computed slice would exceed the available data) andplot_titleis the assembled title string"{title} {month} {day}{ordinal}".
- close()
Closes a chart and saves.
- get_day_data()
Extracts data for a single day.
- plot(close: Any) ReportImageEntry
Plots a chart.
postprocessing.chartbase module
Contains the base class for the charts.
- class postprocessing.chartbase.Chart(output, component_name, output_description, chart_type, units, directory_path, time_correction_factor, output2=None, figure_format=None, path_checker=None)
Bases:
objectParent class for plots to be exported.
- ensure_output_dir() None
Create the per-component output directory if it does not exist yet.
This used to be done unconditionally in
__init__, which made everyChart(and subclass) construction touch the filesystem and depend on the globalresult_path_provider. It is now invoked lazily by theplotmethods, right before they write intoself.filepath2, so that constructing a chart is free of side effects and easy to test.
- label_months_lowercase = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
- months_abbrev_uppercase = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
- rescale_y_axis(y_values: Any, units: Any) Tuple[Any, Any]
Rescale y_values of plots.
postprocessing.charts module
Contains all the chart classes.
- class postprocessing.charts.BarChart(output: Any, component_name: str, units: Any, directory_path: str, time_correction_factor: float, output_description: str, figure_format: FigureFormat, path_checker=None)
Bases:
Chart,ChartFontsAndSizeMakes Bar charts.
- original_pv_sol = [385.66, 484.01, 981.05, 1096.7, 1157, 1299.9, 1415.3, 1266.1, 1075.8, 714.44, 422.51, 366.83]
Reference monthly PV production values (in kWh) used as a baseline for comparison.
- plot(data: Any) ReportImageEntry
Plots the bar chart.
- class postprocessing.charts.Carpet(output: Any, component_name: str, units: Any, directory_path: str, time_correction_factor: float, output_description: str, figure_format: FigureFormat, path_checker=None)
Bases:
Chart,ChartFontsAndSizeClass for carpet plots.
- plot(xdims: int, data: Any) ReportImageEntry | None
Makes a carpet plot.
- Returns:
ReportImageEntry or None – None when data cannot be reshaped into entire days.
- class postprocessing.charts.Line(output: Any, component_name: str, units: Any, directory_path: str, time_correction_factor: float, output_description: str, figure_format: FigureFormat, path_checker=None)
Bases:
Chart,ChartFontsAndSizeMakes a line chart.
- plot(data: Any) ReportImageEntry
Makes a line plot.
postprocessing.compute_kpis module
postprocessing.generate_csv_for_housing_database module
postprocessing.postprocessing_datatransfer module
Data Transfer Object to get all the result data to the post processing.
- class postprocessing.postprocessing_datatransfer.PostProcessingDataTransfer(results: DataFrame, all_outputs: List[ComponentOutput], simulation_parameters: SimulationParameters, wrapped_components: List[ComponentWrapper], mode: int, setup_function: str, module_filename: str, my_module_config: str | None, execution_time: float, results_monthly: DataFrame | None, results_hourly: DataFrame | None, results_cumulative: DataFrame | None, results_daily: DataFrame | None, kpi_collection_dict: Dict | None = None)
Bases:
objectData class for transferring the result data to this class.
postprocessing.postprocessing_main module
Main postprocessing module that starts all other modules.
- class postprocessing.postprocessing_main.PostProcessor
Bases:
objectCore Post processor class.
- compute_and_write_capex_costs_to_report(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator | None, building_objects_in_district_list: list) None
Computes CAPEX costs and CO2-emissions for production of devices and writes them to report and csv.
- compute_and_write_opex_costs_to_report(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator | None, building_objects_in_district_list: list) None
Computes OPEX costs and operational CO2-emissions and writes them to report and csv.
- compute_kpis_and_write_to_report_and_to_ppdt(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator | None, building_objects_in_district_list: list) PostProcessingDataTransfer
Computes KPI’s and writes them to report and to ppdt kpi collection.
- export_results_to_csv(ppdt: PostProcessingDataTransfer) None
Exports the results to a CSV file.
- export_results_to_pickle(ppdt: PostProcessingDataTransfer) None
Exports the results to a Pickle file.
- export_sankeys()
Exports Sankeys plots.
ToDo: implement
- get_building_object_in_district(ppdt: PostProcessingDataTransfer) list[str]
Get building names in district.
- get_dict_from_opex_capex_lists(value_list: List[str]) Dict[str, Any]
Get dict with values for webtool from opex capex lists.
- get_variable_name_and_unit_from_ppdt_results_column(column: str) Tuple[str, str]
Get variable name and unit for pyam dictionary.
- iterate_over_results_and_add_values_to_dict(results_df: DataFrame, timeseries: Any) DataFrame
Iterate over results and add values to dict, write to dataframe and save as csv.
- make_carpet_plots(ppdt: PostProcessingDataTransfer, report_image_entries: List[ReportImageEntry]) None
Make carpet plots.
- make_csv_export(ppdt: PostProcessingDataTransfer) None
Exports all data to CSV.
- make_line_plots(ppdt: PostProcessingDataTransfer, report_image_entries: List[ReportImageEntry]) None
Makes the line plots.
- make_monthly_bar_charts(ppdt: PostProcessingDataTransfer, report_image_entries: List[ReportImageEntry]) None
Make bar charts.
- make_network_charts(ppdt: PostProcessingDataTransfer) List[SystemChartEntry]
Generates the network charts that show the connection of the elements.
- make_pkl_export(ppdt: PostProcessingDataTransfer) None
Exports all data to Pickle.
- make_single_day_plots(days: Dict[str, int], ppdt: PostProcessingDataTransfer, report_image_entries: List[ReportImageEntry]) None
Makes plots for selected days.
- make_special_one_day_debugging_plots(ppdt: PostProcessingDataTransfer, report_image_entries: List[ReportImageEntry]) None
Makes special plots for debugging if only a single day was calculated.
- open_dir_in_file_explorer(ppdt: PostProcessingDataTransfer) None
Opens files in given path.
The keyword darwin is used for supporting macOS, xdg-open will be available on any unix client running X.
- prepare_results_for_scenario_evaluation(ppdt: PostProcessingDataTransfer, my_sim: Simulator) None
Prepare the results for the scenario evaluation.
- run(ppdt: PostProcessingDataTransfer, my_sim: Simulator) None
Runs the main post processing.
- set_dir_results(dirname: str | None = None) None
Sets the results directory.
- shorten_path(path, max_length=250)
Shorten path if its longer than 250.
- write_all_outputs_to_report(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator) None
Write all outputs to report.
- write_component_configurations_to_json(ppdt: PostProcessingDataTransfer, my_sim: Simulator) None
Collect all component configurations and write into JSON file in result directory.
- write_components_to_report(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator, report_image_entries: List[ReportImageEntry]) None
Writes information about the components used in the simulation to the simulation report.
- write_config_data_for_scenario_evaluation(ppdt: PostProcessingDataTransfer, my_sim: Simulator) None
Prepare the results for the scenario evaluation.
- write_filename_and_save_to_csv(dataframe: DataFrame, folder: str, time_resolution_of_data: str, simulation_duration: int) None
Write file to csv.
- write_kpis_in_dict(ppdt: PostProcessingDataTransfer, simple_dict_cumulative_data: Dict[str, Any]) Dict
Write kpis in dictionary.
- write_kpis_to_json_file(ppdt: PostProcessingDataTransfer) None
Write all KPIs o json file.
- write_kpis_to_json_for_building_sizer(ppdt: PostProcessingDataTransfer, building_objects_in_district_list: list) None
Write KPIs to json file for building sizer.
- write_network_charts_to_report(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator, system_chart_entries: List[SystemChartEntry]) None
Write network charts to report.
- write_new_chapter_with_table_to_report(report: reportgenerator.ReportGenerator, table_as_list_of_list: List, headline: str, comment: List) None
Write new chapter with headline and a table to report.
- write_new_chapter_with_text_content_to_report(report: reportgenerator.ReportGenerator, lines: List, headline: str) None
Write new chapter with headline and some general information e.g. KPIs to report.
- write_operation_data_for_webtool(ppdt: PostProcessingDataTransfer) None
Collect daily operation results and write into json for webtool.
- write_results_for_webtool_to_json_file(ppdt: PostProcessingDataTransfer, building_objects_in_district_list: list) None
Collect results and write into json for webtool.
- write_simulation_parameters_to_report(ppdt: PostProcessingDataTransfer, report: reportgenerator.ReportGenerator) None
Write simulation parameters to report.
postprocessing.reportgenerator module
Module for generating reports.
- class postprocessing.reportgenerator.MyDocTemplate(filename, **kw)
Bases:
BaseDocTemplateMyDocTemplate class.
- afterFlowable(flowable)
Registers TOC entries.
- class postprocessing.reportgenerator.ReportGenerator(dirpath: str)
Bases:
objectClass for generating reports.
- add_page_number(canvas, doc)
Add page number to report.
- add_spacer()
Add spacer.
- close()
Close the report.
- copy_story()
Replace the story with a deep copy of itself.
- get_story(**kwargs)
Core function.
- open()
Open a file.
- page_break()
Make a page break.
- write_figures_to_report(file_path: str) None
Add figure to the report.
- write_figures_to_report_with_size_four_six(file_path: str) None
Add figure to the report with certain size.
- write_figures_to_report_with_size_seven_four(file_path: str) None
Add figure to the report with certain size.
- write_heading_with_style_heading_one(text: List[str]) None
Write text as heading.
- write_heading_with_style_heading_two(text: List[str]) None
Write text as heading.
- write_preamble()
Write the preamble.
- write_table_of_content(**kwargs)
Core function.
- write_table_of_contents()
Write the table of contents.
- write_tables_to_report(table_as_list_of_lists: List) None
Add table to the report.
- write_with_center_alignment(text: List[str]) None
Write a paragraph.
- write_with_normal_alignment(text: List[str] | List[str | None]) None
Write a paragraph.
postprocessing.system_chart module
Module for visualizing the entire system as a flow chart.
- class postprocessing.system_chart.SystemChart(ppdt: PostProcessingDataTransfer)
Bases:
objectClass for generating charts that show all the components.
- make_chart() List[SystemChartEntry]
Generate four variants of the system flow chart and return their entries.
Produces four Graphviz-rendered PNG charts of the simulated system: without edge labels (with and without class names), with edge labels, and with edge labels plus cumulative result values. Each successfully generated chart is appended to the returned list; failed charts are skipped.
- Returns:
A list of
SystemChartEntryobjects, one per successfully generated chart variant.
- make_graphviz_chart(with_labels: bool, with_class_names: bool, filename: str, caption: str, with_results: bool = False) SystemChartEntry | None
Render a single system flow chart to a PNG file using Graphviz.
Builds a directed graph (via
_build_graph()) where each wrapped component is a node and each input connection is an edge, optionally annotating edges with labels and cumulative result values, then writes the rendered PNG to the simulation result directory.- Args:
- with_labels: If True, edges are annotated with input/field/unit
(and optionally result) text.
- with_class_names: If True, appends the component’s Python class
name to each node label.
- filename: Base filename (including extension) for the output PNG,
written under the simulation result directory.
caption: Human-readable caption stored in the returned entry. with_results: If True, appends the cumulative result value to each
edge label (requires
with_labelsfor visible effect).- Returns:
A
SystemChartEntryfor the generated chart, orNoneif chart generation failed (e.g., Graphviz is not installed on the system). Failures are logged and swallowed rather than raised.