analysis package
analysis.Analysis module
analysis.Analysis_modules module
analysis.Distributions_fit module
Fits statistical distributions to survey data on user preferences.
This script reads user preference data from an Excel file, preprocesses it, and fits a beta distribution to several data columns for different user groups. The primary goal is to find the parameters (alpha, beta) of a beta distribution that best describes the empirical data for each preference.
For each user group and preference variable, the script performs the following: 1. Loads and preprocesses the data by handling NaNs, truncating outliers,
and normalising values to the (0, 1) interval.
Fits a beta distribution using SciPy’s beta.fit method.
Generates and saves diagnostic plots (QQ plot and CDF comparison) to visually assess the goodness-of-fit.
Performs a Kolmogorov-Smirnov (K-S) test to statistically quantify the goodness-of-fit.
Exports the fitted distribution parameters and K-S test results to an Excel file for further use and analysis.
The script also contains a commented-out section for fitting a Weibull distribution, which follows a similar process.
- Authors:
Ivan Digel <ivan.digel@uni-kassel.de>
analysis.analyse_by_ahid module
Performs analysis and visualisation of model outputs using methods of AgentHomeID (ahid) by Fraunhofer IEE.
This script acts as a bridge to reuse visualisation capabilities. It loads and transforms the output data from the current model into a format compatible with the ‘ahid’ plotting functions. Using Python’s ‘mock’ library, it intercepts data loading calls within the ‘ahid’ functions, injects the transformed data, and generates the desired plots.
- Authors:
Sascha Holzhauer <sascha.holzhauer@uni-kassel.de>
- read_output_data(run_id=None)[source]
Reads the agent output DataFrame from a pickle file.
- Parameters:
- run_idint, optional
The ID of the simulation run from which to load the data. If None, it uses the default path settings.
- Returns:
- pandas.DataFrame
A DataFrame containing the agent data for the specified run.
- convert_output_data()[source]
Converts and reformats the model’s output data for ‘ahid’ compatibility.
This function fetches the raw agent data and applies several transformations to make it suitable for the ‘building_stock_model’ evaluation functions. Transformations include adding a scale factor, renaming columns to match the expected schema, adding a placeholder ID, and converting simulation steps into calendar years. The result is cached to avoid redundant processing.
- Returns:
- pandas.DataFrame
The transformed and analysis-ready DataFrame.
- ahoi_plot_total_num_heatingsystems(mocked_path, mocked_data)[source]
Generates a plot of the total number of heating systems using an ‘ahid’ function.
This wrapper uses mocking to inject the model’s converted data into the plot_total_num_heatingsystems function from the ‘building_stock_model’. It bypasses that function’s data loading and path discovery mechanisms, allowing it to work directly with the local model’s output.
- Parameters:
- mocked_pathunittest.mock.MagicMock
A mock object that replaces get_output_path in the target module.
- mocked_dataunittest.mock.MagicMock
A mock object that replaces get_data in the target module.
Generates a plot of the market share of heating systems using an ‘ahid’ function.
Similar to ahoi_plot_total_num_heatingsystems, this wrapper uses mocking to inject this model’s data into the plot_share_heatingsystems__sns visualisation function from the ‘building_stock_model’.
- Parameters:
- mocked_pathunittest.mock.MagicMock
A mock object that replaces get_output_path in the target module.
- mocked_dataunittest.mock.MagicMock
A mock object that replaces get_data in the target module.
analysis.analyse_sa_morris module
analysis.analyse_sa_sobol module
analysis.dynaconf_filter module
Provides a custom Dynaconf loader that merges settings without overriding.
This module contains a custom loader function for the Dynaconf settings management library. Unlike the default loaders which override existing keys, this loader implements a “fill-in” logic. It reads settings from specified TOML files and only adds keys (or sub-keys) that are not already present in the settings object. This is particularly useful for loading default values that should not overwrite any user-specified configurations.
- Authors:
Sascha Holzhauer <sascha.holzhauer@uni-kassel.de>
- load(obj, env=None, silent=True, key=None, filename=None)[source]
Loads settings from TOML files without overriding existing values.
This function iterates through a list of filenames defined in the settings variable EVAL.AHID_SETTINGS_FILES. For each file, it parses the content and merges it into the main settings object (obj) under the condition that the keys do not already exist.
The merging logic is as follows: 1. If a top-level key from the file is not in obj, the key and its
entire value are added.
If a top-level key exists, the function checks its sub-keys. Only the sub-keys from the file that are not already in obj[key] are added.
- Parameters:
- objdynaconf.base.LazySettings
The Dynaconf settings instance to be loaded into.
- envstr, optional
The environment to load. This parameter is part of the standard loader signature but is not used by this function. Defaults to None.
- silentbool, optional
If True, exceptions during file loading (e.g., file not found) are suppressed. Defaults to True.
- keystr, optional
Load only this specific key. This parameter is not used by this function. Defaults to None.
- filenamestr, optional
A specific file to be loaded. This parameter is not used; the function relies on the EVAL.AHID_SETTINGS_FILES list in obj. Defaults to None.
analysis.prepare_sa_settings module
analysis.statistical_testing module
Performs a Mann-Whitney U statistical test to compare model outputs.
This script is designed to assess the statistical significance of differences in simulation outputs between two experimental scenarios (e.g., a baseline vs. a policy intervention). It locates and loads pickled model DataFrames based on a naming convention that includes the scenario, run ID, and an experiment prefix.
The script specifically extracts data on installation obstacles encountered by agents for various heating systems. It aggregates this data across multiple simulation seeds for each of the two scenarios being compared. Finally, it performs a non-parametric Mann-Whitney U test on the collected samples for each obstacle and prints the p-values to the console.
- Authors:
Ivan Digel <ivan.digel@uni-kassel.de>
- perform_obstacle_significance_test(scenarios: list, run_ids: list, scenario1_prefix: str, scenario2_prefix: str)[source]
Compares obstacle data between two scenarios using the Mann-Whitney U test.
This function handles the process of finding data, aggregating it, and running statistical tests.
The workflow is as follows: 1. Data Aggregation: It iterates through the specified scenarios and
run IDs, searching for output pickle files matching scenario1_prefix and scenario2_prefix. For each file found (representing one seed), it extracts the ‘Obstacles’ dictionary from the last time step. The obstacle values are collected into two main groups corresponding to the two prefixes.
Statistical Testing: After gathering data from all seeds, it iterates through each heating system and obstacle type. For each obstacle, it compares the sample of values from the first scenario against the sample from the second.
Output: A two-sided Mann-Whitney U test is performed. The resulting p-value is printed to the console, along with an interpretation of whether the difference is significant at the p < 0.05 level.
- Parameters:
- scenarioslist
A list of scenario class name strings to analyse.
- run_idslist
A list of integer run IDs to include in the analysis.
- scenario1_prefixstr
The file prefix for the first group, typically the baseline or control group (e.g., ‘DEZ_Baseline’).
- scenario2_prefixstr
The file prefix for the second group, typically the treatment or campaign group (e.g., ‘DEZ_Beraterkampagne’).