uesgraphs.systemmodels_pp.utilities
This module collects the functions for creating a pandapipes model from a UESGraph and simulating it.
Functions
|
Reads CSV-pandapipes results (Junctions & Pipes) and saves them as Pandas Series in UESGraph. |
|
Assigns energy demand data to buildings in a UES (Urban Energy Systems) graph. |
|
Generic model generation for setup defined through the parameters |
|
Generate pandapipes simulation model using Excel-based parameter system. |
|
Load component parameters from an Excel file. |
|
|
|
Load simulation settings from Excel 'Simulation' sheet. |
|
Save simulation setup parameters to a CSV file. |
|
Set up a full file+console logger for major functions. |
|
Set up a file-based logger with timestamp and detailed formatting. |
|
Convert an Urban Energy System Graph (UESGraph) to pandapipes model and simulate it. |
|
Validate if the provided file and directory paths exist. |
- uesgraphs.systemmodels_pp.utilities.set_up_file_logger(name: str, log_dir: str | None = None, level: int = 40) Logger[source]
Set up a full file+console logger for major functions.
- Parameters:
name – Logger name
log_dir – Directory for log files (default: temp directory)
level – Logging level (default: ERROR)
- Returns:
Configured file+console logger
- uesgraphs.systemmodels_pp.utilities.set_up_logger(name, log_dir=None, level=20)[source]
Set up a file-based logger with timestamp and detailed formatting.
- Parameters:
- Returns:
Configured logger instance writing to timestamped file
- Return type:
- uesgraphs.systemmodels_pp.utilities.assign_csv_data_to_uesgraph(uesgraph_input, base_folder, mappings, supply_type=None, logger=None)[source]
Reads CSV-pandapipes results (Junctions & Pipes) and saves them as Pandas Series in UESGraph.
base_folder must have these folders: - res_junction/ - res_pipe/
Files and the names in the graph: res_junction/p_bar.csv → pressure res_junction/t_k.csv → temperature res_pipe/mdot_from_kg_per_s.csv → mflow res_pipe/v_mean_m_per_s.csv → velocity
- Parameters:
uesgraph_input (uesgraphs.uesgraph.UESGraph object) – UESGraph to assign the data to
base_folder (str) – Folder where the CSV results are stored
logger (logging.Logger, optional) – Logger instance for debugging
- Returns:
UESGraph with assigned data
- Return type:
uesgraphs.uesgraph.UESGraph object
- uesgraphs.systemmodels_pp.utilities.create_model(name, save_at, graph, start_time, stop_time, timestep, mode, t_ground_prescribed=None, logger=None)[source]
Generic model generation for setup defined through the parameters
- Parameters:
name (str) – Name of the model (First character will be capitalized, cannot start with digit)
save_at (str) – Directory where to store the generated model results
graph (uesgraphs.uesgraph.UESGraph) – Network graph with all necessary data for model generation
start_time (int) – Start time of the simulation in seconds
stop_time (int) – Stop time of the simulation in seconds
timestep (int) – Timestep of the simulation in seconds
t_ground_prescribed (list) – List of ground temperatures for every time step
logger (logging.Logger, optional) – Logger instance for debugging
- Returns:
new_model (spp.SystemModelHeating) – Generated system model
graph (uesgraphs.uesgraph.UESGraph) – Graph of the network with assigned simulation results
- uesgraphs.systemmodels_pp.utilities.uesgraph_to_pandapipes(uesgraph, simplification_level, workspace, sim_setup_path, input_heating, input_dhw, input_cooling, ground_temp_path, logger=None, log_level=10)[source]
Convert an Urban Energy System Graph (UESGraph) to pandapipes model and simulate it.
This function processes a UESGraph, applies simplification, adds demand data, and generates the pandapipes results based on simulation parameters.
Parameters:
- uesgraphUESGraph object or str
The UESGraph object or path to a JSON file containing the UESGraph data
- simplification_levelint
Level of simplification to apply to the UESGraph (higher = more simplified)
- workspacestr or Path
Directory path where output files will be saved
- sim_setup_pathstr or Path
Path to the simulation setup configuration file
- input_heatingstr or Path
Path to heating demand data
- input_dhwstr or Path
Path to domestic hot water demand data
- input_coolingstr or Path
Path to cooling demand data
- ground_temp_pathstr or Path
Path to ground temperature data file
- loggerlogging.Logger, optional
Logger instance. If None, creates a new file logger in temp directory
- log_levelint, optional
Logging level (default is logging.DEBUG). Only used if logger is None
Returns:
—
Raises:
FileNotFoundError: If required files are missing ValueError: If uesgraph parameter is invalid Exception: For various processing errors with detailed messages
- uesgraphs.systemmodels_pp.utilities.load_simulation_settings_from_excel(excel_path, logger=None)[source]
Load simulation settings from Excel ‘Simulation’ sheet.
- Parameters:
excel_path (str or Path) – Path to Excel file containing simulation settings
logger (logging.Logger, optional) – Logger instance
- Returns:
sim_params – Dictionary of simulation parameters
- Return type:
- Raises:
ValueError – If required simulation parameters are missing
- uesgraphs.systemmodels_pp.utilities.load_component_parameters(excel_path, component_type)[source]
Load component parameters from an Excel file.
Reads a specific sheet from an Excel file and returns parameters as a dictionary. Expected Excel structure: - Column A: Parameter (parameter names) - Column B: Value (parameter values)
- Parameters:
- Returns:
Dictionary with parameter names as keys and their values Returns empty dict if sheet not found
- Return type:
- Raises:
FileNotFoundError – If the Excel file does not exist
ValueError – If the component_type is not valid or Excel structure is incorrect
Examples
>>> params = load_component_parameters('parameters.xlsx', 'pipes') >>> print(params['dp_nominal']) 0.10
- uesgraphs.systemmodels_pp.utilities.generate_simulation_model(uesgraph, sim_name, sim_params, ground_temp_list, sim_model_dir, logger=None)[source]
Generate pandapipes simulation model using Excel-based parameter system.
This function assumes parameters are already assigned to uesgraph nodes/edges via the assign_*_parameters functions.
- Parameters:
uesgraph (UESGraph) – Graph with pre-assigned parameters from Excel
sim_name (str) – Name of the simulation
sim_params (dict) – Simulation parameters from Excel ‘Simulation’ sheet
ground_temp_list (list) – Ground temperature data
sim_model_dir (str) – Directory to save pandapipes files
logger (logging.Logger, optional) – Logger instance
- uesgraphs.systemmodels_pp.utilities.assign_demand_data(uesgraph, input_paths_dict, input_types=['heating', 'cooling', 'dhw'])[source]
Assigns energy demand data to buildings in a UES (Urban Energy Systems) graph.
This function reads demand profiles from CSV files and assigns them to building nodes in the graph. For buildings without specific demand data, it uses a fallback profile (dummy demand) based on the first building in the respective CSV file. The function can handle heating, cooling, and domestic hot water (DHW) demands.
- Parameters:
uesgraph (ueesgraphs Graph) – The urban energy system graph containing building nodes.
input_paths_dict (dict) – Dictionary containing file paths for each demand type. Expected keys: ‘heating’, ‘cooling’, ‘dhw’.
input_types (list, optional) – List of demand types to process. Default is [“heating”, “cooling”, “dhw”].
- Returns:
Updated UES graph with demand data assigned to building nodes
Message string containing information about the data assignment process
- Return type:
Notes
- Building nodes are updated with the following attributes:
input_heat: List of heating demand values
input_cool: List of cooling demand values
input_dhw: List of DHW demand values
max_demand_heating: Maximum combined heating/DHW demand
- The function handles missing data by:
Using a dummy profile if a building is not found in demand data
Tracking which buildings exist in CSVs but not in the graph
- uesgraphs.systemmodels_pp.utilities.validate_paths(paths)[source]
Validate if the provided file and directory paths exist.
Parameters:
- pathslist
List of paths (strings or Path objects) to validate
Returns:
- tuple
(existing_paths, missing_paths): Two lists containing the paths that exist and the paths that are missing, respectively
- uesgraphs.systemmodels_pp.utilities.save_setup_params_to_csv(setup_params, sim_name, sim_model_dir)[source]
Save simulation setup parameters to a CSV file.
This function takes a single row from the simulation setup Excel file (as a dictionary) and saves it as a CSV file in a specified directory, with parameters as rows and their values as a single column.
Parameters:
- setup_paramsdict
Dictionary containing simulation setup parameters (a single row from the Excel setup)
- sim_namestr
Name of the current simulation, used for filename generation
- sim_model_dirstr
Directory where to save the CSV file
Returns:
- str
Path to the saved CSV file