8.1.8.1. pelicun.tools.DL_calculation

Main functionality to run a pelicun calculation from the command line.

Functions

convert_df_to_dict(data[, axis])

Convert a pandas DataFrame to a dictionary.

log_msg(msg[, color_codes])

Print a formatted log message with a timestamp.

main()

Parse arguments and run the pelicun calculation.

run_pelicun(config_path, demand_file, ...)

Use settings in the config JSON to prepare and run a Pelicun calculation.

pelicun.tools.DL_calculation.convert_df_to_dict(data: DataFrame | Series, axis: int = 1) dict[source]

Convert a pandas DataFrame to a dictionary.

Parameters:
datapd.DataFrame

The DataFrame to be converted.

axisint, optional

The axis to consider for the conversion. * If 1 (default), the DataFrame is used as-is. * If 0, the DataFrame is transposed before conversion.

Returns:
dict

A dictionary representation of the DataFrame. The structure of the dictionary depends on the levels in the DataFrame’s MultiIndex columns.

Raises:
ValueError

If the axis is not 0 or 1.

Notes

  • If the columns have multiple levels, the function will recursively convert sub-DataFrames.

  • If the column labels at any level are numeric, they will be converted to a list of floats.

  • If the column labels are non-numeric, a dictionary will be created with the index labels as keys and the corresponding data as values.

pelicun.tools.DL_calculation.log_msg(msg: str, color_codes: tuple[str, str] | None = None) None[source]

Print a formatted log message with a timestamp.

Parameters:
msgstr

The message to print.

color_codestuple, optional

Color codes for formatting the message. Default is None.

pelicun.tools.DL_calculation.main() None[source]

Parse arguments and run the pelicun calculation.

pelicun.tools.DL_calculation.run_pelicun(config_path: str, demand_file: str, output_path: str | None, realizations: int, auto_script_path: str | None, custom_model_dir: str | None, output_format: list | None, *, detailed_results: bool, coupled_edp: bool) None[source]

Use settings in the config JSON to prepare and run a Pelicun calculation.

Parameters:
config_path: string

Path pointing to the location of the JSON configuration file.

demand_file: string

Path pointing to the location of a CSV file with the demand data.

output_path: string, optional

Path pointing to the location where results shall be saved.

realizations: int, optional

Number of realizations to generate.

auto_script_path: string, optional

Path pointing to the location of a Python script with an auto_populate method that automatically creates the performance model using data provided in the AIM JSON file.

custom_model_dir: string, optional

Path pointing to a directory with files that define user-provided model parameters for a customized damage and loss assessment.

output_format: list, optional.

Type of output format, JSON or CSV. Valid options: [‘csv’, ‘json’], [‘csv’], [‘json’], [], None

detailed_results: bool, optional

If False, only the main statistics are saved.

coupled_edp: bool, optional

If True, EDPs are not resampled and processed in order.